Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void PassionUpdate(Pawn pawn)
- {
- // changing passion to fit pawn traits
- IDictionary<SkillDef, float> skilldictionary = new Dictionary<SkillDef, float>();
- foreach (var trs in pawn.story.traits.allTraits)
- {
- //skilloffsets
- TraitDegreeData currentData = trs.CurrentData;
- if (currentData.statOffsets != null)
- {
- for (int i = 0; i < currentData.statOffsets.Count; i++)
- {
- if (currentData.statOffsets[i] != null && currentData.statOffsets[i].stat != null)
- {
- //skillneedfactors
- if (currentData.statOffsets[i].stat.skillNeedFactors != null && currentData.statOffsets[i].stat.skillNeedFactors.Count > 0)
- {
- foreach (var snl in currentData.statOffsets[i].stat.skillNeedFactors)
- {
- if (snl.skill != null)
- {
- float iv = TraitUtility.passionvalue(currentData.statOffsets[i].value);
- if (skilldictionary.ContainsKey(snl.skill))
- {
- float oiv;
- skilldictionary.TryGetValue(snl.skill, out oiv);
- if (oiv < 2 && oiv >= 0)
- {
- float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
- skilldictionary.Remove(snl.skill);
- skilldictionary.Add(new KeyValuePair<SkillDef, float>(snl.skill, newvalue));
- }
- }
- else
- {
- float fixediv = Mathf.Clamp(iv, 0, 2);
- skilldictionary.Add(new KeyValuePair<SkillDef, float>(snl.skill, fixediv));
- }
- }
- }
- }
- //skillneedoffsets
- if (currentData.statOffsets[i].stat.skillNeedOffsets != null && currentData.statOffsets[i].stat.skillNeedOffsets.Count > 0)
- {
- foreach (var sno in currentData.statOffsets[i].stat.skillNeedOffsets)
- {
- if (sno.skill != null)
- {
- float iv = TraitUtility.passionvalue(currentData.statOffsets[i].value);
- if (skilldictionary.ContainsKey(sno.skill))
- {
- float oiv;
- skilldictionary.TryGetValue(sno.skill, out oiv);
- if (oiv < 2 && oiv >= 0)
- {
- float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
- skilldictionary.Remove(sno.skill);
- skilldictionary.Add(new KeyValuePair<SkillDef, float>(sno.skill, newvalue));
- }
- }
- else
- {
- float fixediv = Mathf.Clamp(iv, 0, 2);
- skilldictionary.Add(new KeyValuePair<SkillDef, float>(sno.skill, fixediv));
- }
- }
- }
- }
- }
- }
- }
- // skillgains
- if (currentData.skillGains != null)
- {
- foreach (var sgs in currentData.skillGains)
- {
- var ski = sgs.Key;
- if (ski != null)
- {
- float iv = TraitUtility.passionvalue(sgs.Value);
- if (skilldictionary.ContainsKey(ski))
- {
- float oiv;
- skilldictionary.TryGetValue(ski, out oiv);
- if (oiv < 2 && oiv >= 0)
- {
- float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
- skilldictionary.Remove(ski);
- skilldictionary.Add(new KeyValuePair<SkillDef, float>(ski, newvalue));
- }
- }
- else
- {
- float fixediv = Mathf.Clamp(iv, 0, 2);
- skilldictionary.Add(new KeyValuePair<SkillDef, float>(ski, fixediv));
- }
- }
- }
- }
- }
- if (skilldictionary.Count > 0)
- {
- foreach (var mskill in skilldictionary)
- {
- var pawnskills = pawn.skills.skills;
- foreach (var pss in pawnskills)
- {
- if (mskill.Key == pss.def)
- {
- if (!pss.TotallyDisabled)
- {
- pss.passion = TraitUtility.passion(mskill.Value);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment