Guest User

Untitled

a guest
Jun 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. using Verse;
  7. using Verse.AI;
  8. using Verse.Sound;
  9. using RimWorld;
  10.  
  11. namespace SK
  12. {
  13. public static class TraitUtility
  14. {
  15. public static void PassionUpdate(Pawn pawn)
  16. {
  17. // changing passion to fit pawn traits
  18. IDictionary<SkillDef, float> skilldictionary = new Dictionary<SkillDef, float>();
  19. foreach (var trs in pawn.story.traits.allTraits)
  20. {
  21. //skilloffsets
  22. TraitDegreeData currentData = trs.CurrentData;
  23. if (currentData.statOffsets != null)
  24. {
  25. for (int i = 0; i < currentData.statOffsets.Count; i++)
  26. {
  27. if (currentData.statOffsets[i] != null && currentData.statOffsets[i].stat != null)
  28. {
  29. //skillneedfactors
  30. if (currentData.statOffsets[i].stat.skillNeedFactors != null && currentData.statOffsets[i].stat.skillNeedFactors.Count > 0)
  31. {
  32. foreach (var snl in currentData.statOffsets[i].stat.skillNeedFactors)
  33. {
  34. if (snl.skill != null)
  35. {
  36. float iv = TraitUtility.passionvalue(currentData.statOffsets[i].value);
  37. if (skilldictionary.ContainsKey(snl.skill))
  38. {
  39. float oiv;
  40. skilldictionary.TryGetValue(snl.skill, out oiv);
  41. if (oiv < 2 && oiv >= 0)
  42. {
  43. float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
  44. skilldictionary.Remove(snl.skill);
  45. skilldictionary.Add(new KeyValuePair<SkillDef, float>(snl.skill, newvalue));
  46. }
  47. }
  48. else
  49. {
  50. float fixediv = Mathf.Clamp(iv, 0, 2);
  51. skilldictionary.Add(new KeyValuePair<SkillDef, float>(snl.skill, fixediv));
  52. }
  53. }
  54. }
  55. }
  56.  
  57. //skillneedoffsets
  58. if (currentData.statOffsets[i].stat.skillNeedOffsets != null && currentData.statOffsets[i].stat.skillNeedOffsets.Count > 0)
  59. {
  60. foreach (var sno in currentData.statOffsets[i].stat.skillNeedOffsets)
  61. {
  62. if (sno.skill != null)
  63. {
  64. float iv = TraitUtility.passionvalue(currentData.statOffsets[i].value);
  65. if (skilldictionary.ContainsKey(sno.skill))
  66. {
  67. float oiv;
  68. skilldictionary.TryGetValue(sno.skill, out oiv);
  69. if (oiv < 2 && oiv >= 0)
  70. {
  71. float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
  72. skilldictionary.Remove(sno.skill);
  73. skilldictionary.Add(new KeyValuePair<SkillDef, float>(sno.skill, newvalue));
  74. }
  75. }
  76. else
  77. {
  78. float fixediv = Mathf.Clamp(iv, 0, 2);
  79. skilldictionary.Add(new KeyValuePair<SkillDef, float>(sno.skill, fixediv));
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. // skillgains
  88. if (currentData.skillGains != null)
  89. {
  90. foreach (var sgs in currentData.skillGains)
  91. {
  92. var ski = sgs.Key;
  93. if (ski != null)
  94. {
  95. float iv = TraitUtility.passionvalue(sgs.Value);
  96. if (skilldictionary.ContainsKey(ski))
  97. {
  98. float oiv;
  99. skilldictionary.TryGetValue(ski, out oiv);
  100. if (oiv < 2 && oiv >= 0)
  101. {
  102. float newvalue = Mathf.Clamp(oiv + iv, 0, 2);
  103. skilldictionary.Remove(ski);
  104. skilldictionary.Add(new KeyValuePair<SkillDef, float>(ski, newvalue));
  105. }
  106. }
  107. else
  108. {
  109. float fixediv = Mathf.Clamp(iv, 0, 2);
  110. skilldictionary.Add(new KeyValuePair<SkillDef, float>(ski, fixediv));
  111. }
  112. }
  113. }
  114. }
  115. }
  116. if (skilldictionary.Count > 0)
  117. {
  118. foreach (var mskill in skilldictionary)
  119. {
  120. var pawnskills = pawn.skills.skills;
  121. foreach (var pss in pawnskills)
  122. {
  123. if (mskill.Key == pss.def)
  124. {
  125. if (!pss.TotallyDisabled)
  126. {
  127. pss.passion = TraitUtility.passion(mskill.Value);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134.  
  135. public static Passion passion(float f)
  136. {
  137. if (f == 1)
  138. {
  139. return Passion.Minor;
  140. }
  141. if (f == 2)
  142. {
  143. return Passion.Major;
  144. }
  145. return Passion.None;
  146. }
  147.  
  148. public static float passionvalue(float v)
  149. {
  150. float iv = 0;
  151. if (v > 0)
  152. {
  153. iv += 1;
  154. }
  155. if (v < 0)
  156. {
  157. iv -= 1;
  158. }
  159. if (v == 0)
  160. {
  161. iv = 0;
  162. }
  163. return iv;
  164. }
  165. }
  166. }
Add Comment
Please, Sign In to add comment