Guest User

Untitled

a guest
Jun 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. public static void PassionUpdate(Pawn pawn)
  2. {
  3. // changing passion to fit pawn traits
  4. IDictionary<SkillDef, float> skilldictionary = new Dictionary<SkillDef, float>();
  5. foreach (var trs in pawn.story.traits.allTraits)
  6. {
  7. //skilloffsets
  8. TraitDegreeData currentData = trs.CurrentData;
  9. if (currentData.statOffsets != null)
  10. {
  11. for (int i = 0; i < currentData.statOffsets.Count; i++)
  12. {
  13. if (currentData.statOffsets[i] != null && currentData.statOffsets[i].stat != null)
  14. {
  15. //skillneedfactors
  16. if (currentData.statOffsets[i].stat.skillNeedFactors != null && currentData.statOffsets[i].stat.skillNeedFactors.Count > 0)
  17. {
  18. foreach (var snl in currentData.statOffsets[i].stat.skillNeedFactors)
  19. {
  20. if (snl.skill != null)
  21. {
  22. float iv = TraitUtility.passionvalue(currentData.statOffsets[i].value);
  23. if (skilldictionary.ContainsKey(snl.skill))
  24. {
  25. float oiv;
  26. skilldictionary.TryGetValue(snl.skill, out oiv);
  27. if (oiv < 2 && oiv >= 0)
  28. {
  29. float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
  30. skilldictionary.Remove(snl.skill);
  31. skilldictionary.Add(new KeyValuePair<SkillDef, float>(snl.skill, newvalue));
  32. }
  33. }
  34. else
  35. {
  36. float fixediv = Mathf.Clamp(iv, 0, 2);
  37. skilldictionary.Add(new KeyValuePair<SkillDef, float>(snl.skill, fixediv));
  38. }
  39. }
  40. }
  41. }
  42.  
  43. //skillneedoffsets
  44. if (currentData.statOffsets[i].stat.skillNeedOffsets != null && currentData.statOffsets[i].stat.skillNeedOffsets.Count > 0)
  45. {
  46. foreach (var sno in currentData.statOffsets[i].stat.skillNeedOffsets)
  47. {
  48. if (sno.skill != null)
  49. {
  50. float iv = TraitUtility.passionvalue(currentData.statOffsets[i].value);
  51. if (skilldictionary.ContainsKey(sno.skill))
  52. {
  53. float oiv;
  54. skilldictionary.TryGetValue(sno.skill, out oiv);
  55. if (oiv < 2 && oiv >= 0)
  56. {
  57. float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
  58. skilldictionary.Remove(sno.skill);
  59. skilldictionary.Add(new KeyValuePair<SkillDef, float>(sno.skill, newvalue));
  60. }
  61. }
  62. else
  63. {
  64. float fixediv = Mathf.Clamp(iv, 0, 2);
  65. skilldictionary.Add(new KeyValuePair<SkillDef, float>(sno.skill, fixediv));
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. // skillgains
  74. if (currentData.skillGains != null)
  75. {
  76. foreach (var sgs in currentData.skillGains)
  77. {
  78. var ski = sgs.Key;
  79. if (ski != null)
  80. {
  81. float iv = TraitUtility.passionvalue(sgs.Value);
  82. if (skilldictionary.ContainsKey(ski))
  83. {
  84. float oiv;
  85. skilldictionary.TryGetValue(ski, out oiv);
  86. if (oiv < 2 && oiv >= 0)
  87. {
  88. float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
  89. skilldictionary.Remove(ski);
  90. skilldictionary.Add(new KeyValuePair<SkillDef, float>(ski, newvalue));
  91. }
  92. }
  93. else
  94. {
  95. float fixediv = Mathf.Clamp(iv, 0, 2);
  96. skilldictionary.Add(new KeyValuePair<SkillDef, float>(ski, fixediv));
  97. }
  98. }
  99. }
  100. }
  101. }
  102. if (skilldictionary.Count > 0)
  103. {
  104. foreach (var mskill in skilldictionary)
  105. {
  106. var pawnskills = pawn.skills.skills;
  107. foreach (var pss in pawnskills)
  108. {
  109. if (mskill.Key == pss.def)
  110. {
  111. if (!pss.TotallyDisabled)
  112. {
  113. pss.passion = TraitUtility.passion(mskill.Value);
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
Add Comment
Please, Sign In to add comment