Skip to content

Commit 3b9ee9d

Browse files
committed
[Player] pass whether resource is increasing to resource callback functor
1 parent e983975 commit 3b9ee9d

3 files changed

Lines changed: 71 additions & 48 deletions

File tree

engine/player/player.cpp

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14133,47 +14133,64 @@ void player_t::reset_resource_callbacks()
1413314133
/**
1413414134
* Checks if a resource callback condition has been met and if yes activate it.
1413514135
*/
14136-
void player_t::check_resource_change_for_callback(resource_e resource, double previous_amount, double previous_pct_points)
14137-
{
14138-
for (auto& callback : resource_callbacks)
14139-
{
14140-
if (callback.is_consumed)
14141-
continue;
14142-
if (callback.resource != resource)
14143-
continue;
14144-
14145-
// Evaluate if callback condition is met.
14146-
bool callback_condition_valid = false;
14147-
if (callback.is_pct)
14148-
{
14149-
double current_pct_points = resources.current[ resource ] / resources.max[ resource ] * 100.0;
14150-
if ((callback.value < previous_pct_points && callback.value >= current_pct_points) ||
14151-
(callback.value >= previous_pct_points && callback.value < current_pct_points))
14152-
{
14153-
callback_condition_valid = true;
14154-
}
14155-
}
14156-
else
14157-
{
14158-
double current_amount = resources.current[ resource ];
14159-
if ((callback.value < previous_amount && callback.value >= current_amount) ||
14160-
(callback.value >= previous_amount && callback.value < current_amount))
14161-
{
14162-
callback_condition_valid = true;
14163-
}
14164-
}
14165-
if (!callback_condition_valid)
14166-
{
14167-
continue;
14168-
}
14169-
14170-
sim->print_debug("{} resource callback triggered.", name());
14171-
// We have a callback event, trigger stuff.
14172-
callback.callback();
14173-
if (callback.fire_once)
14174-
{
14175-
callback.is_consumed = true;
14176-
}
14136+
void player_t::check_resource_change_for_callback( resource_e resource, double previous_amount,
14137+
double previous_pct_points )
14138+
{
14139+
for ( auto& callback : resource_callbacks )
14140+
{
14141+
if ( callback.is_consumed )
14142+
continue;
14143+
14144+
if ( callback.resource != resource )
14145+
continue;
14146+
14147+
// Evaluate if callback condition is met.
14148+
bool callback_condition_valid = false;
14149+
bool increasing;
14150+
14151+
if ( callback.is_pct )
14152+
{
14153+
double current_pct_points = resources.current[ resource ] / resources.max[ resource ] * 100.0;
14154+
if ( callback.value < previous_pct_points && callback.value >= current_pct_points )
14155+
{
14156+
callback_condition_valid = true;
14157+
increasing = false;
14158+
}
14159+
else if ( callback.value >= previous_pct_points && callback.value < current_pct_points )
14160+
{
14161+
callback_condition_valid = true;
14162+
increasing = true;
14163+
}
14164+
}
14165+
else
14166+
{
14167+
double current_amount = resources.current[ resource ];
14168+
if ( callback.value < previous_amount && callback.value >= current_amount )
14169+
{
14170+
callback_condition_valid = true;
14171+
increasing = false;
14172+
}
14173+
else if ( callback.value >= previous_amount && callback.value < current_amount )
14174+
{
14175+
callback_condition_valid = true;
14176+
increasing = true;
14177+
}
14178+
}
14179+
14180+
if ( !callback_condition_valid )
14181+
{
14182+
continue;
14183+
}
14184+
14185+
sim->print_debug( "{} resource callback triggered.", name() );
14186+
14187+
// We have a callback event, trigger stuff.
14188+
callback.callback( increasing );
14189+
14190+
if ( callback.fire_once )
14191+
{
14192+
callback.is_consumed = true;
14193+
}
1417714194
}
1417814195

1417914196
check_resource_callback_deactivation();

engine/player/player.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ struct player_t : public actor_t
716716
/// Current execution type
717717
execute_type current_execute_type;
718718

719-
using resource_callback_function_t = std::function<void()>;
719+
using resource_callback_function_t = std::function<void( bool )>;
720720

721721
template <typename T>
722722
struct player_option_t

engine/sim/raid_event.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,9 @@ void raid_event_t::combat_begin()
19261926
if ( !target )
19271927
sim->error( "Unknown pull target '{}'", pull_target_str );
19281928

1929-
target->register_resource_callback( RESOURCE_HEALTH, last_pct, [ this ]() { deactivate( "last_pct reached" ); }, true );
1929+
target->register_resource_callback( RESOURCE_HEALTH, last_pct, [ this ]( bool ) {
1930+
deactivate( "last_pct reached" );
1931+
}, true );
19301932
}
19311933
else if ( sim->current_iteration == 0 || sim->fixed_time )
19321934
{
@@ -1949,7 +1951,9 @@ void raid_event_t::combat_begin()
19491951
if ( !target )
19501952
sim->error( "Unknown pull target '{}'", pull_target_str );
19511953

1952-
target->register_resource_callback( RESOURCE_HEALTH, first_pct, [ this ]() { activate( "first_pct reached" ); }, true );
1954+
target->register_resource_callback( RESOURCE_HEALTH, first_pct, [ this ]( bool ) {
1955+
activate( "first_pct reached" );
1956+
}, true );
19531957
}
19541958
else if ( sim->current_iteration == 0 || sim->fixed_time )
19551959
{
@@ -2107,15 +2111,17 @@ void raid_event_t::parse_options( util::string_view options_str )
21072111
if ( last_pct != -1 && !sim->fixed_time )
21082112
{
21092113
assert( sim->target );
2110-
sim->target->register_resource_callback(
2111-
RESOURCE_HEALTH, last_pct, [ this ]() { deactivate( "last_pct reached" ); }, true );
2114+
sim->target->register_resource_callback( RESOURCE_HEALTH, last_pct, [ this ]( bool ) {
2115+
deactivate( "last_pct reached" );
2116+
}, true );
21122117
}
21132118

21142119
if ( first_pct != -1 && !sim->fixed_time )
21152120
{
21162121
assert( sim->target );
2117-
sim->target->register_resource_callback(
2118-
RESOURCE_HEALTH, first_pct, [ this ]() { activate( "first_pct reached" ); }, true );
2122+
sim->target->register_resource_callback( RESOURCE_HEALTH, first_pct, [ this ]( bool ) {
2123+
activate( "first_pct reached" );
2124+
}, true );
21192125
}
21202126
}
21212127
else

0 commit comments

Comments
 (0)