Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Objects/AbstractUnitEquipmentItemSelection.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children | 7179c585d31d |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (AbstractUnitEquipmentItemSelection.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 and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | |
4 | |
5 using System; | |
6 | |
7 namespace IBBoard.WarFoundry.API.Objects | |
8 { | |
9 /// <summary> | |
10 /// An abstract class that defines a selection of equipment for a unit | |
11 /// </summary> | |
12 public abstract class AbstractUnitEquipmentItemSelection | |
13 { | |
14 private Unit selectionForUnit; | |
15 private UnitEquipmentItem selectedItem; | |
16 private double amountTaken; | |
17 | |
18 public AbstractUnitEquipmentItemSelection(Unit unit, UnitEquipmentItem item, double amount) | |
19 { | |
20 selectionForUnit = unit; | |
21 selectedItem = item; | |
22 AmountTaken = amount; | |
23 } | |
24 | |
25 public Unit EquipmentForUnit | |
26 { | |
27 get | |
28 { | |
29 return selectionForUnit; | |
30 } | |
31 } | |
32 | |
33 public UnitEquipmentItem EquipmentItem | |
34 { | |
35 get | |
36 { | |
37 return selectedItem; | |
38 } | |
39 } | |
40 | |
41 public double AmountTaken | |
42 { | |
43 get | |
44 { | |
45 return amountTaken; | |
46 } | |
47 set | |
48 { | |
49 amountTaken = value; | |
50 | |
51 if (!IsValidValue(value)) | |
52 { | |
53 //Fire validation failed event (once we have one) | |
54 } | |
55 } | |
56 } | |
57 | |
58 public bool IsValid | |
59 { | |
60 get | |
61 { | |
62 return IsValidValue(AmountTaken) && IsInRange(AmountTaken); | |
63 } | |
64 } | |
65 | |
66 protected virtual bool IsValidValue(double newValue) | |
67 { | |
68 return true; | |
69 } | |
70 | |
71 protected bool IsInRange(double newValue) | |
72 { | |
73 int unitSize = EquipmentForUnit.Size; | |
74 int minLimit = EquipmentItem.MinLimit.GetLimit(unitSize); | |
75 int maxLimit = EquipmentItem.MaxLimit.GetLimit(unitSize); | |
76 return (minLimit <= newValue) && (newValue <= maxLimit); | |
77 } | |
78 | |
79 public double TotalCost | |
80 { | |
81 get | |
82 { | |
83 return NumberTaken * EquipmentItem.Cost; | |
84 } | |
85 } | |
86 | |
87 public abstract int NumberTaken | |
88 { | |
89 get; | |
90 } | |
91 } | |
92 } |