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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
1 // This file (SetUnitEquipmentAmountCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
2 //
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
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.
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
4
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
5 using System;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.Commands;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
8 using IBBoard.WarFoundry.API.Objects;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
9
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
10 namespace IBBoard.WarFoundry.API.Commands
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
11 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
12 /// <summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
13 /// Summary description for SetUnitEquipmentAmountCommand.
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
14 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
15 public class SetUnitEquipmentAmountCommand : Command
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
16 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
17 private Unit unit;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
20 private double oldAmount;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
21
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
22 public SetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item, double amount)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
23 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
24 this.unit = unit;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
25 equip = item;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
26 newAmount = amount;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
27 oldAmount = unit.GetEquipmentAmount(equip.ID);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
28 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
29
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
30 public override bool CanExecute()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
31 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
32 return (unit!=null && equip!=null);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
33 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
34
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
35 public override string Description
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
36 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
37 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, newAmount); }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
38 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
39
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
40 public override string UndoDescription
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
41 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
42 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, oldAmount); }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
43 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
44
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
45 public override bool Execute()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
46 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
47 this.Redo();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
48 return true;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
49 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
50
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
60 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
61 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
62
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
72 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
73 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
74
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
75 public override string Name
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
76 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
77 get { return "Set equipment amount"; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
78 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
79
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
80 public UnitEquipmentItem EquipItem
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
81 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
82 get { return equip; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
83 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
84
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
85 public Unit Unit
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
86 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
87 get { return unit; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
88 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
89 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
90 }