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

120 lines
2.2 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 ),
m_severity( Common::ActionHitSeverityType::NormalDamage ),
m_type( Common::ActionEffectType::Nothing ),
2020-01-05 17:09:27 +09:00
m_param( 0 ),
m_flag( 0 )
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;
}
void EffectResult::setParam( uint8_t param )
{
m_param = param;
}
2019-07-25 22:46:10 +10:00
void EffectResult::damage( uint32_t amount, Common::ActionHitSeverityType severity )
{
m_severity = severity;
m_value = amount;
m_type = Common::ActionEffectType::Damage;
}
2020-01-05 17:09:27 +09:00
void EffectResult::heal( uint32_t amount, Sapphire::Common::ActionHitSeverityType severity, bool isSelfHeal )
2019-07-25 22:46:10 +10:00
{
m_severity = severity;
m_value = amount;
2020-01-05 17:09:27 +09:00
m_flag = isSelfHeal ? 0x80 : 0; // flag == 0x80 displays healing text at source actor
2019-07-25 22:46:10 +10:00
m_type = Common::ActionEffectType::Heal;
}
2020-01-05 17:09:27 +09:00
void EffectResult::restoreMP( uint32_t amount )
{
m_value = amount;
m_flag = 0x80;
m_type = Common::ActionEffectType::MpGain;
}
void EffectResult::startCombo( uint16_t actionId )
{
m_value = actionId;
m_flag = 0x80;
m_type = Common::ActionEffectType::StartActionCombo;
}
void EffectResult::comboVisualEffect()
{
m_type = Common::ActionEffectType::ComboVisualEffect;
}
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();
entry.hitSeverity = m_severity;
entry.effectType = m_type;
entry.param = m_param;
2020-01-05 17:09:27 +09:00
entry.flags = 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
}