From 8cc455d23f494eed88ca1b89db63885607e87b14 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 21 Aug 2011 10:21:07 +1200 Subject: [PATCH] fix #1105; decloak sound was never used --- OpenRA.Mods.RA/Cloak.cs | 53 +++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/OpenRA.Mods.RA/Cloak.cs b/OpenRA.Mods.RA/Cloak.cs index fa1507970c..7dedd326c7 100644 --- a/OpenRA.Mods.RA/Cloak.cs +++ b/OpenRA.Mods.RA/Cloak.cs @@ -28,13 +28,12 @@ namespace OpenRA.Mods.RA public class Cloak : IRenderModifier, INotifyDamageStateChanged, INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, ISync { - [Sync] - int remainingTime; - [Sync] - bool canCloak = true; - + [Sync] int remainingTime; + [Sync] bool canCloak = true; + Actor self; CloakInfo info; + public Cloak(Actor self, CloakInfo info) { this.info = info; @@ -43,25 +42,29 @@ namespace OpenRA.Mods.RA remainingTime = info.InitialDelay; } - void DoUncloak() - { - if (remainingTime <= 0) - OnCloak(); + public void Uncloak() { Uncloak(info.CloakDelay); } - remainingTime = Math.Max(remainingTime, info.CloakDelay); + public void Uncloak(int time) + { + if (Cloaked) + Sound.Play(info.UncloakSound, self.CenterLocation); + + remainingTime = Math.Max(remainingTime, time); } - public void Attacking(Actor self, Target target) { DoUncloak(); } + public void Attacking(Actor self, Target target) { Uncloak(); } + + public bool Cloaked { get { return remainingTime <= 0; } } + public void DamageStateChanged(Actor self, AttackInfo e) { canCloak = (e.DamageState < DamageState.Critical); - if (Cloaked && !canCloak) - DoUncloak(); + if (!canCloak) Uncloak(); } static readonly Renderable[] Nothing = { }; - public IEnumerable - ModifyRender(Actor self, IEnumerable rs) + + public IEnumerable ModifyRender(Actor self, IEnumerable rs) { if (remainingTime > 0) return rs; @@ -76,21 +79,9 @@ namespace OpenRA.Mods.RA { if (remainingTime > 0 && canCloak) if (--remainingTime <= 0) - OnCloak(); + Sound.Play(info.CloakSound, self.CenterLocation); } - void OnUncloak() - { - Sound.Play(info.UncloakSound, self.CenterLocation); - } - - void OnCloak() - { - Sound.Play(info.CloakSound, self.CenterLocation); - } - - public bool Cloaked { get { return remainingTime == 0; } } - public bool IsVisible(Actor self) { if (!Cloaked || self.Owner == self.World.LocalPlayer || @@ -110,11 +101,5 @@ namespace OpenRA.Mods.RA c = Color.FromArgb(128, c); return c; } - - public void Decloak(int time) - { - DoUncloak(); - remainingTime = Math.Max(remainingTime, time); - } } }