openclonk/planet/System.ocg/Heal.c

40 lines
835 B
C
Raw Permalink Normal View History

2015-10-27 18:10:13 +00:00
/**
Heal.c
Function to heal livings over time.
@author Armin
2015-10-27 18:10:13 +00:00
*/
/**
Heals the object over time for /amount/ HP.
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.
2015-10-27 18:10:13 +00:00
*/
global func Heal(int amount, int interval)
2015-10-27 18:10:13 +00:00
{
AssertObjectContext();
2015-10-27 18:10:13 +00:00
// Add effect.
var fx = CreateEffect(FxHealingOverTime, 1, interval ?? 36);
2015-10-27 18:10:13 +00:00
fx.healing_amount = amount;
fx.done = 0;
return fx;
}
static const FxHealingOverTime = new Effect
2015-10-27 18:10:13 +00:00
{
Timer = func ()
{
// Stop healing the Clonk if he reached full health.
if (Target->GetEnergy() >= Target->GetMaxEnergy() || this.done >= this.healing_amount)
{
return FX_Execute_Kill;
}
Target->DoEnergy(1);
++this.done;
return FX_OK;
}
};