diff --git a/OpenRA.Mods.RA/PoweredCashTrickler.cs b/OpenRA.Mods.RA/PoweredCashTrickler.cs new file mode 100644 index 0000000..a9690f7 --- /dev/null +++ b/OpenRA.Mods.RA/PoweredCashTrickler.cs @@ -0,0 +1,53 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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.Linq; +using OpenRA.Traits; +using OpenRA.Mods.RA.Effects; + +namespace OpenRA.Mods.RA +{ + class PoweredCashTricklerInfo : ITraitInfo + { + public readonly int Period = 50; + public readonly int Amount = 15; + public readonly bool ShowTicks = true; + public readonly int TickLifetime = 30; + public readonly int TickVelocity = 1; + + public object Create (ActorInitializer init) { return new PoweredCashTrickler(this); } + } + + class PoweredCashTrickler : ITick, ISync + { + [Sync] + int ticks; + PoweredCashTricklerInfo Info; + public PoweredCashTrickler(PoweredCashTricklerInfo info) + { + Info = info; + } + + public void Tick(Actor self) + { + // Check if powered: no trickling if disabled + if (self.TraitsImplementing().Any(d => d.Disabled)) + return; + + if (--ticks < 0) + { + self.Owner.PlayerActor.Trait().GiveCash(Info.Amount); + ticks = Info.Period; + if (Info.ShowTicks) + self.World.AddFrameEndTask(w => w.Add(new CashTick(Info.Amount, Info.TickLifetime, Info.TickVelocity, self.CenterLocation, self.Owner.ColorRamp.GetColor(0)))); + } + } + } +}