Mercurial > repos > snowblizz-super-API-ideas
annotate api/Util/UnitEquipmentUtil.cs @ 213:c6713a1b4c0d
* Line ending changes
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Nov 2009 20:06:36 +0000 |
parents | dce340f9cedc |
children | 6fe0cb1bf74f |
rev | line source |
---|---|
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (UnitEquipmentUtil.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
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. |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.Text; |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
8 using IBBoard.CustomMath; |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
182
diff
changeset
|
9 using IBBoard.Limits; |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard.WarFoundry.API.Objects; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 namespace IBBoard.WarFoundry.API.Util |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 { |
162
624422e91a1c
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
161
diff
changeset
|
14 public class UnitEquipmentUtil |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 /// <summary> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 /// Gets an array of allowed <see cref="UnitEquipmentItem"/>s based on the current selections of the unit, taking in to account Mutex groups and other limits. |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 /// </summary> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 /// <param name="unit">The <see cref="Unit"/> to get equipment items for</param> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 /// <returns>The array of allowed <see cref="UnitEquipmentItem"/>s</returns> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 public static UnitEquipmentItem[] GetAllowedEquipmentItems(Unit unit) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 UnitEquipmentItem[] currItems = unit.GetEquipment(); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 foreach (UnitEquipmentItem item in GetAllEquipmentItems(unit)) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 bool allowed = IsAllowedByMutex(item, currItems); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 if (allowed) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 list.Add(item); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 return list.ToArray(); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 private static bool IsAllowedByMutex(UnitEquipmentItem item, UnitEquipmentItem[] currItems) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 bool allowed = true; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 foreach (UnitEquipmentItem currItem in currItems) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 if (ItemsAreMutuallyExclusive(currItem, item)) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 allowed = false; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 break; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 return allowed; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 /// <summary> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 /// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups. |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 /// </summary> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 /// <param name="unit">The unit that wants to take the equipment item</param> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 /// <param name="item">The item to check blocking items for</param> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 /// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns> |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 public static List<UnitEquipmentItem> GetBlockingEquipmentItems(Unit unit, UnitEquipmentItem item) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 List<UnitEquipmentItem> items = new List<UnitEquipmentItem>(); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 UnitEquipmentItem[] currItems = unit.GetEquipment(); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 |
174 | 66 foreach (UnitEquipmentItem unitItem in currItems) |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 { |
194
1412a42190a1
* Fix mutex group clash checking
IBBoard <dev@ibboard.co.uk>
parents:
190
diff
changeset
|
68 if (ItemsAreMutuallyExclusive(unitItem, item)) |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 items.Add(unitItem); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 return items; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 public static UnitEquipmentItem[] GetAllEquipmentItems(Unit unit) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 return unit.UnitType.GetEquipmentItems(); |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 public static bool ItemsAreMutuallyExclusive(UnitEquipmentItem item1, UnitEquipmentItem item2) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 bool areMutex = false; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 string[] item1mutex = item1.MutexGroups; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
86 string[] item2mutex = item2.MutexGroups; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
88 foreach (string mutex in item1mutex) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 foreach (string otherMutex in item2mutex) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 if (mutex.Equals(otherMutex)) |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 { |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 areMutex = true; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 goto postLoop; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
97 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
99 postLoop: |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 return areMutex; |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 } |
182
6fe336109128
Re #198: Add slots with count to unit
IBBoard <dev@ibboard.co.uk>
parents:
174
diff
changeset
|
103 |
6fe336109128
Re #198: Add slots with count to unit
IBBoard <dev@ibboard.co.uk>
parents:
174
diff
changeset
|
104 public static int GetMaxEquipmentCount (Unit unit, UnitEquipmentItem equip) |
203 | 105 { |
106 return GetEquipmentCountLimit (unit, equip.MaxLimit.GetLimit(unit.Size), equip); | |
185 | 107 } |
108 | |
187 | 109 private static int GetEquipmentCountLimit (Unit unit, int currLimit, UnitEquipmentItem equip) |
185 | 110 { |
187 | 111 int newLimit = currLimit; |
189 | 112 AbstractLimit limit = GetSlotLimitForItem(unit, equip); |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
182
diff
changeset
|
113 |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
182
diff
changeset
|
114 if (!(limit is UnlimitedLimit)) |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
182
diff
changeset
|
115 { |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
116 int slotMax = limit.GetLimit (unit.Size) - unit.GetEquipmentAmountInSlotExcludingItem(equip); |
187 | 117 newLimit = Math.Min (slotMax, newLimit); |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
182
diff
changeset
|
118 } |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
182
diff
changeset
|
119 |
187 | 120 return newLimit; |
182
6fe336109128
Re #198: Add slots with count to unit
IBBoard <dev@ibboard.co.uk>
parents:
174
diff
changeset
|
121 } |
189 | 122 |
123 private static AbstractLimit GetSlotLimitForItem(Unit unit, UnitEquipmentItem equip) | |
124 { | |
125 return unit.UnitType.GetEquipmentSlotLimit(equip.SlotName); | |
126 } | |
127 | |
186 | 128 |
185 | 129 public static int GetMinEquipmentCount (Unit unit, UnitEquipmentItem equip) |
203 | 130 { |
131 return GetEquipmentCountLimit (unit, equip.MinLimit.GetLimit(unit.Size), equip); | |
185 | 132 } |
186 | 133 |
134 public static bool IsEquipmentRatioLimited(Unit unit, UnitEquipmentItem equip) | |
135 { | |
189 | 136 AbstractLimit limit = GetSlotLimitForItem(unit, equip); |
186 | 137 return equip.IsRatioLimit && (limit is IPercentageLimit || limit is UnlimitedLimit); |
138 } | |
187 | 139 |
140 public static double GetMaxEquipmentPercentage(Unit unit, UnitEquipmentItem equip) | |
141 { | |
210
e586ea79c102
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
209
diff
changeset
|
142 return GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MaxLimit, unit); |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
143 } |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
144 |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
145 private static double GetPercentageOfUnitSize(int number, Unit unit) |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
146 { |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
147 return IBBMath.Percentage(number, unit.Size); |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
148 } |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
149 |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
150 private static double GetMinOfSlotLimitAndEquipmentLimit(UnitEquipmentItem equip, AbstractLimit equipLimit, Unit unit) |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
151 { |
187 | 152 double limit = 0; |
189 | 153 AbstractLimit slotLimit = GetSlotLimitForItem(unit, equip); |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
154 |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
155 if (slotLimit is IPercentageLimit) |
187 | 156 { |
203 | 157 limit = ((IPercentageLimit)slotLimit).Percentage - GetPercentageOfUnitSize(unit.GetEquipmentAmountInSlotExcludingItem(equip), unit); |
187 | 158 } |
188 | 159 else |
160 { | |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
161 int remaining = slotLimit.GetLimit(unit.Size) - unit.GetEquipmentAmountInSlotExcludingItem(equip); |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
162 limit = GetPercentageOfUnitSize(remaining, unit); |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
163 } |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
164 |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
165 if (equip.IsRatioLimit) |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
166 { |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
167 limit = Math.Min(limit, ((IPercentageLimit)equipLimit).Percentage); |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
168 } |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
169 else |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
170 { |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
171 limit = Math.Min(limit, GetPercentageOfUnitSize(equipLimit.GetLimit(unit.Size), unit)); |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
172 } |
187 | 173 |
174 return limit; | |
175 } | |
190 | 176 |
177 public static double GetMinEquipmentPercentage(Unit unit, UnitEquipmentItem equip) | |
203 | 178 { |
209
1cde49671c8b
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
203
diff
changeset
|
179 return GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MinLimit, unit); |
190 | 180 } |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
181 |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
182 public static double GetEquipmentAmount(Unit unit, UnitEquipmentItem item) |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
183 { |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
184 double amount = 0; |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
185 AbstractUnitEquipmentItemSelection selection = unit.GetEquipmentSelection(item); |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
186 |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
187 if (selection != null) |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
188 { |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
189 amount = selection.AmountTaken; |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
190 } |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
191 |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
192 return amount; |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
193 } |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
194 |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
195 public static bool GetEquipmentAmountIsRatio(Unit unit, UnitEquipmentItem item) |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
196 { |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
197 return (unit.GetEquipmentSelection(item) is UnitEquipmentRatioSelection); |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
198 } |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
199 |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
200 public static int GetEquipmentAmountTaken(Unit unit, UnitEquipmentItem item) |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
201 { |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
202 AbstractUnitEquipmentItemSelection selection = unit.GetEquipmentSelection(item); |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
203 return (selection == null ? 0 : selection.NumberTaken); |
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
210
diff
changeset
|
204 } |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
205 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
206 } |