-
Notifications
You must be signed in to change notification settings - Fork 761
Expand file tree
/
Copy pathraid_event.cpp
More file actions
2604 lines (2223 loc) · 73.3 KB
/
raid_event.cpp
File metadata and controls
2604 lines (2223 loc) · 73.3 KB
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to natehieter@gmail.com
// ==========================================================================
#include "action/heal.hpp"
#include "action/action.hpp"
#include "action/spell.hpp"
#include "buff/buff.hpp"
#include "dbc/dbc.hpp"
#include "player/pet.hpp"
#include "player/player.hpp"
#include "player/player_demise_event.hpp"
#include "player/pet_spawner.hpp"
#include "raid_event.hpp"
#include "sim/event.hpp"
#include "sim/expressions.hpp"
#include "sim/sim.hpp"
#include "util/rng.hpp"
// ==========================================================================
// Raid Events
// ==========================================================================
namespace
{ // UNNAMED NAMESPACE
struct adds_event_t final : public raid_event_t
{
double count;
double health;
std::string master_str;
player_t* master;
std::vector<pet_t*> adds;
double count_range;
size_t adds_to_remove;
double spawn_x_coord;
double spawn_y_coord;
int spawn_stacked;
double spawn_radius_min;
double spawn_radius_max;
double spawn_radius;
double spawn_angle_start;
double spawn_angle_end;
std::string race_str;
race_e race;
std::string enemy_type_str;
player_e enemy_type;
bool same_duration;
adds_event_t( sim_t* s, util::string_view options_str )
: raid_event_t( s, "adds" ),
count( 1 ),
health( 100000 ),
master_str(),
master(),
count_range( false ),
adds_to_remove( 0 ),
spawn_x_coord( 0 ),
spawn_y_coord( 0 ),
spawn_stacked( 0 ),
spawn_radius_min( 0 ),
spawn_radius_max( 0 ),
spawn_radius( 0 ),
spawn_angle_start( -1 ),
spawn_angle_end( -1 ),
race_str(),
race( RACE_NONE ),
enemy_type_str(),
enemy_type( ENEMY_ADD ),
same_duration( false )
{
add_option( opt_string( "master", master_str ) );
add_option( opt_float( "count", count ) );
add_option( opt_float( "health", health ) );
add_option( opt_float( "count_range", count_range ) );
add_option( opt_float( "spawn_x", spawn_x_coord ) );
add_option( opt_float( "spawn_y", spawn_y_coord ) );
add_option( opt_int( "stacked", spawn_stacked ) );
add_option( opt_float( "spawn_distance_min", spawn_radius_min ) );
add_option( opt_float( "spawn_distance_max", spawn_radius_max ) );
add_option( opt_float( "distance", spawn_radius ) );
add_option( opt_float( "angle_start", spawn_angle_start ) );
add_option( opt_float( "angle_end", spawn_angle_end ) );
add_option( opt_string( "race", race_str ) );
add_option( opt_string( "type", enemy_type_str ) );
add_option( opt_bool( "same_duration", same_duration ) );
parse_options( options_str );
if ( !master_str.empty() )
{
master = sim->find_player( master_str );
if ( !master )
{
throw std::invalid_argument( fmt::format( "cannot find master '{}'.", master_str ) );
}
}
// If the master is not found, default the master to the first created enemy
if ( !master )
master = sim->target_list.data().front();
if ( !master )
{
throw std::invalid_argument( fmt::format( "no enemy target available in the sim." ) );
}
double overlap = 1;
timespan_t min_cd = cooldown.mean;
if ( cooldown.stddev != 0_ms )
{
min_cd -= cooldown.stddev * 6;
if ( min_cd <= 0_ms )
{
throw std::invalid_argument(
fmt::format( "the cooldown standard deviation ({}) is too large, creating a too short minimum cooldown ({})",
cooldown.stddev, min_cd ) );
}
}
if ( min_cd > 0_ms )
overlap = duration.mean / min_cd;
if ( overlap > 1 )
{
throw std::invalid_argument(
fmt::format( "does not support overlapping add spawning in a single raid event. Duration ({}) > reasonable "
"minimum cooldown ({}).",
duration.mean, min_cd ) );
}
if ( !race_str.empty() )
{
race = util::parse_race_type( race_str );
if ( race == RACE_UNKNOWN )
{
throw std::invalid_argument( fmt::format( "could not parse race from '{}'.", race_str ) );
}
}
else if ( !sim->target_race.empty() )
{
race = util::parse_race_type( sim->target_race );
if ( race == RACE_UNKNOWN )
{
throw std::invalid_argument(
fmt::format( "could not parse race from sim target race '{}'.", sim->target_race ) );
}
}
if ( !enemy_type_str.empty() )
{
enemy_type = util::parse_player_type( enemy_type_str );
if ( !( enemy_type == ENEMY_ADD || enemy_type == ENEMY_ADD_BOSS ) )
{
throw std::invalid_argument( fmt::format( "could not parse enemy type from '{}'.", enemy_type_str ) );
}
}
sim->add_waves++;
if ( fabs( spawn_radius ) > 0 || fabs( spawn_radius_max ) > 0 || fabs( spawn_radius_min ) > 0 )
{
sim->distance_targeting_enabled = true;
if ( fabs( spawn_radius ) > 0 )
{
spawn_radius_min = spawn_radius_max = fabs( spawn_radius );
}
double tempangle;
if ( spawn_angle_start > 360 )
{
tempangle = fmod( spawn_angle_start, 360 );
if ( tempangle != spawn_angle_start )
{
spawn_angle_start = tempangle;
}
}
if ( spawn_angle_end > 360 )
{
tempangle = fmod( spawn_angle_end, 360 );
if ( tempangle != spawn_angle_end )
{
spawn_angle_end = tempangle;
}
}
if ( spawn_angle_start == spawn_angle_end && spawn_angle_start >= 0 ) // Full circle
{
spawn_angle_start = 0;
spawn_angle_end = 360;
}
else // Not a full circle, or, one/both of the values is not specified
{
if ( spawn_x_coord != 0 || spawn_y_coord != 0 ) // Not default placement
{
if ( spawn_angle_start < 0 )
{
spawn_angle_start = 0;
}
if ( spawn_angle_end < 0 )
{
spawn_angle_end = 360;
}
}
else if ( spawn_x_coord == 0 && spawn_y_coord == 0 && spawn_angle_start < 0 &&
spawn_angle_end < 0 ) // Default placement, only spawn adds on near side
{
spawn_angle_start = 90;
spawn_angle_end = 270;
}
if ( spawn_angle_start < 0 ) // Default start value if not specified
{
spawn_angle_start = 90;
}
if ( spawn_angle_end < 0 ) // Default end value if not specified
{
spawn_angle_end = 270;
}
if ( spawn_angle_end < spawn_angle_start )
{
spawn_angle_end += 360;
}
}
if ( sim->log )
{
sim->out_log.printf( "Spawn Angle set between %f and %f degrees.", spawn_angle_start, spawn_angle_end );
}
}
for ( int i = 0; i < util::ceil( overlap ); i++ )
{
for ( unsigned add = 0; add < util::ceil( count + count_range ); add++ )
{
std::string add_name_str;
if ( sim->add_waves > 1 &&
name.empty() ) // Only add wave to secondary wave that aren't given manual names.
{
add_name_str += "Wave";
add_name_str += util::to_string( sim->add_waves );
add_name_str += "_";
}
add_name_str += name;
add_name_str += util::to_string( add + 1 );
pet_t* p = master->create_pet( add_name_str );
assert( p );
p->resources.base[ RESOURCE_HEALTH ] = health;
p->race = race;
p->type = enemy_type;
adds.push_back( p );
}
}
}
void regenerate_cache()
{
for ( auto p : affected_players )
{
// Invalidate target caches
for ( size_t i = 0, end = p->action_list.size(); i < end; i++ )
p->action_list[ i ]->target_cache.is_valid = false; // Regenerate Cache.
}
}
void _start() override
{
adds_to_remove = static_cast<size_t>(
util::round( std::max( 0.0, sim->rng().range( count - count_range, count + count_range ) ) ) );
double x_offset = 0;
double y_offset = 0;
bool offset_computed = false;
// Keep track of each add duration so after summons (and dismissals) are done, we can adjust the saved_duration of
// the add event to match the add with the longest lifetime.
timespan_t add_duration = saved_duration;
std::vector<timespan_t> add_lifetimes;
for ( size_t i = 0; i < adds.size(); i++ )
{
if ( i >= adds_to_remove )
{
adds[ i ]->dismiss();
continue;
}
if ( std::fabs( spawn_radius_max ) > 0 )
{
if ( spawn_stacked == 0 || !offset_computed )
{
double angle_start = spawn_angle_start * ( m_pi / 180 );
double angle_end = spawn_angle_end * ( m_pi / 180 );
double angle = sim->rng().range( angle_start, angle_end );
double radius = sim->rng().range( std::fabs( spawn_radius_min ), std::fabs( spawn_radius_max ) );
x_offset = radius * cos( angle );
y_offset = radius * sin( angle );
offset_computed = true;
}
}
if ( !same_duration )
{
add_duration = duration_time();
add_lifetimes.push_back( add_duration );
}
adds[ i ]->summon( add_duration );
adds[ i ]->x_position = x_offset + spawn_x_coord;
adds[ i ]->y_position = y_offset + spawn_y_coord;
if ( sim->log )
{
if ( x_offset != 0 || y_offset != 0 )
{
sim->out_log.printf( "New add spawned at %f, %f.", x_offset, y_offset );
}
}
}
if ( !add_lifetimes.empty() )
{
saved_duration = *range::max_element( add_lifetimes );
}
regenerate_cache();
if ( enemy_type == ENEMY_ADD_BOSS )
{
for ( auto p : affected_players )
{
p->in_boss_encounter++;
}
}
}
void _finish() override
{
if ( adds.size() < adds_to_remove )
{
adds_to_remove = adds.size();
}
for ( size_t i = 0; i < adds_to_remove; i++ )
{
adds[ i ]->dismiss();
}
if ( enemy_type == ENEMY_ADD_BOSS )
{
for ( auto p : affected_players )
{
assert( p->in_boss_encounter );
p->in_boss_encounter--;
}
}
// trigger leave combat state callbacks if no adds are remaining
if ( sim->fight_style == fight_style_e::FIGHT_STYLE_DUNGEON_SLICE && !sim->target_non_sleeping_list.size() )
{
for ( auto p : affected_players )
p->leave_combat();
}
}
};
struct pull_event_t final : raid_event_t
{
struct mob_t : public pet_t
{
pull_event_t* pull_event;
mob_t( player_t* o, util::string_view n = "Mob", pet_e pt = PET_ENEMY ) : pet_t( o->sim, o, n, pt ),
pull_event( nullptr )
{
}
timespan_t time_to_percent( double percent ) const override
{
double target_hp = resources.initial[ RESOURCE_HEALTH ] * (percent / 100);
if ( target_hp >= resources.current[ RESOURCE_HEALTH ])
return timespan_t::zero();
// Per-Add DPS Calculation
// This extrapolates the DTPS of the current add only. Potentially more precise but also volatile
//double add_dps = ( resources.initial[ RESOURCE_HEALTH ] - resources.current[ RESOURCE_HEALTH ] ) / ( sim->current_time() - arise_time ).total_seconds();
//if ( add_dps > 0 )
//{
// return timespan_t::from_seconds( ( resources.current[ RESOURCE_HEALTH ] - target_hp ) / add_dps );
//}
// Per-Wave DPS Calculation
// This extrapolates the DTPS of the wave and divides evenly across all targets, less volatile but potentially incaccurate
int add_count = 0;
double pull_damage = 0;
for ( auto add : pull_event->adds_spawner->active_pets() )
{
if ( add->is_active() )
add_count++;
pull_damage += add->resources.initial[ RESOURCE_HEALTH ] - add->resources.current[ RESOURCE_HEALTH ];
}
if ( pull_damage > 0 )
{
double pull_dps = pull_damage / ( sim->current_time() - pull_event->spawn_time ).total_seconds();
return timespan_t::from_seconds( ( resources.current[ RESOURCE_HEALTH ] - target_hp ) / ( pull_dps / add_count ) );
}
return pet_t::time_to_percent( percent );
}
void init_resources( bool force ) override
{
base_t::init_resources( force );
}
resource_e primary_resource() const override
{
return RESOURCE_HEALTH;
}
};
struct redistribute_event_t : public event_t
{
pull_event_t* pull;
redistribute_event_t( pull_event_t* pull_ )
: event_t( *pull_->sim, 1.0_s ),
pull( pull_ )
{ }
const char* name() const override
{
return "redistribute_event_t";
}
void execute() override
{
pull->redistribute_event = nullptr;
double max_hp = 0.0;
double current_hp = 0.0;
auto active_adds = pull->adds_spawner->active_pets();
for ( auto add : active_adds )
{
max_hp += add->resources.initial[ RESOURCE_HEALTH ];
current_hp += add->resources.current[ RESOURCE_HEALTH ];
}
double pct = current_hp / max_hp;
for ( auto add : active_adds )
{
double new_hp = pct * add->resources.initial[ RESOURCE_HEALTH ];
double old_hp = add->resources.current[ RESOURCE_HEALTH ];
if ( new_hp > old_hp )
{
add->resource_gain( RESOURCE_HEALTH, new_hp - old_hp );
}
else if ( new_hp < old_hp )
{
add->resource_loss( RESOURCE_HEALTH, old_hp - new_hp );
}
}
pull->redistribute_event = make_event<redistribute_event_t>( sim(), pull );
}
};
player_t* master;
std::string enemies_str;
timespan_t delay;
timespan_t spawn_time;
bool bloodlust;
bool shared_health;
bool has_boss;
event_t* spawn_event;
event_t* redistribute_event;
extended_sample_data_t real_duration;
std::vector<std::unique_ptr<raid_event_t>> child_events;
struct spawn_parameter
{
std::string name;
bool boss = false;
double health = 0;
race_e race = RACE_HUMANOID;
};
std::vector<spawn_parameter> spawn_parameters;
spawner::pet_spawner_t<mob_t, player_t>* adds_spawner;
pull_event_t( sim_t* s, util::string_view options_str )
: raid_event_t( s, "pull" ),
enemies_str(),
delay( 0_ms ),
spawn_time( 0_s ),
bloodlust( false ),
shared_health( false ),
has_boss( false ),
spawn_event( nullptr ),
redistribute_event( nullptr ),
real_duration( "Pull Length", false )
{
add_option( opt_string( "enemies", enemies_str ) );
add_option( opt_timespan( "delay", delay ) );
add_option( opt_bool( "bloodlust", bloodlust ) );
add_option( opt_bool( "shared_health", shared_health ) );
parse_options( options_str );
force_stop = true;
first = last = timespan_t::min();
first_pct = last_pct = -1.0;
cooldown.mean = delay;
duration.mean = timespan_t::max();
cooldown.stddev = cooldown.min = cooldown.max = 0_ms;
duration.stddev = duration.min = duration.max = 0_ms;
name = "Pull_" + util::to_string( pull );
real_duration.name_str = name + " Length";
master = sim->target_list.data().front();
if ( !master )
{
throw std::invalid_argument( fmt::format( "no enemy available in the sim." ) );
}
std::string spawner_name = master->name();
spawner_name += " spawner";
adds_spawner = dynamic_cast<spawner::pet_spawner_t<mob_t, player_t>*>( master->find_spawner( spawner_name ) );
if ( !adds_spawner )
{
adds_spawner = new spawner::pet_spawner_t<mob_t, player_t>( spawner_name, master );
adds_spawner->set_event_callback( spawner::pet_event_type::DEMISE, []( spawner::pet_event_type, mob_t* mob ) {
mob->pull_event->mob_demise();
} );
}
if ( enemies_str.empty() )
{
throw std::invalid_argument( fmt::format( "no enemies string." ) );
}
else
{
auto enemy_splits = util::string_split<util::string_view>( enemies_str, "|" );
if ( enemy_splits.empty() )
{
throw std::invalid_argument( fmt::format( "at least one enemy is required.") );
}
else
{
for ( const util::string_view enemy_str : util::string_split<util::string_view>( enemies_str, "|" ) )
{
auto splits = util::string_split<util::string_view>( enemy_str, ":" );
if ( splits.size() < 2 )
{
throw std::invalid_argument( fmt::format( "bad enemy string '{}'.", enemy_str ) );
}
else
{
spawn_parameter spawn;
if ( util::starts_with( splits[ 0 ], "BOSS_" ) )
{
spawn.boss = true;
has_boss = true;
}
spawn.name = splits[ 0 ];
spawn.health = util::to_double( splits[ 1 ] );
if ( splits.size() > 2 )
spawn.race = util::parse_race_type( util::tokenize_fn( splits[ 2 ] ) );
spawn_parameters.emplace_back( spawn );
}
}
// Sort adds by descending HP order to improve retargeting logic if the dungeon_route_smart_targeting option is
// set to true
if ( sim->dungeon_route_smart_targeting )
{
range::sort( spawn_parameters,
[]( const spawn_parameter a, const spawn_parameter b ) { return a.health > b.health; } );
}
}
}
}
void mob_demise()
{
// Don't schedule another pull until all mobs from this one demise.
if ( adds_spawner->active_pets().empty() )
{
for ( auto& child_event : child_events )
{
child_event->deactivate( "pull ended" );
}
deactivate( "pull ended" );
}
}
void regenerate_cache()
{
for ( auto p : affected_players )
{
for ( size_t i = 0, end = p->action_list.size(); i < end; i++ )
p->action_list[ i ]->target_cache.is_valid = false;
}
}
void _start() override
{
spawn_time = sim->current_time();
if ( bloodlust )
{
if ( !sim->single_actor_batch )
{
// use indices since it's possible to spawn new actors when bloodlust is triggered
for ( size_t i = 0; i < sim->player_non_sleeping_list.size(); i++ )
{
auto* p = sim->player_non_sleeping_list[ i ];
if ( p->is_pet() )
continue;
p->buffs.bloodlust->trigger();
p->buffs.exhaustion->trigger();
}
}
else
{
auto p = sim->player_no_pet_list[ sim->current_index ];
if ( p )
{
p->buffs.bloodlust->trigger();
p->buffs.exhaustion->trigger();
}
}
}
auto adds = adds_spawner->spawn( as<unsigned>( spawn_parameters.size() ) );
double total_health = 0;
for ( size_t i = 0; i < adds.size(); i++ )
{
adds[ i ]->resources.base[ RESOURCE_HEALTH ] = spawn_parameters[ i ].health;
adds[ i ]->resources.infinite_resource[ RESOURCE_HEALTH ] = false;
adds[ i ]->init_resources( true );
adds[ i ]->pull_event = this;
adds[ i ]->type = spawn_parameters[ i ].boss ? ENEMY_ADD_BOSS : ENEMY_ADD;
adds[ i ]->race = spawn_parameters[ i ].race;
std::string mob_name = name + "_" + spawn_parameters[ i ].name;
sim->print_log( "Renaming {} to {}", adds[ i ]->name_str, mob_name );
adds[ i ]->full_name_str = adds[ i ]->name_str = mob_name;
total_health += spawn_parameters[ i ].health;
}
if ( shared_health )
redistribute_event = make_event<redistribute_event_t>( *sim, this );
sim->print_log( "Spawned Pull {}: {} mobs with {} total health, {:.1f}s delay from previous",
pull, adds.size(), total_health, delay.total_seconds() );
regenerate_cache();
if ( has_boss )
{
for ( auto& p : affected_players )
{
if ( p->is_player() )
{
p->in_boss_encounter++;
}
}
}
for ( auto& raid_event : child_events )
raid_event->combat_begin();
}
void _finish() override
{
double length = ( sim->current_time() - spawn_time ).total_seconds();
sim->print_log( "Finished Pull {} in {:.1f} seconds", pull, length );
real_duration.add( length );
saved_duration = timespan_t::from_seconds( length );
event_t::cancel( redistribute_event );
if ( has_boss )
{
for ( auto p : affected_players )
{
if ( p->is_player() )
{
assert( p->in_boss_encounter );
p->in_boss_encounter--;
}
}
}
// Trigger leave combat state callbacks if no mobs are remaining.
if ( !sim->target_non_sleeping_list.size() )
{
for ( auto p : affected_players )
p->leave_combat();
}
}
void merge( pull_event_t* other )
{
real_duration.merge( other->real_duration );
}
timespan_t remains() const override
{
double pull_dtps = 0;
double pull_hp = 0;
for ( pet_t* add : adds_spawner->active_pets() )
{
pull_dtps += ( add->resources.initial[ RESOURCE_HEALTH ] - add->resources.current[ RESOURCE_HEALTH ] ) / ( sim->current_time() - add->arise_time ).total_seconds();
pull_hp += add->resources.current[ RESOURCE_HEALTH ];
}
return timespan_t::from_seconds( pull_hp / pull_dtps );
}
timespan_t duration_time() override
{
if ( real_duration.count() )
return timespan_t::from_seconds( real_duration.mean() );
else
return sim->max_time / sim->raid_events.size();
}
void reset() override
{
raid_event_t::reset();
for ( auto& raid_event : child_events )
raid_event->reset();
redistribute_event = nullptr;
}
};
struct move_enemy_t final : public raid_event_t
{
double x_coord;
double y_coord;
std::string enemy_name;
player_t* enemy;
double original_x;
double original_y;
move_enemy_t( sim_t* s, util::string_view options_str )
: raid_event_t( s, "move_enemy" ),
x_coord( 0.0 ),
y_coord( 0.0 ),
enemy_name(),
enemy( nullptr ),
original_x( 0.0 ),
original_y( 0.0 )
{
add_option( opt_float( "x", x_coord ) );
add_option( opt_float( "y", y_coord ) );
add_option( opt_string( "enemy_name", enemy_name ) );
parse_options( options_str );
enemy = sim->find_player( enemy_name );
sim->distance_targeting_enabled = true;
if ( !enemy )
{
throw std::invalid_argument(
fmt::format( "Move enemy event cannot be created, there is no enemy named '{}'.", enemy_name ) );
}
}
void regenerate_cache()
{
for ( auto p : affected_players )
{
// Invalidate target caches
for ( size_t i = 0, end = p->action_list.size(); i < end; i++ )
p->action_list[ i ]->target_cache.is_valid = false; // Regenerate Cache.
}
}
void reset() override
{
raid_event_t::reset();
if ( enemy )
{
enemy->x_position = enemy->default_x_position;
enemy->y_position = enemy->default_y_position;
}
}
void _start() override
{
if ( enemy )
{
original_x = enemy->x_position;
original_y = enemy->y_position;
enemy->x_position = x_coord;
enemy->y_position = y_coord;
regenerate_cache();
}
}
void _finish() override
{
if ( enemy )
{
enemy->x_position = enemy->default_x_position;
enemy->y_position = enemy->default_y_position;
regenerate_cache();
}
}
};
// Casting ==================================================================
struct casting_event_t final : public raid_event_t
{
casting_event_t( sim_t* s, util::string_view options_str ) : raid_event_t( s, "casting" )
{
parse_options( options_str );
}
void _start() override
{
sim->target->debuffs.casting->increment();
}
void _finish() override
{
sim->target->debuffs.casting->decrement();
}
};
// Distraction ==============================================================
struct distraction_event_t final : public raid_event_t
{
double skill;
distraction_event_t( sim_t* s, util::string_view options_str ) : raid_event_t( s, "distraction" ), skill( 0.2 )
{
players_only = true; // Pets shouldn't have less "skill"
add_option( opt_float( "skill", skill ) );
parse_options( options_str );
}
void _start() override
{
for ( auto p : affected_players )
{
p->current.skill_debuff += skill;
}
}
void _finish() override
{
for ( auto p : affected_players )
{
p->current.skill_debuff -= skill;
}
}
};
// Invulnerable =============================================================
struct invulnerable_event_t final : public raid_event_t
{
bool retarget;
player_t* target;
std::string target_str;
invulnerable_event_t( sim_t* s, util::string_view options_str )
: raid_event_t( s, "invulnerable" ), retarget( false ), target( s->target )
{
add_option( opt_bool( "retarget", retarget ) );
if ( sim->fight_style == FIGHT_STYLE_DUNGEON_ROUTE )
add_option( opt_string( "target", target_str ) );
else
add_option( opt_func( "target", [this](sim_t* sim, util::string_view name, util::string_view value) { return parse_target(sim, name, value); } ) );
parse_options( options_str );
if ( sim->fight_style == FIGHT_STYLE_DUNGEON_ROUTE )
target_str = "Pull_" + util::to_string( pull ) + "_" + target_str;
}
bool parse_target( sim_t* /* sim */, util::string_view /* name */, util::string_view value )
{
auto it = range::find_if( sim->target_list, [ &value ]( const player_t* target ) {
return util::str_compare_ci( value, target->name() );
} );
if ( it != sim->target_list.end() )
{
target = *it;
return true;
}
else
{
sim->error( "Unknown invulnerability raid event target '{}'", value );
return false;
}
}
void _start() override
{
if ( sim->fight_style == FIGHT_STYLE_DUNGEON_ROUTE )
target = sim->find_player( target_str );
if ( !target )
throw std::invalid_argument( fmt::format( "Unknown invulnerability raid event target '{}'", target_str ) );
target->clear_debuffs();
target->debuffs.invulnerable->increment();
range::for_each( sim->player_non_sleeping_list, []( player_t* p ) {
p->in_combat =
true; // FIXME? this is done to ensure we don't end up in infinite loops of non-harmful actions with gcd=0
p->halt();
} );
if ( retarget )
{
range::for_each( sim->player_non_sleeping_list,
[ this ]( player_t* p ) { p->acquire_target( retarget_source::ACTOR_INVULNERABLE, target ); } );
}
}
void _finish() override
{
target->debuffs.invulnerable->decrement();
if ( retarget )
{
range::for_each( sim->player_non_sleeping_list,
[ this ]( player_t* p ) { p->acquire_target( retarget_source::ACTOR_VULNERABLE, target ); } );
}
}
};
// Flying ===================================================================
struct flying_event_t final : public raid_event_t
{
flying_event_t( sim_t* s, util::string_view options_str ) : raid_event_t( s, "flying" )
{
parse_options( options_str );
}
void _start() override
{
sim->target->debuffs.flying->increment();
}
void _finish() override
{
sim->target->debuffs.flying->decrement();
}
};
// Movement =================================================================
struct movement_ticker_t : public event_t
{
const std::vector<player_t*>& players;
timespan_t duration;
movement_ticker_t( sim_t& s, const std::vector<player_t*>& p, timespan_t d = timespan_t::zero() )
: event_t( s, d > timespan_t::zero() ? d : next_execute( p ) ), players( p )
{
if ( d > timespan_t::zero() )
{
duration = d;