3 internal sealed
class CharacterAbilityGiveExperience : CharacterAbility
5 public override bool AppliesEffectOnIntervalUpdate =>
true;
7 private readonly
int amount;
8 private readonly
int level;
10 public CharacterAbilityGiveExperience(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
12 amount = abilityElement.GetAttributeInt(
"amount", 0);
13 level = abilityElement.GetAttributeInt(
"level", 0);
15 if (amount == 0 && level == 0)
17 DebugConsole.ThrowError($
"Error in talent {CharacterTalent.DebugIdentifier} - no exp amount or level defined in {nameof(CharacterAbilityGiveExperience)}.",
18 contentPackage: abilityElement.ContentPackage);
20 if (amount > 0 && level > 0)
22 DebugConsole.ThrowError($
"Error in talent {CharacterTalent.DebugIdentifier} - {nameof(CharacterAbilityGiveExperience)} defines both an exp amount and a level.",
23 contentPackage: abilityElement.ContentPackage);
27 private void ApplyEffectSpecific(Character targetCharacter)
31 targetCharacter.Info?.GiveExperience(targetCharacter.Info.GetExperienceRequiredForLevel(level) + amount);
35 targetCharacter.Info?.GiveExperience(amount);
39 protected override void ApplyEffect(AbilityObject abilityObject)
41 if (abilityObject is AbilityCharacterKill { Killer: { } killer })
43 ApplyEffectSpecific(killer);
45 else if ((abilityObject as IAbilityCharacter)?.Character is { } targetCharacter)
47 ApplyEffectSpecific(targetCharacter);
51 ApplyEffectSpecific(Character);
55 protected override void ApplyEffect()
57 ApplyEffectSpecific(Character);