Create a PlayLaunchSounds method in SupportPower.cs

This commit is contained in:
abcdefg30
2016-09-06 14:08:08 +02:00
parent 08d84c5b90
commit 620e005cfd
4 changed files with 15 additions and 25 deletions

View File

@@ -127,14 +127,7 @@ namespace OpenRA.Mods.Common.Traits
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var renderPlayer = self.World.RenderPlayer; PlayLaunchSounds();
var isAllied = self.Owner.IsAlliedWith(renderPlayer);
Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound);
// IsAlliedWith returns true if renderPlayer is null, so we are safe here.
var toPlayer = isAllied ? renderPlayer ?? self.Owner : renderPlayer;
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
Game.Sound.PlayNotification(self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
Actor distanceTestActor = null; Actor distanceTestActor = null;
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++) for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)

View File

@@ -92,15 +92,7 @@ namespace OpenRA.Mods.Common.Traits
public override void Activate(Actor self, Order order, SupportPowerManager manager) public override void Activate(Actor self, Order order, SupportPowerManager manager)
{ {
base.Activate(self, order, manager); base.Activate(self, order, manager);
PlayLaunchSounds();
var renderPlayer = self.World.RenderPlayer;
var isAllied = self.Owner.IsAlliedWith(renderPlayer);
Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound);
// IsAlliedWith returns true if renderPlayer is null, so we are safe here.
var toPlayer = isAllied ? renderPlayer ?? self.Owner : renderPlayer;
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
Game.Sound.PlayNotification(self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
if (!string.IsNullOrEmpty(info.ActivationSequence)) if (!string.IsNullOrEmpty(info.ActivationSequence))
{ {

View File

@@ -120,5 +120,17 @@ namespace OpenRA.Mods.Common.Traits
Info.RadarPingDuration); Info.RadarPingDuration);
} }
} }
public virtual void PlayLaunchSounds()
{
var renderPlayer = Self.World.RenderPlayer;
var isAllied = Self.Owner.IsAlliedWith(renderPlayer);
Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound);
// IsAlliedWith returns true if renderPlayer is null, so we are safe here.
var toPlayer = isAllied ? renderPlayer ?? Self.Owner : renderPlayer;
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
Game.Sound.PlayNotification(Self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
}
} }
} }

View File

@@ -153,14 +153,7 @@ namespace OpenRA.Mods.RA.Traits
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var renderPlayer = self.World.RenderPlayer; PlayLaunchSounds();
var isAllied = self.Owner.IsAlliedWith(renderPlayer);
Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound);
// IsAlliedWith returns true if renderPlayer is null, so we are safe here.
var toPlayer = isAllied ? renderPlayer ?? self.Owner : renderPlayer;
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
Game.Sound.PlayNotification(self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
Actor distanceTestActor = null; Actor distanceTestActor = null;