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