Gen7Data/Scripts/Pokemon/HealEachEndOfTurn.as

38 lines
1.1 KiB
ActionScript

namespace Gen7 {
[Pokemon effect=HealEachEndOfTurn]
shared class HealEachEndOfTurnEffect : PkmnScript {
float _factor;
void OnEndTurn() override {
auto target = cast<Pokemon@>(GetOwner());
if (target is null){
throw("target was null");
}
auto healAmount = target.MaxHealth * _factor;
if (target.HasHeldItem("big_root")){
healAmount *= 1.3;
}
target.Heal(uint(healAmount));
}
void SetBaseHealAmount(float factor){
_factor = factor;
}
}
}
#if TESTS
[Test name="Heal Each End Of Turn effect: Heals on end of turn"]
void HealEachEndOfTurn_HealsOnEndOfTurn(){
auto battle = CreateSimpleBattle(0, "charizard", "venusaur", 100);
auto mon = battle.GetParty(0).Party.GetAtIndex(0);
mon.Damage(100, DamageSource::AttackDamage);
auto effect = cast<Gen7::HealEachEndOfTurnEffect@>(mon.AddVolatile("HealEachEndOfTurn"));
effect.SetBaseHealAmount(0.0625);
effect.OnEndTurn();
RequireEquals(215, mon.CurrentHealth);
}
#endif