0
|
1 using System;
|
|
2 using IBBoard.Commands;
|
|
3 using IBBoard.Lang;
|
|
4 using IBBoard.WarFoundry.API.Objects;
|
|
5
|
|
6 namespace IBBoard.WarFoundry.API.Commands
|
|
7 {
|
|
8 /// <summary>
|
|
9 /// Summary description for SetUnitEquipmentAmountCommand.
|
|
10 /// </summary>
|
|
11 public class SetUnitEquipmentAmountCommand : Command
|
|
12 {
|
|
13 private Unit unit;
|
|
14 private EquipmentItem equip;
|
|
15 private float newAmount, oldAmount;
|
|
16
|
|
17 public SetUnitEquipmentAmountCommand(Unit unit, EquipmentItem item, float amount)
|
|
18 {
|
|
19 this.unit = unit;
|
|
20 equip = item;
|
|
21 newAmount = amount;
|
|
22 oldAmount = unit.GetEquipmentAmount(equip.ID);
|
|
23 }
|
|
24
|
|
25 public override bool CanExecute()
|
|
26 {
|
|
27 return (unit!=null && equip!=null);
|
|
28 }
|
|
29
|
|
30 public override string Description
|
|
31 {
|
|
32 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItemObj.FormatEquipmentAmount(equip, newAmount); }
|
|
33 }
|
|
34
|
|
35 public override string UndoDescription
|
|
36 {
|
|
37 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItemObj.FormatEquipmentAmount(equip, oldAmount); }
|
|
38 }
|
|
39
|
|
40 public override bool Execute()
|
|
41 {
|
|
42 this.Redo();
|
|
43 return true;
|
|
44 }
|
|
45
|
|
46 public override void Redo()
|
|
47 {
|
|
48 unit.SetEquipmentAmount(equip.ID, newAmount);
|
|
49 }
|
|
50
|
|
51 public override void Undo()
|
|
52 {
|
|
53 unit.SetEquipmentAmount(equip.ID, oldAmount);
|
|
54 }
|
|
55
|
|
56 public override string Name
|
|
57 {
|
|
58 get { return "Set equipment amount"; }
|
|
59 }
|
|
60
|
|
61 public EquipmentItem EquipItem
|
|
62 {
|
|
63 get { return equip; }
|
|
64 }
|
|
65
|
|
66 public Unit Unit
|
|
67 {
|
|
68 get { return unit; }
|
|
69 }
|
|
70 }
|
|
71 }
|