From 685fd9c3bf16522049e79e5bfb7a6fdc5820570b Mon Sep 17 00:00:00 2001 From: collett Date: Mon, 13 Jan 2020 03:48:42 +0900 Subject: [PATCH] move applyShieldProtection to chara --- src/world/Action/Action.cpp | 2 +- src/world/Actor/Chara.cpp | 45 ++++++++++++++++++++++++++++++++++++ src/world/Actor/Chara.h | 2 ++ src/world/Math/CalcStats.cpp | 45 ------------------------------------ src/world/Math/CalcStats.h | 2 -- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index aa39048a..99aa456a 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -469,7 +469,7 @@ void Action::Action::buildEffects() if( dmg.first > 0 ) { actor->onActionHostile( m_pSource ); - dmg.first = Math::CalcStats::applyShieldProtection( actor, dmg.first ); + dmg.first = actor->applyShieldProtection( dmg.first ); m_effectBuilder->damage( actor, actor, dmg.first, dmg.second, dmg.first == 0 ? Common::ActionEffectResultFlag::Absorbed : Common::ActionEffectResultFlag::None ); } diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 06cf3f4c..ffe0cf72 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -980,3 +980,48 @@ uint32_t Sapphire::Entity::Chara::getStatValue( Sapphire::Common::BaseParam base return value + getBonusStat( baseParam ); } + +float Sapphire::Entity::Chara::applyShieldProtection( float damage ) +{ + float remainingDamage = damage; + bool shieldChanged = false; + std::vector< uint8_t > destroyedShieldSlotList; + + for( auto const& entry : getStatusEffectMap() ) + { + auto status = entry.second; + auto effectEntry = status->getEffectEntry(); + + if( static_cast< Sapphire::Common::StatusEffectType >( effectEntry.effectType ) == Sapphire::Common::StatusEffectType::Shield ) + { + shieldChanged = true; + if( remainingDamage < effectEntry.effectValue1 ) + { + effectEntry.effectValue1 -= static_cast< int32_t >( remainingDamage ); + status->replaceEffectEntry( effectEntry ); + remainingDamage = 0; + break; + } + else + { + remainingDamage -= effectEntry.effectValue1; + destroyedShieldSlotList.push_back( entry.first ); + } + } + } + + if( shieldChanged ) + { + if( !destroyedShieldSlotList.empty() ) + { + for( auto const& slotId : destroyedShieldSlotList ) + { + removeStatusEffect( slotId, true, false ); + } + sendStatusEffectUpdate(); + } + else + sendEffectResultToUpdateShieldValue(); // yes this is the packet to update shield value + } + return remainingDamage; +} \ No newline at end of file diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index 2f97844b..62476df7 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -288,6 +288,8 @@ namespace Sapphire::Entity Common::BaseParam getPrimaryStat() const; + float applyShieldProtection( float damage ); + }; } diff --git a/src/world/Math/CalcStats.cpp b/src/world/Math/CalcStats.cpp index adf3f41a..1a87ce08 100644 --- a/src/world/Math/CalcStats.cpp +++ b/src/world/Math/CalcStats.cpp @@ -754,49 +754,4 @@ float CalcStats::calcAbsorbHP( Sapphire::Entity::CharaPtr pChara, float damage, } } return result; -} - -float CalcStats::applyShieldProtection( Sapphire::Entity::CharaPtr pChara, float damage ) -{ - float remainingDamage = damage; - bool shieldChanged = false; - std::vector< uint8_t > destroyedShieldSlotList; - - for( auto const& entry : pChara->getStatusEffectMap() ) - { - auto status = entry.second; - auto effectEntry = status->getEffectEntry(); - - if( static_cast< Common::StatusEffectType >( effectEntry.effectType ) == Common::StatusEffectType::Shield ) - { - shieldChanged = true; - if( remainingDamage < effectEntry.effectValue1 ) - { - effectEntry.effectValue1 -= static_cast< int32_t >( remainingDamage ); - status->replaceEffectEntry( effectEntry ); - remainingDamage = 0; - break; - } - else - { - remainingDamage -= effectEntry.effectValue1; - destroyedShieldSlotList.push_back( entry.first ); - } - } - } - - if( shieldChanged ) - { - if( !destroyedShieldSlotList.empty() ) - { - for( auto const& slotId : destroyedShieldSlotList ) - { - pChara->removeStatusEffect( slotId, true, false ); - } - pChara->sendStatusEffectUpdate(); - } - else - pChara->sendEffectResultToUpdateShieldValue(); // yes this is the packet to update shield value - } - return remainingDamage; } \ No newline at end of file diff --git a/src/world/Math/CalcStats.h b/src/world/Math/CalcStats.h index b97658a9..7d82fed9 100644 --- a/src/world/Math/CalcStats.h +++ b/src/world/Math/CalcStats.h @@ -148,8 +148,6 @@ namespace Sapphire::Math static float calcAbsorbHP( Sapphire::Entity::CharaPtr pChara, float damage, Sapphire::Common::ActionTypeFilter filter ); - static float applyShieldProtection( Sapphire::Entity::CharaPtr pChara, float damage ); - static std::random_device dev; static std::mt19937 rng; static std::uniform_int_distribution< std::mt19937::result_type > range100;