view api/Commands/ReplaceUnitEquipmentCommand.cs @ 54:3a90f70dac73

Re #61 - Complete structure of WarFoundry API objects * Remove min/max from EquipmentItem and add description * Add min/max numbers and percentages to UnitEquipmentItem * Make Race schema define min/max number without the ratio (which is the percentage) * Replace use of EquipmentItem with UnitEquipmentItem because of increased use of UnitEquipmentItem for unit-specific data * Use doubles instead of floats for equipment amounts * Distinguish between ratio and absolute limits * Delete UnitEquipmentItemObj helper class that was purely used for UI Re #9 - Use smaller methods * Deprecate long Race and EquipmentItem constructors and ensure all getters/setters exist Also: * Migrate Unit to using genericed collections * Always use GameSystem object for Race, not ID string
author IBBoard <dev@ibboard.co.uk>
date Sun, 05 Apr 2009 13:45:23 +0000
parents 306558904c2a
children 3ea0ab04352b
line wrap: on
line source

// This file (ReplaceUnitEquipmentCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
//
// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.

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

namespace IBBoard.WarFoundry.API.Commands
{
	/// <summary>
	/// Summary description for ReplaceUnitEquipmentCommand.
	/// </summary>
	public class ReplaceUnitEquipmentCommand : Command
	{
		private SetUnitEquipmentAmountCommand removeOldCommand, addNewCommand;
		
		public ReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, UnitEquipmentItem newItem, double amount)
		{
			removeOldCommand = new SetUnitEquipmentAmountCommand(unit, oldItem, 0);
			addNewCommand = new SetUnitEquipmentAmountCommand(unit, newItem, amount);
		}

		public override bool CanExecute()
		{
			return removeOldCommand.CanExecute() && addNewCommand.CanExecute();
		}

		public override string Description
		{
			get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); }
		}

		public override string UndoDescription
		{
			get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); }
		}

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

		public override void Redo()
		{
			removeOldCommand.Redo();
			addNewCommand.Redo();
		}

		public override void Undo()
		{
			addNewCommand.Undo();
			removeOldCommand.Undo();
		}


		public override string Name
		{
			get { return "Replace required equipment"; }
		}
	}
}