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

127 lines
2.5 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"
2019-07-25 22:46:10 +10:00
using namespace Sapphire;
using namespace Sapphire::World::Action;
EffectResult::EffectResult( Entity::CharaPtr target, uint64_t runAfter ) :
2019-07-25 22:46:10 +10:00
m_target( std::move( target ) ),
m_delayMs( runAfter ),
2019-07-25 22:46:10 +10:00
m_value( 0 ),
2020-01-08 17:21:01 +09:00
m_param0( 0 ),
m_param1( 0 ),
m_type( Common::ActionEffectType::Nothing ),
2020-01-08 17:21:01 +09:00
m_param2( 0 ),
2020-01-05 20:49:50 +09:00
m_flag( Common::ActionEffectResultFlag::None )
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;
}
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;
}
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
}
2020-01-06 19:25:01 +09:00
void EffectResult::applyStatusEffect( uint16_t statusId, uint8_t param )
{
m_value = statusId;
2020-01-08 17:21:01 +09:00
m_param2 = param;
2020-01-06 19:25:01 +09:00
m_type = Common::ActionEffectType::ApplyStatusEffect;
}
2019-07-25 22:46:10 +10:00
Common::EffectEntry EffectResult::buildEffectEntry() const
{
Common::EffectEntry entry{};
// todo: that retarded shit so > u16 max numbers work
entry.value = getValue();
2020-01-08 17:21:01 +09:00
entry.param0 = m_param0;
entry.param1 = m_param1;
2019-07-25 22:46:10 +10:00
entry.effectType = m_type;
2020-01-08 17:21:01 +09:00
entry.param2 = m_param2;
2020-01-05 20:49:50 +09:00
entry.flags = static_cast< uint8_t >( m_flag );
2019-07-25 22:46:10 +10:00
return entry;
}
void EffectResult::execute()
{
switch( m_type )
{
case Common::ActionEffectType::Damage:
{
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;
}
default:
break;
}
2019-07-25 22:46:10 +10:00
}