call DoAttack from activities instead of from Tick in AttackPlane/AttackHeli
This commit is contained in:
@@ -14,24 +14,39 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class FlyAttack : CancelableActivity
|
||||
{
|
||||
Target Target;
|
||||
readonly Target Target;
|
||||
IActivity inner;
|
||||
|
||||
public FlyAttack(Target target) { Target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
if( !Target.IsValid )
|
||||
Cancel( self );
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
|
||||
return NextActivity;
|
||||
if( limitedAmmo != null && !limitedAmmo.HasAmmo() )
|
||||
Cancel( self );
|
||||
|
||||
return Util.SequenceActivities(
|
||||
self.Trait<AttackPlane>().DoAttack( self );
|
||||
|
||||
if( IsCanceled && inner == null ) return NextActivity;
|
||||
|
||||
if( inner == null )
|
||||
{
|
||||
inner = Util.SequenceActivities(
|
||||
Fly.ToPx(Target.CenterLocation),
|
||||
new FlyTimed(50),
|
||||
this);
|
||||
new FlyTimed(50));
|
||||
}
|
||||
inner = inner.Tick( self );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override bool OnCancel( Actor self )
|
||||
{
|
||||
if( inner != null )
|
||||
inner.Cancel( self );
|
||||
return base.OnCancel( self );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
var range = self.Trait<AttackBase>().GetMaximumRange() - 1;
|
||||
var attack = self.Trait<AttackBase>();
|
||||
var range = attack.GetMaximumRange() - 1;
|
||||
var dist = target.CenterLocation - self.CenterLocation;
|
||||
|
||||
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
|
||||
@@ -49,6 +50,8 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
|
||||
aircraft.center += (rawSpeed / dist.Length) * dist;
|
||||
|
||||
attack.DoAttack( self );
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,18 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
readonly int FacingTolerance;
|
||||
|
||||
public override void Tick(Actor self)
|
||||
protected override bool CanAttack( Actor self )
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
if (!target.IsValid) return;
|
||||
if( !base.CanAttack( self ) )
|
||||
return false;
|
||||
|
||||
var facing = self.Trait<IFacing>().Facing;
|
||||
var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, facing);
|
||||
|
||||
if (Math.Abs(facingToTarget - facing) % 256 < FacingTolerance)
|
||||
DoAttack(self);
|
||||
if( Math.Abs( facingToTarget - facing ) % 256 >= FacingTolerance )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user