35 public virtual bool IsMeleeWeapon
45 private void OnSerializing(StreamingContext context)
47 this.list =
new List<int>();
48 foreach (
Element element
in this.dict.Values)
50 if (element.vBase != 0 || element.vExp != 0 || element.vPotential != 0 || element.vTempPotential != 0)
52 this.list.AddRange(
new int[]
58 element.vTempPotential
62 if (this.list.Count == 0)
70 private void OnDeserialized(StreamingContext context)
72 if (this.list !=
null)
74 for (
int i = 0; i < this.list.Count; i += 5)
76 Element orCreateElement = this.GetOrCreateElement(this.list[i]);
77 if (orCreateElement !=
null)
79 orCreateElement.vBase += this.list[i + 1];
80 orCreateElement.vExp += this.list[i + 2];
81 orCreateElement.vPotential += this.list[i + 3];
82 orCreateElement.vTempPotential = this.list[i + 4];
83 orCreateElement.owner =
this;
90 public void ApplyElementMap(
int uid, SourceValueType type, Dictionary<int, int> map,
int lv,
bool invert =
false,
bool applyFeat =
false)
92 int num = invert ? -1 : 1;
94 foreach (KeyValuePair<int, int> keyValuePair
in map)
96 Element orCreateElement = this.GetOrCreateElement(keyValuePair.Key);
97 int value = keyValuePair.Value;
100 if (orCreateElement.source.category ==
"skill")
102 orCreateElement.vSourcePotential += orCreateElement.GetSourcePotential(value) * num;
104 int num2 = orCreateElement.GetSourceValue(value, lv, type) * num;
105 orCreateElement.vSource += num2;
106 if (applyFeat && orCreateElement is
Feat)
108 (orCreateElement as
Feat).Apply(num2,
this,
false);
116 public void ApplyMaterialElementMap(
Thing t,
bool invert =
false)
118 int num = invert ? -1 : 1;
121 foreach (KeyValuePair<int, int> keyValuePair
in material.elementMap)
123 int value = keyValuePair.Value;
126 Element orCreateElement = this.GetOrCreateElement(keyValuePair.Key);
127 if (!orCreateElement.source.IsEncAppliable(t))
129 if (orCreateElement.vBase == 0 && orCreateElement.vSource == 0 && orCreateElement.vLink == 0 && orCreateElement.vExp == 0 && orCreateElement.vPotential == 0)
131 this.Remove(orCreateElement.id);
136 int num2 = orCreateElement.GetMaterialSourceValue(t, value) * num;
137 orCreateElement.vSource += num2;
138 if (orCreateElement.vBase == 0 && orCreateElement.vSource == 0 && orCreateElement.vLink == 0 && orCreateElement.vExp == 0 && orCreateElement.vPotential == 0)
140 this.Remove(orCreateElement.id);
149 public void ImportElementMap(Dictionary<int, int> map)
151 foreach (KeyValuePair<int, int> keyValuePair
in map)
153 this.GetOrCreateElement(keyValuePair.Key).vSource += keyValuePair.Value;
160 for (
int i = 0; i < ints.Length; i += 2)
162 this.GetOrCreateElement(ints[i]).vSource += ints[i + 1];
168 public void ApplyPotential(
int mode = 0)
170 foreach (
Element element
in this.dict.Values)
172 if (element.HasTag(
"primary"))
174 element.vTempPotential = (element.ValueWithoutLink - ((mode == 2) ? 0 : 7)) * 5;
180 public int Value(
int ele)
182 Element element = this.GetElement(ele);
185 return element.Value;
187 if (
EClass.core.game ==
null ||
this.Card ==
null || !
this.Card.IsPCFactionOrMinion)
193 return EClass.pc.faction.charaElements.Value(ele);
195 return this.GetOrCreateElement(ele).Value;
199 public virtual int ValueBonus(
Element e)
205 public int ValueWithoutLink(
int ele)
207 Element element = this.GetElement(ele);
212 return element.ValueWithoutLink;
216 public int ValueWithoutLink(
string alias)
218 Element element = this.GetElement(alias);
223 return element.ValueWithoutLink;
227 public int GetFeatRef(
int ele,
int idx = 0)
229 Feat feat = this.GetElement(ele) as
Feat;
234 feat.Apply(feat.Value,
this,
false);
235 return Feat.featRef[idx].ToInt();
239 public int Exp(
int ele)
241 Element element = this.GetElement(ele);
250 public bool Has(
int ele)
252 Element element = this.GetElement(ele);
253 return element !=
null && element.Value > 0;
259 return this.Has(row.id);
263 public bool Has(
string alias)
265 return this.Has(
EClass.sources.elements.alias[alias].id);
269 public bool HasBase(
int ele)
271 Element element = this.GetElement(ele);
276 int num = element.ValueWithoutLink;
281 num += this.Value(1524) * -4;
282 num += this.Value(1525) * 4;
287 num += this.Value(1516) * -4;
288 num += this.Value(1517) * 4;
294 public int Base(
int ele)
296 Element element = this.GetElement(ele);
301 return element.ValueWithoutLink;
305 public void Learn(
int ele,
int v = 1)
307 this.ModBase(ele, v);
312 public void Train(
int ele,
int a = 10)
315 this.ModTempPotential(ele, a, 0);
319 public void ModExp(
int ele,
int a,
bool chain =
false)
321 if (this.
Card !=
null && this.
Card.isChara &&
this.Card.Chara.isDead)
329 Element element = this.GetElement(ele);
330 if (element ==
null || !element.CanGainExp)
334 int value = element.UsePotential ? element.Potential : 100;
335 if (element.UseExpMod)
337 a = a * Mathf.Clamp(value, 10, 1000) / (100 + Mathf.Max(0, element.ValueWithoutLink) * 25);
338 if (a >= 0 &&
EClass.rnd(element.ValueWithoutLink + 1) < 10)
344 if (!chain && element.source.parentFactor > 0f &&
this.Card !=
null && !element.source.aliasParent.IsEmpty())
347 if (element2.CanGainExp)
349 this.ModExp(element2.id, (
int)Math.Max(1f, (
float)a * element.source.parentFactor / 100f),
true);
352 if (element.vExp >= element.ExpToNext)
354 int num = element.vExp - element.ExpToNext;
355 int vBase = element.vBase;
356 this.ModBase(ele, 1);
357 this.OnLevelUp(element, vBase);
358 element.vExp = Mathf.Clamp(num / 2, 0, element.ExpToNext / 2);
359 if (element.vTempPotential > 0)
361 element.vTempPotential -= element.vTempPotential / 4 +
EClass.rnd(5) + 5;
362 if (element.vTempPotential < 0)
364 element.vTempPotential = 0;
368 else if (element.vTempPotential < 0)
370 element.vTempPotential += -element.vTempPotential / 4 +
EClass.rnd(5) + 5;
371 if (element.vTempPotential > 0)
373 element.vTempPotential = 0;
378 else if (element.vExp < 0)
380 if (element.ValueWithoutLink <= 1)
385 int vBase2 = element.vBase;
386 this.ModBase(ele, -1);
387 this.OnLevelDown(element, vBase2);
388 element.vExp = Mathf.Max(element.ExpToNext / 2, element.ExpToNext + element.vExp);
393 public virtual void OnLearn(
int ele)
398 public virtual void OnTrain(
int ele)
403 public virtual void OnLevelUp(
Element e,
int lastValue)
408 public virtual void OnLevelDown(
Element e,
int lastValue)
413 public Element SetBase(
string alias,
int v,
int potential = 0)
415 return this.SetBase(
EClass.sources.elements.alias[alias].id, v, potential);
419 public Element SetBase(
int id,
int v,
int potential = 0)
421 Element orCreateElement = this.GetOrCreateElement(
id);
422 if (this.parent !=
null && orCreateElement.CanLink(
this))
424 this.parent.ModLink(
id, -orCreateElement.vBase + v);
426 orCreateElement.vBase = v;
427 orCreateElement.vExp = 0;
428 orCreateElement.vPotential = potential;
429 orCreateElement.OnChangeValue();
430 if (orCreateElement.vBase == 0 && orCreateElement.vSource == 0 && orCreateElement.vLink == 0 && orCreateElement.vPotential == 0 && orCreateElement.vExp == 0)
432 this.Remove(orCreateElement.id);
434 return orCreateElement;
438 public void SetTo(
int id,
int v)
440 Element orCreateElement = this.GetOrCreateElement(
id);
441 int num = v - (orCreateElement.vBase + orCreateElement.vSource);
444 this.ModBase(
id, num);
446 if (orCreateElement.vBase == 0 && orCreateElement.vSource == 0 && orCreateElement.vLink == 0 && orCreateElement.vPotential == 0 && orCreateElement.vExp == 0)
448 this.Remove(orCreateElement.id);
453 public void Remove(
int id)
455 Element element = this.GetElement(
id);
460 if (this.parent !=
null && element.CanLink(
this))
462 this.parent.ModLink(
id, -element.Value);
464 this.dict.Remove(
id);
468 public Element ModBase(
int ele,
int v)
470 Element orCreateElement = this.GetOrCreateElement(ele);
471 orCreateElement.vBase += v;
472 if (this.parent !=
null && orCreateElement.CanLink(
this))
474 this.parent.ModLink(ele, v);
476 orCreateElement.CheckLevelBonus(
this,
null);
477 orCreateElement.OnChangeValue();
478 if (orCreateElement.vBase == 0 && orCreateElement.vSource == 0 && orCreateElement.vLink == 0 && orCreateElement.vPotential == 0 && orCreateElement.vExp == 0)
480 this.Remove(orCreateElement.id);
482 return orCreateElement;
486 public virtual void OnChangeValue()
491 public Element ModPotential(
int ele,
int v)
493 Element orCreateElement = this.GetOrCreateElement(ele);
494 orCreateElement.vPotential += v;
495 if (orCreateElement.vPotential > 1000)
497 orCreateElement.vPotential = 1000;
499 return orCreateElement;
503 public Element ModTempPotential(
int ele,
int v,
int threshMsg = 0)
505 Element orCreateElement = this.GetOrCreateElement(ele);
506 orCreateElement.vTempPotential += v;
507 if (orCreateElement.vTempPotential > 1000)
509 orCreateElement.vTempPotential = 1000;
511 this.OnModTempPotential(orCreateElement, v, threshMsg);
512 return orCreateElement;
516 public virtual void OnModTempPotential(
Element e,
int v,
int threshMsg)
521 private Element ModLink(
int id,
int v)
523 Element orCreateElement = this.GetOrCreateElement(
id);
524 orCreateElement.vLink += v;
525 orCreateElement.OnChangeValue();
526 if (this.parent !=
null && orCreateElement.CanLink(
this))
528 this.parent.ModLink(
id, v);
530 return orCreateElement;
534 public int GetSpellExp(
Chara c,
Element e,
int costMod = 100)
537 int num = cost.cost * ((cost.type ==
Act.CostType.SP) ? 20 : 5) * (100 + c.Evalue(1208) * 30) / 100 + 10;
538 num = num * costMod / 100;
539 if (!e.source.aliasParent.IsEmpty())
541 int num2 = this.ValueWithoutLink(e.source.aliasParent) - this.ValueWithoutLink(e.source.id);
544 num = num * (100 + num2 * 5) / 100;
548 num = num * 100 / (100 - num2 * 25);
559 public Element GetElement(
string alias)
561 return this.GetElement(
EClass.sources.elements.alias[alias].id);
565 public Element GetElement(
int id)
567 return this.dict.TryGetValue(
id,
null);
571 public Element CreateElement(
int id)
578 element.owner =
this;
579 this.dict.Add(
id, element);
586 return this.GetOrCreateElement(ele.id);
590 public Element GetOrCreateElement(
string alias)
592 return this.GetOrCreateElement(
EClass.sources.elements.alias[alias].id);
596 public Element GetOrCreateElement(
int id)
599 if (!this.dict.TryGetValue(
id, out result))
601 result = this.CreateElement(
id);
607 public void SetParent(
Card c)
609 this.SetParent((c !=
null) ? c.elements :
null);
615 if (this.parent !=
null)
617 foreach (
Element element
in this.dict.Values)
619 if (element.CanLink(
this))
621 this.parent.ModLink(element.id, -(element.vBase + element.vSource));
625 if (newParent !=
null)
627 foreach (
Element element2
in this.dict.Values)
629 if (element2.CanLink(
this))
631 newParent.ModLink(element2.id, element2.vBase + element2.vSource);
635 this.parent = newParent;
639 public List<Element> ListElements(Func<Element, bool> shoudList =
null, Comparison<Element> comparison =
null)
641 List<Element> list =
new List<Element>();
643 CS$<>8__locals1.eles = this.dict.Values.ToList<
Element>();
644 if (this.
Card !=
null && this.
Card.Chara !=
null)
646 if (this.
Card.Chara.IsPCFaction)
650 ElementContainer.<ListElements>g__AddElements|55_0(this.
Card.Chara.faithElements, ref CS$<>8__locals1);
652 foreach (
Element element
in CS$<>8__locals1.eles)
654 if (shoudList ==
null || shoudList(element))
659 if (comparison !=
null)
661 list.Sort(comparison);
667 public List<Element> ListBestAttributes()
669 List<Element> list = this.ListElements((
Element a) => a.HasTag(
"primary"),
null);
670 list.Sort((
Element a,
Element b) => (b.ValueWithoutLink - a.ValueWithoutLink) * 100000 + a.id - b.id);
675 public List<Element> ListBestSkills()
677 List<Element> list = this.ListElements((
Element a) => a.source.category ==
"skill",
null);
678 list.Sort((
Element a,
Element b) => (b.ValueWithoutLink - a.ValueWithoutLink) * 100000 + a.id - b.id);
683 public List<Element> ListGeneFeats()
685 return this.ListElements((
Element a) => a.Value > 0 && a.source.category ==
"feat" && a.source.cost.Length != 0 && a.source.cost[0] > 0,
null);
689 public List<Element> ListLearnable(
Chara c)
691 List<Element> list =
new List<Element>();
692 foreach (KeyValuePair<int, Element> keyValuePair
in c.elements.dict)
694 if (!this.dict.ContainsKey(keyValuePair.Key))
696 list.Add(keyValuePair.Value);
705 container.dict.Clear();
706 foreach (KeyValuePair<int, Element> keyValuePair
in this.dict)
708 Element element = container.CreateElement(keyValuePair.Key);
709 element.vBase = keyValuePair.Value.vBase;
710 element.vExp = keyValuePair.Value.vExp;
711 element.vSource = keyValuePair.Value.vSource;
716 public static int GetSortVal(
Element a)
719 if (a.source.textAlt.Length <= 2 || a.Value < 0)
727 if (a.IsFoodTraitMain)
735 public void AddNote(UINote n, Func<Element, bool> isValid =
null, Action onAdd =
null,
ElementContainer.NoteMode mode =
ElementContainer.NoteMode.Default,
bool addRaceFeat =
false, Func<Element, string, string> funcText =
null, Action<UINote, Element> onAddNote =
null)
737 List<Element> list =
new List<Element>();
738 foreach (
Element element
in this.dict.Values)
740 if ((isValid ==
null || isValid(element)) && (mode !=
ElementContainer.NoteMode.CharaMake || element.ValueWithoutLink != 0) && (element.Value != 0 || mode ==
ElementContainer.NoteMode.CharaMakeAttributes) && (!element.HasTag(
"hidden") ||
EClass.debug.showExtra))
748 element2.owner =
this;
763 list.Sort((
Element a,
Element b) => a.SortVal(
false) - b.SortVal(
false));
772 list.Sort((
Element a,
Element b) => a.GetSortVal(UIList.SortMode.ByElementParent) - b.GetSortVal(UIList.SortMode.ByElementParent));
774 using (List<Element>.Enumerator enumerator2 = list.GetEnumerator())
776 while (enumerator2.MoveNext())
778 Element e = enumerator2.Current;
784 bool flag = e.source.tag.Contains(
"common");
785 string categorySub = e.source.categorySub;
787 bool flag3 = e.source.tag.Contains(
"neg") ? (e.Value > 0) : (e.Value < 0);
788 int num = Mathf.Abs(e.Value);
789 bool flag4 = this.Card !=
null && this.
Card.ShowFoodEnc;
790 bool flag5 = this.Card !=
null && this.Card.IsWeapon && e is
Ability;
792 if (e.IsTrait || (flag4 && e.IsFoodTrait))
794 string[] textArray = e.source.GetTextArray(
"textAlt");
795 int num2 = Mathf.Clamp(e.Value / 10 + 1, (e.Value >= 0 && textArray.Length > 2) ? 2 : 1, textArray.Length - 1);
796 text =
"altEnc".lang(textArray[0].IsEmpty(e.Name), textArray[num2],
EClass.debug.showExtra ? (e.Value.ToString() +
" " + e.Name) :
"",
null,
null);
797 flag3 = (num2 <= 1 || textArray.Length <= 2);
802 text =
"isProc".lang(e.Name,
null,
null,
null,
null);
805 else if (categorySub ==
"resist")
807 text = (
"isResist" + (flag3 ?
"Neg" :
"")).lang(e.Name,
null,
null,
null,
null);
809 else if (categorySub ==
"eleAttack")
811 text =
"isEleAttack".lang(e.Name,
null,
null,
null,
null);
813 else if (!e.source.textPhase.IsEmpty() && e.Value > 0)
815 text = e.source.GetText(
"textPhase",
false);
819 string name = e.Name;
820 bool flag6 = e.source.category ==
"skill" || (e.source.category ==
"attribute" && !e.source.textPhase.IsEmpty());
821 bool flag7 = e.source.category ==
"enchant";
822 if (e.source.tag.Contains(
"multiplier"))
824 flag7 = (flag6 =
false);
825 name =
EClass.sources.elements.alias[e.source.aliasRef].GetName();
827 flag2 = (!flag6 && !flag7);
828 text = (flag6 ?
"textEncSkill" : (flag7 ?
"textEncEnc" :
"textEnc")).lang(name, num.ToString() + (e.source.tag.Contains(
"ratio") ?
"%" :
""), ((e.Value > 0) ?
"encIncrease" :
"encDecrease").lang(),
null,
null);
831 if (!flag && !flag2 && !e.source.tag.Contains(
"flag"))
833 text =
string.Concat(
new string[]
837 "*".Repeat(Mathf.Clamp(num * e.source.mtp / 5 + num3, 1, 5)),
838 (num * e.source.mtp / 5 + num3 > 5) ?
"+" :
"",
842 if (e.HasTag(
"hidden"))
844 text =
"(debug)" + text;
846 FontColor color = flag ? FontColor.Default : (flag3 ? FontColor.Bad : FontColor.Good);
847 if (e.IsGlobalElement)
849 text = text +
" " + (e.IsFactionWideElement ?
"_factionWide" :
"_partyWide").lang();
850 if (this.
Card !=
null && !this.
Card.c_idDeity.IsEmpty() &&
this.Card.c_idDeity !=
EClass.pc.idFaith)
854 color = FontColor.Myth;
856 if (flag4 && e.IsFoodTrait && !e.IsFoodTraitMain)
858 color = FontColor.FoodMisc;
860 if (e.id == 2 && e.Value >= 0)
862 color = FontColor.FoodQuality;
864 if (funcText !=
null)
866 text = funcText(e, text);
868 n.AddText(
"NoteText_prefwidth", text, color);
869 if (onAddNote !=
null)
877 n.AddText(e.Name, FontColor.Default);
880 UIItem uiitem = n.AddTopic(
"TopicAttribute", e.Name,
"".TagColor((e.ValueWithoutLink > 0) ? SkinManager.CurrentColors.textGood : SkinManager.CurrentColors.textBad, e.ValueWithoutLink.ToString() ??
""));
883 uiitem.button1.tooltip.onShowTooltip = delegate(UITooltip t)
885 e.WriteNote(t.note,
EClass.pc.elements,
null);
888 e.SetImage(uiitem.image1);
889 Image image = uiitem.image2;
890 int value = (e.Potential - 80) / 20;
891 image.enabled = (e.Potential != 80);
892 image.sprite =
EClass.core.refs.spritesPotential[Mathf.Clamp(Mathf.Abs(value), 0,
EClass.core.refs.spritesPotential.Count - 1)];
893 image.color = ((e.Potential - 80 >= 0) ? Color.white :
new Color(1f, 0.7f, 0.7f));
899 public void AddNoteAll(UINote n)
901 Transform transform = n.AddExtra<Transform>(
"noteRace");
902 UINote n2 = transform.Find(
"note1").GetComponent<UINote>();
903 UINote n3 = transform.Find(
"note2").GetComponent<UINote>();
904 this.AddNote(n3, (
Element e) => e.HasTag(
"primary"), delegate
906 n3.AddHeader(
"HeaderNoteSmall",
"attributes", null);
908 this.AddNote(n2, (
Element e) => e.source.category ==
"skill" && !e.HasTag(
"hidden") && e.ValueWithoutLink > 1 && e.source.categorySub !=
"weapon", delegate
910 n2.AddHeader(
"HeaderNoteSmall",
"skills", null);
912 this.AddNote(n2, (
Element e) => e is
Feat, delegate
914 n2.AddHeader(
"HeaderNoteSmall",
"feats",
null);
922 if (container ==
null)
926 foreach (
Element element
in container.dict.Values)
929 foreach (
Element element2
in A_1.eles)
931 if (element.id == element2.id)
937 if (flag && element.Value != 0)
939 A_1.eles.Add(element);
945 public Dictionary<int, Element> dict =
new Dictionary<int, Element>();
951 public const int sizeElement = 5;
954 [JsonProperty(PropertyName =
"A")]
955 public List<int> list;