SelfHealing trait
This commit is contained in:
@@ -244,6 +244,7 @@
|
|||||||
<Compile Include="Traits\Repairable.cs" />
|
<Compile Include="Traits\Repairable.cs" />
|
||||||
<Compile Include="Traits\Reservable.cs" />
|
<Compile Include="Traits\Reservable.cs" />
|
||||||
<Compile Include="Traits\Selectable.cs" />
|
<Compile Include="Traits\Selectable.cs" />
|
||||||
|
<Compile Include="Traits\SelfHealing.cs" />
|
||||||
<Compile Include="Traits\Spy.cs" />
|
<Compile Include="Traits\Spy.cs" />
|
||||||
<Compile Include="Traits\SquishByTank.cs" />
|
<Compile Include="Traits\SquishByTank.cs" />
|
||||||
<Compile Include="Traits\Plane.cs" />
|
<Compile Include="Traits\Plane.cs" />
|
||||||
|
|||||||
37
OpenRa.Game/Traits/SelfHealing.cs
Normal file
37
OpenRa.Game/Traits/SelfHealing.cs
Normal 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"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user