mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-28 20:27:46 +00:00
move applyShieldProtection to chara
This commit is contained in:
parent
0573138e1b
commit
685fd9c3bf
5 changed files with 48 additions and 48 deletions
|
@ -469,7 +469,7 @@ void Action::Action::buildEffects()
|
||||||
if( dmg.first > 0 )
|
if( dmg.first > 0 )
|
||||||
{
|
{
|
||||||
actor->onActionHostile( m_pSource );
|
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 );
|
m_effectBuilder->damage( actor, actor, dmg.first, dmg.second, dmg.first == 0 ? Common::ActionEffectResultFlag::Absorbed : Common::ActionEffectResultFlag::None );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -980,3 +980,48 @@ uint32_t Sapphire::Entity::Chara::getStatValue( Sapphire::Common::BaseParam base
|
||||||
|
|
||||||
return value + getBonusStat( baseParam );
|
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;
|
||||||
|
}
|
|
@ -288,6 +288,8 @@ namespace Sapphire::Entity
|
||||||
|
|
||||||
Common::BaseParam getPrimaryStat() const;
|
Common::BaseParam getPrimaryStat() const;
|
||||||
|
|
||||||
|
float applyShieldProtection( float damage );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -755,48 +755,3 @@ float CalcStats::calcAbsorbHP( Sapphire::Entity::CharaPtr pChara, float damage,
|
||||||
}
|
}
|
||||||
return result;
|
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;
|
|
||||||
}
|
|
|
@ -148,8 +148,6 @@ namespace Sapphire::Math
|
||||||
|
|
||||||
static float calcAbsorbHP( Sapphire::Entity::CharaPtr pChara, float damage, Sapphire::Common::ActionTypeFilter filter );
|
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::random_device dev;
|
||||||
static std::mt19937 rng;
|
static std::mt19937 rng;
|
||||||
static std::uniform_int_distribution< std::mt19937::result_type > range100;
|
static std::uniform_int_distribution< std::mt19937::result_type > range100;
|
||||||
|
|
Loading…
Add table
Reference in a new issue