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.
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);
199 if (chara.GetBool(
"cwl_tags_applied"))
205 chara.RemoveThings();
207 foreach (
string[] item3
in equipments.Select((
string t) => t.Split(
'#')))
209 if (!Enum.TryParse<
Rarity>(item3.TryGet(1, returnNull:
true), out var result))
213 if (HasValidContentId(item3[0]))
215 chara.EQ_ID(item3[0], -1, result);
218 foreach (
string[] item4
in things.Select((
string t) => t.Split(
'#')))
220 if (!
int.TryParse(item4.TryGet(1, returnNull:
true), out var result2))
224 if (HasValidContentId(item4[0]))
226 chara.AddThing(item4[0]).SetNum(result2);
229 bool HasValidContentId(
string id)
235 ModUtil.LogModError(
"source chara row '" + base.ContentId +
"' has invalid addEq/addThing spec '" +
id +
"'", base.Owner);
246 Debug.Log(
$"#mod-content loading {this}");
248 List<Zone> list =
new List<Zone>();
251 Zone zone = ModUtil.FindZoneByFullName(spawnZone);
257 ModUtil.LogModError(
"source chara row '" + base.SourceId +
"' has invalid addZone spec '" + spawnZone +
"'", base.Owner);
259 List<Chara> list2 = lookup[base.SourceId].ToList();
260 int count = list2.Count;
261 if (list.Count == 0 && count == 0)
263 ModUtil.LogModError(
"source chara row '" + base.SourceId +
"' has invalid addZone spec", base.Owner);
266 int num = Math.Max(0, list.Count - count);
281 Debug.LogWarning(
"#mod-content adventurer '" + base.SourceId +
"' has spawned more than once");
290 Debug.Log(
"#mod-content skipping existing character '" + base.SourceId +
"', " +
$"{count} at {string.Join(',', list2.Select((Chara c) => c.currentZone?.ZoneFullName))}");
293 for (
int i = 0; i < num; i++)
296 Chara chara = SpawnToZone(z2);
299 ModUtil.LogModError(
"can't spawn character '" + base.SourceId +
"'", base.Owner);
311 if (chara2.
id ==
"chicken")
317 Debug.Log(
"#mod-content spawned character '" + base.SourceId +
"' to " + z.
ZoneFullName);
324 StringBuilder stringBuilder =
new StringBuilder();
325 stringBuilder.AppendLine(
$"{base.ContentId}/{spawnType}/{base.Owner.id}");
326 stringBuilder.AppendLine(
$" - zones({spawnZones.Count})/{string.Join(';', spawnZones)}");
329 stringBuilder.AppendLine(
$" - things({things.Count})/{string.Join(';', things)}");
333 stringBuilder.AppendLine(
$" - equipments({equipments.Count})/{string.Join(';', equipments)}");
337 stringBuilder.AppendLine(
" - stocks/" +
string.Join(
';',
stocks));
341 stringBuilder.AppendLine(
" - str/" +
string.Join(
';',
mapStr.Select((KeyValuePair<string, string> kv) => kv.Key +
"=" + kv.Value)));
345 stringBuilder.AppendLine(
" - int/" +
string.Join(
';',
mapInt.Select((KeyValuePair<string, int> kv) =>
$"{kv.Key}={kv.Value}")));
347 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=null)
static string string string[] kv GetParams(string tag)
static SourceManager sources
Dictionary< string, CardRow > map