1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-21 17:47:45 +00:00

Automatic status reapplication

Status will be reapplied if "canApplyMultipleTimes" is false. Otherwise the status will be applied as a new status.
This commit is contained in:
Kooper16 2023-07-21 22:55:47 +02:00
parent d1c7b97d9e
commit 6361e4e52e
3 changed files with 27 additions and 1 deletions

View file

@ -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 );
}

View file

@ -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;

View file

@ -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 );