Merge pull request #4803 from reaperrr/obelisk-fix2
Building charge improvements
This commit is contained in:
118
OpenRA.Mods.RA/Attack/AttackCharge.cs
Normal file
118
OpenRA.Mods.RA/Attack/AttackCharge.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class AttackChargeInfo : AttackOmniInfo
|
||||
{
|
||||
public readonly int MaxCharges = 1;
|
||||
[Desc("Reload time (for all charges).")]
|
||||
public readonly int ReloadTime = 120;
|
||||
[Desc("Delay for first charge. Needs to match FireDelay for Obelisk.")]
|
||||
public readonly int InitialChargeDelay = 22;
|
||||
[Desc("Delay for additional charges if MaxCharge is larger than 1.")]
|
||||
public readonly int ChargeDelay = 3;
|
||||
public override object Create(ActorInitializer init) { return new AttackCharge(init.self); }
|
||||
}
|
||||
|
||||
class AttackCharge : AttackOmni, ITick, INotifyAttack, ISync
|
||||
{
|
||||
[Sync] int charges;
|
||||
[Sync] int timeToRecharge;
|
||||
|
||||
public AttackCharge(Actor self)
|
||||
: base(self)
|
||||
{
|
||||
charges = self.Info.Traits.Get<AttackChargeInfo>().MaxCharges;
|
||||
}
|
||||
|
||||
public override void Tick( Actor self )
|
||||
{
|
||||
if( --timeToRecharge <= 0 )
|
||||
charges = self.Info.Traits.Get<AttackChargeInfo>().MaxCharges;
|
||||
|
||||
base.Tick( self );
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||
{
|
||||
--charges;
|
||||
timeToRecharge = self.Info.Traits.Get<AttackChargeInfo>().ReloadTime;
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
|
||||
{
|
||||
return new ChargeAttack(newTarget);
|
||||
}
|
||||
|
||||
|
||||
public override void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
base.ResolveOrder(self, order);
|
||||
|
||||
if (order.OrderString == "Stop")
|
||||
self.CancelActivity();
|
||||
}
|
||||
|
||||
class ChargeAttack : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
public ChargeAttack(Target target)
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
return NextActivity;
|
||||
|
||||
var initDelay = self.Info.Traits.Get<AttackChargeInfo>().InitialChargeDelay;
|
||||
|
||||
var attack = self.Trait<AttackCharge>();
|
||||
if(attack.charges == 0 || !attack.CanAttack(self, target))
|
||||
return this;
|
||||
|
||||
self.Trait<RenderBuildingCharge>().PlayCharge(self);
|
||||
return Util.SequenceActivities(new Wait(initDelay), new ChargeFire(target), this);
|
||||
}
|
||||
}
|
||||
|
||||
class ChargeFire : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
public ChargeFire(Target target)
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
return NextActivity;
|
||||
|
||||
var chargeDelay = self.Info.Traits.Get<AttackChargeInfo>().ChargeDelay;
|
||||
|
||||
var attack = self.Trait<AttackCharge>();
|
||||
if(attack.charges == 0)
|
||||
return NextActivity;
|
||||
|
||||
attack.DoAttack(self, target);
|
||||
|
||||
return Util.SequenceActivities(new Wait(chargeDelay), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
#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
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class AttackTeslaInfo : AttackOmniInfo
|
||||
{
|
||||
public readonly int MaxCharges = 3;
|
||||
public readonly int ReloadTime = 120;
|
||||
public override object Create(ActorInitializer init) { return new AttackTesla(init.self); }
|
||||
}
|
||||
|
||||
class AttackTesla : AttackOmni, ITick, INotifyAttack, ISync
|
||||
{
|
||||
[Sync] int charges;
|
||||
[Sync] int timeToRecharge;
|
||||
|
||||
public AttackTesla( Actor self )
|
||||
: base( self )
|
||||
{
|
||||
charges = self.Info.Traits.Get<AttackTeslaInfo>().MaxCharges;
|
||||
}
|
||||
|
||||
public override void Tick( Actor self )
|
||||
{
|
||||
if( --timeToRecharge <= 0 )
|
||||
charges = self.Info.Traits.Get<AttackTeslaInfo>().MaxCharges;
|
||||
|
||||
base.Tick( self );
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||
{
|
||||
--charges;
|
||||
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime;
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity( Actor self, Target newTarget, bool allowMove )
|
||||
{
|
||||
return new TeslaAttack( newTarget );
|
||||
}
|
||||
|
||||
|
||||
public override void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
base.ResolveOrder(self, order);
|
||||
|
||||
if (order.OrderString == "Stop")
|
||||
self.CancelActivity();
|
||||
}
|
||||
|
||||
class TeslaAttack : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
public TeslaAttack( Target target ) { this.target = target; }
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
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( 22 ), new TeslaZap( target ), this );
|
||||
}
|
||||
}
|
||||
|
||||
class TeslaZap : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
public TeslaZap( Target target ) { this.target = target; }
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
return NextActivity;
|
||||
|
||||
var attack = self.Trait<AttackTesla>();
|
||||
if( attack.charges == 0 ) return NextActivity;
|
||||
|
||||
attack.DoAttack( self, target );
|
||||
|
||||
return Util.SequenceActivities( new Wait( 3 ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@
|
||||
<Compile Include="Attack\AttackMedic.cs" />
|
||||
<Compile Include="Attack\AttackOmni.cs" />
|
||||
<Compile Include="Attack\AttackPopupTurreted.cs" />
|
||||
<Compile Include="Attack\AttackTesla.cs" />
|
||||
<Compile Include="Attack\AttackCharge.cs" />
|
||||
<Compile Include="Attack\AttackTurreted.cs" />
|
||||
<Compile Include="Attack\AttackWander.cs" />
|
||||
<Compile Include="AutoHeal.cs" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
@@ -8,15 +8,20 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class RenderBuildingChargeInfo : RenderBuildingInfo
|
||||
{
|
||||
public readonly string ChargeAudio = "tslachg2.aud";
|
||||
[Desc("Sound to play when building charges.")]
|
||||
public readonly string ChargeAudio = null;
|
||||
[Desc("Sequence to use for building charge animation.")]
|
||||
public readonly string ChargeSequence = "active";
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingCharge(init, this); }
|
||||
}
|
||||
|
||||
/* used for tesla */
|
||||
/* used for tesla and obelisk */
|
||||
public class RenderBuildingCharge : RenderBuilding
|
||||
{
|
||||
RenderBuildingChargeInfo info;
|
||||
@@ -30,7 +35,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
public void PlayCharge(Actor self)
|
||||
{
|
||||
Sound.Play(info.ChargeAudio, self.CenterPosition);
|
||||
anim.PlayThen(NormalizeSequence(self, "active"),
|
||||
anim.PlayThen(NormalizeSequence(self, info.ChargeSequence),
|
||||
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user