-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathMechanics.cpp
323 lines (242 loc) · 11.4 KB
/
Mechanics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#include "Mechanics.h"
#include "Target.h"
#include "Utils/Check.h"
Mechanics::Mechanics(Target* target) : target(target) {}
double Mechanics::get_yellow_miss_chance(const unsigned wpn_skill) const {
return get_2h_white_miss_chance(wpn_skill);
}
double Mechanics::get_dw_white_miss_chance(const unsigned wpn_skill) const {
return get_2h_white_miss_chance(wpn_skill) * 0.8 + 0.2;
}
double Mechanics::get_2h_white_miss_chance(const unsigned wpn_skill) const {
const int t_defense_to_p_wpn_skill = static_cast<int>(target->get_defense()) - static_cast<int>(wpn_skill);
if (t_defense_to_p_wpn_skill > 10)
return 0.05 + 0.01 + t_defense_to_p_wpn_skill * 0.002;
return 0.05 + t_defense_to_p_wpn_skill * 0.001;
}
double Mechanics::get_glancing_blow_chance(const unsigned clvl) const {
// Non-melee classes do not follow this formula.
const int level_diff = static_cast<int>(target->get_lvl()) - static_cast<int>(clvl);
if (level_diff < 0)
return 0.0;
return 0.1 + level_diff * 5 * 0.02;
}
double Mechanics::get_dodge_chance(const unsigned wpn_skill) const {
// https://us.forums.blizzard.com/en/wow/t/bug-hit-tables/185675/12
// "Creatures at your level have a 5% chance to Dodge your attacks. Each additional
// level the target has over the player grants them 0.5% additional chance to dodge.""
// Further, according to testing described in https://github.com/magey/classic-warrior/wiki/Attack-table#dodge
// weapon skill counters this difference slightly.
const int defense_diff = static_cast<int>(target->get_defense()) - static_cast<int>(wpn_skill);
return std::max(0.0, 0.05 + defense_diff * 0.001);
}
double Mechanics::get_parry_chance(const unsigned wpn_skill) const {
const int defense_diff = static_cast<int>(target->get_defense()) - static_cast<int>(wpn_skill);
return std::max(0.0, 0.14 + defense_diff * 0.001);
}
double Mechanics::get_block_chance() const {
return 0.0;
}
double Mechanics::get_glancing_blow_dmg_penalty_min(const unsigned clvl, const unsigned wpn_skill) const {
const int level_diff = static_cast<int>(target->get_lvl()) - static_cast<int>(clvl);
if (level_diff < 1)
return 1.0;
const int t_defense_to_p_wpn_skill = static_cast<int>(target->get_defense()) - static_cast<int>(wpn_skill);
const double glance_max_range_penalty = 1.3 - 0.05 * t_defense_to_p_wpn_skill;
if (glance_max_range_penalty < 0.55)
return 0.55;
if (glance_max_range_penalty > 0.91)
return 0.91;
return glance_max_range_penalty;
}
double Mechanics::get_glancing_blow_dmg_penalty_max(const unsigned clvl, const unsigned wpn_skill) const {
const int level_diff = static_cast<int>(target->get_lvl()) - static_cast<int>(clvl);
if (level_diff < 1)
return 1.0;
const int t_defense_to_p_wpn_skill = static_cast<int>(target->get_defense()) - static_cast<int>(wpn_skill);
const double glance_max_range_penalty = 1.2 - 0.03 * t_defense_to_p_wpn_skill;
if (glance_max_range_penalty < 0.75)
return 0.75;
if (glance_max_range_penalty > 0.99)
return 0.99;
return glance_max_range_penalty;
}
int Mechanics::get_boss_base_armor() {
return 3750;
}
double Mechanics::get_reduction_from_armor(const int armor, const unsigned clvl) {
return static_cast<double>(armor) / (static_cast<double>(armor) + 400 + 85 * clvl);
}
double Mechanics::get_melee_crit_suppression(const unsigned clvl) const {
const int level_diff = static_cast<int>(target->get_lvl()) - static_cast<int>(clvl);
return std::max(0.0, 0.01 * level_diff);
}
unsigned Mechanics::get_suppressed_aura_crit_chance(const unsigned clvl, const unsigned aura_crit) const {
const int level_diff = static_cast<int>(target->get_lvl()) - static_cast<int>(clvl);
if (level_diff <= 0)
return aura_crit;
const unsigned penalty = 60 * static_cast<unsigned>(level_diff);
return aura_crit > penalty ? aura_crit - penalty : 0;
}
double Mechanics::get_spell_miss_chance_from_lvl_diff(const unsigned clvl, const double spell_hit) const {
const int level_diff = static_cast<int>(target->get_lvl()) - static_cast<int>(clvl);
if (level_diff < -2)
return 0.01;
double lvl_diff_penalty;
switch (level_diff) {
case -2:
lvl_diff_penalty = 0.02;
break;
case -1:
lvl_diff_penalty = 0.03;
break;
case 0:
lvl_diff_penalty = 0.04;
break;
case 1:
lvl_diff_penalty = 0.05;
break;
case 2:
lvl_diff_penalty = 0.06;
break;
case 3:
lvl_diff_penalty = 0.17;
break;
case 4:
lvl_diff_penalty = 0.28;
break;
default:
lvl_diff_penalty = 0.39;
break;
}
return std::max(0.01, lvl_diff_penalty - spell_hit);
}
double Mechanics::get_full_resist_chance(const unsigned t_resistance) {
// Piecewise-linear function that implements the following resistance table:
//
// Target resistance | 0-150 | 150-200 | 200-300 |
// % Occurance | 0-1 % | 1-4 % | 4-25 % |
//
// This formula only serves as an initial approximation and is likely incorrect.
if (t_resistance < 150)
return get_linear_increase_in_range(0, 0.0, 150, 0.01, t_resistance);
if (t_resistance < 200)
return get_linear_increase_in_range(150, 0.01, 200, 0.04, t_resistance);
if (t_resistance < 300)
return get_linear_increase_in_range(200, 0.04, 300, 0.25, t_resistance);
return 0.25;
}
double Mechanics::get_linear_increase_in_range(
const unsigned x_min, const double y_min, const unsigned x_max, const double y_max, const unsigned x_curr) {
check((x_curr >= x_min), "x_curr < x_min");
check((x_curr <= x_max), "x_curr > x_max");
int x_delta = static_cast<int>(x_max) - static_cast<int>(x_min);
double y_delta = y_max - y_min;
double k = y_delta / x_delta;
return (x_curr - x_min) * k + y_min;
}
double Mechanics::get_partial_75_chance(const unsigned t_resistance) {
// Piecewise-linear function that implements the following resistance table:
//
// Target resistance | 0-20 | 20-50 | 50-80 | 80-100 | 100-120 | 120-150 | 150-200 | 200-300 |
// % Occurance | 0-1 % | 1-2 % | 2-3 % | 3-4 % | 4-6 % | 6-11 % | 11-23 % | 23-55% |
//
// This formula only serves as an initial approximation and is likely incorrect.
if (t_resistance < 20)
return get_linear_increase_in_range(0, 0.0, 20, 0.01, t_resistance);
if (t_resistance < 50)
return get_linear_increase_in_range(20, 0.01, 50, 0.02, t_resistance);
if (t_resistance < 80)
return get_linear_increase_in_range(50, 0.02, 80, 0.03, t_resistance);
if (t_resistance < 100)
return get_linear_increase_in_range(80, 0.03, 100, 0.04, t_resistance);
if (t_resistance < 120)
return get_linear_increase_in_range(100, 0.04, 120, 0.06, t_resistance);
if (t_resistance < 150)
return get_linear_increase_in_range(120, 0.06, 150, 0.11, t_resistance);
if (t_resistance < 200)
return get_linear_increase_in_range(150, 0.11, 200, 0.23, t_resistance);
if (t_resistance < 300)
return get_linear_increase_in_range(200, 0.23, 300, 0.55, t_resistance);
return 0.55;
}
double Mechanics::get_partial_50_chance(const unsigned t_resistance) {
// Piecewise-linear function that implements the following resistance table:
//
// Target resistance | 0-10 | 10-20 | 20-30 | 30-40 | 40-50 | 50-60 | 60-70 | 70-80 |
// % Occurance | 0-2 % | 2-4 % | 4-5 % | 5-7 % | 7-9% | 9-11 % | 11-13% | 13-15% |
// cont.
// Target resistance | 80-90 | 90-100 | 100-120 | 120-150 | 150-200 | 200-300 |
// % Occurance | 15-17% | 17-19% | 19-24 % | 24-37 % | 37-48 % | 48-16 % |
//
// This formula only serves as an initial approximation and is likely incorrect.
if (t_resistance < 10)
return get_linear_increase_in_range(0, 0.0, 10, 0.02, t_resistance);
if (t_resistance < 20)
return get_linear_increase_in_range(10, 0.02, 20, 0.04, t_resistance);
if (t_resistance < 30)
return get_linear_increase_in_range(20, 0.04, 30, 0.05, t_resistance);
if (t_resistance < 40)
return get_linear_increase_in_range(30, 0.05, 40, 0.07, t_resistance);
if (t_resistance < 50)
return get_linear_increase_in_range(40, 0.07, 50, 0.09, t_resistance);
if (t_resistance < 60)
return get_linear_increase_in_range(50, 0.09, 60, 0.11, t_resistance);
if (t_resistance < 70)
return get_linear_increase_in_range(60, 0.11, 70, 0.13, t_resistance);
if (t_resistance < 80)
return get_linear_increase_in_range(70, 0.13, 80, 0.15, t_resistance);
if (t_resistance < 90)
return get_linear_increase_in_range(80, 0.15, 90, 0.17, t_resistance);
if (t_resistance < 100)
return get_linear_increase_in_range(90, 0.17, 100, 0.19, t_resistance);
if (t_resistance < 120)
return get_linear_increase_in_range(100, 0.19, 120, 0.24, t_resistance);
if (t_resistance < 150)
return get_linear_increase_in_range(120, 0.24, 150, 0.37, t_resistance);
if (t_resistance < 200)
return get_linear_increase_in_range(150, 0.37, 200, 0.48, t_resistance);
if (t_resistance < 300)
return get_linear_increase_in_range(200, 0.48, 300, 0.16, t_resistance);
return 0.16;
}
double Mechanics::get_partial_25_chance(const unsigned t_resistance) {
// Piecewise-linear function that implements the following resistance table:
//
// Target resistance | 0-10 | 10-20 | 20-30 | 30-40 | 40-50 | 50-60 | 60-70 | 70-80 |
// % Occurance | 0-6 % | 6-12 % | 12-18 % | 18-23 % | 23-28% | 28-33 % | 33-37% | 37-41% |
// cont.
// Target resistance | 80-90 | 90-100 | 100-120 | 120-150 | 150-200 | 200-300 |
// % Occurance | 41-45% | 45-47% | 47-49 % | 49-39 % | 39-21 % | 21-3 % |
//
// This formula only serves as an initial approximation and is likely incorrect.
if (t_resistance < 10)
return get_linear_increase_in_range(0, 0.0, 10, 0.06, t_resistance);
if (t_resistance < 20)
return get_linear_increase_in_range(10, 0.06, 20, 0.12, t_resistance);
if (t_resistance < 30)
return get_linear_increase_in_range(20, 0.12, 30, 0.18, t_resistance);
if (t_resistance < 40)
return get_linear_increase_in_range(30, 0.18, 40, 0.23, t_resistance);
if (t_resistance < 50)
return get_linear_increase_in_range(40, 0.23, 50, 0.28, t_resistance);
if (t_resistance < 60)
return get_linear_increase_in_range(50, 0.28, 60, 0.33, t_resistance);
if (t_resistance < 70)
return get_linear_increase_in_range(60, 0.33, 70, 0.37, t_resistance);
if (t_resistance < 80)
return get_linear_increase_in_range(70, 0.37, 80, 0.41, t_resistance);
if (t_resistance < 90)
return get_linear_increase_in_range(80, 0.41, 90, 0.45, t_resistance);
if (t_resistance < 100)
return get_linear_increase_in_range(90, 0.45, 100, 0.47, t_resistance);
if (t_resistance < 120)
return get_linear_increase_in_range(100, 0.47, 120, 0.49, t_resistance);
if (t_resistance < 150)
return get_linear_increase_in_range(120, 0.49, 150, 0.39, t_resistance);
if (t_resistance < 200)
return get_linear_increase_in_range(150, 0.39, 200, 0.21, t_resistance);
if (t_resistance < 300)
return get_linear_increase_in_range(200, 0.21, 300, 0.03, t_resistance);
return 0.3;
}