2023-03-09 21:54:30 +01:00
|
|
|
#include "ActionResult.h"
|
2019-07-25 22:46:10 +10:00
|
|
|
|
|
|
|
#include <Util/Util.h>
|
|
|
|
|
2023-02-10 12:11:11 -03:00
|
|
|
#include <Service.h>
|
|
|
|
#include <Manager/PlayerMgr.h>
|
|
|
|
|
2019-07-27 13:59:35 +10:00
|
|
|
#include "Actor/Chara.h"
|
2020-01-23 22:36:01 +09:00
|
|
|
#include "Actor/Player.h"
|
2019-07-27 13:59:35 +10:00
|
|
|
|
2019-07-25 22:46:10 +10:00
|
|
|
using namespace Sapphire;
|
|
|
|
using namespace Sapphire::World::Action;
|
|
|
|
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
ActionResult::ActionResult( Entity::CharaPtr target, uint64_t runAfter ) :
|
2019-07-25 22:46:10 +10:00
|
|
|
m_target( std::move( target ) ),
|
2023-02-28 10:31:59 +01:00
|
|
|
m_delayMs( runAfter )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Arg0 = 0;
|
|
|
|
m_result.Arg1 = 0;
|
|
|
|
m_result.Arg2 = 0;
|
|
|
|
m_result.Value = 0;
|
2023-03-09 21:54:30 +01:00
|
|
|
m_result.Flag = static_cast< uint8_t >( Common::ActionResultFlag::None );
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_NONE;
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
Entity::CharaPtr ActionResult::getTarget() const
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
|
|
|
return m_target;
|
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
uint64_t ActionResult::getDelay()
|
2019-07-27 13:59:35 +10:00
|
|
|
{
|
|
|
|
return m_delayMs;
|
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::damage( uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionResultFlag flag )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Arg0 = static_cast< uint8_t >( severity );
|
|
|
|
m_result.Value = static_cast< int16_t >( amount );
|
|
|
|
m_result.Flag = static_cast< uint8_t >( flag );
|
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_DAMAGE_HP;
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::heal( uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionResultFlag flag )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Arg1 = static_cast< uint8_t >( severity );
|
|
|
|
m_result.Value = static_cast< int16_t >( amount );
|
|
|
|
m_result.Flag = static_cast< uint8_t >( flag );
|
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_HP;
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::restoreMP( uint32_t amount, Common::ActionResultFlag flag )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Value = static_cast< int16_t >( amount );
|
|
|
|
m_result.Flag = static_cast< uint8_t >( flag );
|
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_MP;
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::startCombo( uint16_t actionId )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Value = static_cast< int16_t >( actionId );
|
2023-03-09 21:54:30 +01:00
|
|
|
m_result.Flag = static_cast< uint8_t >( Common::ActionResultFlag::EffectOnSource );
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_COMBO;
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::comboSucceed()
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2020-01-05 20:49:50 +09:00
|
|
|
// no EffectOnSource flag on this
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_COMBO_HIT;
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::applyStatusEffect( uint16_t statusId, uint8_t param )
|
2020-01-06 19:25:01 +09:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Value = static_cast< int16_t >( statusId );
|
|
|
|
m_result.Arg2 = param;
|
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_SET_STATUS;
|
2020-01-06 19:25:01 +09:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::mount( uint16_t mountId )
|
2020-01-23 22:36:01 +09:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_result.Value = static_cast< int16_t >( mountId );
|
|
|
|
m_result.Arg0 = 1;
|
|
|
|
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_MOUNT;
|
2020-01-23 22:36:01 +09:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
const Common::CalcResultParam& ActionResult::getCalcResultParam() const
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
return m_result;
|
2019-07-27 13:59:35 +10:00
|
|
|
}
|
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
void ActionResult::execute()
|
2019-07-27 13:59:35 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
switch( m_result.Type )
|
2019-07-27 13:59:35 +10:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
case Common::ActionEffectType::CALC_RESULT_TYPE_DAMAGE_HP:
|
2019-07-27 13:59:35 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_target->takeDamage( m_result.Value );
|
2019-07-27 13:59:35 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
case Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_HP:
|
2019-07-27 13:59:35 +10:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_target->heal( m_result.Value );
|
2019-07-27 13:59:35 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
case Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_MP:
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2023-02-28 10:31:59 +01:00
|
|
|
m_target->restoreMP( m_result.Value );
|
2020-01-05 17:09:27 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
case Common::ActionEffectType::CALC_RESULT_TYPE_MOUNT:
|
2020-01-23 22:36:01 +09:00
|
|
|
{
|
|
|
|
auto pPlayer = m_target->getAsPlayer();
|
2023-03-06 10:12:29 +01:00
|
|
|
pPlayer->setMount( m_result.Value );
|
2020-01-23 22:36:01 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-27 13:59:35 +10:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|