Advertisement
Guest User

Downgrading Skills

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 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(SkillInfo child, SkillInfo 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.     SkillInfo 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(SkillInfo skill)
  25. {
  26.     if (skill.CurLevel <= 0) return false;
  27.  
  28.     //make sure the integrity will be intact
  29.     int specTreeSP = 0;
  30.     foreach (SkillInfo s in Talents)
  31.     {
  32.         if (!IsSkillDescended(s, skill)) specCost += (int)s.totalCost[s.CurLevel];
  33.     }
  34.     //now remove the final level cost
  35.     specTreeSP -= (int)skill.cost[skill.CurLevel];
  36.  
  37.     foreach (SkillInfo s in Talents.Where((SkillInfo x) => x.CurLevel > 0))
  38.     {
  39.         //make sure that we can still afford this skill
  40.         //and we won't get a broken level
  41.         if (s.spRequirement > specTreeSP
  42.         || (s.prerequisite == skill && skill.CurLevel == 1))
  43.             return false;
  44.     }
  45.  
  46.     //it's a valid downgrade
  47.     return true;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement