Files
OpenRA/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs
Taryn Hill dd17a99ab5 Checks to make sure Attacker is not null.
Ignores self-attacking.
Ignores friendly-fire that does <= 0 damage (repairs).
2013-10-31 11:56:01 -04:00

58 lines
1.5 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2012 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 System;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class BaseAttackNotifierInfo : ITraitInfo
{
public readonly int NotifyInterval = 30; // seconds
public object Create(ActorInitializer init) { return new BaseAttackNotifier(this); }
}
public class BaseAttackNotifier : INotifyDamage
{
BaseAttackNotifierInfo info;
public int lastAttackTime = -1;
public CPos lastAttackLocation;
public BaseAttackNotifier(BaseAttackNotifierInfo info) { this.info = info; }
public void Damaged(Actor self, AttackInfo e)
{
// only track last hit against our base
if (!self.HasTrait<Building>())
return;
if (e.Attacker == null)
return;
if (e.Attacker.Owner == self.Owner)
return;
if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0)
return;
if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25)
Sound.PlayNotification(self.Owner, "Speech", "BaseAttack", self.Owner.Country.Race);
lastAttackLocation = self.CenterPosition.ToCPos();
lastAttackTime = self.World.FrameNumber;
}
}
}