mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 14:57:44 +00:00
Merge pull request #540 from NotAdam/develop
add primary cost handling for actions for mp/tp
This commit is contained in:
commit
ed081053bd
4 changed files with 92 additions and 4 deletions
|
@ -266,6 +266,13 @@ void Sapphire::Action::Action::execute()
|
|||
{
|
||||
assert( m_pSource );
|
||||
|
||||
// subtract costs first, if somehow the caster stops meeting those requirements cancel the cast
|
||||
if( !consumeResources() )
|
||||
{
|
||||
interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||
|
||||
if( hasCastTime() )
|
||||
|
@ -398,9 +405,8 @@ bool Sapphire::Action::Action::playerPrecheck( Entity::Player& player )
|
|||
// validate range
|
||||
|
||||
|
||||
// todo: validate costs/conditionals here
|
||||
|
||||
calculateActionCost();
|
||||
if( !hasResources() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -425,4 +431,63 @@ bool Sapphire::Action::Action::isComboAction() const
|
|||
}
|
||||
|
||||
return m_actionData->actionCombo == lastActionId;
|
||||
}
|
||||
|
||||
bool Sapphire::Action::Action::primaryCostCheck( bool subtractCosts )
|
||||
{
|
||||
switch( m_primaryCostType )
|
||||
{
|
||||
case Common::ActionPrimaryCostType::TacticsPoints:
|
||||
{
|
||||
auto curTp = m_pSource->getTp();
|
||||
|
||||
if( curTp < m_primaryCost )
|
||||
return false;
|
||||
|
||||
if( subtractCosts )
|
||||
m_pSource->setTp( curTp - m_primaryCost );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case Common::ActionPrimaryCostType::MagicPoints:
|
||||
{
|
||||
auto curMp = m_pSource->getMp();
|
||||
|
||||
auto cost = Math::CalcStats::calculateMpCost( *m_pSource, m_primaryCost );
|
||||
|
||||
if( curMp < cost )
|
||||
return false;
|
||||
|
||||
if( subtractCosts )
|
||||
m_pSource->setMp( curMp - cost );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// free casts, likely just pure ogcds
|
||||
case Common::ActionPrimaryCostType::None:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
|
@ -47,6 +47,18 @@ namespace Sapphire::Action
|
|||
|
||||
bool isComboAction() const;
|
||||
|
||||
/*!
|
||||
* @brief Checks if a chara has enough resources available to cast the action (tp/mp/etc)
|
||||
* @return true if they have the required resources
|
||||
*/
|
||||
bool hasResources();
|
||||
|
||||
/*!
|
||||
* @brief Checks if a chara has enough resources available to cast the action and then consumes them (tp/mp/etc)
|
||||
* @return true if they have the required resources
|
||||
*/
|
||||
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.
|
||||
|
@ -91,7 +103,9 @@ namespace Sapphire::Action
|
|||
protected:
|
||||
|
||||
void calculateActionCost();
|
||||
void calculateMPCost( uint16_t baseCost );
|
||||
|
||||
bool primaryCostCheck( bool subtractCosts );
|
||||
bool secondaryCostCheck( bool subtractCosts );
|
||||
|
||||
bool playerPrecheck( Entity::Player& player );
|
||||
|
||||
|
|
|
@ -181,6 +181,13 @@ void Sapphire::Entity::Chara::setGp( uint32_t gp )
|
|||
sendStatusUpdate();
|
||||
}
|
||||
|
||||
/*! \param tp amount to set*/
|
||||
void Sapphire::Entity::Chara::setTp( uint32_t tp )
|
||||
{
|
||||
m_tp = tp;
|
||||
sendStatusUpdate();
|
||||
}
|
||||
|
||||
/*! \param type invincibility type to set */
|
||||
void Sapphire::Entity::Chara::setInvincibilityType( Common::InvincibilityType type )
|
||||
{
|
||||
|
|
|
@ -217,6 +217,8 @@ namespace Sapphire::Entity
|
|||
|
||||
void setGp( uint32_t gp );
|
||||
|
||||
void setTp( uint32_t tp );
|
||||
|
||||
void setInvincibilityType( Common::InvincibilityType type );
|
||||
|
||||
void die();
|
||||
|
|
Loading…
Add table
Reference in a new issue