Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Commands/SetUnitEquipmentAmountCommand.cs @ 82:3ea0ab04352b
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 18:59:49 +0000 |
parents | 3a90f70dac73 |
children |
rev | line source |
---|---|
15 | 1 // This file (SetUnitEquipmentAmountCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
2 // | |
3 // 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. | |
4 | |
82 | 5 using System; |
0 | 6 using IBBoard.Commands; |
7 using IBBoard.Lang; | |
82 | 8 using IBBoard.WarFoundry.API.Objects; |
9 | |
10 namespace IBBoard.WarFoundry.API.Commands | |
11 { | |
12 /// <summary> | |
13 /// Summary description for SetUnitEquipmentAmountCommand. | |
14 /// </summary> | |
15 public class SetUnitEquipmentAmountCommand : Command | |
16 { | |
17 private Unit unit; | |
18 private UnitEquipmentItem equip; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
19 private double newAmount; |
82 | 20 private double oldAmount; |
21 | |
22 public SetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item, double amount) | |
23 { | |
24 this.unit = unit; | |
25 equip = item; | |
26 newAmount = amount; | |
27 oldAmount = unit.GetEquipmentAmount(equip.ID); | |
28 } | |
29 | |
30 public override bool CanExecute() | |
31 { | |
32 return (unit!=null && equip!=null); | |
33 } | |
34 | |
35 public override string Description | |
36 { | |
37 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, newAmount); } | |
38 } | |
39 | |
40 public override string UndoDescription | |
41 { | |
42 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, oldAmount); } | |
43 } | |
44 | |
45 public override bool Execute() | |
46 { | |
47 this.Redo(); | |
48 return true; | |
49 } | |
50 | |
51 public override void Redo() | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
52 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
53 if (equip.IsRatioLimit) |
82 | 54 { |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
55 unit.SetEquipmentRatio(equip, newAmount); |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
56 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
57 else |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
58 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
59 unit.SetEquipmentAmount(equip, (int)newAmount); |
82 | 60 } |
61 } | |
62 | |
63 public override void Undo() | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
64 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
65 if (equip.IsRatioLimit) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
66 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
67 unit.SetEquipmentRatio(equip, oldAmount); |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
68 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
69 else |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
70 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
71 unit.SetEquipmentAmount(equip, (int)oldAmount); |
82 | 72 } |
73 } | |
74 | |
75 public override string Name | |
76 { | |
77 get { return "Set equipment amount"; } | |
78 } | |
79 | |
80 public UnitEquipmentItem EquipItem | |
81 { | |
82 get { return equip; } | |
83 } | |
84 | |
85 public Unit Unit | |
86 { | |
87 get { return unit; } | |
88 } | |
89 } | |
90 } |