Files
OpenRA/OpenRA.Mods.Common/Traits/Sound/AnnounceOnKill.cs
reaperrr 3777a8bca9 Moved Voice-related extensions to VoiceExts.
Note: This is a work-around until Selectable can be moved to Mods.Common, which is when the voice extensions should be moved back to ActorExts.

Pulled phrase check before foreach in PlayVoice ActorExts.
Removed superflous actor parameter from PlayVoice/PlayVoiceLocal.

Simplified PlayVoice extensions.

variant is no longer customisable, as all current usages use self.Owner.Country.Race anyway.
2015-05-23 13:46:01 +02:00

49 lines
1.3 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Play the Kill voice of this actor when eliminating enemies.")]
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)
{
// Don't notify suicides
if (e.DamageState == DamageState.Dead && damaged != e.Attacker)
{
if (self.World.WorldTick - lastAnnounce > info.Interval * 25)
self.PlayVoice("Kill");
lastAnnounce = self.World.WorldTick;
}
}
}
}