Corrected StartBurstReport sound synchronisation when used with FireDelay.

This commit is contained in:
darkademic
2022-02-13 17:36:03 +00:00
committed by Smittytron
parent 9605e5ad9c
commit e082497a1a

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
int currentBarrel; int currentBarrel;
readonly int barrelCount; readonly int barrelCount;
readonly List<(int Ticks, Action Func)> delayedActions = new List<(int, Action)>(); readonly List<(int Ticks, int Burst, Action<int> Func)> delayedActions = new List<(int, int, Action<int>)>();
public WDist Recoil; public WDist Recoil;
public int FireDelay { get; protected set; } public int FireDelay { get; protected set; }
@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var x = delayedActions[i]; var x = delayedActions[i];
if (--x.Ticks <= 0) if (--x.Ticks <= 0)
x.Func(); x.Func(x.Burst);
delayedActions[i] = x; delayedActions[i] = x;
} }
@@ -225,12 +225,12 @@ namespace OpenRA.Mods.Common.Traits
Tick(self); Tick(self);
} }
protected void ScheduleDelayedAction(int t, Action a) protected void ScheduleDelayedAction(int t, int b, Action<int> a)
{ {
if (t > 0) if (t > 0)
delayedActions.Add((t, a)); delayedActions.Add((t, b, a));
else else
a(); a(b);
} }
protected virtual bool CanFire(Actor self, in Target target) protected virtual bool CanFire(Actor self, in Target target)
@@ -322,7 +322,7 @@ namespace OpenRA.Mods.Common.Traits
// Lambdas can't use 'in' variables, so capture a copy for later // Lambdas can't use 'in' variables, so capture a copy for later
var delayedTarget = target; var delayedTarget = target;
ScheduleDelayedAction(Info.FireDelay, () => ScheduleDelayedAction(Info.FireDelay, Burst, (burst) =>
{ {
if (args.Weapon.Projectile != null) if (args.Weapon.Projectile != null)
{ {
@@ -333,7 +333,7 @@ namespace OpenRA.Mods.Common.Traits
if (args.Weapon.Report != null && args.Weapon.Report.Any()) if (args.Weapon.Report != null && args.Weapon.Report.Any())
Game.Sound.Play(SoundType.World, args.Weapon.Report, self.World, self.CenterPosition); Game.Sound.Play(SoundType.World, args.Weapon.Report, self.World, self.CenterPosition);
if (Burst == args.Weapon.Burst && args.Weapon.StartBurstReport != null && args.Weapon.StartBurstReport.Any()) if (burst == args.Weapon.Burst && args.Weapon.StartBurstReport != null && args.Weapon.StartBurstReport.Any())
Game.Sound.Play(SoundType.World, args.Weapon.StartBurstReport, self.World, self.CenterPosition); Game.Sound.Play(SoundType.World, args.Weapon.StartBurstReport, self.World, self.CenterPosition);
foreach (var na in notifyAttacks) foreach (var na in notifyAttacks)
@@ -360,7 +360,7 @@ namespace OpenRA.Mods.Common.Traits
Burst = Weapon.Burst; Burst = Weapon.Burst;
if (Weapon.AfterFireSound != null && Weapon.AfterFireSound.Any()) if (Weapon.AfterFireSound != null && Weapon.AfterFireSound.Any())
ScheduleDelayedAction(Weapon.AfterFireSoundDelay, () => Game.Sound.Play(SoundType.World, Weapon.AfterFireSound, self.World, self.CenterPosition)); ScheduleDelayedAction(Weapon.AfterFireSoundDelay, Burst, (burst) => Game.Sound.Play(SoundType.World, Weapon.AfterFireSound, self.World, self.CenterPosition));
foreach (var nbc in notifyBurstComplete) foreach (var nbc in notifyBurstComplete)
nbc.FiredBurst(self, target, this); nbc.FiredBurst(self, target, this);