1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-30 08:07:46 +00:00

Remove statuseffects in the same tick if the expiry time is the same

This commit is contained in:
Lucy 2023-02-21 06:10:46 +01:00
parent 7b8cf18851
commit b1132d9ef3
2 changed files with 12 additions and 13 deletions

View file

@ -602,11 +602,11 @@ void Sapphire::Entity::Chara::removeSingleStatusEffectById( uint32_t id )
} }
} }
void Sapphire::Entity::Chara::removeStatusEffect( uint8_t effectSlotId ) std::map< uint8_t, Sapphire::StatusEffect::StatusEffectPtr >::iterator Sapphire::Entity::Chara::removeStatusEffect( uint8_t effectSlotId )
{ {
auto pEffectIt = m_statusEffectMap.find( effectSlotId ); auto pEffectIt = m_statusEffectMap.find( effectSlotId );
if( pEffectIt == m_statusEffectMap.end() ) if( pEffectIt == m_statusEffectMap.end() )
return; return pEffectIt;
statusEffectFreeSlot( effectSlotId ); statusEffectFreeSlot( effectSlotId );
@ -615,12 +615,14 @@ void Sapphire::Entity::Chara::removeStatusEffect( uint8_t effectSlotId )
server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeActorControl( getId(), StatusEffectLose, pEffect->getId() ) ); server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeActorControl( getId(), StatusEffectLose, pEffect->getId() ) );
m_statusEffectMap.erase( effectSlotId ); auto it = m_statusEffectMap.erase( pEffectIt );
if( isPlayer() ) if( isPlayer() )
server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeHudParam( *getAsPlayer() ) ); server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeHudParam( *getAsPlayer() ) );
else if( isBattleNpc() ) else if( isBattleNpc() )
server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeHudParam( *getAsBNpc() ) ); server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeHudParam( *getAsBNpc() ) );
return it;
} }
std::map< uint8_t, Sapphire::StatusEffect::StatusEffectPtr > Sapphire::Entity::Chara::getStatusEffectMap() const std::map< uint8_t, Sapphire::StatusEffect::StatusEffectPtr > Sapphire::Entity::Chara::getStatusEffectMap() const
@ -672,10 +674,10 @@ void Sapphire::Entity::Chara::updateStatusEffects()
{ {
uint64_t currentTimeMs = Util::getTimeMs(); uint64_t currentTimeMs = Util::getTimeMs();
for( const auto& effectIt : m_statusEffectMap ) for( auto effectIt = m_statusEffectMap.begin(); effectIt != m_statusEffectMap.end(); )
{ {
uint8_t effectIndex = effectIt.first; uint8_t effectIndex = effectIt->first;
auto effect = effectIt.second; auto effect = effectIt->second;
uint64_t lastTick = effect->getLastTickMs(); uint64_t lastTick = effect->getLastTickMs();
uint64_t startTime = effect->getStartTimeMs(); uint64_t startTime = effect->getStartTimeMs();
@ -683,12 +685,9 @@ void Sapphire::Entity::Chara::updateStatusEffects()
uint32_t tickRate = effect->getTickRate(); uint32_t tickRate = effect->getTickRate();
if( duration > 0 && ( currentTimeMs - startTime ) > duration ) if( duration > 0 && ( currentTimeMs - startTime ) > duration )
{ effectIt = removeStatusEffect( effectIndex );
// remove status effect else
removeStatusEffect( effectIndex ); ++effectIt;
// break because removing invalidates iterators
break;
}
if( ( currentTimeMs - lastTick ) > tickRate ) if( ( currentTimeMs - lastTick ) > tickRate )
{ {

View file

@ -110,7 +110,7 @@ namespace Sapphire::Entity
/// Status effect functions /// Status effect functions
void addStatusEffect( StatusEffect::StatusEffectPtr pEffect ); void addStatusEffect( StatusEffect::StatusEffectPtr pEffect );
void removeStatusEffect( uint8_t effectSlotId ); std::map< uint8_t, StatusEffect::StatusEffectPtr >::iterator removeStatusEffect( uint8_t effectSlotId );
void removeSingleStatusEffectById( uint32_t id ); void removeSingleStatusEffectById( uint32_t id );