From 399275e5f3c3751a97dda7e97e4b801ceea59d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 5 Oct 2014 14:48:51 +0200 Subject: [PATCH] add a configurable interval to announce on kill to avoid spam --- OpenRA.Mods.RA/AnnounceOnKill.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/AnnounceOnKill.cs b/OpenRA.Mods.RA/AnnounceOnKill.cs index 9033636a27..c45b19e7ce 100644 --- a/OpenRA.Mods.RA/AnnounceOnKill.cs +++ b/OpenRA.Mods.RA/AnnounceOnKill.cs @@ -13,14 +13,35 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { [Desc("Play the Kill voice of this actor when eliminating enemies.")] - public class AnnounceOnKillInfo : TraitInfo { } + public class AnnounceOnKillInfo : ITraitInfo + { + [Desc("Minimum duration (in seconds) between sound events.")] + public readonly int Interval = 5; + + public object Create(ActorInitializer init) { return new AnnounceOnKill(init.self, this); } + } public class AnnounceOnKill : INotifyAppliedDamage { + readonly AnnounceOnKillInfo info; + + int lastAnnounce; + + public AnnounceOnKill(Actor self, AnnounceOnKillInfo info) + { + this.info = info; + lastAnnounce = -info.Interval * 25; + } + public void AppliedDamage(Actor self, Actor damaged, AttackInfo e) { if (e.DamageState == DamageState.Dead) - Sound.PlayVoice("Kill", self, self.Owner.Country.Race); + { + if (self.World.WorldTick - lastAnnounce > info.Interval * 25) + Sound.PlayVoice("Kill", self, self.Owner.Country.Race); + + lastAnnounce = self.World.WorldTick; + } } } }