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(SkillInfo child, SkillInfo potentialParent)
- {
- //require skills to belong here
- if (child == null || potentialParent == null || !Talents.Contains(child) || !Talents.Contains(potentialParent)) return false;
- if (child == potentialParent) return false;
- SkillInfo 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(SkillInfo skill)
- {
- if (skill.CurLevel <= 0) return false;
- //make sure the integrity will be intact
- int specTreeSP = 0;
- foreach (SkillInfo s in Talents)
- {
- if (!IsSkillDescended(s, skill)) specCost += (int)s.totalCost[s.CurLevel];
- }
- //now remove the final level cost
- specTreeSP -= (int)skill.cost[skill.CurLevel];
- foreach (SkillInfo s in Talents.Where((SkillInfo x) => x.CurLevel > 0))
- {
- //make sure that we can still afford this skill
- //and we won't get a broken level
- if (s.spRequirement > specTreeSP
- || (s.prerequisite == skill && skill.CurLevel == 1))
- return false;
- }
- //it's a valid downgrade
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement