Move unwanted AttackBase logic to the individual Armaments.

This commit is contained in:
Paul Chote
2014-03-17 11:14:09 +13:00
parent b31240ccc5
commit 0ca7ee280f
7 changed files with 59 additions and 55 deletions

View File

@@ -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,25 +8,39 @@
*/
#endregion
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderUnitReloadInfo : RenderUnitInfo
class RenderUnitReloadInfo : RenderUnitInfo, Requires<ArmamentInfo>, Requires<AttackBaseInfo>
{
public override object Create(ActorInitializer init) { return new RenderUnitReload(init.self); }
[Desc("Armament name")]
public readonly string Armament = "primary";
public override object Create(ActorInitializer init) { return new RenderUnitReload(init.self, this); }
}
class RenderUnitReload : RenderUnit
{
public RenderUnitReload(Actor self)
: base(self) { }
readonly AttackBase attack;
readonly Armament armament;
public RenderUnitReload(Actor self, RenderUnitReloadInfo info)
: base(self)
{
attack = self.Trait<AttackBase>();
armament = self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == info.Armament);
}
public override void Tick(Actor self)
{
var attack = self.TraitOrDefault<AttackBase>();
var sequence = (armament.IsReloading ? "empty-" : "") + (attack.IsAttacking ? "aim" : "idle");
if (sequence != anim.CurrentSequence.Name)
anim.ReplaceAnim(sequence);
if (attack != null)
anim.ReplaceAnim((attack.IsReloading() ? "empty-" : "")
+ (attack.IsAttacking ? "aim" : "idle"));
base.Tick(self);
}
}