#region Copyright & License Information /* * Copyright 2007-2010 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 LICENSE. */ #endregion using System; using OpenRA.Mods.RA.Render; using OpenRA.Traits; namespace OpenRA.Mods.RA.Activities { public class Repair : IActivity { public IActivity NextActivity { get; set; } bool isCanceled; int remainingTicks; Actor host; public Repair(Actor host) { this.host = host; } public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; if (remainingTicks == 0) { var health = self.TraitOrDefault(); if (health == null) return NextActivity; var unitCost = self.Info.Traits.Get().Cost; var repairsUnits = host.Info.Traits.Get(); var costPerHp = (repairsUnits.URepairPercent * unitCost) / health.MaxHP; var hpToRepair = Math.Min(host.Info.Traits.Get().URepairStep, health.MaxHP - health.HP); var cost = (int)Math.Ceiling(costPerHp * hpToRepair); if (!self.Owner.PlayerActor.Trait().TakeCash(cost)) { remainingTicks = 1; return this; } self.InflictDamage(self, -hpToRepair, null); if (health.DamageState == DamageState.Undamaged) return NextActivity; if (host != null) host.Trait() .PlayCustomAnim(host, "active"); remainingTicks = (int)(repairsUnits.RepairRate * 60 * 25); } else --remainingTicks; return this; } public void Cancel(Actor self) { isCanceled = true; NextActivity = null; } } }