diff --git a/bin/scripts/chai/skill/skillDef_121.chai b/bin/scripts/chai/skill/skillDef_121.chai index 1fb31f67..56286409 100644 --- a/bin/scripts/chai/skill/skillDef_121.chai +++ b/bin/scripts/chai/skill/skillDef_121.chai @@ -10,7 +10,7 @@ class skillDef_121Def def onFinish( player, target ) { - target.addStatusEffectById(143, 20000, 0); + target.addStatusEffectByIdIfNotExist(143, 20000, 0); } }; diff --git a/src/servers/Server_Zone/Actor.cpp b/src/servers/Server_Zone/Actor.cpp index 9016ab41..efcf3d6e 100644 --- a/src/servers/Server_Zone/Actor.cpp +++ b/src/servers/Server_Zone/Actor.cpp @@ -631,3 +631,14 @@ void Core::Entity::Actor::addStatusEffectById( int32_t id, int32_t duration, uin addStatusEffect( effect ); } +/*! \param StatusEffectPtr to be applied to the actor */ +void Core::Entity::Actor::addStatusEffectByIdIfNotExist( int32_t id, int32_t duration, uint16_t param ) +{ + if( !m_pStatusEffectContainer->hasStatusEffect( id ) ) + { + StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, shared_from_this(), shared_from_this(), duration, 3000 ) ); + effect->setParam( param ); + addStatusEffect( effect ); + } +} + diff --git a/src/servers/Server_Zone/Actor.h b/src/servers/Server_Zone/Actor.h index 8cab76b7..6c7d1df9 100644 --- a/src/servers/Server_Zone/Actor.h +++ b/src/servers/Server_Zone/Actor.h @@ -293,6 +293,9 @@ public: // add a status effect by id void addStatusEffectById( int32_t id, int32_t duration, uint16_t param = 0 ); + // add a status effect by id if it doesn't exist + void addStatusEffectByIdIfNotExist( int32_t id, int32_t duration, uint16_t param = 0 ); + // TODO: Why did i even declare them publicly here?! std::set< ActorPtr > m_inRangeActors; std::set< PlayerPtr > m_inRangePlayers; diff --git a/src/servers/Server_Zone/ScriptManagerInit.cpp b/src/servers/Server_Zone/ScriptManagerInit.cpp index 4a125ce0..ca374640 100644 --- a/src/servers/Server_Zone/ScriptManagerInit.cpp +++ b/src/servers/Server_Zone/ScriptManagerInit.cpp @@ -35,6 +35,7 @@ int Core::Scripting::ScriptManager::init() m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getTargetId ), "getTargetId" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffect ), "addStatusEffect" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectById ), "addStatusEffectById" ); + m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectByIdIfNotExist ), "addStatusEffectByIdIfNotExist" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::takeDamage ), "takeDamage" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::forceZoneing ), "setZone" ); diff --git a/src/servers/Server_Zone/StatusEffectContainer.cpp b/src/servers/Server_Zone/StatusEffectContainer.cpp index 85a9a392..5ecdfbe1 100644 --- a/src/servers/Server_Zone/StatusEffectContainer.cpp +++ b/src/servers/Server_Zone/StatusEffectContainer.cpp @@ -185,3 +185,16 @@ void Core::StatusEffect::StatusEffectContainer::update() m_pOwner->sendToInRangeSet( ActorControlPacket142( m_pOwner->getId(), HPFloatingText, 0, 4, thisTickHeal ) ); } } + +bool Core::StatusEffect::StatusEffectContainer::hasStatusEffect( uint32_t id ) +{ + for( auto effectIt : m_effectMap ) + { + if( effectIt.second->getId() == id ) + { + return true; + } + } + + return false; +} \ No newline at end of file diff --git a/src/servers/Server_Zone/StatusEffectContainer.h b/src/servers/Server_Zone/StatusEffectContainer.h index 6f4acb9c..824becc9 100644 --- a/src/servers/Server_Zone/StatusEffectContainer.h +++ b/src/servers/Server_Zone/StatusEffectContainer.h @@ -23,6 +23,8 @@ public: void removeStatusEffect( uint8_t effectSlotId ); void update(); + bool hasStatusEffect( uint32_t id ); + int8_t getFreeSlot(); void freeSlot( uint8_t slotId );