Rename tesla attack logic and move to Mods.Cnc.

This commit is contained in:
Paul Chote
2017-02-04 17:48:55 +00:00
parent ba69bfe494
commit a8d46adb2d
12 changed files with 72 additions and 38 deletions

View File

@@ -262,7 +262,6 @@
<Compile Include="Traits\Armor.cs" />
<Compile Include="Traits\AttackMove.cs" />
<Compile Include="Traits\Attack\AttackBase.cs" />
<Compile Include="Traits\Attack\AttackCharge.cs" />
<Compile Include="Traits\Attack\AttackFollow.cs" />
<Compile Include="Traits\Attack\AttackFrontal.cs" />
<Compile Include="Traits\Attack\AttackGarrisoned.cs" />
@@ -431,8 +430,6 @@
<Compile Include="Traits\Render\WithSiloAnimation.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
<Compile Include="Traits\Render\WithChargeAnimation.cs" />
<Compile Include="Traits\Render\WithChargeOverlay.cs" />
<Compile Include="Traits\Render\WithCrateBody.cs" />
<Compile Include="Traits\Render\WithDamageOverlay.cs" />
<Compile Include="Traits\Render\WithDeathAnimation.cs" />

View File

@@ -1,134 +0,0 @@
#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.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Charges up before being able to attack.")]
class AttackChargeInfo : AttackOmniInfo
{
[Desc("How many charges this actor has to attack with, once charged.")]
public readonly int MaxCharges = 1;
[Desc("Reload time for all charges (in ticks).")]
public readonly int ReloadDelay = 120;
[Desc("Delay for initial charge attack (in ticks).")]
public readonly int InitialChargeDelay = 22;
[Desc("Delay between charge attacks (in ticks).")]
public readonly int ChargeDelay = 3;
[Desc("Sound to play when actor charges.")]
public readonly string ChargeAudio = null;
public override object Create(ActorInitializer init) { return new AttackCharge(init.Self, this); }
}
class AttackCharge : AttackOmni, ITick, INotifyAttack
{
readonly AttackChargeInfo info;
[Sync] int charges;
[Sync] int timeToRecharge;
public AttackCharge(Actor self, AttackChargeInfo info)
: base(self, info)
{
this.info = info;
charges = info.MaxCharges;
}
public void Tick(Actor self)
{
if (--timeToRecharge <= 0)
charges = info.MaxCharges;
}
protected override bool CanAttack(Actor self, Target target)
{
if (!IsReachableTarget(target, true))
return false;
return base.CanAttack(self, target);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
{
--charges;
timeToRecharge = info.ReloadDelay;
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
{
return new ChargeAttack(this, newTarget);
}
class ChargeAttack : Activity
{
readonly AttackCharge attack;
readonly Target target;
public ChargeAttack(AttackCharge attack, Target target)
{
this.attack = attack;
this.target = target;
}
public override Activity Tick(Actor self)
{
if (IsCanceled || !attack.CanAttack(self, target))
return NextActivity;
if (attack.charges == 0)
return this;
foreach (var notify in self.TraitsImplementing<INotifyCharging>())
notify.Charging(self, target);
if (!string.IsNullOrEmpty(attack.info.ChargeAudio))
Game.Sound.Play(SoundType.World, attack.info.ChargeAudio, self.CenterPosition);
return ActivityUtils.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
}
}
class ChargeFire : Activity
{
readonly AttackCharge attack;
readonly Target target;
public ChargeFire(AttackCharge attack, Target target)
{
this.attack = attack;
this.target = target;
}
public override Activity Tick(Actor self)
{
if (IsCanceled || !attack.CanAttack(self, target))
return NextActivity;
if (attack.charges == 0)
return NextActivity;
attack.DoAttack(self, target);
return ActivityUtils.SequenceActivities(new Wait(attack.info.ChargeDelay), this);
}
}
}
}

View File

@@ -14,12 +14,12 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
class AttackOmniInfo : AttackBaseInfo
public class AttackOmniInfo : AttackBaseInfo
{
public override object Create(ActorInitializer init) { return new AttackOmni(init.Self, this); }
}
class AttackOmni : AttackBase
public class AttackOmni : AttackBase
{
public AttackOmni(Actor self, AttackOmniInfo info)
: base(self, info) { }

View File

@@ -1,41 +0,0 @@
#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("This actor displays a charge-up animation before firing.")]
public class WithChargeAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
{
[Desc("Sequence to use for charge animation.")]
[SequenceReference] public readonly string ChargeSequence = "active";
public object Create(ActorInitializer init) { return new WithChargeAnimation(init, this); }
}
public class WithChargeAnimation : INotifyCharging
{
readonly WithChargeAnimationInfo info;
readonly WithSpriteBody wsb;
public WithChargeAnimation(ActorInitializer init, WithChargeAnimationInfo info)
{
this.info = info;
wsb = init.Self.Trait<WithSpriteBody>();
}
public void Charging(Actor self, Target target)
{
wsb.PlayCustomAnimation(self, info.ChargeSequence, () => wsb.CancelCustomAnimation(self));
}
}
}

View File

@@ -1,69 +0,0 @@
#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("Rendered together with AttackCharge.")]
public class WithChargeOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] 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, this); }
}
public class WithChargeOverlay : INotifyCharging, INotifyDamageStateChanged, INotifySold
{
readonly Animation overlay;
readonly RenderSprites renderSprites;
readonly WithChargeOverlayInfo info;
bool charging;
public WithChargeOverlay(ActorInitializer init, WithChargeOverlayInfo info)
{
this.info = info;
renderSprites = init.Self.Trait<RenderSprites>();
overlay = new Animation(init.World, renderSprites.GetImage(init.Self));
renderSprites.Add(new AnimationWithOffset(overlay, null, () => !charging),
info.Palette, info.IsPlayerPalette);
}
void INotifyCharging.Charging(Actor self, Target target)
{
charging = true;
overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence), () => charging = false);
}
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, info.Sequence));
}
void INotifySold.Sold(Actor self) { }
void INotifySold.Selling(Actor self)
{
charging = false;
}
}
}

View File

@@ -81,7 +81,6 @@ namespace OpenRA.Mods.Common.Traits
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
public interface INotifyRepair { void Repairing(Actor self, Actor target); }
public interface INotifyBurstComplete { void FiredBurst(Actor self, Target target, Armament a); }
public interface INotifyCharging { void Charging(Actor self, Target target); }
public interface INotifyChat { bool OnChat(string from, string message); }
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); }
public interface INotifyOtherProduction { void UnitProducedByOther(Actor self, Actor producer, Actor produced); }

View File

@@ -818,6 +818,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
if (engineVersion < 20170210)
{
if (node.Key.StartsWith("AttackCharge", StringComparison.Ordinal))
RenameNodeKey(node, "AttackTesla");
if (node.Key.StartsWith("WithChargeOverlay", StringComparison.Ordinal))
RenameNodeKey(node, "WithTeslaChargeOverlay");
if (node.Key.StartsWith("WithChargeAnimation", StringComparison.Ordinal))
RenameNodeKey(node, "WithTeslaChargeAnimation");
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}