From 6361e4e52e93e1d60d47eae66f2266f936936353 Mon Sep 17 00:00:00 2001 From: Kooper16 <56591765+Kooper16@users.noreply.github.com> Date: Fri, 21 Jul 2023 22:55:47 +0200 Subject: [PATCH] Automatic status reapplication Status will be reapplied if "canApplyMultipleTimes" is false. Otherwise the status will be applied as a new status. --- src/world/Action/ActionLutData.h | 2 ++ src/world/Actor/Chara.cpp | 24 +++++++++++++++++++++++- src/world/Actor/Chara.h | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/world/Action/ActionLutData.h b/src/world/Action/ActionLutData.h index 22cf62bf..9b9dad8f 100644 --- a/src/world/Action/ActionLutData.h +++ b/src/world/Action/ActionLutData.h @@ -35,6 +35,8 @@ namespace Sapphire::World::Action j.at( "duration" ).get_to( statusEntry.duration ); if( j.contains( "flag" ) ) j.at( "flag" ).get_to( statusEntry.flag ); + if( j.contains( "canApplyMultipleTimes" ) ) + j.at( "canApplyMultipleTimes" ).get_to( statusEntry.canApplyMultipleTimes ); if( j.contains( "modifiers" ) ) j.at( "modifiers" ).get_to( statusEntry.modifiers ); } diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 07194934..2994cfce 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -492,7 +492,16 @@ void Chara::addStatusEffect( StatusEffect::StatusEffectPtr pEffect ) auto& teriMgr = Common::Service< Manager::TerritoryMgr >::ref(); auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); - int8_t nextSlot = getStatusEffectFreeSlot(); + int8_t nextSlot = -1; + if( !pEffect->getCanApplyMultipleTimes() ) + { + nextSlot = getStatusEffectSlotWithId( pEffect->getId() ); + } + if( nextSlot == -1 || pEffect->getCanApplyMultipleTimes() ) + { + nextSlot = getStatusEffectFreeSlot(); + } + // if there is no slot left, do not add the effect if( nextSlot == -1 ) return; @@ -517,6 +526,19 @@ void Chara::addStatusEffectByIdIfNotExist( StatusEffect::StatusEffectPtr pStatus addStatusEffect( pStatus ); } +int8_t Chara::getStatusEffectSlotWithId( uint8_t id ) +{ + for( const auto& effectIt : m_statusEffectMap ) + { + if( effectIt.second->getId() == id ) + { + return effectIt.first; + } + } + + return -1; +} + int8_t Chara::getStatusEffectFreeSlot() { int8_t freeEffectSlot = -1; diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index 722f4af3..f36a6702 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -120,6 +120,8 @@ namespace Sapphire::Entity bool hasStatusEffect( uint32_t id ); + int8_t getStatusEffectSlotWithId( uint8_t id ); + int8_t getStatusEffectFreeSlot(); void statusEffectFreeSlot( uint8_t slotId );