Elin Decompiled Documentation EA 23.342.1 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/" + r.id))
111 {
112 CustomBiographyContent customBiographyContent = CustomBiographyContent.CreateFromId(text4, owner, r.id);
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, string charaId=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 SpawnType spawnType = ((trait2 is TraitAdventurer) ? SpawnType.Adventurer : ((trait2 is TraitMerchant) ? SpawnType.Merchant : ((trait2 is TraitUniqueChara) ? SpawnType.Unique : SpawnType.Common)));
144 return _cachedSpawnTypes[trait] = spawnType;
145 }
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 147 of file CustomCharaContent.cs.

148 {
149 if (chara.GetBool("custom_content") || chara.id != base.SourceId)
150 {
151 return;
152 }
153 chara.SetBool("custom_content", enable: true);
154 chara.SetStr("custom_content_id", base.ContentId);
155 chara.SetStr("custom_content_package", base.Owner.id);
156 string key2;
157 foreach (KeyValuePair<string, string> item in mapStr)
158 {
159 item.Deconstruct(out var key, out key2);
160 string id = key;
161 string value = key2;
162 chara.SetStr(id, value);
163 }
164 foreach (KeyValuePair<string, int> item2 in mapInt)
165 {
166 item2.Deconstruct(out key2, out var value2);
167 string id2 = key2;
168 int value3 = value2;
169 chara.SetInt(id2, value3);
170 }
171 if (chara.GetBool("cwl_tags_applied"))
172 {
173 return;
174 }
175 if (things.Count > 0 || equipments.Count > 0)
176 {
177 chara.RemoveThings();
178 }
179 foreach (string[] item3 in equipments.Select((string t) => t.Split('#')))
180 {
181 if (!Enum.TryParse<Rarity>(item3.TryGet(1, returnNull: true), out var result))
182 {
183 result = Rarity.Random;
184 }
185 if (HasValidContentId(item3[0]))
186 {
187 chara.EQ_ID(item3[0], -1, result);
188 }
189 }
190 foreach (string[] item4 in things.Select((string t) => t.Split('#')))
191 {
192 if (!int.TryParse(item4.TryGet(1, returnNull: true), out var result2))
193 {
194 result2 = 1;
195 }
196 if (HasValidContentId(item4[0]))
197 {
198 chara.AddThing(item4[0]).SetNum(result2);
199 }
200 }
201 bool HasValidContentId(string text)
202 {
203 if (EClass.sources.cards.map.ContainsKey(text))
204 {
205 return true;
206 }
207 ModUtil.LogModError("source chara row '" + base.ContentId + "' has invalid addEq/addThing spec '" + text + "'", base.Owner);
208 return false;
209 }
210 }
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:3280
Thing SetNum(int a)
Definition: Card.cs:3676
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:3491
Thing EQ_ID(string s, int mat=-1, Rarity r=Rarity.Random)
Definition: Chara.cs:5374
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 212 of file CustomCharaContent.cs.

213 {
214 if (spawnZones.Count == 0)
215 {
216 return;
217 }
218 Debug.Log($"#mod-content loading {this}");
219 ILookup<string, Chara> lookup = EClass.game.cards.globalCharas.Values.ToLookup((Chara c) => c.id);
220 List<Zone> list = new List<Zone>();
221 foreach (string spawnZone in spawnZones)
222 {
223 Zone zone = ModUtil.FindZoneByFullName(spawnZone);
224 if (zone != null)
225 {
226 list.Add(zone);
227 continue;
228 }
229 ModUtil.LogModError("source chara row '" + base.SourceId + "' has invalid addZone spec '" + spawnZone + "'", base.Owner);
230 }
231 List<Chara> list2 = lookup[base.SourceId].ToList();
232 int count = list2.Count;
233 if (list.Count == 0 && count == 0)
234 {
235 ModUtil.LogModError("source chara row '" + base.SourceId + "' has invalid addZone spec", base.Owner);
236 return;
237 }
238 int num = Math.Max(0, list.Count - count);
239 int num2 = count;
240 if (num2 <= 1)
241 {
242 if (num2 != 1)
243 {
244 goto IL_01d6;
245 }
246 if (IsAdventurer)
247 {
248 goto IL_017f;
249 }
250 }
251 else if (IsAdventurer)
252 {
253 Debug.LogWarning("#mod-content adventurer '" + base.SourceId + "' has spawned more than once");
254 return;
255 }
256 if (num == 0)
257 {
258 goto IL_017f;
259 }
260 goto IL_01d6;
261 IL_017f:
262 Debug.Log("#mod-content skipping existing character '" + base.SourceId + "', " + $"{count} at {string.Join(',', list2.Select((Chara c) => c.currentZone?.ZoneFullName))}");
263 return;
264 IL_01d6:
265 HashSet<Zone> occupied = list2.Select((Chara c) => c.homeZone).ToHashSet();
266 foreach (Zone item in list.Where((Zone z) => !occupied.Contains(z)).Take(num))
267 {
268 Chara chara = SpawnToZone(item);
269 if (chara == null)
270 {
271 ModUtil.LogModError("can't spawn character '" + base.SourceId + "'", base.Owner);
272 break;
273 }
274 if (IsAdventurer)
275 {
276 EClass.game.cards.listAdv.Add(chara);
277 break;
278 }
279 }
280 Chara SpawnToZone(Zone z)
281 {
282 Chara chara2 = CharaGen.Create(base.SourceId);
283 if (chara2.id == "chicken")
284 {
285 return null;
286 }
287 chara2.SetHomeZone(z);
288 chara2.MoveZone(z, ZoneTransition.EnterState.RandomVisit);
289 Debug.Log("#mod-content spawned character '" + base.SourceId + "' to " + z.ZoneFullName);
290 return chara2;
291 }
292 }
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
Zone homeZone
Definition: Chara.cs:271
void MoveZone(string alias)
Definition: Chara.cs:3548
static Game game
Definition: EClass.cs:9
CardManager cards
Definition: Game.cs:156
Definition: Zone.cs:12
string ZoneFullName
Definition: Zone.cs:88

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

◆ ToString()

override string CustomCharaContent.ToString ( )
inline

Definition at line 294 of file CustomCharaContent.cs.

295 {
296 StringBuilder stringBuilder = new StringBuilder();
297 stringBuilder.AppendLine($"{base.ContentId}/{spawnType}/{base.Owner.id}");
298 stringBuilder.AppendLine($" - zones({spawnZones.Count})/{string.Join(';', spawnZones)}");
299 if (things.Count > 0)
300 {
301 stringBuilder.AppendLine($" - things({things.Count})/{string.Join(';', things)}");
302 }
303 if (equipments.Count > 0)
304 {
305 stringBuilder.AppendLine($" - equipments({equipments.Count})/{string.Join(';', equipments)}");
306 }
307 if (stocks.Count > 0)
308 {
309 stringBuilder.AppendLine(" - stocks/" + string.Join(';', stocks));
310 }
311 if (mapStr.Count > 0)
312 {
313 stringBuilder.AppendLine(" - str/" + string.Join(';', mapStr.Select((KeyValuePair<string, string> kv) => kv.Key + "=" + kv.Value)));
314 }
315 if (mapInt.Count > 0)
316 {
317 stringBuilder.AppendLine(" - int/" + string.Join(';', mapInt.Select((KeyValuePair<string, int> kv) => $"{kv.Key}={kv.Value}")));
318 }
319 return stringBuilder.ToString();
320 }

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: