fix tesla animations and firing at multiple targets

This commit is contained in:
Bob
2010-11-14 16:35:53 +13:00
parent e7a07ea9c3
commit f4e04ece12
2 changed files with 39 additions and 25 deletions

View File

@@ -11,6 +11,7 @@
using System;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Mods.RA.Activities;
namespace OpenRA.Mods.RA
{
@@ -32,44 +33,58 @@ namespace OpenRA.Mods.RA
charges = self.Info.Traits.Get<AttackTeslaInfo>().MaxCharges;
}
protected override bool CanAttack( Actor self, Target target )
{
return base.CanAttack( self, target ) && ( charges > 0 );
}
public override void Tick( Actor self )
{
if( --timeToRecharge <= 0 )
charges = self.Info.Traits.Get<AttackTeslaInfo>().MaxCharges;
if( charges <= 0 )
{
foreach( var w in Weapons )
w.FireDelay = Math.Max( w.FireDelay, timeToRecharge );
previousTarget = null;
}
base.Tick( self );
}
Actor previousTarget;
public override int FireDelay( Actor self, Target target, AttackBaseInfo info )
{
return target.Actor == previousTarget ? 3 : base.FireDelay(self, target, info);
}
public void Attacking(Actor self, Target target)
{
foreach (var w in Weapons)
w.FireDelay = 8;
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime;
--charges;
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime;
}
if (target.Actor != previousTarget)
protected override IActivity GetAttackActivity( Actor self, Target newTarget, bool allowMove )
{
return new TeslaAttack( newTarget );
}
class TeslaAttack : CancelableActivity
{
readonly Target target;
public TeslaAttack( Target target ) { this.target = target; }
public override IActivity Tick( Actor self )
{
previousTarget = target.Actor;
if( IsCanceled || !target.IsValid ) return NextActivity;
var attack = self.Trait<AttackTesla>();
if( attack.charges == 0 || !attack.CanAttack( self, target ) )
return this;
self.Trait<RenderBuildingCharge>().PlayCharge(self);
return Util.SequenceActivities( new Wait( 8 ), new TeslaZap( target ), this );
}
}
class TeslaZap : CancelableActivity
{
readonly Target target;
public TeslaZap( Target target ) { this.target = target; }
public override IActivity Tick( Actor self )
{
if( IsCanceled || !target.IsValid ) return NextActivity;
var attack = self.Trait<AttackTesla>();
if( attack.charges == 0 ) return NextActivity;
attack.DoAttack( self, target );
return Util.SequenceActivities( new Wait( 3 ), this );
}
}
}

View File

@@ -253,7 +253,6 @@ TSLA:
RenderBuildingCharge:
AttackTesla:
PrimaryWeapon: TeslaZap
FireDelay: 8
ReloadTime: 120
AutoTarget:
IronCurtainable: