view api/Commands/SetUnitEquipmentAmountCommand.cs @ 11:5a1df00b0359

Re #9 - Make WarFoundry API load files in small methods * Add "add unit type" and "add equipment" methods to Race * Deprecate old "set unit types" and "set equipment" methods on Race * Update WarFoundryXmlFactory to use new methods * Create DuplicateItemException for later use
author IBBoard <dev@ibboard.co.uk>
date Sun, 18 Jan 2009 16:24:03 +0000
parents 520818033bb6
children 306558904c2a
line wrap: on
line source

using System;
using IBBoard.Commands;
using IBBoard.Lang;
using IBBoard.WarFoundry.API.Objects;

namespace IBBoard.WarFoundry.API.Commands
{
	/// <summary>
	/// Summary description for SetUnitEquipmentAmountCommand.
	/// </summary>
	public class SetUnitEquipmentAmountCommand : Command
	{
		private Unit unit;
		private EquipmentItem equip;
		private float newAmount, oldAmount;
		
		public SetUnitEquipmentAmountCommand(Unit unit, EquipmentItem item, float amount)
		{
			this.unit = unit;
			equip = item;
			newAmount = amount;
			oldAmount = unit.GetEquipmentAmount(equip.ID);
		}

		public override bool CanExecute()
		{
			return (unit!=null && equip!=null);
		}

		public override string Description
		{
			get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItemObj.FormatEquipmentAmount(equip, newAmount); }
		}

		public override string UndoDescription
		{
			get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItemObj.FormatEquipmentAmount(equip, oldAmount); }
		}

		public override bool Execute()
		{
			this.Redo();
			return true;
		}

		public override void Redo()
		{
			unit.SetEquipmentAmount(equip.ID, newAmount);
		}

		public override void Undo()
		{
			unit.SetEquipmentAmount(equip.ID, oldAmount);
		}

		public override string Name
		{
			get { return "Set equipment amount"; }
		}

		public EquipmentItem EquipItem
		{
			get { return equip; }
		}

		public Unit Unit
		{
			get { return unit; }
		}
	}
}