7 internal sealed
class AbilityConditionHasLevel : AbilityConditionDataless
9 private readonly Option<int> matchedLevel;
10 private readonly Option<int> minLevel;
11 private readonly Option<int> maxLevel;
13 public AbilityConditionHasLevel(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
15 matchedLevel = conditionElement.GetAttributeInt(
"levelequals", 0) is var match and not 0
16 ? Option<int>.Some(match)
19 minLevel = conditionElement.GetAttributeInt(
"minlevel", 0) is var min and not 0
20 ? Option<int>.Some(min)
23 maxLevel = conditionElement.GetAttributeInt(
"maxlevel", 0) is var max and not 0
24 ? Option<int>.Some(max)
27 if (matchedLevel.IsNone() && minLevel.IsNone() && maxLevel.IsNone())
29 throw new Exception($
"{nameof(AbilityConditionHasLevel)} must have either \"levelequals\", \"minlevel\" or \"maxlevel\" attribute.");
33 protected override bool MatchesConditionSpecific()
36 if (matchedLevel.TryUnwrap(out
int match))
38 return currentLevel == match;
41 if (minLevel.TryUnwrap(out
int min))
43 return currentLevel >= min;
46 if (maxLevel.TryUnwrap(out
int max))
48 return currentLevel <= max;