2using System.Collections.Generic;
8[JsonObject(MemberSerialization.OptOut)]
19 private static readonly Dictionary<string, SpawnType>
_cachedSpawnTypes =
new Dictionary<string, SpawnType>();
23 public Dictionary<string, int>
mapInt =
new Dictionary<string, int>();
25 public Dictionary<string, string>
mapStr =
new Dictionary<string, string>();
31 public List<string>
stocks =
new List<string>();
33 public List<string>
things =
new List<string>();
41 string trait = r.trait.TryGet(0, returnNull:
true) ??
"Chara";
44 owner = ModUtil.FindSourceRowPackage(r);
54 for (
int i = 0; i < tag.Length; i++)
77 customCharaContent.
things.Add(text2);
82 string text3 = text2.IsEmpty(r.id);
83 if (!ModUtil.HasContent(
"MerchantStock/" + text3))
86 if (customMerchantStock ==
null)
90 ModUtil.AddContent(customMerchantStock);
92 if (!customCharaContent.
stocks.Contains(text3))
94 customCharaContent.
stocks.Add(text3);
95 customCharaContent.
mapStr[
"merchant_override"] =
string.Join(
'|', customCharaContent.
stocks);
100 if (!text2.IsEmpty())
102 customCharaContent.
mapStr[
"drama_override"] = text2;
108 string text4 = text2.IsEmpty(r.id);
109 customCharaContent.
mapStr[
"biography_override"] = text4;
110 if (!ModUtil.HasContent(
"Biography/" + text4))
113 if (customBiographyContent !=
null)
115 ModUtil.AddContent(customBiographyContent);
122 customCharaContent.
mapInt[array[0]] = array.TryGet(1, returnNull:
true)?.ToInt() ?? 1;
126 if (!array.TryGet(1, returnNull:
true).IsEmpty())
128 customCharaContent.
mapStr[array[0]] = array[1];
133 return customCharaContent;
177 if (chara.
GetBool(
"custom_content") || chara.
GetBool(
"cwl_tags_applied") || chara.
id != base.SourceId)
181 chara.
SetBool(
"custom_content", enable:
true);
182 chara.
SetStr(
"custom_content_id", base.ContentId);
183 chara.
SetStr(
"custom_content_package", base.Owner.id);
185 foreach (KeyValuePair<string, string>
item in mapStr)
187 item.Deconstruct(out var key, out key2);
190 chara.SetStr(id2, value);
192 foreach (KeyValuePair<string, int> item2
in mapInt)
194 item2.Deconstruct(out key2, out var value2);
197 chara.SetInt(id3, value3);
201 chara.RemoveThings();
203 foreach (
string[] item3
in equipments.Select((
string t) => t.Split(
'#')))
205 if (!Enum.TryParse<
Rarity>(item3.TryGet(1, returnNull:
true), out var result))
209 if (HasValidContentId(item3[0]))
211 chara.EQ_ID(item3[0], -1, result);
214 foreach (
string[] item4
in things.Select((
string t) => t.Split(
'#')))
216 if (!
int.TryParse(item4.TryGet(1, returnNull:
true), out var result2))
220 if (HasValidContentId(item4[0]))
222 chara.AddThing(item4[0]).SetNum(result2);
225 bool HasValidContentId(
string id)
231 ModUtil.LogModError(
"source chara row '" + base.ContentId +
"' has invalid addEq/addThing spec '" +
id +
"'", base.Owner);
242 Debug.Log(
$"#mod-content loading {this}");
244 List<Zone> list =
new List<Zone>();
247 Zone zone = ModUtil.FindZoneByFullName(spawnZone);
253 ModUtil.LogModError(
"source chara row '" + base.SourceId +
"' has invalid addZone spec '" + spawnZone +
"'", base.Owner);
255 List<Chara> list2 = lookup[base.SourceId].ToList();
256 int count = list2.Count;
257 if (list.Count == 0 && count == 0)
259 ModUtil.LogModError(
"source chara row '" + base.SourceId +
"' has invalid addZone spec", base.Owner);
262 int num = Math.Max(0, list.Count - count);
277 ModUtil.LogModError(
"adventurer '" + base.SourceId +
"' has spawned more than once", base.Owner);
286 Debug.Log(
"#mod-content skipping existing character '" + base.SourceId +
"', " +
$"{count} at {string.Join('/', list2.Select((Chara c) => c.currentZone.ZoneFullName))}");
289 for (
int i = 0; i < num; i++)
292 Chara chara = SpawnToZone(z2);
295 ModUtil.LogModError(
"can't spawn character '" + base.SourceId +
"'", base.Owner);
307 if (chara2.
id ==
"chicken")
313 Debug.Log(
"#mod-content spawned character '" + base.SourceId +
"' to " + z.
ZoneFullName);
320 StringBuilder stringBuilder =
new StringBuilder();
321 stringBuilder.AppendLine(
$"{base.ContentId}/{spawnType}/{base.Owner.id}");
322 stringBuilder.AppendLine(
$" - zones({spawnZones.Count})/{string.Join(';', spawnZones)}");
325 stringBuilder.AppendLine(
$" - things({things.Count})/{string.Join(';', things)}");
329 stringBuilder.AppendLine(
$" - equipments({equipments.Count})/{string.Join(';', equipments)}");
333 stringBuilder.AppendLine(
" - stocks/" +
string.Join(
';',
stocks));
337 stringBuilder.AppendLine(
" - str/" +
string.Join(
';',
mapStr.Select((KeyValuePair<string, string> kv) => kv.Key +
"=" + kv.Value)));
341 stringBuilder.AppendLine(
" - int/" +
string.Join(
';',
mapInt.Select((KeyValuePair<string, int> kv) =>
$"{kv.Key}={kv.Value}")));
343 return stringBuilder.ToString();
GlobalCharaList globalCharas
void SetStr(string id, string value=null)
void SetBool(string id, bool enable)
static Chara Create(string id, int lv=-1)
Chara SetHomeZone(Zone zone)
void MoveZone(string alias)
static CustomBiographyContent CreateFromId(string biographyId, ModPackage owner=null)
Dictionary< string, string > mapStr
Dictionary< string, int > mapInt
static SpawnType GetSpawnTypeFromTrait(string trait)
override void OnGameLoad(GameIOContext context)
List< string > spawnZones
override string ToString()
static CustomCharaContent CreateFromRow(SourceChara.Row r, ModPackage owner=null)
void OnCharaCreated(Chara chara)
override string SourceType
List< string > equipments
static readonly Dictionary< string, SpawnType > _cachedSpawnTypes
static CustomMerchantStock CreateFromId(string stockId, ModPackage owner)
static string string string[] kv GetParams(string tag)
static SourceManager sources
Dictionary< string, CardRow > map