mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 22:37:45 +00:00
add primary cost handling for actions for mp/tp
This commit is contained in:
parent
4ba59e92fd
commit
a0aa7ea977
4 changed files with 82 additions and 4 deletions
|
@ -266,6 +266,13 @@ void Sapphire::Action::Action::execute()
|
||||||
{
|
{
|
||||||
assert( m_pSource );
|
assert( m_pSource );
|
||||||
|
|
||||||
|
// subtract costs first, if somehow the caster stops meeting those requirements cancel the cast
|
||||||
|
if( !casterHasCostRequirements( true ) )
|
||||||
|
{
|
||||||
|
interrupt();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||||
|
|
||||||
if( hasCastTime() )
|
if( hasCastTime() )
|
||||||
|
@ -398,9 +405,8 @@ bool Sapphire::Action::Action::playerPrecheck( Entity::Player& player )
|
||||||
// validate range
|
// validate range
|
||||||
|
|
||||||
|
|
||||||
// todo: validate costs/conditionals here
|
if( !casterHasCostRequirements() )
|
||||||
|
return false;
|
||||||
calculateActionCost();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -425,4 +431,58 @@ bool Sapphire::Action::Action::isComboAction() const
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_actionData->actionCombo == lastActionId;
|
return m_actionData->actionCombo == lastActionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Sapphire::Action::Action::casterHasCostRequirements( bool subtractCosts )
|
||||||
|
{
|
||||||
|
return primaryCostCheck( subtractCosts ) && secondaryCostCheck( subtractCosts );
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
|
@ -47,6 +47,13 @@ namespace Sapphire::Action
|
||||||
|
|
||||||
bool isComboAction() const;
|
bool isComboAction() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Checks whether the source chara has the required stats/debuffs/etc to cast an action.
|
||||||
|
* @param subtractCosts Whether we should subtract the costs (eg, mp/tp) from the player or to just check them
|
||||||
|
* @return whether the requirements are met by the caster
|
||||||
|
*/
|
||||||
|
bool casterHasCostRequirements( bool subtractCosts = false );
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Checks if the action *may* target a resident instead of an actor
|
* @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.
|
* @return true if the target *may* be a resident and not an actor, otherwise false.
|
||||||
|
@ -91,7 +98,9 @@ namespace Sapphire::Action
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void calculateActionCost();
|
void calculateActionCost();
|
||||||
void calculateMPCost( uint16_t baseCost );
|
|
||||||
|
bool primaryCostCheck( bool subtractCosts );
|
||||||
|
bool secondaryCostCheck( bool subtractCosts );
|
||||||
|
|
||||||
bool playerPrecheck( Entity::Player& player );
|
bool playerPrecheck( Entity::Player& player );
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,13 @@ void Sapphire::Entity::Chara::setGp( uint32_t gp )
|
||||||
sendStatusUpdate();
|
sendStatusUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \param tp amount to set*/
|
||||||
|
void Sapphire::Entity::Chara::setTp( uint32_t tp )
|
||||||
|
{
|
||||||
|
m_tp = tp;
|
||||||
|
sendStatusUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
/*! \param type invincibility type to set */
|
/*! \param type invincibility type to set */
|
||||||
void Sapphire::Entity::Chara::setInvincibilityType( Common::InvincibilityType type )
|
void Sapphire::Entity::Chara::setInvincibilityType( Common::InvincibilityType type )
|
||||||
{
|
{
|
||||||
|
|
|
@ -217,6 +217,8 @@ namespace Sapphire::Entity
|
||||||
|
|
||||||
void setGp( uint32_t gp );
|
void setGp( uint32_t gp );
|
||||||
|
|
||||||
|
void setTp( uint32_t tp );
|
||||||
|
|
||||||
void setInvincibilityType( Common::InvincibilityType type );
|
void setInvincibilityType( Common::InvincibilityType type );
|
||||||
|
|
||||||
void die();
|
void die();
|
||||||
|
|
Loading…
Add table
Reference in a new issue