1
2 package hoplugins.commons.vo;
3
4 import plugins.IMatchDetails;
5
6
7 /***
8 * Class with holds the Ratings of a team in the 7 areas of the field
9 *
10 * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
11 */
12 public class MatchRating {
13
14
15 private double centralAttack;
16 private double centralDefense;
17 private double leftAttack;
18 private double leftDefense;
19 private double midfield;
20 private double rightAttack;
21 private double rightDefense;
22
23
24
25 /***
26 * Sets the central attack rating
27 *
28 * @param rating The rating
29 */
30 public final void setCentralAttack(double rating) {
31 centralAttack = rating;
32 }
33
34 /***
35 * Gets the central attack rating
36 *
37 * @return The rating
38 */
39 public final double getCentralAttack() {
40 return centralAttack;
41 }
42
43 /***
44 * Sets the central defense rating
45 *
46 * @param rating The rating
47 */
48 public final void setCentralDefense(double rating) {
49 centralDefense = rating;
50 }
51
52 /***
53 * Gets the central defense rating
54 *
55 * @return The rating
56 */
57 public final double getCentralDefense() {
58 return centralDefense;
59 }
60
61 /***
62 * Returns the calculated <B>HatStats</B><code>(3 midfield) + (sum of defence) + (sum of
63 * attack )</code>
64 *
65 * @return the rating
66 */
67 public final double getHatStats() {
68 return (midfield * 3) + leftAttack + rightAttack + centralAttack + centralDefense
69 + leftDefense + rightDefense;
70 }
71
72 /***
73 * Sets the left attack rating
74 *
75 * @param rating The rating
76 */
77 public final void setLeftAttack(double rating) {
78 leftAttack = rating;
79 }
80
81 /***
82 * Gets the left attack rating
83 *
84 * @return The rating
85 */
86 public final double getLeftAttack() {
87 return leftAttack;
88 }
89
90 /***
91 * Sets the left defense rating
92 *
93 * @param rating The rating
94 */
95 public final void setLeftDefense(double rating) {
96 leftDefense = rating;
97 }
98
99 /***
100 * Gets the left defense rating
101 *
102 * @return The rating
103 */
104 public final double getLeftDefense() {
105 return leftDefense;
106 }
107
108 /***
109 * Returns the calculated LoddarStats
110 *
111 * @param tactic The tactic code
112 * @param level The tactic rating
113 *
114 * @return the rating
115 */
116 public final double getLoddarStats(int tactic, int level) {
117 final double MIDFIELD_SHIFT = 0.0;
118 final double COUNTERATTACK_WEIGHT = 0.25;
119 final double DEFENSE_WEIGHT = 0.47;
120 final double ATTACK_WEIGHT = 1 - DEFENSE_WEIGHT;
121 final double CENTRAL_WEIGHT = 0.37;
122 final double WINGER_WEIGTH = (1 - CENTRAL_WEIGHT) / 2d;
123
124 double correctedCentralWeigth = CENTRAL_WEIGHT;
125
126 switch (tactic) {
127 case IMatchDetails.TAKTIK_MIDDLE:
128 correctedCentralWeigth = CENTRAL_WEIGHT + (((0.2 * (level - 1)) / 19d) + 0.2);
129 break;
130
131 case IMatchDetails.TAKTIK_WINGS:
132 correctedCentralWeigth = CENTRAL_WEIGHT - (((0.2 * (level - 1)) / 19d) + 0.2);
133 break;
134
135 default:
136 break;
137 }
138
139 final double correctedWingerWeight = (1 - correctedCentralWeigth) / 2d;
140
141 double counterCorrection = 0;
142
143 if (tactic == IMatchDetails.TAKTIK_KONTER) {
144 counterCorrection = (COUNTERATTACK_WEIGHT * 2 * level) / (level + 20);
145 }
146
147
148 final double attackStrength = (ATTACK_WEIGHT + counterCorrection) * ((correctedCentralWeigth * hq(centralAttack))
149 + (correctedWingerWeight * (hq(leftAttack) + hq(rightAttack))));
150
151
152 final double defenseStrength = DEFENSE_WEIGHT * ((CENTRAL_WEIGHT * hq(centralDefense))
153 + (WINGER_WEIGTH * (hq(leftDefense) + hq(rightDefense))));
154
155
156 final double midfieldFactor = MIDFIELD_SHIFT + ((1 - MIDFIELD_SHIFT) * hq(midfield));
157
158
159 return 80 * midfieldFactor * (defenseStrength + attackStrength);
160 }
161
162 /***
163 * Sets the midfield rating
164 *
165 * @param rating The rating
166 */
167 public final void setMidfield(double rating) {
168 midfield = rating;
169 }
170
171 /***
172 * Gets the midfield rating
173 *
174 * @return The rating
175 */
176 public final double getMidfield() {
177 return midfield;
178 }
179
180 /***
181 * Returns the calculated <B>PStats</B> (aka PeasoStats)
182 *
183 * @return the rating
184 */
185 public final double getPStats() {
186 final double MIDFIELD = 0.46;
187 final double ATTACK = 0.32;
188 final double DEFENSE = 0.22;
189 final double SIDE = 0.3;
190 final double CENTER = 0.4;
191
192 return (rightDefense * DEFENSE * SIDE) + (centralDefense * DEFENSE * CENTER)
193 + (leftDefense * DEFENSE * SIDE) + (rightAttack * ATTACK * SIDE)
194 + (centralAttack * ATTACK * CENTER) + (leftAttack * ATTACK * SIDE)
195 + (midfield * MIDFIELD);
196 }
197
198 /***
199 * Sets the right attack rating
200 *
201 * @param rating The rating
202 */
203 public final void setRightAttack(double rating) {
204 rightAttack = rating;
205 }
206
207 /***
208 * Gets the right attack rating
209 *
210 * @return The rating
211 */
212 public final double getRightAttack() {
213 return rightAttack;
214 }
215
216 /***
217 * Sets the right defense rating
218 *
219 * @param rating The rating
220 */
221 public final void setRightDefense(double rating) {
222 rightDefense = rating;
223 }
224
225 /***
226 * Gets the right defense rating
227 *
228 * @return The rating
229 */
230 public final double getRightDefense() {
231 return rightDefense;
232 }
233
234 /***
235 * Returns the calculated <B>Smart Squad Rating</B> (<code>Squad Rating / stars</code>)
236 *
237 * @param stars Team star rating
238 *
239 * @return the rating
240 */
241 public final double getSmartSquad(double stars) {
242 return getSquad() / stars;
243 }
244
245 /***
246 * Returns the calculated <B>Squad Rating</B><code>(2 midfield) + (sum of defence) + (sum of
247 * attack )</code>
248 *
249 * @return the rating
250 */
251 public final double getSquad() {
252 return (midfield * 2) + leftAttack + rightAttack + centralAttack + centralDefense
253 + leftDefense + rightDefense;
254 }
255
256 /***
257 * Convert reduced float rating (1.00....20.99) to original integer HT rating (1...80) one +0.5
258 * is because of correct rounding to integer
259 *
260 * @param x HO float rating
261 *
262 * @return Integer HT rating
263 */
264 public final int float2HTint(float x) {
265 return (int) (((x - 1.0f) * 4.0f) + 1.0f);
266 }
267
268 /***
269 * {@inheritDoc}
270 */
271 public final String toString() {
272 final StringBuffer buffer = new StringBuffer();
273
274 buffer.append("MatchRating[");
275 buffer.append("midfield = " + midfield);
276 buffer.append(", leftDefense = " + leftDefense);
277 buffer.append(", centralDefense = " + centralDefense);
278 buffer.append(", rightDefense = " + rightDefense);
279 buffer.append(", leftAttack = " + leftAttack);
280 buffer.append(", centralAttack = " + centralAttack);
281 buffer.append(", rightAttack = " + rightAttack);
282 buffer.append("]");
283
284 return buffer.toString();
285 }
286
287 /***
288 * Hattrick Quality function
289 *
290 * @param value Official Hattrick value
291 *
292 * @return Hattrick Quality value
293 */
294 private double hq(double value) {
295 return (2 * value) / (value + 80);
296 }
297 }