Elin Decompiled Documentation EA 23.329 Nightly
Loading...
Searching...
No Matches
CustomCharaContent Class Reference
Inheritance diagram for CustomCharaContent:
CustomSourceContent CustomContent EClass

Public Types

enum  SpawnType { Common , Adventurer , Merchant , Unique }
 

Public Member Functions

void OnCharaCreated (Chara chara)
 
override void OnGameLoad (GameIOContext context)
 
override string ToString ()
 
- Public Member Functions inherited from CustomContent
virtual void OnGameLoad (GameIOContext context)
 
virtual void OnGameSave (GameIOContext context)
 
override string ToString ()
 

Static Public Member Functions

static CustomCharaContent CreateFromRow (SourceChara.Row r, ModPackage owner=null)
 
static SpawnType GetSpawnTypeFromTrait (string trait)
 
- Static Public Member Functions inherited from CustomSourceContent
static string string string[] kv GetParams (string tag)
 
- Static Public Member Functions inherited from EClass
static int rndSeed (int a, int seed)
 
static int rnd (long a)
 
static int rnd (int a)
 
static int curve (long _a, int start, int step, int rate=75)
 
static int sqrt (int a)
 
static int rndHalf (int a)
 
static float rndf (float a)
 
static int rndSqrt (int a)
 
static void Wait (float a, Card c)
 
static void Wait (float a, Point p)
 
static int Bigger (int a, int b)
 
static int Smaller (int a, int b)
 

Public Attributes

List< string > equipments = new List<string>()
 
Dictionary< string, int > mapInt = new Dictionary<string, int>()
 
Dictionary< string, string > mapStr = new Dictionary<string, string>()
 
SpawnType spawnType
 
List< string > spawnZones = new List<string>()
 
List< string > stocks = new List<string>()
 
List< string > things = new List<string>()
 

Properties

override string SourceType [get]
 
bool IsAdventurer [get]
 
- Properties inherited from CustomSourceContent
virtual string SourceType [get]
 
string SourceId [get, set]
 
- Properties inherited from CustomContent
string ContentId [get, protected set]
 
EMod Owner [get, protected set]
 
- Properties inherited from EClass
static Game game [get]
 
static bool AdvMode [get]
 
static Player player [get]
 
static Chara pc [get]
 
static UI ui [get]
 
static Map _map [get]
 
static Zone _zone [get]
 
static FactionBranch Branch [get]
 
static FactionBranch BranchOrHomeBranch [get]
 
static Faction Home [get]
 
static Faction Wilds [get]
 
static Scene scene [get]
 
static BaseGameScreen screen [get]
 
static GameSetting setting [get]
 
static GameData gamedata [get]
 
static ColorProfile Colors [get]
 
static World world [get]
 
static SourceManager sources [get]
 
static SourceManager editorSources [get]
 
static SoundManager Sound [get]
 
static CoreDebug debug [get]
 

Static Private Attributes

static readonly Dictionary< string, SpawnType_cachedSpawnTypes = new Dictionary<string, SpawnType>()
 

Additional Inherited Members

- Static Public Attributes inherited from CustomSourceContent
static string action
 
static string string spec
 
- Static Public Attributes inherited from EClass
static Core core
 

Detailed Description

Definition at line 9 of file CustomCharaContent.cs.

Member Enumeration Documentation

◆ SpawnType

Enumerator
Common 
Adventurer 
Merchant 
Unique 

Definition at line 11 of file CustomCharaContent.cs.

Member Function Documentation

◆ CreateFromRow()

static CustomCharaContent CustomCharaContent.CreateFromRow ( SourceChara::Row  r,
ModPackage  owner = null 
)
inlinestatic

Definition at line 39 of file CustomCharaContent.cs.

40 {
41 string trait = r.trait.TryGet(0, returnNull: true) ?? "Chara";
42 if (owner == null)
43 {
44 owner = ModUtil.FindSourceRowPackage(r);
45 }
46 CustomCharaContent customCharaContent = new CustomCharaContent
47 {
48 ContentId = "Chara/" + r.id,
49 SourceId = r.id,
51 Owner = owner
52 };
53 string[] tag = r.tag;
54 for (int i = 0; i < tag.Length; i++)
55 {
56 var (text, text2, array) = CustomSourceContent.GetParams(tag[i]);
57 switch (text)
58 {
59 case "addZone":
60 case "addAdvZone":
61 if (!text2.IsEmpty())
62 {
63 customCharaContent.spawnZones.Add(text2);
64 }
65 break;
66 case "addEq":
67 case "addAdvEq":
68 case "addEquipment":
69 if (!text2.IsEmpty())
70 {
71 customCharaContent.equipments.Add(text2);
72 }
73 break;
74 case "addThing":
75 if (!text2.IsEmpty())
76 {
77 customCharaContent.things.Add(text2);
78 }
79 break;
80 case "addStock":
81 {
82 string text3 = text2.IsEmpty(r.id);
83 if (!ModUtil.HasContent("MerchantStock/" + text3))
84 {
85 CustomMerchantStock customMerchantStock = CustomMerchantStock.CreateFromId(text3, owner);
86 if (customMerchantStock == null)
87 {
88 break;
89 }
90 ModUtil.AddContent(customMerchantStock);
91 }
92 if (!customCharaContent.stocks.Contains(text3))
93 {
94 customCharaContent.stocks.Add(text3);
95 customCharaContent.mapStr["merchant_override"] = string.Join('|', customCharaContent.stocks);
96 }
97 break;
98 }
99 case "addDrama":
100 if (!text2.IsEmpty())
101 {
102 customCharaContent.mapStr["drama_override"] = text2;
103 }
104 break;
105 case "addBio":
106 case "addBiography":
107 {
108 string text4 = text2.IsEmpty(r.id);
109 customCharaContent.mapStr["biography_override"] = text4;
110 if (!ModUtil.HasContent("Biography/" + text4))
111 {
112 CustomBiographyContent customBiographyContent = CustomBiographyContent.CreateFromId(text4, owner);
113 if (customBiographyContent != null)
114 {
115 ModUtil.AddContent(customBiographyContent);
116 }
117 }
118 break;
119 }
120 case "addFlag":
121 case "addInt":
122 customCharaContent.mapInt[array[0]] = array.TryGet(1, returnNull: true)?.ToInt() ?? 1;
123 break;
124 case "addFlagValue":
125 case "addStr":
126 if (!array.TryGet(1, returnNull: true).IsEmpty())
127 {
128 customCharaContent.mapStr[array[0]] = array[1];
129 }
130 break;
131 }
132 }
133 return customCharaContent;
134 }
string[] trait
Definition: CardRow.cs:33
string id
Definition: CardRow.cs:7
static CustomBiographyContent CreateFromId(string biographyId, ModPackage owner=null)
Dictionary< string, string > mapStr
Dictionary< string, int > mapInt
static SpawnType GetSpawnTypeFromTrait(string trait)
List< string > things
List< string > spawnZones
List< string > equipments
List< string > stocks
string ContentId
Definition: CustomContent.cs:6
static CustomMerchantStock CreateFromId(string stockId, ModPackage owner=null)
static string string string[] kv GetParams(string tag)
string[] tag
Definition: RenderRow.cs:58

References CustomContent.ContentId, CustomBiographyContent.CreateFromId(), CustomMerchantStock.CreateFromId(), equipments, CustomSourceContent.GetParams(), GetSpawnTypeFromTrait(), mapInt, mapStr, CustomContent.Owner, CustomSourceContent.SourceId, spawnType, spawnZones, stocks, and things.

Referenced by ModPackage.GenerateCustomContentProfiles().

◆ GetSpawnTypeFromTrait()

static SpawnType CustomCharaContent.GetSpawnTypeFromTrait ( string  trait)
inlinestatic

Definition at line 136 of file CustomCharaContent.cs.

137 {
138 if (_cachedSpawnTypes.TryGetValue(trait, out var value))
139 {
140 return value;
141 }
142 Trait trait2 = ClassCache.Create<Trait>("Trait" + trait, "Elin");
143 if (!(trait2 is TraitChara traitChara))
144 {
145 goto IL_005f;
146 }
148 if (traitChara.AdvType == TraitChara.Adv_Type.None)
149 {
150 if (!(trait2 is TraitMerchant))
151 {
152 if (!(trait2 is TraitUniqueChara))
153 {
154 goto IL_005f;
155 }
156 spawnType = SpawnType.Unique;
157 }
158 else
159 {
160 spawnType = SpawnType.Merchant;
161 }
162 }
163 else
164 {
165 spawnType = SpawnType.Adventurer;
166 }
167 goto IL_0061;
168 IL_0061:
169 return _cachedSpawnTypes[trait] = spawnType;
170 IL_005f:
171 spawnType = SpawnType.Common;
172 goto IL_0061;
173 }
static readonly Dictionary< string, SpawnType > _cachedSpawnTypes
Definition: Trait.cs:7

References _cachedSpawnTypes, and spawnType.

Referenced by CreateFromRow().

◆ OnCharaCreated()

void CustomCharaContent.OnCharaCreated ( Chara  chara)
inline

Definition at line 175 of file CustomCharaContent.cs.

176 {
177 if (chara.GetBool("custom_content") || chara.id != base.SourceId)
178 {
179 return;
180 }
181 chara.SetBool("custom_content", enable: true);
182 chara.SetStr("custom_content_id", base.ContentId);
183 chara.SetStr("custom_content_package", base.Owner.id);
184 string key2;
185 foreach (KeyValuePair<string, string> item in mapStr)
186 {
187 item.Deconstruct(out var key, out key2);
188 string id2 = key;
189 string value = key2;
190 chara.SetStr(id2, value);
191 }
192 foreach (KeyValuePair<string, int> item2 in mapInt)
193 {
194 item2.Deconstruct(out key2, out var value2);
195 string id3 = key2;
196 int value3 = value2;
197 chara.SetInt(id3, value3);
198 }
199 if (chara.GetBool("cwl_tags_applied"))
200 {
201 return;
202 }
203 if (things.Count > 0 || equipments.Count > 0)
204 {
205 chara.RemoveThings();
206 }
207 foreach (string[] item3 in equipments.Select((string t) => t.Split('#')))
208 {
209 if (!Enum.TryParse<Rarity>(item3.TryGet(1, returnNull: true), out var result))
210 {
211 result = Rarity.Random;
212 }
213 if (HasValidContentId(item3[0]))
214 {
215 chara.EQ_ID(item3[0], -1, result);
216 }
217 }
218 foreach (string[] item4 in things.Select((string t) => t.Split('#')))
219 {
220 if (!int.TryParse(item4.TryGet(1, returnNull: true), out var result2))
221 {
222 result2 = 1;
223 }
224 if (HasValidContentId(item4[0]))
225 {
226 chara.AddThing(item4[0]).SetNum(result2);
227 }
228 }
229 bool HasValidContentId(string id)
230 {
231 if (EClass.sources.cards.map.ContainsKey(id))
232 {
233 return true;
234 }
235 ModUtil.LogModError("source chara row '" + base.ContentId + "' has invalid addEq/addThing spec '" + id + "'", base.Owner);
236 return false;
237 }
238 }
Rarity
Definition: Rarity.cs:2
string id
Definition: Card.cs:36
void SetInt(string id, int value=0)
Definition: Card.cs:2586
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3273
Thing SetNum(int a)
Definition: Card.cs:3669
void SetStr(string id, string value=null)
Definition: Card.cs:2600
bool GetBool(string id)
Definition: Card.cs:2557
void SetBool(string id, bool enable)
Definition: Card.cs:2562
void RemoveThings()
Definition: Card.cs:3484
Thing EQ_ID(string s, int mat=-1, Rarity r=Rarity.Random)
Definition: Chara.cs:5340
Definition: EClass.cs:6
static SourceManager sources
Definition: EClass.cs:43
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
SourceCard cards

References SourceManager.cards, equipments, Card.GetBool(), Card.id, item, SourceCard.map, mapInt, mapStr, Card.SetBool(), Card.SetStr(), EClass.sources, and things.

◆ OnGameLoad()

override void CustomCharaContent.OnGameLoad ( GameIOContext  context)
inlinevirtual

Reimplemented from CustomContent.

Definition at line 240 of file CustomCharaContent.cs.

241 {
242 if (spawnZones.Count == 0)
243 {
244 return;
245 }
246 Debug.Log($"#mod-content loading {this}");
247 ILookup<string, Chara> lookup = EClass.game.cards.globalCharas.Values.ToLookup((Chara c) => c.id);
248 List<Zone> list = new List<Zone>();
249 foreach (string spawnZone in spawnZones)
250 {
251 Zone zone = ModUtil.FindZoneByFullName(spawnZone);
252 if (zone != null)
253 {
254 list.Add(zone);
255 continue;
256 }
257 ModUtil.LogModError("source chara row '" + base.SourceId + "' has invalid addZone spec '" + spawnZone + "'", base.Owner);
258 }
259 List<Chara> list2 = lookup[base.SourceId].ToList();
260 int count = list2.Count;
261 if (list.Count == 0 && count == 0)
262 {
263 ModUtil.LogModError("source chara row '" + base.SourceId + "' has invalid addZone spec", base.Owner);
264 return;
265 }
266 int num = Math.Max(0, list.Count - count);
267 int num2 = count;
268 if (num2 <= 1)
269 {
270 if (num2 != 1)
271 {
272 goto IL_01cf;
273 }
274 if (IsAdventurer)
275 {
276 goto IL_0178;
277 }
278 }
279 else if (IsAdventurer)
280 {
281 Debug.LogWarning("#mod-content adventurer '" + base.SourceId + "' has spawned more than once");
282 return;
283 }
284 if (num == 0)
285 {
286 goto IL_0178;
287 }
288 goto IL_01cf;
289 IL_0178:
290 Debug.Log("#mod-content skipping existing character '" + base.SourceId + "', " + $"{count} at {string.Join(',', list2.Select((Chara c) => c.currentZone?.ZoneFullName))}");
291 return;
292 IL_01cf:
293 for (int i = 0; i < num; i++)
294 {
295 Zone z2 = list[i];
296 Chara chara = SpawnToZone(z2);
297 if (chara == null)
298 {
299 ModUtil.LogModError("can't spawn character '" + base.SourceId + "'", base.Owner);
300 break;
301 }
302 if (IsAdventurer)
303 {
304 EClass.game.cards.listAdv.Add(chara);
305 break;
306 }
307 }
308 Chara SpawnToZone(Zone z)
309 {
310 Chara chara2 = CharaGen.Create(base.SourceId);
311 if (chara2.id == "chicken")
312 {
313 return null;
314 }
315 chara2.SetHomeZone(z);
316 chara2.MoveZone(z, ZoneTransition.EnterState.RandomVisit);
317 Debug.Log("#mod-content spawned character '" + base.SourceId + "' to " + z.ZoneFullName);
318 return chara2;
319 }
320 }
List< Chara > listAdv
Definition: CardManager.cs:64
GlobalCharaList globalCharas
Definition: CardManager.cs:46
static Chara Create(string id, int lv=-1)
Definition: CharaGen.cs:17
Definition: Chara.cs:10
Chara SetHomeZone(Zone zone)
Definition: Chara.cs:1498
void MoveZone(string alias)
Definition: Chara.cs:3533
static Game game
Definition: EClass.cs:9
CardManager cards
Definition: Game.cs:156
Definition: Zone.cs:12
string ZoneFullName
Definition: Zone.cs:85

References $, Game.cards, CharaGen.Create(), Debug, EClass.game, CardManager.globalCharas, Card.id, IsAdventurer, CardManager.listAdv, Chara.MoveZone(), Chara.SetHomeZone(), spawnZones, and Zone.ZoneFullName.

◆ ToString()

override string CustomCharaContent.ToString ( )
inline

Definition at line 322 of file CustomCharaContent.cs.

323 {
324 StringBuilder stringBuilder = new StringBuilder();
325 stringBuilder.AppendLine($"{base.ContentId}/{spawnType}/{base.Owner.id}");
326 stringBuilder.AppendLine($" - zones({spawnZones.Count})/{string.Join(';', spawnZones)}");
327 if (things.Count > 0)
328 {
329 stringBuilder.AppendLine($" - things({things.Count})/{string.Join(';', things)}");
330 }
331 if (equipments.Count > 0)
332 {
333 stringBuilder.AppendLine($" - equipments({equipments.Count})/{string.Join(';', equipments)}");
334 }
335 if (stocks.Count > 0)
336 {
337 stringBuilder.AppendLine(" - stocks/" + string.Join(';', stocks));
338 }
339 if (mapStr.Count > 0)
340 {
341 stringBuilder.AppendLine(" - str/" + string.Join(';', mapStr.Select((KeyValuePair<string, string> kv) => kv.Key + "=" + kv.Value)));
342 }
343 if (mapInt.Count > 0)
344 {
345 stringBuilder.AppendLine(" - int/" + string.Join(';', mapInt.Select((KeyValuePair<string, int> kv) => $"{kv.Key}={kv.Value}")));
346 }
347 return stringBuilder.ToString();
348 }

References $, equipments, mapInt, mapStr, stocks, and things.

Member Data Documentation

◆ _cachedSpawnTypes

readonly Dictionary<string, SpawnType> CustomCharaContent._cachedSpawnTypes = new Dictionary<string, SpawnType>()
staticprivate

Definition at line 19 of file CustomCharaContent.cs.

Referenced by GetSpawnTypeFromTrait().

◆ equipments

List<string> CustomCharaContent.equipments = new List<string>()

Definition at line 21 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), OnCharaCreated(), and ToString().

◆ mapInt

Dictionary<string, int> CustomCharaContent.mapInt = new Dictionary<string, int>()

Definition at line 23 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), OnCharaCreated(), and ToString().

◆ mapStr

Dictionary<string, string> CustomCharaContent.mapStr = new Dictionary<string, string>()

Definition at line 25 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), OnCharaCreated(), and ToString().

◆ spawnType

SpawnType CustomCharaContent.spawnType

Definition at line 27 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), and GetSpawnTypeFromTrait().

◆ spawnZones

List<string> CustomCharaContent.spawnZones = new List<string>()

Definition at line 29 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), and OnGameLoad().

◆ stocks

List<string> CustomCharaContent.stocks = new List<string>()

Definition at line 31 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), and ToString().

◆ things

List<string> CustomCharaContent.things = new List<string>()

Definition at line 33 of file CustomCharaContent.cs.

Referenced by CreateFromRow(), OnCharaCreated(), and ToString().

Property Documentation

◆ IsAdventurer

bool CustomCharaContent.IsAdventurer
get

Definition at line 37 of file CustomCharaContent.cs.

Referenced by OnGameLoad().

◆ SourceType

override string CustomCharaContent.SourceType
get

Definition at line 35 of file CustomCharaContent.cs.


The documentation for this class was generated from the following file: