annotate api/Util/UnitEquipmentUtil.cs @ 188:354d51cc002b

Re #198: Add equipment slots * Pass tests
author IBBoard <dev@ibboard.co.uk>
date Tue, 27 Oct 2009 20:58:10 +0000
parents 104a683b5ef8
children 0b413f41e6e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 182
diff changeset
8 using IBBoard.Limits;
161
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.WarFoundry.API.Objects;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 namespace IBBoard.WarFoundry.API.Util
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
162
624422e91a1c Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents: 161
diff changeset
13 public class UnitEquipmentUtil
161
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 /// <summary>
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 /// 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
17 /// </summary>
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// <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
19 /// <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
20 public static UnitEquipmentItem[] GetAllowedEquipmentItems(Unit unit)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 UnitEquipmentItem[] currItems = unit.GetEquipment();
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 foreach (UnitEquipmentItem item in GetAllEquipmentItems(unit))
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 bool allowed = IsAllowedByMutex(item, currItems);
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 if (allowed)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 list.Add(item);
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
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 return list.ToArray();
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
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 private static bool IsAllowedByMutex(UnitEquipmentItem item, UnitEquipmentItem[] currItems)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 bool allowed = true;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 foreach (UnitEquipmentItem currItem in currItems)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 if (ItemsAreMutuallyExclusive(currItem, item))
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 allowed = false;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 break;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 }
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 return allowed;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
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 /// <summary>
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 /// 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
56 /// </summary>
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 /// <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
58 /// <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
59 /// <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
60 public static List<UnitEquipmentItem> GetBlockingEquipmentItems(Unit unit, UnitEquipmentItem item)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 List<UnitEquipmentItem> items = new List<UnitEquipmentItem>();
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 UnitEquipmentItem[] currItems = unit.GetEquipment();
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
174
33433862467f * Make use of local variable
IBBoard <dev@ibboard.co.uk>
parents: 162
diff changeset
65 foreach (UnitEquipmentItem unitItem in currItems)
161
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 if (!ItemsAreMutuallyExclusive(unitItem, item))
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 items.Add(unitItem);
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 }
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 return items;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }
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 public static UnitEquipmentItem[] GetAllEquipmentItems(Unit unit)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 return unit.UnitType.GetEquipmentItems();
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 }
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 public static bool ItemsAreMutuallyExclusive(UnitEquipmentItem item1, UnitEquipmentItem item2)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 bool areMutex = false;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 string[] item1mutex = item1.MutexGroups;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 string[] item2mutex = item2.MutexGroups;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 foreach (string mutex in item1mutex)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 foreach (string otherMutex in item2mutex)
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 if (mutex.Equals(otherMutex))
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 {
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 areMutex = true;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 goto postLoop;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 }
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 postLoop:
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 return areMutex;
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 }
182
6fe336109128 Re #198: Add slots with count to unit
IBBoard <dev@ibboard.co.uk>
parents: 174
diff changeset
102
6fe336109128 Re #198: Add slots with count to unit
IBBoard <dev@ibboard.co.uk>
parents: 174
diff changeset
103 public static int GetMaxEquipmentCount (Unit unit, UnitEquipmentItem equip)
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
104 {
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
105 int unitSize = unit.Size;
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
106 int max = Math.Max(equip.MinLimit.GetLimit(unitSize), equip.MaxLimit.GetLimit (unitSize));
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
107 return GetEquipmentCountLimit (unit, max, equip);
185
3577bfb7702b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
108 }
3577bfb7702b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
109
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
110 private static int GetEquipmentCountLimit (Unit unit, int currLimit, UnitEquipmentItem equip)
185
3577bfb7702b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
111 {
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
112 int newLimit = currLimit;
185
3577bfb7702b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
113 AbstractLimit limit = unit.UnitType.GetEquipmentSlotLimit (equip.SlotName);
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 182
diff changeset
114
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 182
diff changeset
115 if (!(limit is UnlimitedLimit))
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 182
diff changeset
116 {
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
117 int slotMax = limit.GetLimit (unit.Size) - unit.GetEquipmentAmountInSlot (equip.SlotName);
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
118 newLimit = Math.Min (slotMax, newLimit);
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 182
diff changeset
119 }
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 182
diff changeset
120
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
121 return newLimit;
182
6fe336109128 Re #198: Add slots with count to unit
IBBoard <dev@ibboard.co.uk>
parents: 174
diff changeset
122 }
186
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
123
185
3577bfb7702b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
124 public static int GetMinEquipmentCount (Unit unit, UnitEquipmentItem equip)
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
125 {
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
126 int unitSize = unit.Size;
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
127 int min = Math.Min (equip.MinLimit.GetLimit (unitSize), equip.MaxLimit.GetLimit (unitSize));
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
128 return GetEquipmentCountLimit (unit, min, equip);
185
3577bfb7702b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
129 }
186
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
130
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
131 public static bool IsEquipmentRatioLimited(Unit unit, UnitEquipmentItem equip)
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
132 {
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
133 AbstractLimit limit = unit.UnitType.GetEquipmentSlotLimit(equip.SlotName);
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
134 return equip.IsRatioLimit && (limit is IPercentageLimit || limit is UnlimitedLimit);
c8682d206a73 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 185
diff changeset
135 }
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
136
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
137 public static double GetMaxEquipmentPercentage(Unit unit, UnitEquipmentItem equip)
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
138 {
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
139 double limit = 0;
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
140
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
141 if (equip.IsRatioLimit)
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
142 {
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
143 limit = Math.Max(((IPercentageLimit)equip.MinLimit).Percentage, ((IPercentageLimit)equip.MaxLimit).Percentage);
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
144 }
188
354d51cc002b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 187
diff changeset
145 else
354d51cc002b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 187
diff changeset
146 {
354d51cc002b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 187
diff changeset
147 int unitSize = unit.Size;
354d51cc002b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 187
diff changeset
148 limit = (equip.MaxLimit.GetLimit(unitSize) / (double)unitSize) * 100.0;
354d51cc002b Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 187
diff changeset
149 }
187
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
150
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
151 return limit;
104a683b5ef8 Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 186
diff changeset
152 }
161
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 }
81abc04b3dbe Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 }