From ebb1c457867b094469109fa81c930ea508274cb7 Mon Sep 17 00:00:00 2001 From: abc013 Date: Mon, 5 Sep 2016 13:28:29 +0200 Subject: [PATCH] Added an AttackSequences property to WithInfantryBody --- .../Traits/Render/WithInfantryBody.cs | 26 ++++++++++++++++--- OpenRA.Mods.RA/Activities/Leap.cs | 6 ++--- OpenRA.Mods.RA/Traits/Attack/AttackLeap.cs | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs index 4ff82366cb..543e7e964c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs @@ -25,9 +25,23 @@ namespace OpenRA.Mods.Common.Traits.Render [SequenceReference] public readonly string MoveSequence = "run"; [SequenceReference] public readonly string AttackSequence = null; + + // TODO: [SequenceReference] isn't smart enough to use Dictionarys. + [Desc("Attack sequence to use for each armament.")] + [FieldLoader.LoadUsing("LoadWeaponSequences")] + public readonly Dictionary AttackSequences = new Dictionary(); [SequenceReference] public readonly string[] IdleSequences = { }; [SequenceReference] public readonly string[] StandSequences = { "stand" }; + public static object LoadWeaponSequences(MiniYaml yaml) + { + var md = yaml.ToDictionary(); + + return md.ContainsKey("AttackSequences") + ? md["AttackSequences"].ToDictionary(my => FieldLoader.GetValue("(value)", my.Value)) + : new Dictionary(); + } + public override object Create(ActorInitializer init) { return new WithInfantryBody(init, this); } public IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) @@ -96,18 +110,22 @@ namespace OpenRA.Mods.Common.Traits.Render return !IsModifyingSequence; } - public void Attacking(Actor self, Target target) + public void Attacking(Actor self, Target target, Armament a) { - if (!string.IsNullOrEmpty(Info.AttackSequence) && DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, Info.AttackSequence))) + string sequence; + if (!Info.AttackSequences.TryGetValue(a.Info.Name, out sequence)) + sequence = Info.AttackSequence; + + if (!string.IsNullOrEmpty(sequence) && DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, sequence))) { state = AnimationState.Attacking; - DefaultAnimation.PlayThen(NormalizeInfantrySequence(self, Info.AttackSequence), () => state = AnimationState.Idle); + DefaultAnimation.PlayThen(NormalizeInfantrySequence(self, sequence), () => state = AnimationState.Idle); } } void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { - Attacking(self, target); + Attacking(self, target, a); } void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) { } diff --git a/OpenRA.Mods.RA/Activities/Leap.cs b/OpenRA.Mods.RA/Activities/Leap.cs index a5f10f5d5f..39b548296b 100644 --- a/OpenRA.Mods.RA/Activities/Leap.cs +++ b/OpenRA.Mods.RA/Activities/Leap.cs @@ -30,13 +30,13 @@ namespace OpenRA.Mods.RA.Activities int ticks; WAngle angle; - public Leap(Actor self, Actor target, WeaponInfo weapon, WDist speed, WAngle angle) + public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle) { var targetMobile = target.TraitOrDefault(); if (targetMobile == null) throw new InvalidOperationException("Leap requires a target actor with the Mobile trait"); - this.weapon = weapon; + this.weapon = a.Weapon; this.angle = angle; mobile = self.Trait(); mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, targetMobile.FromCell, targetMobile.FromSubCell); @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Activities length = Math.Max((to - from).Length / speed.Length, 1); // HACK: why isn't this using the interface? - self.Trait().Attacking(self, Target.FromActor(target)); + self.Trait().Attacking(self, Target.FromActor(target), a); if (weapon.Report != null && weapon.Report.Any()) Game.Sound.Play(weapon.Report.Random(self.World.SharedRandom), self.CenterPosition); diff --git a/OpenRA.Mods.RA/Traits/Attack/AttackLeap.cs b/OpenRA.Mods.RA/Traits/Attack/AttackLeap.cs index 938dc0dfcd..edf70fc868 100644 --- a/OpenRA.Mods.RA/Traits/Attack/AttackLeap.cs +++ b/OpenRA.Mods.RA/Traits/Attack/AttackLeap.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Traits return; self.CancelActivity(); - self.QueueActivity(new Leap(self, target.Actor, a.Weapon, info.Speed, info.Angle)); + self.QueueActivity(new Leap(self, target.Actor, a, info.Speed, info.Angle)); } } }