diff --git a/engine/player/azerite_data.cpp b/engine/player/azerite_data.cpp index c5211a5c914..6b32787c0a1 100644 --- a/engine/player/azerite_data.cpp +++ b/engine/player/azerite_data.cpp @@ -1566,8 +1566,7 @@ void elemental_whirl( special_effect_t& effect ) void execute( action_t* /* a */, action_state_t* /* state */ ) override { - size_t buff_index = rng().range( buffs.size() ); - buffs[ buff_index ] -> trigger(); + rng().range( buffs )->trigger(); } }; @@ -2503,7 +2502,7 @@ void wandering_soul( special_effect_t& effect ) const auto& tl = action -> target_list(); if ( tl.empty() ) return; - action -> set_target( tl[ action -> rng().range( tl.size() ) ] ); + action->set_target( action->rng().range( tl ) ); action -> execute(); } ); } @@ -2720,8 +2719,7 @@ void combined_might( special_effect_t& effect ) void execute( action_t*, action_state_t* ) override { - size_t index = rng().range( buffs.size() ); - buffs[ index ]->trigger(); + rng().range( buffs )->trigger(); } }; diff --git a/engine/player/soulbinds.cpp b/engine/player/soulbinds.cpp index 7acf787b82f..a0b152755d6 100644 --- a/engine/player/soulbinds.cpp +++ b/engine/player/soulbinds.cpp @@ -866,7 +866,7 @@ void party_favors( special_effect_t& effect ) } if ( buffs.size() > 0 ) - effect.player->register_combat_begin( [ buffs ] ( player_t* p ) { buffs[ p->rng().range( buffs.size() ) ]->trigger(); } ); + effect.player->register_combat_begin( [ buffs ] ( player_t* p ) { p->rng().range( buffs )->trigger(); } ); else effect.player->sim->error( "Warning: Invalid type '{}' for Party Favors, ignoring.", opt_str ); } diff --git a/engine/player/unique_gear.cpp b/engine/player/unique_gear.cpp index 66f158c8835..394ead7197c 100644 --- a/engine/player/unique_gear.cpp +++ b/engine/player/unique_gear.cpp @@ -2471,7 +2471,7 @@ struct felmouth_frenzy_driver_t : public spell_t timespan_t composite_dot_duration( const action_state_t* ) const override { - size_t ticks = n_ticks[ rng().range( n_ticks.size() ) ]; + size_t ticks = rng().range( n_ticks ); assert( ticks >= 4 && ticks <= 6 ); return base_tick_time * ticks; } diff --git a/engine/player/unique_gear_bfa.cpp b/engine/player/unique_gear_bfa.cpp index 70901129f02..6bfd728e5fa 100644 --- a/engine/player/unique_gear_bfa.cpp +++ b/engine/player/unique_gear_bfa.cpp @@ -1655,8 +1655,7 @@ struct waycrest_legacy_damage_t : public generic_proc_t } void execute() override { - size_t target_index = static_cast( rng().range( 0, as( target_list().size() ) ) ); - set_target( target_list()[ target_index ] ); + set_target( rng().range( target_list() ) ); generic_proc_t::execute(); } @@ -1672,8 +1671,7 @@ struct waycrest_legacy_heal_t : public base_generic_proc_t } void execute() override { - size_t target_index = static_cast( rng().range( 0, as( sim->player_no_pet_list.data().size() ) ) ); - set_target( sim->player_list.data()[ target_index ] ); + set_target( rng().range( sim->player_no_pet_list ) ); base_generic_proc_t::execute(); } @@ -1700,8 +1698,7 @@ void items::lady_waycrests_music_box( special_effect_t& effect ) // Pick a random active target from the range void execute() override { - size_t target_index = static_cast( rng().range( 0, as( target_list().size() ) ) ); - set_target( target_list()[ target_index ] ); + set_target( rng().range( target_list() ) ); generic_proc_t::execute(); if ( waycrests_legacy_heal != nullptr ) @@ -1739,9 +1736,7 @@ void items::lady_waycrests_music_box_heal( special_effect_t& effect ) void execute() override { - size_t target_index = - static_cast( rng().range( 0, as( sim->player_no_pet_list.data().size() ) ) ); - set_target( sim->player_list.data()[ target_index ] ); + set_target( rng().range( sim->player_no_pet_list ) ); base_generic_proc_t::execute(); @@ -3125,8 +3120,7 @@ void items::storm_of_the_eternal_arcane_damage( special_effect_t& effect ) void execute() override { - size_t index = static_cast( rng().range( 0, as( target_list().size() ) ) ); - set_target( target_list()[ index ] ); + set_target( rng().range( target_list() ) ); generic_proc_t::execute(); } @@ -5191,8 +5185,7 @@ void items::shorting_bit_band( special_effect_t& effect ) const auto& targets = targets_in_range_list( target_list() ); if ( targets.size() != 0 ) // Skip action_t::execute if no targets are in range. { - size_t index = rng().range( targets.size() ); - set_target( targets[ index ] ); + set_target( rng().range( targets ) ); generic_proc_t::execute(); } diff --git a/engine/player/unique_gear_dragonflight.cpp b/engine/player/unique_gear_dragonflight.cpp index b472126b6be..8c911ceb620 100644 --- a/engine/player/unique_gear_dragonflight.cpp +++ b/engine/player/unique_gear_dragonflight.cpp @@ -178,7 +178,7 @@ void phial_of_elemental_chaos( special_effect_t& effect ) buff = make_buff( effect.player, effect.name(), effect.driver() ) ->set_tick_callback( [ buff_list ]( buff_t* b, int, timespan_t ) { - buff_list[ b->rng().range( buff_list.size() ) ]->trigger(); + b->rng().range( buff_list )->trigger(); } ); } @@ -3628,8 +3628,7 @@ void bushwhackers_compass(special_effect_t& effect) { dbc_proc_callback_t::execute( a, s ); - auto buff = effect.player -> sim -> rng().range( buffs.size() ); - buffs[ buff ] -> trigger(); + effect.player->sim->rng().range( buffs )->trigger(); } }; effect.buff_disabled = true; @@ -3908,8 +3907,7 @@ void ruby_whelp_shell( special_effect_t& effect ) } else { - size_t choice = rng().range( whelp_types.size() ); - trigger_whelp_proc( whelp_types[ choice ], s ); + trigger_whelp_proc( rng().range( whelp_types ), s ); } } @@ -6019,7 +6017,7 @@ void pips_emerald_friendship_badge( special_effect_t& e ) } e.player->register_combat_begin( [ buffs ]( player_t* p ) { - buffs.at( p->rng().range( buffs.size() ) ).first->trigger(); + p->rng().range( buffs ).first->trigger(); } ); struct pips_cb_t : public dbc_proc_callback_t @@ -6429,7 +6427,7 @@ void pinch_of_dream_magic( special_effect_t& effect ) effect.player->callbacks.register_callback_execute_function( effect.driver()->id(), [ buffs ]( const dbc_proc_callback_t* cb, action_t*, action_state_t* ) { - buffs[ cb->rng().range( buffs.size() ) ]->trigger(); + cb->rng().range( buffs )->trigger(); } ); new dbc_proc_callback_t( effect.player, effect ); @@ -8296,8 +8294,7 @@ void thorncaller_claw( special_effect_t& effect ) { if ( targets.size() != 0 ) { // Choose a random new target to spread to - player_t* new_target = - targets[ static_cast( effect.player->rng().range( 0, static_cast( targets.size() ) ) ) ]; + auto new_target = effect.player->rng().range( targets ); effect.player->sim->print_debug( "{} demised with Thorn Spirit active. Spreading to new target {}.", t->name(), new_target->name() ); thorn_spirit->execute_on_target( new_target ); } @@ -8724,7 +8721,7 @@ void elemental_lariat( special_effect_t& effect ) effect.player->callbacks.register_callback_execute_function( effect.driver()->id(), [ buffs ]( const dbc_proc_callback_t* cb, action_t*, action_state_t* ) { - buffs[ cb->rng().range( buffs.size() ) ]->trigger(); + cb->rng().range( buffs )->trigger(); } ); } @@ -9530,7 +9527,7 @@ void verdant_conduit( special_effect_t& effect ) { effect.player->callbacks.register_callback_execute_function( effect.driver()->id(), [ buffs ]( const dbc_proc_callback_t* cb, action_t*, action_state_t* ) { - buffs[ cb->rng().range( buffs.size() ) ]->trigger(); + cb->rng().range( buffs )->trigger(); } ); } } @@ -10593,8 +10590,7 @@ void obscure_pastel_stone( special_effect_t& effect ) if ( result_is_hit( s->result ) ) { // TODO: If heal and absorb procs are implemented, they should target the player. - auto action = stone_actions[ rng().range( stone_actions.size() ) ]; - if ( action ) + if ( auto action = rng().range( stone_actions ) ) action->execute_on_target( s->target ); } } @@ -10823,8 +10819,8 @@ void explosive_barrage( special_effect_t& effect ) if ( tl.empty() ) return; - barrage->execute_on_target( tl[ rng().range( tl.size() ) ] ); - barrage->execute_on_target( tl[ rng().range( tl.size() ) ] ); + barrage->execute_on_target( rng().range( tl ) ); + barrage->execute_on_target( rng().range( tl ) ); } ); } } @@ -10887,7 +10883,7 @@ void wildfire( special_effect_t& effect ) else { const auto& tl = target_list(); - target = tl[ rng().range( tl.size() ) ]; + target = rng().range( tl ); } } @@ -11128,7 +11124,7 @@ void arcanists_edge( special_effect_t& effect ) else { const auto& tl = target_list(); - target = tl[ rng().range( tl.size() ) ]; + target = rng().range( tl ); } } @@ -11355,7 +11351,7 @@ void sunstriders_flourish( special_effect_t& effect ) else { const auto& tl = target_list(); - target = tl[ rng().range( tl.size() ) ]; + target = rng().range( tl ); } } diff --git a/engine/player/unique_gear_legion.cpp b/engine/player/unique_gear_legion.cpp index 867b10b8454..62b475b17d1 100644 --- a/engine/player/unique_gear_legion.cpp +++ b/engine/player/unique_gear_legion.cpp @@ -1595,8 +1595,7 @@ struct injector_proc_cb_t : public dbc_proc_callback_t void execute( action_t* /* a */, action_state_t* /* state */ ) override { - auto buff_index = static_cast( rng().range( size_t(0), small_buffs.size() ) ); - auto buff = small_buffs[ buff_index ]; + auto buff = rng().range( small_buffs ); buff -> trigger(); if ( buff -> check() == buff -> max_stack() ) @@ -2849,7 +2848,7 @@ struct ceaseless_toxin_t : public proc_spell_t // Remove targets randomly until thre's only one left. while ( tl.size() > 1 ) { - size_t index = static_cast( rng().range( 0.0, as( tl.size() ) ) ); + size_t index = rng().range( tl.size() ); tl.erase( tl.begin() + index ); } @@ -3186,8 +3185,7 @@ struct dreadstone_proc_cb_t : public dbc_proc_callback_t void execute( action_t* /* a */, action_state_t* /* state */ ) override { - size_t buff_index = rng().range( size_t(), buffs.size() ); - buffs[ buff_index ] -> trigger(); + rng().range( buffs )->trigger(); } }; @@ -3735,13 +3733,11 @@ void item::draught_of_souls( special_effect_t& effect ) } } ); - auto random_idx = rng().range(size_t(), targets.size() ); - return !targets.empty() ? targets[ random_idx ] : nullptr; + return !targets.empty() ? rng().range( targets ) : nullptr; } else { - auto random_idx = rng().range( size_t(), sim -> target_non_sleeping_list.size() ); - return sim -> target_non_sleeping_list[ random_idx ]; + return rng().range( sim->target_non_sleeping_list ); } } diff --git a/engine/player/unique_gear_shadowlands.cpp b/engine/player/unique_gear_shadowlands.cpp index 23fed7a2058..a367c7c90d1 100644 --- a/engine/player/unique_gear_shadowlands.cpp +++ b/engine/player/unique_gear_shadowlands.cpp @@ -3909,7 +3909,7 @@ void prismatic_brilliance( special_effect_t& effect ) effect.player->callbacks.register_callback_execute_function( effect.driver()->id(), [ buffs ]( const dbc_proc_callback_t* cb, action_t*, action_state_t* ) { - buffs[ cb->rng().range( buffs.size() ) ]->trigger(); + cb->rng().range( buffs )->trigger(); } ); } diff --git a/engine/player/unique_gear_thewarwithin.cpp b/engine/player/unique_gear_thewarwithin.cpp index 610657b45e4..232a538dfa4 100644 --- a/engine/player/unique_gear_thewarwithin.cpp +++ b/engine/player/unique_gear_thewarwithin.cpp @@ -671,7 +671,7 @@ void elemental_focusing_lens( special_effect_t& effect ) effect.player->callbacks.register_callback_execute_function( effect.spell_id, [ damages ]( const dbc_proc_callback_t* cb, action_t*, const action_state_t* s ) { - damages.at( cb->rng().range( damages.size() ) )->execute_on_target( s->target ); + cb->rng().range( damages )->execute_on_target( s->target ); } ); } @@ -974,10 +974,8 @@ void siphoning_stilleto( special_effect_t& effect ) { self->execute_on_target( listener ); // TODO: implement range check if it ever matters for specilizations that can use this. - make_event( *listener->sim, duration, [ & ] { - auto target = listener->sim - ->target_non_sleeping_list[ rng().range( listener->sim->target_non_sleeping_list.size() ) ]; - damage->execute_on_target( target ); + make_event( *listener->sim, duration, [ this ] { + damage->execute_on_target( rng().range( listener->sim->target_non_sleeping_list ) ); } ); } }; @@ -2963,7 +2961,7 @@ void empowering_crystal_of_anubikkaj( special_effect_t& effect ) effect.player->callbacks.register_callback_execute_function( effect.spell_id, [ buffs ]( const dbc_proc_callback_t* cb, action_t*, action_state_t* ) { - auto buff = buffs[ cb->listener->rng().range( 0U, as( buffs.size() ) ) ]; + auto buff = cb->listener->rng().range( buffs ); for ( auto b : buffs ) { if ( b == buff ) @@ -4064,14 +4062,12 @@ void unstable_power_core( special_effect_t& effect ) if ( remains > 0_ms ) return; - auto buff_idx = effect.player->sim->rng().range( buffs.size() ); - buffs[ buff_idx ]->trigger( effect.player->rng().range( 10_s, 30_s ) ); + effect.player->rng().range( buffs )->trigger( effect.player->rng().range( 10_s, 30_s ) ); } ); } effect.player->register_precombat_begin( [ buffs ]( player_t* p ) { - auto buff_idx = p->sim->rng().range( buffs.size() ); - buffs[ buff_idx ]->trigger( p->rng().range( 10_s, 30_s ) ); + p->rng().range( buffs )->trigger( p->rng().range( 10_s, 30_s ) ); } ); } @@ -4112,9 +4108,9 @@ void shadowbinding_ritual_knife( special_effect_t& effect ) if ( negative_buffs.size() > 0 ) { effect.player->callbacks.register_callback_execute_function( - effect.driver()->id(), [ negative_buffs ]( const dbc_proc_callback_t* cb, action_t*, const action_state_t* ) { - negative_buffs[ cb->listener->rng().range( negative_buffs.size() ) ]->trigger(); - } ); + effect.driver()->id(), [ negative_buffs ]( const dbc_proc_callback_t* cb, action_t*, const action_state_t* ) { + cb->listener->rng().range( negative_buffs )->trigger(); + } ); } effect.buff_disabled = true; @@ -4619,7 +4615,7 @@ void everburning_lantern( special_effect_t& effect ) cb->activate(); } ); - counter->set_expire_callback( [ fireflies, cb ]( buff_t*, int s, timespan_t ) { + counter->set_expire_callback( [ fireflies ]( buff_t*, int s, timespan_t ) { fireflies->trigger( -1, as( s ) ); } ); @@ -4803,7 +4799,7 @@ void wildfire_wick( special_effect_t& effect ) if ( auto tnsl = p->sim->target_non_sleeping_list.data(); tnsl.size() > 1 ) // make a copy { range::erase_remove( tnsl, s->target ); - cb->proc_action->execute_on_target( tnsl.at( p->rng().range( tnsl.size() ) ) ); + cb->proc_action->execute_on_target( p->rng().range( tnsl ) ); } } diff --git a/engine/util/vector_with_callback.hpp b/engine/util/vector_with_callback.hpp index b7df8c825ff..b4c1aa0791b 100644 --- a/engine/util/vector_with_callback.hpp +++ b/engine/util/vector_with_callback.hpp @@ -21,6 +21,7 @@ struct vector_with_callback public: using callback_type = std::function; using iterator = typename std::vector::const_iterator; + using value_type = const T; /* Register your custom callback, which will be called when the vector is modified */ @@ -57,6 +58,9 @@ struct vector_with_callback const T& operator[]( size_t i ) const { return _data[ i ]; } + const T& at( size_t i ) const + { return _data.at( i );} + size_t size() const { return _data.size(); }