Mercurial > repos > snowblizz-super-API-ideas
view api/Commands/ReplaceUnitEquipmentCommand.cs @ 79:284ebe05158c
Re #61 - Complete structure of API objects
* Add methods for new cost multiplier and rounding
* Reduce "train wreck" code by making some EquipmentItem properties visible on the UnitEquipmentItem
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 19 May 2009 14:40:10 +0000 |
parents | 3a90f70dac73 |
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"; } } } }