diff --git a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs index 24df531d2d..9de38d242d 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Sound public AmbientSound(Actor self, AmbientSoundInfo info) : base(info) { - delay = RandomDelay(self.World, info.Delay); + delay = Util.RandomDelay(self.World, info.Delay); loop = Info.Interval.Length == 0 || (Info.Interval.Length == 1 && Info.Interval[0] == 0); } @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits.Sound { StartSound(self); if (!loop) - delay = RandomDelay(self.World, Info.Interval); + delay = Util.RandomDelay(self.World, Info.Interval); } } @@ -89,18 +89,7 @@ namespace OpenRA.Mods.Common.Traits.Sound currentSound = null; } - static int RandomDelay(World world, int[] range) - { - if (range.Length == 0) - return 0; - - if (range.Length == 1) - return range[0]; - - return world.SharedRandom.Next(range[0], range[1]); - } - - protected override void TraitEnabled(Actor self) { delay = RandomDelay(self.World, Info.Delay); } + protected override void TraitEnabled(Actor self) { delay = Util.RandomDelay(self.World, Info.Delay); } protected override void TraitDisabled(Actor self) { StopSound(); } void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) { StopSound(); } diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index cbd10b5b0a..f2820bf75e 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -164,5 +164,16 @@ namespace OpenRA.Mods.Common yield return p; } } + + public static int RandomDelay(World world, int[] range) + { + if (range.Length == 0) + return 0; + + if (range.Length == 1) + return range[0]; + + return world.SharedRandom.Next(range[0], range[1]); + } } }