Move unwanted AttackBase logic to the individual Armaments.

This commit is contained in:
Paul Chote
2014-03-17 11:14:09 +13:00
parent b31240ccc5
commit 0ca7ee280f
7 changed files with 59 additions and 55 deletions

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA
public abstract object Create(ActorInitializer init);
}
public abstract class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier, IOrderVoice, ISync
public abstract class AttackBase : IIssueOrder, IResolveOrder, IOrderVoice, ISync
{
[Sync] public bool IsAttacking { get; internal set; }
@@ -35,7 +35,6 @@ namespace OpenRA.Mods.RA
protected Lazy<IFacing> facing;
Lazy<IEnumerable<Armament>> armaments;
protected IEnumerable<Armament> Armaments { get { return armaments.Value; } }
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
public AttackBase(Actor self, AttackBaseInfo info)
{
@@ -63,38 +62,13 @@ namespace OpenRA.Mods.RA
return true;
}
public bool ShouldExplode(Actor self) { return !IsReloading(); }
public bool IsReloading() { return Armaments.Any(a => a.IsReloading); }
public virtual void Tick(Actor self)
{
for (var i = 0; i < delayedActions.Count; i++)
{
var x = delayedActions[i];
if (--x.First <= 0)
x.Second();
delayedActions[i] = x;
}
delayedActions.RemoveAll(a => a.First <= 0);
}
internal void ScheduleDelayedAction(int t, Action a)
{
if (t > 0)
delayedActions.Add(Pair.New(t, a));
else
a();
}
public virtual void DoAttack(Actor self, Target target)
{
if (!CanAttack(self, target))
return;
foreach (var a in Armaments)
a.CheckFire(self, this, facing.Value, target);
a.CheckFire(self, facing.Value, target);
}
public IEnumerable<IOrderTargeter> Orders

View File

@@ -41,12 +41,10 @@ namespace OpenRA.Mods.RA
charges = aci.MaxCharges;
}
public override void Tick(Actor self)
public void Tick(Actor self)
{
if (--timeToRecharge <= 0)
charges = aci.MaxCharges;
base.Tick(self);
}
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
var facing = self.TraitOrDefault<IFacing>();
foreach (var a in Armaments)
a.CheckFire(self, this, facing, target);
a.CheckFire(self, facing, target);
if (target.Actor != null)
target.Actor.ChangeOwner(self.Owner);

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA
public override object Create(ActorInitializer init) { return new AttackTurreted(init.self, this); }
}
class AttackTurreted : AttackBase, INotifyBuildComplete, ISync
class AttackTurreted : AttackBase, ITick, INotifyBuildComplete, ISync
{
public Target Target { get; protected set; }
protected IEnumerable<Turreted> turrets;
@@ -53,9 +53,8 @@ namespace OpenRA.Mods.RA
return base.CanAttack(self, target);
}
public override void Tick(Actor self)
public void Tick(Actor self)
{
base.Tick(self);
DoAttack(self, Target);
IsAttacking = Target.IsValidFor(self);
}