Heal: Updated to new effect format, added variable interval

The healing interval defaults to the old fixed value.
install-platforms
Mark 2017-06-28 19:32:51 +02:00
parent 42b6e1f69c
commit 6208d99b98
1 changed files with 20 additions and 10 deletions

View File

@ -8,22 +8,32 @@
/** /**
Heals the object over time for /amount/ HP. Heals the object over time for /amount/ HP.
Calling the function multiple times results in faster healing (as opposed to longer healing). Calling the function multiple times results in faster healing (as opposed to longer healing).
If necessary, a custom interval can be set. The healing effect restores 1 energy per interval.
*/ */
global func Heal(int amount) global func Heal(int amount, int interval)
{ {
AssertObjectContext();
// Add effect. // Add effect.
var fx = this->AddEffect("HealingOverTime", this, 1, 36); var fx = CreateEffect(FxHealingOverTime, 1, interval ?? 36);
fx.healing_amount = amount; fx.healing_amount = amount;
fx.done = 0; fx.done = 0;
return fx; return fx;
} }
global func FxHealingOverTimeTimer(object target, effect fx)
static const FxHealingOverTime = new Effect
{ {
// Stop healing the Clonk if he reached full health. Timer = func ()
if (target->GetEnergy() >= target.MaxEnergy/1000 || fx.done >= fx.healing_amount) {
return -1; // Stop healing the Clonk if he reached full health.
target->DoEnergy(1); if (Target->GetEnergy() >= Target->GetMaxEnergy() || this.done >= this.healing_amount)
fx.done++; {
return FX_OK; return FX_Execute_Kill;
} }
Target->DoEnergy(1);
++this.done;
return FX_OK;
}
};