1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-23 18:17:46 +00:00
sapphire/src/world/Action/ActionResult.cpp

156 lines
3.9 KiB
C++
Raw Normal View History

#include "ActionResult.h"
2019-07-25 22:46:10 +10:00
#include <Util/Util.h>
#include <Service.h>
#include <Manager/PlayerMgr.h>
#include "Actor/Chara.h"
2020-01-23 22:36:01 +09:00
#include "Actor/Player.h"
#include "StatusEffect/StatusEffect.h"
2019-07-25 22:46:10 +10:00
using namespace Sapphire;
2023-03-16 21:56:57 +01:00
using namespace Sapphire::Common;
2019-07-25 22:46:10 +10:00
using namespace Sapphire::World::Action;
ActionResult::ActionResult( Entity::CharaPtr target ) :
m_target( std::move( target ) )
2019-07-25 22:46:10 +10:00
{
m_result.Arg0 = 0;
m_result.Arg1 = 0;
m_result.Arg2 = 0;
m_result.Value = 0;
2023-03-16 21:56:57 +01:00
m_result.Flag = static_cast< uint8_t >( ActionResultFlag::None );
m_result.Type = CalcResultType::TypeNone;
2019-07-25 22:46:10 +10:00
}
Entity::CharaPtr ActionResult::getTarget() const
2019-07-25 22:46:10 +10:00
{
return m_target;
}
2023-03-16 21:56:57 +01:00
void ActionResult::damage( uint32_t amount, CalcResultType hitType, uint8_t hitEffect, ActionResultFlag flag )
{
m_result.Arg0 = hitEffect;
m_result.Value = static_cast< int16_t >( amount );
m_result.Flag = static_cast< uint8_t >( flag );
m_result.Type = hitType;
2019-07-25 22:46:10 +10:00
}
2023-03-16 21:56:57 +01:00
void ActionResult::heal( uint32_t amount, CalcResultType hitType, uint8_t hitEffect, ActionResultFlag flag )
2019-07-25 22:46:10 +10:00
{
m_result.Arg0 = hitEffect;
m_result.Value = static_cast< int16_t >( amount );
m_result.Flag = static_cast< uint8_t >( flag );
m_result.Type = hitType;
2019-07-25 22:46:10 +10:00
}
2023-03-16 21:56:57 +01:00
void ActionResult::restoreMP( uint32_t amount, ActionResultFlag flag )
2020-01-05 17:09:27 +09:00
{
m_result.Value = static_cast< int16_t >( amount );
m_result.Flag = static_cast< uint8_t >( flag );
2023-03-16 21:56:57 +01:00
m_result.Type = CalcResultType::TypeRecoverMp;
2020-01-05 17:09:27 +09:00
}
void ActionResult::startCombo( uint16_t actionId )
2020-01-05 17:09:27 +09:00
{
m_result.Value = static_cast< int16_t >( actionId );
2023-03-16 21:56:57 +01:00
m_result.Flag = static_cast< uint8_t >( ActionResultFlag::EffectOnSource );
m_result.Type = CalcResultType::TypeCombo;
2020-01-05 17:09:27 +09: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-03-16 21:56:57 +01:00
m_result.Type = CalcResultType::TypeComboHit;
2020-01-05 17:09:27 +09:00
}
void ActionResult::applyStatusEffect( uint32_t id, int32_t duration, Entity::Chara& source, uint8_t param, bool shouldOverride )
2020-01-06 19:25:01 +09:00
{
m_result.Value = static_cast< int16_t >( id );
m_result.Arg2 = param;
2023-03-16 21:56:57 +01:00
m_result.Type = CalcResultType::TypeSetStatus;
m_bOverrideStatus = shouldOverride;
m_pStatus = StatusEffect::make_StatusEffect( id, source.getAsChara(), m_target, duration, 3000 );
m_pStatus->setParam( param );
2020-01-06 19:25:01 +09:00
}
void ActionResult::applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t param, bool shouldOverride )
{
m_result.Value = static_cast< int16_t >( id );
m_result.Arg2 = param;
2023-03-16 21:56:57 +01:00
m_result.Type = CalcResultType::TypeSetStatusMe;
m_result.Flag = static_cast< uint8_t >( ActionResultFlag::EffectOnSource );
m_bOverrideStatus = shouldOverride;
2024-01-16 08:41:55 +01:00
m_pStatus = Sapphire::StatusEffect::make_StatusEffect( id, m_target, m_target, duration, 3000 );
m_pStatus->setParam( param );
}
void ActionResult::mount( uint16_t mountId )
2020-01-23 22:36:01 +09:00
{
m_result.Value = static_cast< int16_t >( mountId );
m_result.Arg0 = 1;
2023-03-16 21:56:57 +01:00
m_result.Type = CalcResultType::TypeMount;
2020-01-23 22:36:01 +09:00
}
const Common::CalcResultParam& ActionResult::getCalcResultParam() const
2019-07-25 22:46:10 +10:00
{
return m_result;
}
const StatusEffect::StatusEffectPtr ActionResult::getStatusEffect() const
{
return m_pStatus;
}
void ActionResult::execute()
{
if( !m_target )
return;
switch( m_result.Type )
{
2023-03-16 21:56:57 +01:00
case CalcResultType::TypeDamageHp:
case CalcResultType::TypeCriticalDamageHp:
{
m_target->takeDamage( m_result.Value );
break;
}
2023-03-16 21:56:57 +01:00
case CalcResultType::TypeRecoverHp:
case CalcResultType::TypeCriticalRecoverHp:
{
m_target->heal( m_result.Value );
break;
}
2023-03-16 21:56:57 +01:00
case CalcResultType::TypeRecoverMp:
2020-01-05 17:09:27 +09:00
{
m_target->restoreMP( m_result.Value );
2020-01-05 17:09:27 +09:00
break;
}
2023-03-16 21:56:57 +01:00
case CalcResultType::TypeSetStatus:
case CalcResultType::TypeSetStatusMe:
{
if( !m_bOverrideStatus )
2023-03-12 21:06:37 +01:00
m_target->addStatusEffectByIdIfNotExist( m_pStatus );
else
2023-03-12 21:06:37 +01:00
m_target->addStatusEffectById( m_pStatus );
break;
}
2023-03-16 21:56:57 +01:00
case CalcResultType::TypeMount:
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;
}
default:
break;
}
2019-07-25 22:46:10 +10:00
}