From 48870f72b682e9fd70f36a878f8d01ad1cee57ac Mon Sep 17 00:00:00 2001 From: NotAdam Date: Thu, 4 Apr 2019 22:16:00 +1100 Subject: [PATCH] costcheck refactored to has/consumeResources --- src/world/Action/Action.cpp | 19 ++++++++++++------- src/world/Action/Action.h | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 60714b24..b072a768 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -267,7 +267,7 @@ void Sapphire::Action::Action::execute() assert( m_pSource ); // subtract costs first, if somehow the caster stops meeting those requirements cancel the cast - if( !costCheck( true ) ) + if( !consumeResources() ) { interrupt(); return; @@ -405,7 +405,7 @@ bool Sapphire::Action::Action::playerPrecheck( Entity::Player& player ) // validate range - if( !costCheck() ) + if( !hasResources() ) return false; return true; @@ -433,11 +433,6 @@ bool Sapphire::Action::Action::isComboAction() const return m_actionData->actionCombo == lastActionId; } -bool Sapphire::Action::Action::costCheck( bool subtractCosts ) -{ - return primaryCostCheck( subtractCosts ) && secondaryCostCheck( subtractCosts ); -} - bool Sapphire::Action::Action::primaryCostCheck( bool subtractCosts ) { switch( m_primaryCostType ) @@ -485,4 +480,14 @@ bool Sapphire::Action::Action::secondaryCostCheck( bool subtractCosts ) { // todo: these need to be mapped return true; +} + +bool Sapphire::Action::Action::hasResources() +{ + return primaryCostCheck( false ) && secondaryCostCheck( false ); +} + +bool Sapphire::Action::Action::consumeResources() +{ + return primaryCostCheck( true ) && secondaryCostCheck( true ); } \ No newline at end of file diff --git a/src/world/Action/Action.h b/src/world/Action/Action.h index 6c01d239..948aa15e 100644 --- a/src/world/Action/Action.h +++ b/src/world/Action/Action.h @@ -54,6 +54,10 @@ namespace Sapphire::Action */ bool costCheck( bool subtractCosts = false ); + bool hasResources(); + + bool consumeResources(); + /*! * @brief Checks if the action *may* target a resident instead of an actor * @return true if the target *may* be a resident and not an actor, otherwise false.