Elin Decompiled Documentation EA 23.319 Nightly Patch 1
Loading...
Searching...
No Matches
CustomReligionContent.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.IO;
5using System.Linq;
6using System.Text;
7using Newtonsoft.Json;
8using UnityEngine;
9
10[JsonObject(MemberSerialization.OptOut)]
11public class CustomReligionContent : CustomSourceContent
12{
13 public static Dictionary<string, ReligionCustom> managed = new Dictionary<string, ReligionCustom>();
14
15 public List<string> artifacts = new List<string>();
16
17 [DefaultValue(true)]
18 public bool canJoin = true;
19
20 public bool isMinorGod;
21
22 public bool noPunish;
23
24 public bool noPunishTakeover;
25
26 public List<string> elements = new List<string>();
27
28 public List<string> godAbilities = new List<string>();
29
30 public Dictionary<string, int> offeringMtp = new Dictionary<string, int>();
31
32 public Dictionary<string, string> offeringValue = new Dictionary<string, string>();
33
34 public override string SourceType => "SourceReligion";
35
36 public string ChunkName => "custom_religion_" + base.SourceId;
37
38 public static CustomReligionContent CreateFromRow(SourceReligion.Row r, ModPackage owner = null)
39 {
40 string text = r.id.Split('#')[0];
41 if (owner == null)
42 {
43 owner = ModUtil.FindSourceRowPackage(r);
44 }
45 CustomReligionContent obj = new CustomReligionContent
46 {
47 ContentId = "Religion/" + text,
48 SourceId = text,
49 Owner = owner,
50 canJoin = (!r.id.Contains("#noJoin") && !r.id.Contains("#cannot")),
51 isMinorGod = r.id.Contains("#minor")
52 };
53 EClass.sources.religions.map[text] = r;
54 if (!Portrait.modPortraits.dict.ContainsKey("UN_" + r.id) && SpriteReplacer.dictModItems.TryGetValue(r.id, out var value))
55 {
56 Portrait.modPortraits.Add("UN_" + r.id, new FileInfo(value + ".png"));
57 }
58 obj.RegisterCustomReligion();
59 return obj;
60 }
61
62 public void RegisterCustomReligion(ReligionCustom religionCustom = null)
63 {
64 Dictionary<string, ReligionCustom> dictionary = managed;
65 string sourceId = base.SourceId;
66 ReligionCustom obj = religionCustom ?? new ReligionCustom();
67 ReligionCustom religionCustom2 = obj;
68 dictionary[sourceId] = obj;
69 religionCustom2.content = this;
70 }
71
72 public static void Init()
73 {
74 (FileInfo, EMod)[] filesEx = PackageIterator.GetFilesEx("Data/religion_data.json");
75 for (int i = 0; i < filesEx.Length; i++)
76 {
77 var (fileInfo, package) = filesEx[i];
78 try
79 {
80 foreach (var (key, customReligionContent2) in IO.LoadFile<Dictionary<string, CustomReligionContent>>(fileInfo.FullName))
81 {
82 if (managed.TryGetValue(key, out var value))
83 {
84 value.content.canJoin = customReligionContent2.canJoin;
85 value.content.isMinorGod = customReligionContent2.isMinorGod;
86 value.content.artifacts = customReligionContent2.artifacts;
87 value.content.offeringMtp = customReligionContent2.offeringMtp;
88 value.content.offeringValue = customReligionContent2.offeringValue;
89 value.content.godAbilities = customReligionContent2.godAbilities;
90 }
91 }
92 }
93 catch (Exception ex)
94 {
95 ModUtil.LogModError("exception while loading religion data '" + fileInfo.ShortPath() + "'\n" + ex.Message, package);
96 Debug.LogException(ex);
97 }
98 }
99 LoadDeprecatedCwlSpec();
100 static void LoadDeprecatedCwlSpec()
101 {
102 foreach (SourceThing.Row row2 in EClass.sources.things.rows)
103 {
104 if (row2.HasTag(CTAG.godArtifact))
105 {
106 managed.Values.FirstOrDefault((ReligionCustom r) => row2.tag.Contains(r.id))?.content.artifacts.Add(row2.id);
107 }
108 }
109 foreach (SourceElement.Row row in EClass.sources.elements.rows)
110 {
111 if (row.tag.Contains("godAbility"))
112 {
113 managed.Values.FirstOrDefault((ReligionCustom r) => row.tag.Contains(r.id))?.content.godAbilities.Add(row.alias);
114 }
115 }
116 (FileInfo, EMod)[] filesEx2 = PackageIterator.GetFilesEx("Data/religion_elements.json");
117 string key2;
118 for (int j = 0; j < filesEx2.Length; j++)
119 {
120 var (fileInfo2, package2) = filesEx2[j];
121 try
122 {
123 foreach (KeyValuePair<string, List<string>> item in IO.LoadFile<Dictionary<string, List<string>>>(fileInfo2.FullName))
124 {
125 item.Deconstruct(out key2, out var value2);
126 string key3 = key2;
127 List<string> collection = value2;
128 if (managed.TryGetValue(key3, out var value3))
129 {
130 value3.content.elements.AddRange(collection);
131 }
132 }
133 }
134 catch (Exception ex2)
135 {
136 ModUtil.LogModError("exception while loading '" + fileInfo2.ShortPath() + "'\n" + ex2.Message, package2);
137 Debug.LogException(ex2);
138 }
139 }
140 filesEx2 = PackageIterator.GetFilesEx("Data/religion_offerings.json");
141 for (int j = 0; j < filesEx2.Length; j++)
142 {
143 var (fileInfo3, package3) = filesEx2[j];
144 try
145 {
146 foreach (KeyValuePair<string, Dictionary<string, int>> item2 in IO.LoadFile<Dictionary<string, Dictionary<string, int>>>(fileInfo3.FullName))
147 {
148 item2.Deconstruct(out key2, out var value4);
149 string key4 = key2;
150 Dictionary<string, int> other = value4;
151 if (managed.TryGetValue(key4, out var value5))
152 {
153 value5.content.offeringMtp.Merge(other);
154 }
155 }
156 }
157 catch (Exception ex3)
158 {
159 ModUtil.LogModError("exception while loading '" + fileInfo3.ShortPath() + "'\n" + ex3.Message, package3);
160 Debug.LogException(ex3);
161 }
162 }
163 }
164 }
165
166 public static List<ReligionCustom> GetCustomReligions()
167 {
168 List<ReligionCustom> list = new List<ReligionCustom>();
169 foreach (ReligionCustom value in managed.Values)
170 {
171 if (value.content != null && EClass.sources.religions.map.ContainsKey(value.content.SourceId))
172 {
173 value.relation = value.source.relation;
174 list.Add(value);
175 Debug.Log($"#mod-content {value.content}");
176 }
177 }
178 return list;
179 }
180
181 internal static void LoadReligionData(GameIOContext context)
182 {
183 if (!context.Load<Dictionary<string, ReligionCustom>>("custom_religion_data", out var data))
184 {
185 return;
186 }
187 foreach (var (key, religionCustom2) in data)
188 {
189 if (EClass.game.religions.dictAll.TryGetValue(key, out var value))
190 {
191 Debug.Log("#mod-content loading Religion/" + value.id);
192 value.mood = religionCustom2.mood;
193 value.relation = religionCustom2.relation;
194 value.giftRank = religionCustom2.giftRank;
195 }
196 }
197 }
198
199 internal static void SaveReligionData(GameIOContext context)
200 {
201 if (!context.Load<Dictionary<string, ReligionCustom>>("custom_religion_data", out var data))
202 {
203 data = new Dictionary<string, ReligionCustom>();
204 }
206 {
207 data[item.id] = item;
208 }
209 if (data.Count > 0)
210 {
211 context.SaveUncompressed("custom_religion_data", data);
212 }
213 }
214
215 public override string ToString()
216 {
217 StringBuilder stringBuilder = new StringBuilder();
218 stringBuilder.AppendLine($"{base.ContentId}/canJoin={canJoin}/minorGod={isMinorGod}");
219 if (artifacts.Count > 0)
220 {
221 stringBuilder.AppendLine($" - artifacts({artifacts.Count})/{string.Join(';', artifacts)}");
222 }
223 if (elements.Count > 0)
224 {
225 stringBuilder.AppendLine($" - elements({elements.Count})/{string.Join(';', elements)}");
226 }
227 if (offeringMtp.Count > 0)
228 {
229 stringBuilder.AppendLine($" - offeringMtp({offeringMtp.Count})/{string.Join(';', offeringMtp.Select((KeyValuePair<string, int> kv) => $"{kv.Key}={kv.Value}"))}");
230 }
231 if (offeringValue.Count > 0)
232 {
233 stringBuilder.AppendLine(string.Format(" - offeringValue({0})/{1}", offeringValue.Count, string.Join(';', offeringValue.Select((KeyValuePair<string, string> kv) => kv.Key + "=" + kv.Value))));
234 }
235 if (godAbilities.Count > 0)
236 {
237 stringBuilder.AppendLine($" - godAbilities({godAbilities.Count})/{string.Join(';', godAbilities)}");
238 }
239 return stringBuilder.ToString();
240 }
241}
CTAG
Definition: CTAG.cs:2
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static SourceManager sources
Definition: EClass.cs:43
ReligionManager religions
Definition: Game.cs:159
Definition: IO.cs:10
void Add(FileInfo fi, string path=null, string prefix="")
Definition: ModItemList.cs:85
Dictionary< string, ModItem< T > > dict
Definition: ModItemList.cs:11
static ModItemList< Sprite > modPortraits
Definition: Portrait.cs:12
override string id
CustomReligionContent content
Dictionary< string, Religion > dictAll
List< Religion > list
SourceReligion.Row source
Definition: Religion.cs:33
SourceThing things
SourceElement elements
SourceReligion religions
static Dictionary< string, string > dictModItems