SelfHealing trait

This commit is contained in:
Chris Forbes
2010-01-16 11:30:31 +13:00
parent b0fed3be91
commit 3521f1cc45
2 changed files with 38 additions and 0 deletions

View File

@@ -244,6 +244,7 @@
<Compile Include="Traits\Repairable.cs" />
<Compile Include="Traits\Reservable.cs" />
<Compile Include="Traits\Selectable.cs" />
<Compile Include="Traits\SelfHealing.cs" />
<Compile Include="Traits\Spy.cs" />
<Compile Include="Traits\SquishByTank.cs" />
<Compile Include="Traits\Plane.cs" />

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class SelfHealingInfo : ITraitInfo
{
public readonly int Step = 5;
public readonly int Ticks = 5;
public readonly float HealIfBelow = .5f;
public object Create(Actor self) { return new SelfHealing(); }
}
class SelfHealing : ITick
{
int ticks;
public void Tick(Actor self)
{
var info = self.Info.Traits.Get<SelfHealingInfo>();
if ((float)self.Health / self.GetMaxHP() >= info.HealIfBelow)
return;
if (--ticks <= 0)
{
ticks = info.Ticks;
self.InflictDamage(self, -info.Step, Rules.WarheadInfo["Super"]);
}
}
}
}