Move PlayVoice and PlayVoiceLocal from Sound to Voiced.
Move HasVoice, HasVoices and GetVoices from WorldUtils to Voiced.
This commit is contained in:
@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (order.OrderString != "Unload" || IsEmpty(self))
|
||||
return null;
|
||||
|
||||
return self.HasVoice("Unload") ? "Unload" : "Move";
|
||||
return self.TraitsImplementing<IVoiced>().FirstOrDefault().HasVoice(self, "Unload") ? "Unload" : "Move";
|
||||
}
|
||||
|
||||
public bool MoveDisabled(Actor self) { return reserves.Any(); }
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public void BuildingComplete(Actor self)
|
||||
{
|
||||
Sound.PlayVoice("Build", self, self.Owner.Country.Race);
|
||||
foreach (var voiced in self.TraitsImplementing<IVoiced>())
|
||||
voiced.PlayVoice("Build", self, self.Owner.Country.Race);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (e.DamageState == DamageState.Dead && damaged != e.Attacker)
|
||||
{
|
||||
if (self.World.WorldTick - lastAnnounce > info.Interval * 25)
|
||||
Sound.PlayVoice("Kill", self, self.Owner.Country.Race);
|
||||
foreach (var voiced in self.TraitsImplementing<IVoiced>())
|
||||
voiced.PlayVoice("Kill", self, self.Owner.Country.Race);
|
||||
|
||||
lastAnnounce = self.World.WorldTick;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var cp = self.CenterPosition;
|
||||
|
||||
if (info.DeathTypes.Contains(e.Warhead.DeathType) ||
|
||||
(!info.DeathTypes.Any() && !self.Info.Traits.WithInterface<DeathSoundsInfo>().Any(dsi => dsi.DeathTypes.Contains(e.Warhead.DeathType))))
|
||||
Sound.PlayVoiceLocal(info.DeathSound, self, self.Owner.Country.Race, cp, info.VolumeMultiplier);
|
||||
foreach (var voiced in self.TraitsImplementing<IVoiced>())
|
||||
if (info.DeathTypes.Contains(e.Warhead.DeathType) ||
|
||||
(!info.DeathTypes.Any() && !self.Info.Traits.WithInterface<DeathSoundsInfo>()
|
||||
.Any(dsi => dsi.DeathTypes.Contains(e.Warhead.DeathType))))
|
||||
voiced.PlayVoiceLocal(info.DeathSound, self, self.Owner.Country.Race, cp, info.VolumeMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -30,6 +31,54 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public bool PlayVoice(string phrase, Actor voicedActor, string variant)
|
||||
{
|
||||
if (voicedActor == null || phrase == null)
|
||||
return false;
|
||||
|
||||
var mi = voicedActor.TraitOrDefault<IVoiced>();
|
||||
if (mi == null || mi.VoiceSet == null)
|
||||
return false;
|
||||
|
||||
var type = mi.VoiceSet.ToLowerInvariant();
|
||||
return Sound.PlayPredefined(voicedActor.World.Map.Rules, null, voicedActor, type, phrase, variant, true, WPos.Zero, 1f, true);
|
||||
}
|
||||
|
||||
public bool PlayVoiceLocal(string phrase, Actor voicedActor, string variant, WPos pos, float volume)
|
||||
{
|
||||
if (voicedActor == null || phrase == null)
|
||||
return false;
|
||||
|
||||
var mi = voicedActor.TraitOrDefault<IVoiced>();
|
||||
if (mi == null || mi.VoiceSet == null)
|
||||
return false;
|
||||
|
||||
var type = mi.VoiceSet.ToLowerInvariant();
|
||||
return Sound.PlayPredefined(voicedActor.World.Map.Rules, null, voicedActor, type, phrase, variant, false, pos, volume, true);
|
||||
}
|
||||
|
||||
public bool HasVoices(Actor actor)
|
||||
{
|
||||
var voice = actor.TraitsImplementing<IVoiced>().FirstOrDefault();
|
||||
return voice != null && voice.VoiceSet != null;
|
||||
}
|
||||
|
||||
public bool HasVoice(Actor actor, string voice)
|
||||
{
|
||||
var v = GetVoices(actor);
|
||||
return v != null && v.Voices.ContainsKey(voice);
|
||||
}
|
||||
|
||||
public SoundInfo GetVoices(Actor actor)
|
||||
{
|
||||
var voice = actor.TraitsImplementing<IVoiced>().FirstOrDefault();
|
||||
if (voice == null)
|
||||
return null;
|
||||
|
||||
var v = voice.VoiceSet;
|
||||
return (v == null) ? null : actor.World.Map.Rules.Voices[v.ToLowerInvariant()];
|
||||
}
|
||||
|
||||
public string VoiceSet { get { return Info.VoiceSet; } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user