Change SoundOnDamageTransition to randomly select
from a string[] instead of a single string.
This commit is contained in:
@@ -8,14 +8,18 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class SoundOnDamageTransitionInfo : ITraitInfo
|
||||
{
|
||||
public readonly string DamagedSound;
|
||||
public readonly string DestroyedSound;
|
||||
[Desc("Play a random sound from this list when damaged.")]
|
||||
public readonly string[] DamagedSounds = { };
|
||||
|
||||
[Desc("Play a random sound from this list when destroyed.")]
|
||||
public readonly string[] DestroyedSounds = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new SoundOnDamageTransition(this); }
|
||||
}
|
||||
@@ -31,10 +35,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
var rand = Game.CosmeticRandom;
|
||||
|
||||
if (e.DamageState == DamageState.Dead)
|
||||
Sound.Play(info.DestroyedSound, self.CenterPosition);
|
||||
{
|
||||
var sound = info.DestroyedSounds.RandomOrDefault(rand);
|
||||
Sound.Play(sound, self.CenterPosition);
|
||||
}
|
||||
else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
|
||||
Sound.Play(info.DamagedSound, self.CenterPosition);
|
||||
{
|
||||
var sound = info.DamagedSounds.RandomOrDefault(rand);
|
||||
Sound.Play(sound, self.CenterPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,6 +707,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
node.Key = "Refinery";
|
||||
}
|
||||
|
||||
// Append an 's' as the fields were changed from string to string[]
|
||||
if (engineVersion < 20150311)
|
||||
{
|
||||
if (depth == 2 && parentKey == "SoundOnDamageTransition")
|
||||
{
|
||||
if (node.Key == "DamagedSound")
|
||||
node.Key = "DamagedSounds";
|
||||
else if (node.Key == "DestroyedSound")
|
||||
node.Key = "DestroyedSounds";
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user