-
Notifications
You must be signed in to change notification settings - Fork 720
/
Copy pathaction_state.cpp
406 lines (351 loc) · 11.6 KB
/
action_state.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================
#include "action/action_state.hpp"
#include "action/action.hpp"
#include "player/player.hpp"
#include "sim/sim.hpp"
#include <sstream>
action_state_t* action_t::get_state( const action_state_t* other )
{
action_state_t* s = nullptr;
if ( state_cache )
{
s = state_cache;
state_cache = s->next;
}
else
{
s = new_state();
}
s->action = this;
if ( !other )
{
s->initialize();
}
else
{
s->copy_state( other );
}
return s;
}
action_state_t* action_t::new_state()
{
return new action_state_t( this, target );
}
void action_t::release_state( action_state_t* s )
{
assert( s->action == this );
s->next = state_cache;
state_cache = s;
}
// Initialize contains all variables that must be reset every time a new
// state object is retrieved using get_state()
void action_state_t::initialize()
{
result = RESULT_NONE;
result_type = result_amount_type::NONE;
block_result = BLOCK_RESULT_UNBLOCKED;
result_raw = result_total = result_mitigated = result_absorbed =
result_amount = blocked_amount = self_absorb_amount = 0;
}
/*
void action_state_t::copy_state( const action_state_t* o )
{
if ( this == o || o == 0 ) return;
*this = *o;
}
*/
void action_state_t::copy_state( const action_state_t* o )
{
#ifndef NDEBUG
assert( o );
if ( typeid( this ) != typeid( const_cast<action_state_t*>( o ) ) )
{
throw std::runtime_error( fmt::format("action_state_t::operator=: state runtime types not equal! this={} o={}\n",
typeid( this ).name(), typeid( const_cast<action_state_t*>( o ) ).name() ) );
}
#endif
target = o->target;
assert( target );
n_targets = o->n_targets;
chain_target = o->chain_target;
original_x = o->original_x;
original_y = o->original_y;
result_type = o->result_type;
result = o->result;
result_raw = o->result_raw;
result_total = o->result_total;
result_mitigated = o->result_mitigated;
result_absorbed = o->result_absorbed;
result_crit_bonus = o->result_crit_bonus;
result_amount = o->result_amount;
blocked_amount = o->blocked_amount;
self_absorb_amount = o->self_absorb_amount;
haste = o->haste;
crit_chance = o->crit_chance;
target_crit_chance = o->target_crit_chance;
attack_power = o->attack_power;
spell_power = o->spell_power;
versatility = o->versatility;
da_multiplier = o->da_multiplier;
ta_multiplier = o->ta_multiplier;
rolling_ta_multiplier = o->rolling_ta_multiplier;
player_multiplier = o->player_multiplier;
persistent_multiplier = o->persistent_multiplier;
pet_multiplier = o->pet_multiplier;
target_da_multiplier = o->target_da_multiplier;
target_ta_multiplier = o->target_ta_multiplier;
target_pet_multiplier = o->target_pet_multiplier;
target_mitigation_da_multiplier = o->target_mitigation_da_multiplier;
target_mitigation_ta_multiplier = o->target_mitigation_ta_multiplier;
target_armor = o->target_armor;
}
action_state_t::action_state_t( action_t* a, player_t* t )
: next( nullptr ),
action( a ),
target( t ),
n_targets( 0 ),
chain_target( 0 ),
original_x( 0 ),
original_y( 0 ),
result_type( result_amount_type::NONE ),
result( RESULT_NONE ),
block_result( BLOCK_RESULT_UNKNOWN ),
result_raw( 0 ),
result_total( 0 ),
result_mitigated( 0 ),
result_absorbed( 0 ),
result_crit_bonus( 0 ),
result_amount( 0 ),
blocked_amount( 0 ),
self_absorb_amount( 0 ),
haste( 1.0 ),
crit_chance( 0 ),
target_crit_chance( 0 ),
attack_power( 0 ),
spell_power( 0 ),
versatility( 1.0 ),
da_multiplier( 1.0 ),
ta_multiplier( 1.0 ),
rolling_ta_multiplier( 1.0 ),
player_multiplier( 1.0 ),
persistent_multiplier( 1.0 ),
pet_multiplier( 1.0 ),
target_da_multiplier( 1.0 ),
target_ta_multiplier( 1.0 ),
target_pet_multiplier( 1.0 ),
target_mitigation_da_multiplier( 1.0 ),
target_mitigation_ta_multiplier( 1.0 ),
target_armor( 0 )
{
assert( target );
}
std::ostringstream& action_state_t::debug_str( std::ostringstream& s )
{
s << std::showbase;
std::streamsize ss = s.precision();
s << action->player->name() << " " << action->name() << " " << target->name()
<< ":";
s << std::hex;
s << " snapshot_flags=";
if ( action->snapshot_flags > 0 )
{
s << "{ " << flags_to_str( action->snapshot_flags ) << " }";
}
else
{
s << action->snapshot_flags;
}
s << " update_flags=";
if ( action->update_flags > 0 )
{
s << "{ " << flags_to_str( action->update_flags ) << " }";
}
else
{
s << action->update_flags;
}
s << " result=" << util::result_type_string( result );
s << " type=" << util::amount_type_string( result_type );
s << " proc_type=" << util::proc_type_string( proc_type() );
s << " cast_proc_type=" << util::proc_type2_string( cast_proc_type2() );
s << " exec_proc_type=" << util::proc_type2_string( execute_proc_type2() );
s << " impact_proc_type=" << util::proc_type2_string( impact_proc_type2() );
s << " interrupt_proc_type=" << util::proc_type2_string( interrupt_proc_type2() );
s << std::dec;
s << " n_targets=" << n_targets;
s << " chain_target=" << chain_target;
s << " original_x=" << original_x;
s << " original_y=" << original_y;
s << " raw_amount=" << result_raw;
s << " total_amount=" << result_total;
s << " mitigated_amount=" << result_mitigated;
s << " absorbed_amount=" << result_absorbed;
s << " crit_bonus=" << result_crit_bonus;
s << " actual_amount=" << result_amount;
s << " only_blocked_damage=" << blocked_amount;
s << " self_absorbed_damage=" << self_absorb_amount;
s << " ap=" << attack_power;
s << " sp=" << spell_power;
s.precision( 4 );
s << " haste=" << haste;
s << " crit=" << crit_chance;
s << " tgt_crit=" << target_crit_chance;
s << " versatility=" << versatility;
s << " da_mul=" << da_multiplier;
s << " ta_mul=" << ta_multiplier;
s << " rolling_ta_mul=" << rolling_ta_multiplier;
s << " ply_mul=" << player_multiplier;
s << " per_mul=" << persistent_multiplier;
if ( action->player->is_pet() )
{
s << " pet_mul=" << pet_multiplier;
s << " tgt_pet_mul=" << target_pet_multiplier;
}
s << " tgt_da_mul=" << target_da_multiplier;
s << " tgt_ta_mul=" << target_ta_multiplier;
s << " tgt_mitg_da_mul=" << target_mitigation_da_multiplier;
s << " tgt_mitg_ta_mul=" << target_mitigation_ta_multiplier;
s << " target_armor=" << target_armor;
s.precision( ss );
return s;
}
void action_state_t::debug()
{
std::ostringstream s;
action->sim->out_debug.print( "{}", debug_str( s ).str() );
}
travel_event_t::travel_event_t( action_t* a, action_state_t* state,
timespan_t time_to_travel )
: event_t( *a->player, time_to_travel ), action( a ), state( state )
{
sim().print_debug( "New Stateless Action Travel Event: {} {} {}", *a->player, *a, time_to_travel );
}
travel_event_t::~travel_event_t()
{
if (state && canceled) action_state_t::release(state);
}
void travel_event_t::execute()
{
if ( !state->target->is_sleeping() )
{
action->impact( state );
}
action_state_t::release( state );
action->remove_travel_event( this );
}
void action_state_t::release( action_state_t*& s )
{
assert( s );
s->action->release_state( s );
s = nullptr;
}
std::string action_state_t::flags_to_str( unsigned flags )
{
std::string str;
auto concat_flag_str = [flags]( std::string& str, const char* flag_str,
snapshot_state_e state ) {
if ( flags & state )
{
if ( !str.empty() )
{
str += "|";
}
str += flag_str;
}
};
concat_flag_str( str, "AP", STATE_AP );
concat_flag_str( str, "SP", STATE_SP );
concat_flag_str( str, "HST", STATE_HASTE );
concat_flag_str( str, "CRIT", STATE_CRIT );
concat_flag_str( str, "VERS", STATE_VERSATILITY );
concat_flag_str( str, "MUL_DA", STATE_MUL_SPELL_DA );
concat_flag_str( str, "MUL_TA", STATE_MUL_SPELL_TA );
concat_flag_str( str, "MUL_PLY", STATE_MUL_PLAYER_DAM );
concat_flag_str( str, "MUL_PER", STATE_MUL_PERSISTENT );
concat_flag_str( str, "MUL_PET", STATE_MUL_PET );
concat_flag_str( str, "TGT_CRIT", STATE_TGT_CRIT );
concat_flag_str( str, "TGT_MUL_DA", STATE_TGT_MUL_DA );
concat_flag_str( str, "TGT_MUL_TA", STATE_TGT_MUL_TA );
concat_flag_str( str, "TGT_MUL_PET", STATE_TGT_MUL_PET );
concat_flag_str( str, "USR1", STATE_USER_1 );
concat_flag_str( str, "USR2", STATE_USER_2 );
concat_flag_str( str, "USR3", STATE_USER_3 );
concat_flag_str( str, "USR4", STATE_USER_4 );
concat_flag_str( str, "TGT_MIT_DA", STATE_TGT_MITG_DA );
concat_flag_str( str, "TGT_MIT_TA", STATE_TGT_MITG_TA );
concat_flag_str( str, "TGT_ARMOR", STATE_TGT_ARMOR );
concat_flag_str( str, "TGT_USR1", STATE_TGT_USER_1 );
concat_flag_str( str, "TGT_USR2", STATE_TGT_USER_2 );
concat_flag_str( str, "TGT_USR3", STATE_TGT_USER_3 );
concat_flag_str( str, "TGT_USR4", STATE_TGT_USER_4 );
return str;
}
// Primary proc type of the result (direct (aoe) damage/heal, periodic
// damage/heal)
proc_types action_state_t::proc_type() const
{
if ( result_type == result_amount_type::HEAL_DIRECT && action->direct_tick )
return PROC1_HELPFUL_PERIODIC;
else if ( result_type == result_amount_type::DMG_DIRECT || result_type == result_amount_type::HEAL_DIRECT )
return action->proc_type();
else if ( result_type == result_amount_type::DMG_OVER_TIME )
return PROC1_PERIODIC;
else if ( result_type == result_amount_type::HEAL_OVER_TIME )
return PROC1_HELPFUL_PERIODIC;
return PROC1_INVALID;
}
// Secondary proc type of the "finished casting" (i.e., execute()). Only
// triggers the "landing", dodge, parry, and miss procs
proc_types2 action_state_t::execute_proc_type2() const
{
if (result == RESULT_DODGE)
return PROC2_DODGE;
else if (result == RESULT_PARRY)
return PROC2_PARRY;
else if (result == RESULT_MISS)
return PROC2_MISS;
// Bunch up all non-damaging harmful attacks that land into "hit"
else if (action->harmful)
return PROC2_LANDED;
return PROC2_INVALID;
}
proc_types2 action_state_t::cast_proc_type2() const
{
// Only foreground actions may trigger the "on cast" procs
if ( action->background )
{
return PROC2_INVALID;
}
if ( action->has_amount_result() || action->base_ta( this ) || action->base_da_min( this ) ||
action->bonus_ta( this ) || action->bonus_da( this ) )
{
// This is somewhat naive way to differentiate, better way would be to classify based on the
// actual proc types, but it will serve our purposes for now.
return action->harmful ? PROC2_CAST_DAMAGE : PROC2_CAST_HEAL;
}
// Check if the primary action has any relevant abstracted sub-actions
if ( action->execute_action && action->execute_action->has_amount_result() )
{
return action->execute_action->harmful ? PROC2_CAST_DAMAGE : PROC2_CAST_HEAL;
}
if ( action->impact_action && action->impact_action->has_amount_result() )
{
return action->impact_action->harmful ? PROC2_CAST_DAMAGE : PROC2_CAST_HEAL;
}
if ( action->tick_action && action->tick_action->has_amount_result() )
{
return action->tick_action->harmful ? PROC2_CAST_DAMAGE : PROC2_CAST_HEAL;
}
// Generic fallback "on any cast"
return PROC2_CAST_GENERIC;
}
proc_types2 action_state_t::interrupt_proc_type2() const
{
if ( action->is_interrupt )
return PROC2_CAST_INTERRUPT;
else
return PROC2_INVALID;
}