Added an AttackSequences property to WithInfantryBody
This commit is contained in:
@@ -25,9 +25,23 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
[SequenceReference] public readonly string MoveSequence = "run";
|
[SequenceReference] public readonly string MoveSequence = "run";
|
||||||
[SequenceReference] public readonly string AttackSequence = null;
|
[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<string, string> AttackSequences = new Dictionary<string, string>();
|
||||||
[SequenceReference] public readonly string[] IdleSequences = { };
|
[SequenceReference] public readonly string[] IdleSequences = { };
|
||||||
[SequenceReference] public readonly string[] StandSequences = { "stand" };
|
[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<string>("(value)", my.Value))
|
||||||
|
: new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithInfantryBody(init, this); }
|
public override object Create(ActorInitializer init) { return new WithInfantryBody(init, this); }
|
||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
@@ -96,18 +110,22 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
return !IsModifyingSequence;
|
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;
|
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)
|
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) { }
|
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) { }
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
int ticks;
|
int ticks;
|
||||||
WAngle angle;
|
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<Mobile>();
|
var targetMobile = target.TraitOrDefault<Mobile>();
|
||||||
if (targetMobile == null)
|
if (targetMobile == null)
|
||||||
throw new InvalidOperationException("Leap requires a target actor with the Mobile trait");
|
throw new InvalidOperationException("Leap requires a target actor with the Mobile trait");
|
||||||
|
|
||||||
this.weapon = weapon;
|
this.weapon = a.Weapon;
|
||||||
this.angle = angle;
|
this.angle = angle;
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, targetMobile.FromCell, targetMobile.FromSubCell);
|
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);
|
length = Math.Max((to - from).Length / speed.Length, 1);
|
||||||
|
|
||||||
// HACK: why isn't this using the interface?
|
// HACK: why isn't this using the interface?
|
||||||
self.Trait<WithInfantryBody>().Attacking(self, Target.FromActor(target));
|
self.Trait<WithInfantryBody>().Attacking(self, Target.FromActor(target), a);
|
||||||
|
|
||||||
if (weapon.Report != null && weapon.Report.Any())
|
if (weapon.Report != null && weapon.Report.Any())
|
||||||
Game.Sound.Play(weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
|
Game.Sound.Play(weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
self.CancelActivity();
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user