Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Util/UnitEquipmentUtil.cs @ 206:0ca96143aa03
Re #211: Swapping from percentage to numeric selection doesn't remove old selection
* Use Unit's "RemoveEquipmentItem" method instead of just removing from the equipment list and not the slot list
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 09 Nov 2009 12:20:34 +0000 |
parents | df4e56e2ee71 |
children | 1cde49671c8b |
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 { | |
203 | 142 double limitMax = GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MaxLimit, unit); |
143 double countMax = GetPercentageOfUnitSize(GetMaxEquipmentCount(unit, equip), unit); | |
144 return Math.Max(limitMax, countMax); | |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
145 } |
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 private static double GetPercentageOfUnitSize(int number, Unit unit) |
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 return IBBMath.Percentage(number, unit.Size); |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
150 } |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
151 |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
152 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
|
153 { |
187 | 154 double limit = 0; |
189 | 155 AbstractLimit slotLimit = GetSlotLimitForItem(unit, equip); |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
156 |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
157 if (slotLimit is IPercentageLimit) |
187 | 158 { |
203 | 159 limit = ((IPercentageLimit)slotLimit).Percentage - GetPercentageOfUnitSize(unit.GetEquipmentAmountInSlotExcludingItem(equip), unit); |
187 | 160 } |
188 | 161 else |
162 { | |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
163 int remaining = slotLimit.GetLimit(unit.Size) - unit.GetEquipmentAmountInSlotExcludingItem(equip); |
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
164 limit = GetPercentageOfUnitSize(remaining, unit); |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
165 } |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
166 |
202
37ad50823531
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
167 if (equip.IsRatioLimit) |
201
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 limit = Math.Min(limit, ((IPercentageLimit)equipLimit).Percentage); |
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 else |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
172 { |
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
196
diff
changeset
|
173 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
|
174 } |
187 | 175 |
176 return limit; | |
177 } | |
190 | 178 |
179 public static double GetMinEquipmentPercentage(Unit unit, UnitEquipmentItem equip) | |
203 | 180 { |
181 double limitMin = GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MinLimit, unit); | |
182 double countMin = GetPercentageOfUnitSize(GetMinEquipmentCount(unit, equip), unit); | |
183 return Math.Min(limitMin, countMin); | |
190 | 184 } |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
185 } |
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
186 } |