Skip to content

Commit

Permalink
[Gear] use range( vector ) helper
Browse files Browse the repository at this point in the history
  • Loading branch information
gastank committed Sep 25, 2024
1 parent d87c715 commit b8dfa96
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 63 deletions.
8 changes: 3 additions & 5 deletions engine/player/azerite_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand Down Expand Up @@ -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();
} );
}
Expand Down Expand Up @@ -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();
}
};

Expand Down
2 changes: 1 addition & 1 deletion engine/player/soulbinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion engine/player/unique_gear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 6 additions & 13 deletions engine/player/unique_gear_bfa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,8 +1655,7 @@ struct waycrest_legacy_damage_t : public generic_proc_t
}
void execute() override
{
size_t target_index = static_cast<size_t>( rng().range( 0, as<double>( target_list().size() ) ) );
set_target( target_list()[ target_index ] );
set_target( rng().range( target_list() ) );

generic_proc_t::execute();
}
Expand All @@ -1672,8 +1671,7 @@ struct waycrest_legacy_heal_t : public base_generic_proc_t<proc_heal_t>
}
void execute() override
{
size_t target_index = static_cast<size_t>( rng().range( 0, as<double>( 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<proc_heal_t>::execute();
}
Expand All @@ -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<size_t>( rng().range( 0, as<double>( target_list().size() ) ) );
set_target( target_list()[ target_index ] );
set_target( rng().range( target_list() ) );

generic_proc_t::execute();
if ( waycrests_legacy_heal != nullptr )
Expand Down Expand Up @@ -1739,9 +1736,7 @@ void items::lady_waycrests_music_box_heal( special_effect_t& effect )

void execute() override
{
size_t target_index =
static_cast<size_t>( rng().range( 0, as<double>( 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<proc_heal_t>::execute();

Expand Down Expand Up @@ -3125,8 +3120,7 @@ void items::storm_of_the_eternal_arcane_damage( special_effect_t& effect )

void execute() override
{
size_t index = static_cast<size_t>( rng().range( 0, as<double>( target_list().size() ) ) );
set_target( target_list()[ index ] );
set_target( rng().range( target_list() ) );

generic_proc_t::execute();
}
Expand Down Expand Up @@ -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();
}
Expand Down
32 changes: 14 additions & 18 deletions engine/player/unique_gear_dragonflight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<int>( effect.player->rng().range( 0, static_cast<double>( 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 );
}
Expand Down Expand Up @@ -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();
} );
}

Expand Down Expand Up @@ -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();
} );
}
}
Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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 ) );
} );
}
}
Expand Down Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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 );
}
}

Expand Down
14 changes: 5 additions & 9 deletions engine/player/unique_gear_legion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>( 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() )
Expand Down Expand Up @@ -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<size_t>( rng().range( 0.0, as<double>( tl.size() ) ) );
size_t index = rng().range( tl.size() );
tl.erase( tl.begin() + index );
}

Expand Down Expand Up @@ -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();
}
};

Expand Down Expand Up @@ -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 );
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/player/unique_gear_shadowlands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
}

Expand Down
26 changes: 11 additions & 15 deletions engine/player/unique_gear_thewarwithin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
}

Expand Down Expand Up @@ -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 ) );
} );
}
};
Expand Down Expand Up @@ -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<unsigned>( buffs.size() ) ) ];
auto buff = cb->listener->rng().range( buffs );
for ( auto b : buffs )
{
if ( b == buff )
Expand Down Expand Up @@ -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 ) );
} );
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<double>( s ) );
} );

Expand Down Expand Up @@ -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 ) );
}
}

Expand Down
4 changes: 4 additions & 0 deletions engine/util/vector_with_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct vector_with_callback
public:
using callback_type = std::function<void(const T&)>;
using iterator = typename std::vector<T>::const_iterator;
using value_type = const T;

/* Register your custom callback, which will be called when the vector is modified
*/
Expand Down Expand Up @@ -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(); }

Expand Down

0 comments on commit b8dfa96

Please sign in to comment.