declare Burns -> RenderSimple dep; remove first tick weirdness

This commit is contained in:
Chris Forbes
2011-07-17 17:01:08 +12:00
parent 4a0b7bb003
commit 8221b8acca

View File

@@ -13,35 +13,37 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class BurnsInfo : TraitInfo<Burns>
class BurnsInfo : ITraitInfo, Requires<RenderSimpleInfo>
{
public readonly string Anim = "1";
public readonly int Damage = 1;
public readonly int Interval = 8;
public object Create(ActorInitializer init) { return new Burns(init.self, this); }
}
class Burns : ITick, ISync
{
[Sync]
int ticks;
bool isSetup;
BurnsInfo Info;
public Burns(Actor self, BurnsInfo info)
{
Info = info;
var rs = self.Trait<RenderSimple>();
var anim = new Animation("fire", () => 0);
anim.PlayRepeating(Info.Anim);
rs.anims.Add("fire",
new AnimationWithOffset(anim, () => new float2(0, -3), null));
}
public void Tick(Actor self)
{
if (!isSetup)
{
isSetup = true;
var anim = new Animation("fire", () => 0);
anim.PlayRepeating(self.Info.Traits.Get<BurnsInfo>().Anim);
self.Trait<RenderSimple>().anims.Add("fire",
new AnimationWithOffset(anim, () => new float2(0, -3), null));
}
if (--ticks <= 0)
{
self.InflictDamage(self, self.Info.Traits.Get<BurnsInfo>().Damage, null);
ticks = self.Info.Traits.Get<BurnsInfo>().Interval;
self.InflictDamage(self, Info.Damage, null);
ticks = Info.Interval;
}
}
}