Add AttackCharges trait for TD and TS obelisks.
This commit is contained in:
@@ -799,6 +799,9 @@
|
||||
<Compile Include="Traits\World\JumpjetActorLayer.cs" />
|
||||
<Compile Include="Traits\World\ElevatedBridgeLayer.cs" />
|
||||
<Compile Include="Traits\World\ElevatedBridgePlaceholder.cs" />
|
||||
<Compile Include="Traits\Attack\AttackCharges.cs" />
|
||||
<Compile Include="Traits\Render\WithChargeAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithChargeOverlay.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="AfterBuild">
|
||||
|
||||
84
OpenRA.Mods.Common/Traits/Attack/AttackCharges.cs
Normal file
84
OpenRA.Mods.Common/Traits/Attack/AttackCharges.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Actor must charge up its armaments before firing.")]
|
||||
public class AttackChargesInfo : AttackOmniInfo
|
||||
{
|
||||
[Desc("Amount of charge required to attack.")]
|
||||
public readonly int ChargeLevel = 25;
|
||||
|
||||
[Desc("Amount to increase the charge level each tick with a valid target.")]
|
||||
public readonly int ChargeRate = 1;
|
||||
|
||||
[Desc("Amount to decrease the charge level each tick without a valid target.")]
|
||||
public readonly int DischargeRate = 1;
|
||||
|
||||
[GrantedConditionReference]
|
||||
[Desc("The condition to grant to self while the charge level is greater than zero.")]
|
||||
public readonly string ChargingCondition = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AttackCharges(init.Self, this); }
|
||||
}
|
||||
|
||||
public class AttackCharges : AttackOmni, INotifyCreated, ITick, INotifyAttack, INotifySold
|
||||
{
|
||||
readonly AttackChargesInfo info;
|
||||
ConditionManager conditionManager;
|
||||
int chargingToken = ConditionManager.InvalidConditionToken;
|
||||
bool charging;
|
||||
|
||||
public int ChargeLevel { get; private set; }
|
||||
|
||||
public AttackCharges(Actor self, AttackChargesInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
// Stop charging when we lose our target
|
||||
charging &= self.CurrentActivity is SetTarget;
|
||||
|
||||
var delta = charging ? info.ChargeRate : -info.DischargeRate;
|
||||
ChargeLevel = (ChargeLevel + delta).Clamp(0, info.ChargeLevel);
|
||||
|
||||
if (ChargeLevel > 0 && conditionManager != null && !string.IsNullOrEmpty(info.ChargingCondition)
|
||||
&& chargingToken == ConditionManager.InvalidConditionToken)
|
||||
chargingToken = conditionManager.GrantCondition(self, info.ChargingCondition);
|
||||
|
||||
if (ChargeLevel == 0 && conditionManager != null && chargingToken != ConditionManager.InvalidConditionToken)
|
||||
chargingToken = conditionManager.RevokeCondition(self, chargingToken);
|
||||
}
|
||||
|
||||
protected override bool CanAttack(Actor self, Target target)
|
||||
{
|
||||
charging = base.CanAttack(self, target) && IsReachableTarget(target, true);
|
||||
return ChargeLevel >= info.ChargeLevel && charging;
|
||||
}
|
||||
|
||||
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) { ChargeLevel = 0; }
|
||||
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
|
||||
void INotifySold.Selling(Actor self) { ChargeLevel = 0; }
|
||||
void INotifySold.Sold(Actor self) { }
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return new SetTarget(this, newTarget);
|
||||
}
|
||||
|
||||
class SetTarget : Activity
|
||||
protected class SetTarget : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
readonly AttackOmni attack;
|
||||
|
||||
46
OpenRA.Mods.Common/Traits/Render/WithChargeAnimation.cs
Normal file
46
OpenRA.Mods.Common/Traits/Render/WithChargeAnimation.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
[Desc("Render trait that varies the animation frame based on the AttackCharges trait's charge level.")]
|
||||
class WithChargeAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<AttackChargesInfo>
|
||||
{
|
||||
[SequenceReference]
|
||||
[Desc("Sequence to use for the charge levels.")]
|
||||
public readonly string Sequence = "active";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithChargeAnimation(init.Self, this); }
|
||||
}
|
||||
|
||||
class WithChargeAnimation : INotifyBuildComplete
|
||||
{
|
||||
readonly WithChargeAnimationInfo info;
|
||||
readonly WithSpriteBody wsb;
|
||||
readonly AttackCharges attackCharges;
|
||||
|
||||
public WithChargeAnimation(Actor self, WithChargeAnimationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
wsb = self.Trait<WithSpriteBody>();
|
||||
attackCharges = self.Trait<AttackCharges>();
|
||||
}
|
||||
|
||||
void INotifyBuildComplete.BuildingComplete(Actor self)
|
||||
{
|
||||
var attackChargesInfo = (AttackChargesInfo)attackCharges.Info;
|
||||
wsb.DefaultAnimation.PlayFetchIndex(wsb.NormalizeSequence(self, info.Sequence),
|
||||
() => int2.Lerp(0, wsb.DefaultAnimation.CurrentSequence.Length, attackCharges.ChargeLevel, attackChargesInfo.ChargeLevel + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
72
OpenRA.Mods.Common/Traits/Render/WithChargeOverlay.cs
Normal file
72
OpenRA.Mods.Common/Traits/Render/WithChargeOverlay.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
[Desc("Render overlay that varies the animation frame based on the AttackCharges trait's charge level.")]
|
||||
class WithChargeOverlayInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
|
||||
{
|
||||
[SequenceReference]
|
||||
[Desc("Sequence to use for the charge levels.")]
|
||||
public readonly string Sequence = "active";
|
||||
|
||||
[Desc("Custom palette name")]
|
||||
[PaletteReference("IsPlayerPalette")] public readonly string Palette = null;
|
||||
|
||||
[Desc("Custom palette is a player palette BaseName")]
|
||||
public readonly bool IsPlayerPalette = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithChargeOverlay(init.Self, this); }
|
||||
}
|
||||
|
||||
class WithChargeOverlay : INotifyBuildComplete, INotifySold, INotifyDamageStateChanged
|
||||
{
|
||||
readonly WithChargeOverlayInfo info;
|
||||
readonly Animation overlay;
|
||||
readonly RenderSprites rs;
|
||||
readonly WithSpriteBody wsb;
|
||||
|
||||
bool buildComplete;
|
||||
|
||||
public WithChargeOverlay(Actor self, WithChargeOverlayInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSprites>();
|
||||
wsb = self.Trait<WithSpriteBody>();
|
||||
|
||||
var attackCharges = self.Trait<AttackCharges>();
|
||||
var attackChargesInfo = (AttackChargesInfo)attackCharges.Info;
|
||||
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
overlay.PlayFetchIndex(wsb.NormalizeSequence(self, info.Sequence),
|
||||
() => int2.Lerp(0, overlay.CurrentSequence.Length, attackCharges.ChargeLevel, attackChargesInfo.ChargeLevel + 1));
|
||||
|
||||
rs.Add(new AnimationWithOffset(overlay, null, () => !buildComplete, 1024),
|
||||
info.Palette, info.IsPlayerPalette);
|
||||
}
|
||||
|
||||
void INotifyBuildComplete.BuildingComplete(Actor self)
|
||||
{
|
||||
buildComplete = true;
|
||||
}
|
||||
|
||||
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, info.Sequence));
|
||||
}
|
||||
|
||||
void INotifySold.Selling(Actor self) { buildComplete = false; }
|
||||
void INotifySold.Sold(Actor self) { }
|
||||
}
|
||||
}
|
||||
@@ -758,15 +758,17 @@ OBLI:
|
||||
Range: 8c0
|
||||
Bib:
|
||||
HasMinibib: Yes
|
||||
WithTeslaChargeAnimation:
|
||||
WithChargeAnimation:
|
||||
Armament:
|
||||
Weapon: Laser
|
||||
LocalOffset: 0,-85,1280
|
||||
FireDelay: 0
|
||||
AttackTesla:
|
||||
ChargeAudio: obelpowr.aud
|
||||
ReloadDelay: 40
|
||||
InitialChargeDelay: 50
|
||||
AttackCharges:
|
||||
ChargeLevel: 50
|
||||
ChargingCondition: charging
|
||||
AmbientSound:
|
||||
RequiresCondition: charging
|
||||
SoundFile: obelpowr.aud
|
||||
Interval: 30, 40
|
||||
-EmitInfantryOnSell:
|
||||
DetectCloaked:
|
||||
Range: 5c0
|
||||
|
||||
@@ -80,7 +80,7 @@ Napalm:
|
||||
Explosions: med_napalm
|
||||
|
||||
Laser:
|
||||
ReloadDelay: 1
|
||||
ReloadDelay: 40
|
||||
Range: 7c512
|
||||
Report: obelray1.aud
|
||||
Projectile: LaserZap
|
||||
|
||||
@@ -108,11 +108,14 @@ NAOBEL:
|
||||
Armament:
|
||||
Weapon: ObeliskLaserFire
|
||||
LocalOffset: 1400,210,800
|
||||
AttackTesla:
|
||||
ChargeAudio: obelpowr.aud
|
||||
InitialChargeDelay: 65
|
||||
WithTeslaChargeOverlay:
|
||||
Sequence: active
|
||||
AttackCharges:
|
||||
ChargeLevel: 65
|
||||
ChargingCondition: charging
|
||||
AmbientSound:
|
||||
RequiresCondition: charging
|
||||
SoundFile: obelpowr.aud
|
||||
Interval: 30, 40
|
||||
WithChargeOverlay:
|
||||
Palette: player
|
||||
IsPlayerPalette: true
|
||||
WithIdleOverlay@LIGHTS:
|
||||
|
||||
@@ -180,7 +180,7 @@ Proton:
|
||||
|
||||
ObeliskLaserFire:
|
||||
Inherits: ^Laser
|
||||
ReloadDelay: 1
|
||||
ReloadDelay: 120
|
||||
Range: 10c512
|
||||
Report: obelray1.aud
|
||||
Warhead@1Dam: SpreadDamage
|
||||
|
||||
Reference in New Issue
Block a user