Start unbreaking ScaredyCat

This commit is contained in:
Scott_NZ
2013-01-01 15:30:56 +13:00
parent 3b9fac9c84
commit 11c45e4388
4 changed files with 64 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
@@ -15,26 +15,66 @@ namespace OpenRA.Mods.RA
{
class ScaredyCatInfo : ITraitInfo
{
public readonly int MoveRadius = 2;
public readonly int PanicLength = 25 * 10;
public readonly decimal PanicSpeedModifier = 2;
public readonly int AttackPanicChance = 20;
public object Create(ActorInitializer init) { return new ScaredyCat(init.self, this); }
}
class ScaredyCat : INotifyIdle, INotifyDamage
class ScaredyCat : ITick, INotifyIdle, INotifyDamage, INotifyAttack, ISpeedModifier
{
readonly ScaredyCatInfo Info;
public bool Panicked = false;
readonly Actor Self;
public ScaredyCat(Actor self, ScaredyCatInfo info) { Info = info; }
public int PanicStartedTick;
public bool Panicking { get { return PanicStartedTick > 0; } }
public ScaredyCat(Actor self, ScaredyCatInfo info)
{
Self = self;
Info = info;
}
public void Panic()
{
if (!Panicking)
Self.CancelActivity();
PanicStartedTick = Self.World.FrameNumber;
}
public void Tick(Actor self)
{
if (!Panicking) return;
if (self.World.FrameNumber >= PanicStartedTick + Info.PanicLength)
{
self.CancelActivity();
PanicStartedTick = 0;
}
}
public void TickIdle(Actor self)
{
if (!Panicked) return;
if (!Panicking) return;
var target = ( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius ).ToPVecInt().ToCVec() + self.Location;
self.Trait<Mobile>().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target });
self.Trait<Mobile>().Nudge(self, self, true);
}
public void Damaged(Actor self, AttackInfo e) { Panicked = true; }
public void Damaged(Actor self, AttackInfo e)
{
Panic();
}
public void Attacking(Actor self, Target target)
{
if (self.World.SharedRandom.Next(100 / Info.AttackPanicChance) == 0)
Panic();
}
public decimal GetSpeedModifier()
{
return Panicking ? Info.PanicSpeedModifier : 1;
}
}
}