From b1132d9ef3872542616ea971b37052e1c1636cb1 Mon Sep 17 00:00:00 2001 From: Lucy <44952533+Skyliegirl33@users.noreply.github.com> Date: Tue, 21 Feb 2023 06:10:46 +0100 Subject: [PATCH] Remove statuseffects in the same tick if the expiry time is the same --- src/world/Actor/Chara.cpp | 23 +++++++++++------------ src/world/Actor/Chara.h | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index ebe2581f..f28ea986 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -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 ); if( pEffectIt == m_statusEffectMap.end() ) - return; + return pEffectIt; statusEffectFreeSlot( effectSlotId ); @@ -615,12 +615,14 @@ void Sapphire::Entity::Chara::removeStatusEffect( uint8_t effectSlotId ) server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeActorControl( getId(), StatusEffectLose, pEffect->getId() ) ); - m_statusEffectMap.erase( effectSlotId ); + auto it = m_statusEffectMap.erase( pEffectIt ); if( isPlayer() ) server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeHudParam( *getAsPlayer() ) ); else if( isBattleNpc() ) server().queueForPlayers( getInRangePlayerIds( isPlayer() ), makeHudParam( *getAsBNpc() ) ); + + return it; } 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(); - for( const auto& effectIt : m_statusEffectMap ) + for( auto effectIt = m_statusEffectMap.begin(); effectIt != m_statusEffectMap.end(); ) { - uint8_t effectIndex = effectIt.first; - auto effect = effectIt.second; + uint8_t effectIndex = effectIt->first; + auto effect = effectIt->second; uint64_t lastTick = effect->getLastTickMs(); uint64_t startTime = effect->getStartTimeMs(); @@ -683,12 +685,9 @@ void Sapphire::Entity::Chara::updateStatusEffects() uint32_t tickRate = effect->getTickRate(); if( duration > 0 && ( currentTimeMs - startTime ) > duration ) - { - // remove status effect - removeStatusEffect( effectIndex ); - // break because removing invalidates iterators - break; - } + effectIt = removeStatusEffect( effectIndex ); + else + ++effectIt; if( ( currentTimeMs - lastTick ) > tickRate ) { diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index b2f80dc9..e9a49126 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -110,7 +110,7 @@ namespace Sapphire::Entity /// Status effect functions 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 );