From c8c66b00036152214bef4340d71ae0536d34d00d Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sat, 9 Feb 2019 17:36:44 +1100 Subject: [PATCH] damage/heal helpers for actions --- src/world/Action/Action.cpp | 67 +++++++++++++++++++++++++++++++++++++ src/world/Action/Action.h | 27 +++++++++++++-- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index db778334..46933161 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -179,3 +179,70 @@ void Sapphire::Action::Action::onFinish() pScriptMgr->onCastFinish( *pPlayer, m_pTarget, m_id ); } } + +void Sapphire::Action::Action::buildEffectPacket() +{ + for( int i = 0; i < EffectPacketIdentity::MAX_ACTION_EFFECT_PACKET_IDENT; ++i ) + { + auto& packetData = m_effects[ static_cast< EffectPacketIdentity >( i ) ]; + + // todo: this + } +} + +void Sapphire::Action::Action::damageTarget( uint32_t amount, Entity::Chara& chara, + Common::ActionAspect aspect ) +{ + Common::EffectEntry entry{}; + + // todo: handle cases where the action misses/is blocked? + entry.effectType = Common::ActionEffectType::Damage; + + // todo: handle crits + entry.hitSeverity = Common::ActionHitSeverityType::NormalDamage; + + // todo: handle > 65535 damage values, not sure if this is right? + if( amount > 65535 ) + { + entry.value = static_cast< int16_t >( amount / 10 ); + // todo: rename this? need to confirm how it works again + entry.bonusPercent = 1; + } + else + entry.value = static_cast< int16_t >( amount ); + + // todo: aspected damage? + chara.takeDamage( amount ); + + m_effects[ EffectPacketIdentity::DamageEffect ].m_entries.emplace_back( entry ); + + // todo: make sure that we don't add the same actor more than once + m_effects[ EffectPacketIdentity::DamageEffect ].m_hitActors.emplace_back( chara.getId() ); +} + +void Sapphire::Action::Action::healTarget( uint32_t amount, Entity::Chara& chara ) +{ + Common::EffectEntry entry{}; + + entry.effectType = Common::ActionEffectType::Heal; + + // todo: handle crits + entry.hitSeverity = Common::ActionHitSeverityType::NormalHeal; + + // todo: handle > 65535 healing values, not sure if this is right? + if( amount > 65535 ) + { + entry.value = static_cast< int16_t >( amount / 10 ); + // todo: rename this? need to confirm how it works again + entry.bonusPercent = 1; + } + else + entry.value = static_cast< int16_t >( amount ); + + chara.heal( amount ); + + m_effects[ EffectPacketIdentity::HealingEffect ].m_entries.emplace_back( entry ); + + // todo: make sure that we don't add the same actor more than once + m_effects[ EffectPacketIdentity::HealingEffect ].m_hitActors.emplace_back( chara.getId() ); +} diff --git a/src/world/Action/Action.h b/src/world/Action/Action.h index 558173c2..12c32684 100644 --- a/src/world/Action/Action.h +++ b/src/world/Action/Action.h @@ -45,6 +45,11 @@ namespace Sapphire::Action void start(); + void buildEffectPacket(); + + void damageTarget( uint32_t amount, Entity::Chara& chara, Common::ActionAspect aspect = Common::ActionAspect::Unaspected ); + void healTarget( uint32_t amount, Entity::Chara& chara ); + virtual void onStart(); virtual void onFinish(); virtual void onInterrupt(); @@ -53,8 +58,25 @@ namespace Sapphire::Action virtual bool update(); protected: - uint32_t m_id; + /*! + * @brief Some actions are capable of both healing and dealing damage. This identifies them. + */ + enum EffectPacketIdentity : uint8_t + { + DamageEffect, + HealingEffect, + + MAX_ACTION_EFFECT_PACKET_IDENT + }; + + struct EffectPacketData + { + std::vector< Common::EffectEntry > m_entries; + std::vector< uint32_t > m_hitActors; + }; + + uint32_t m_id; Common::HandleActionType m_type; uint64_t m_startTime; @@ -68,8 +90,7 @@ namespace Sapphire::Action FrameworkPtr m_pFw; - - + std::array< EffectPacketData, MAX_ACTION_EFFECT_PACKET_IDENT > m_effects; }; }