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

247 lines
6.1 KiB
C++
Raw Normal View History

2019-07-25 22:46:10 +10:00
#include "EffectResult.h"
#include <Util/Util.h>
#include "Actor/Chara.h"
2020-01-23 22:36:01 +09:00
#include "Actor/Player.h"
2019-07-25 22:46:10 +10:00
using namespace Sapphire;
using namespace Sapphire::World::Action;
2023-03-07 05:12:18 +09:00
EffectResult::EffectResult( Entity::CharaPtr target, Entity::CharaPtr source, uint64_t runAfter ) :
2019-07-25 22:46:10 +10:00
m_target( std::move( target ) ),
2023-03-07 05:12:18 +09:00
m_source( std::move( source ) ),
m_delayMs( runAfter ),
2023-03-07 05:12:18 +09:00
m_type( Common::ActionEffectType::Nothing ),
2019-07-25 22:46:10 +10:00
m_value( 0 ),
2023-03-07 05:12:18 +09:00
m_statusDuration( 0 ),
2020-01-08 17:21:01 +09:00
m_param0( 0 ),
m_param1( 0 ),
m_param2( 0 ),
2023-03-07 05:12:18 +09:00
m_flag( Common::ActionEffectResultFlag::None ),
m_pPreBuiltStatusEffect( nullptr )
2019-07-25 22:46:10 +10:00
{
}
2023-03-07 05:12:18 +09:00
EffectResult::EffectResult( Entity::CharaPtr target, uint64_t delayMs ) :
EffectResult::EffectResult( std::move( target ), nullptr, delayMs )
{
}
Entity::CharaPtr EffectResult::getSource() const
{
return m_source;
}
2019-07-25 22:46:10 +10:00
Entity::CharaPtr EffectResult::getTarget() const
{
return m_target;
}
uint32_t EffectResult::getValue() const
{
return m_value;
}
uint64_t EffectResult::getDelay()
{
return m_delayMs;
}
2023-03-07 05:12:18 +09:00
void EffectResult::dodge( Common::ActionEffectResultFlag flag )
{
m_flag = flag;
m_type = Common::ActionEffectType::Miss;
}
2020-01-05 20:49:50 +09:00
void EffectResult::damage( uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionEffectResultFlag flag )
2019-07-25 22:46:10 +10:00
{
2020-01-08 17:21:01 +09:00
m_param0 = static_cast< uint8_t >( severity );
2019-07-25 22:46:10 +10:00
m_value = amount;
2020-01-05 20:49:50 +09:00
m_flag = flag;
2019-07-25 22:46:10 +10:00
m_type = Common::ActionEffectType::Damage;
}
2023-03-07 05:12:18 +09:00
void EffectResult::blockedDamage( uint32_t amount, uint16_t rate, Common::ActionEffectResultFlag flag )
{
m_value = amount;
m_flag = flag;
m_param2 = rate;
m_type = Common::ActionEffectType::BlockedDamage;
}
void EffectResult::parriedDamage( uint32_t amount, uint16_t rate, Common::ActionEffectResultFlag flag )
{
m_value = amount;
m_flag = flag;
m_param2 = rate;
m_type = Common::ActionEffectType::ParriedDamage;
}
2020-01-05 20:49:50 +09:00
void EffectResult::heal( uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionEffectResultFlag flag )
2019-07-25 22:46:10 +10:00
{
2020-01-08 17:21:01 +09:00
m_param1 = static_cast< uint8_t >( severity );
2019-07-25 22:46:10 +10:00
m_value = amount;
2020-01-05 20:49:50 +09:00
m_flag = flag;
2019-07-25 22:46:10 +10:00
m_type = Common::ActionEffectType::Heal;
}
2020-01-05 20:49:50 +09:00
void EffectResult::restoreMP( uint32_t amount, Common::ActionEffectResultFlag flag )
2020-01-05 17:09:27 +09:00
{
m_value = amount;
2020-01-05 20:49:50 +09:00
m_flag = flag;
2020-01-05 17:09:27 +09:00
m_type = Common::ActionEffectType::MpGain;
}
void EffectResult::startCombo( uint16_t actionId )
{
m_value = actionId;
2020-01-05 20:49:50 +09:00
m_flag = Common::ActionEffectResultFlag::EffectOnSource;
2020-01-05 17:09:27 +09:00
m_type = Common::ActionEffectType::StartActionCombo;
}
2020-01-05 20:49:50 +09:00
void EffectResult::comboSucceed()
2020-01-05 17:09:27 +09:00
{
2020-01-05 20:49:50 +09:00
// no EffectOnSource flag on this
m_type = Common::ActionEffectType::ComboSucceed;
2020-01-05 17:09:27 +09:00
}
void EffectResult::applyStatusEffect( uint16_t statusId, uint32_t duration, uint16_t param, bool statusToSource )
2020-01-06 19:25:01 +09:00
{
m_value = statusId;
2023-03-07 05:12:18 +09:00
m_statusDuration = duration;
2020-01-08 17:21:01 +09:00
m_param2 = param;
m_flag = statusToSource ? Common::ActionEffectResultFlag::EffectOnSource : Common::ActionEffectResultFlag::None;
2020-01-06 19:25:01 +09:00
m_type = statusToSource ? Common::ActionEffectType::ApplyStatusEffectSource : Common::ActionEffectType::ApplyStatusEffectTarget;
2020-01-06 19:25:01 +09:00
}
void EffectResult::applyStatusEffect( StatusEffect::StatusEffectPtr pStatusEffect, bool statusToSource )
2023-03-07 05:12:18 +09:00
{
m_value = pStatusEffect->getId();
m_param2 = pStatusEffect->getParam();
m_pPreBuiltStatusEffect = std::move( pStatusEffect );
m_flag = statusToSource ? Common::ActionEffectResultFlag::EffectOnSource : Common::ActionEffectResultFlag::None;
2023-03-07 05:12:18 +09:00
m_type = statusToSource ? Common::ActionEffectType::ApplyStatusEffectSource : Common::ActionEffectType::ApplyStatusEffectTarget;
2023-03-07 05:12:18 +09:00
}
void EffectResult::statusNoEffect( uint16_t statusId )
{
m_value = statusId;
m_type = Common::ActionEffectType::StatusNoEffect;
}
2020-01-26 21:16:41 +11:00
void EffectResult::mount( uint16_t mountId )
2020-01-23 22:36:01 +09:00
{
2020-01-26 21:16:41 +11:00
m_value = mountId;
2020-01-23 22:36:01 +09:00
m_param0 = 1;
m_type = Common::ActionEffectType::Mount;
}
2023-03-07 05:12:18 +09:00
void Sapphire::World::Action::EffectResult::provoke()
{
m_type = Common::ActionEffectType::Provoke;
}
2019-07-25 22:46:10 +10:00
Common::EffectEntry EffectResult::buildEffectEntry() const
{
Common::EffectEntry entry{};
2020-05-16 02:46:51 +09:00
entry.effectType = m_type;
if( m_value > 0x0000FFFF )
{
entry.value = static_cast< uint16_t >( m_value & 0x0000FFFF );
entry.extendedValueHighestByte = static_cast< uint8_t >( m_value >> 16 );
entry.flags = static_cast< uint8_t >( m_flag ) + static_cast< uint8_t >( Common::ActionEffectResultFlag::ExtendedValue );
}
else
{
entry.value = static_cast< uint16_t >( m_value );
entry.flags = static_cast< uint8_t >( m_flag );
}
2020-01-08 17:21:01 +09:00
entry.param0 = m_param0;
entry.param1 = m_param1;
2023-03-07 05:12:18 +09:00
entry.param2 = static_cast< uint8_t >( m_param2 );
2019-07-25 22:46:10 +10:00
return entry;
}
void EffectResult::execute()
{
switch( m_type )
{
case Common::ActionEffectType::Damage:
2023-03-07 05:12:18 +09:00
case Common::ActionEffectType::BlockedDamage:
case Common::ActionEffectType::ParriedDamage:
{
m_target->takeDamage( m_value );
break;
}
case Common::ActionEffectType::Heal:
{
m_target->heal( m_value );
break;
}
2020-01-05 17:09:27 +09:00
case Common::ActionEffectType::MpGain:
{
m_target->restoreMP( m_value );
break;
}
2023-03-07 05:12:18 +09:00
case Common::ActionEffectType::ApplyStatusEffectTarget:
case Common::ActionEffectType::ApplyStatusEffectSource:
{
auto applyTarget = m_type == Common::ActionEffectType::ApplyStatusEffectTarget ? m_target : m_source;
2023-03-07 05:12:18 +09:00
//refreshing old buff
for( auto const& entry : applyTarget->getStatusEffectMap() )
2023-03-07 05:12:18 +09:00
{
auto statusEffect = entry.second;
if( statusEffect->getId() == m_value && statusEffect->getSrcActorId() == m_source->getId() )
{
if( m_pPreBuiltStatusEffect )
{
statusEffect->refresh( m_pPreBuiltStatusEffect->getEffectEntry() );
}
else
{
statusEffect->refresh();
}
applyTarget->sendStatusEffectUpdate();
2023-03-07 05:12:18 +09:00
return;
}
}
if( m_pPreBuiltStatusEffect )
{
applyTarget->addStatusEffect( m_pPreBuiltStatusEffect );
2023-03-07 05:12:18 +09:00
}
else
applyTarget->addStatusEffectById( m_value, m_statusDuration, *m_source, m_param2 );
2023-03-07 05:12:18 +09:00
break;
}
2020-01-23 22:36:01 +09:00
case Common::ActionEffectType::Mount:
{
auto pPlayer = m_target->getAsPlayer();
pPlayer->mount( m_value );
break;
}
default:
break;
}
2019-07-25 22:46:10 +10:00
}