1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-26 03:27:44 +00:00

move applyShieldProtection to chara

This commit is contained in:
collett 2020-01-13 03:48:42 +09:00
parent 0573138e1b
commit 685fd9c3bf
5 changed files with 48 additions and 48 deletions

View file

@ -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 );
}

View file

@ -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;
}

View file

@ -288,6 +288,8 @@ namespace Sapphire::Entity
Common::BaseParam getPrimaryStat() const;
float applyShieldProtection( float damage );
};
}

View file

@ -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;
}

View file

@ -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;