Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Determines if the first skill is parented by the second
- /// </summary>
- /// <param name="child"></param>
- /// <param name="potentialParent"></param>
- /// <returns></returns>
- public bool IsSkillDescended(Skill child, Skill potentialParent)
- {
- //require skills to belong here
- if (child == null || potentialParent == null || !Talents.Contains(child) || !Talents.Contains(potentialParent)) return false;
- if (child == potentialParent) return false;
- Skill s = child;
- while (s.prerequisite != null && s.prerequisite != potentialParent) s = s.prerequisite;
- return s.prerequisite == potentialParent;
- }
- /// <summary>
- /// Attempts to lower the level of a skill.
- /// Will fail if the skill cannot be lowered validly.
- /// </summary>
- /// <param name="skill"></param>
- /// <returns></returns>
- public bool CanDowngradeSkill(Skill skill)
- {
- if (skill.CurLevel <= 0) return false;
- foreach (Skill s in Skills.Where((Skill x) => x.CurLevel > 0))
- {
- //can't close off a skill with live children
- if (IsSkillDescended(s, skill) && skill.CurLevel == 1) return false;
- //calculate the cost of every non-descendant at a lower req
- int specCost = 0;
- foreach (Skill k in Skills.Where((Skill x) => !IsSkillDescended(x, s) && x.spRequirement < s.spRequirement))
- {
- specCost += k.totalCost[k.CurLevel];
- }
- if (specCost < s.spRequirement) return false;
- }
- //it's a valid downgrade
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement