Advertisement
Guest User

Fixed TT2 Skill Downgrading

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. /// <summary>
  2. /// Determines if the first skill is parented by the second
  3. /// </summary>
  4. /// <param name="child"></param>
  5. /// <param name="potentialParent"></param>
  6. /// <returns></returns>
  7. public bool IsSkillDescended(Skill child, Skill potentialParent)
  8. {
  9.     //require skills to belong here
  10.     if (child == null || potentialParent == null || !Talents.Contains(child) || !Talents.Contains(potentialParent)) return false;
  11.     if (child == potentialParent) return false;
  12.  
  13.     Skill s = child;
  14.     while (s.prerequisite != null && s.prerequisite != potentialParent) s = s.prerequisite;
  15.     return s.prerequisite == potentialParent;
  16. }
  17.  
  18. /// <summary>
  19. /// Attempts to lower the level of a skill.
  20. /// Will fail if the skill cannot be lowered validly.
  21. /// </summary>
  22. /// <param name="skill"></param>
  23. /// <returns></returns>
  24. public bool CanDowngradeSkill(Skill skill)
  25. {
  26.     if (skill.CurLevel <= 0) return false;
  27.  
  28.     foreach (Skill s in Skills.Where((Skill x) => x.CurLevel > 0))
  29.     {
  30.         //can't close off a skill with live children
  31.         if (IsSkillDescended(s, skill) && skill.CurLevel == 1) return false;
  32.  
  33.         //calculate the cost of every non-descendant at a lower req
  34.         int specCost = 0;
  35.         foreach (Skill k in Skills.Where((Skill x) => !IsSkillDescended(x, s) && x.spRequirement < s.spRequirement))
  36.         {
  37.             specCost += k.totalCost[k.CurLevel];
  38.         }
  39.         if (specCost < s.spRequirement) return false;
  40.     }
  41.            
  42.     //it's a valid downgrade
  43.     return true;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement