From 28456e7ac613ccb2542ced334064c1f97f737e74 Mon Sep 17 00:00:00 2001 From: Kooper16 <56591765+Kooper16@users.noreply.github.com> Date: Sat, 22 Jul 2023 00:04:37 +0200 Subject: [PATCH] Status automatically overwriten if by same source Added check for status application that checks if existing status is from the same source. If yes, always overwrite it because the same source can never apply 2 instances of the same status on the same target. --- src/world/Actor/Chara.cpp | 25 +++++++++++++++++++------ src/world/Actor/Chara.h | 4 +++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 2994cfce..2f7bbf8a 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -492,12 +492,12 @@ void Chara::addStatusEffect( StatusEffect::StatusEffectPtr pEffect ) auto& teriMgr = Common::Service< Manager::TerritoryMgr >::ref(); auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); - int8_t nextSlot = -1; - if( !pEffect->getCanApplyMultipleTimes() ) + int8_t nextSlot = getStatusEffectSlotWithIdAndSource( pEffect->getId(), pEffect->getSrcActorId() ); + if( nextSlot == -1 && !pEffect->getCanApplyMultipleTimes() ) { - nextSlot = getStatusEffectSlotWithId( pEffect->getId() ); + nextSlot = getStatusEffectSlotWithId( pEffect->getId()); } - if( nextSlot == -1 || pEffect->getCanApplyMultipleTimes() ) + if( nextSlot == -1) { nextSlot = getStatusEffectFreeSlot(); } @@ -526,11 +526,24 @@ void Chara::addStatusEffectByIdIfNotExist( StatusEffect::StatusEffectPtr pStatus addStatusEffect( pStatus ); } -int8_t Chara::getStatusEffectSlotWithId( uint8_t id ) +int8_t Chara::getStatusEffectSlotWithIdAndSource( uint8_t statusId, uint32_t sourceId ) { for( const auto& effectIt : m_statusEffectMap ) { - if( effectIt.second->getId() == id ) + if( effectIt.second->getId() == statusId && effectIt.second->getSrcActorId() == sourceId ) + { + return effectIt.first; + } + } + + return -1; +} + +int8_t Chara::getStatusEffectSlotWithId( uint8_t statusId ) +{ + for( const auto& effectIt : m_statusEffectMap ) + { + if( effectIt.second->getId() == statusId ) { return effectIt.first; } diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index f36a6702..a48f60f4 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -120,7 +120,9 @@ namespace Sapphire::Entity bool hasStatusEffect( uint32_t id ); - int8_t getStatusEffectSlotWithId( uint8_t id ); + int8_t getStatusEffectSlotWithIdAndSource( uint8_t statusId, uint32_t sourceId ); + + int8_t getStatusEffectSlotWithId( uint8_t statusId ); int8_t getStatusEffectFreeSlot();