Files
OpenRA/OpenRA.Mods.RA/Power/AffectedByPowerOutage.cs

59 lines
1.4 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2014 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.Drawing;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Power
{
public class AffectedByPowerOutageInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new AffectedByPowerOutage(init.self); }
}
public class AffectedByPowerOutage : INotifyCapture, ISelectionBar, IPowerModifier, IDisable
{
PowerManager playerPower;
public AffectedByPowerOutage(Actor self)
{
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
public float GetValue()
{
if (playerPower.PowerOutageRemainingTicks <= 0)
return 0;
return (float)playerPower.PowerOutageRemainingTicks / playerPower.PowerOutageTotalTicks;
}
public Color GetColor()
{
return Color.Yellow;
}
public int GetPowerModifier()
{
return playerPower.PowerOutageRemainingTicks > 0 ? 0 : 100;
}
public bool Disabled
{
get { return playerPower.PowerOutageRemainingTicks > 0; }
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
playerPower = newOwner.PlayerActor.Trait<PowerManager>();
}
}
}