1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

Implemented onTriggerOwnerDeaggro for handling forced spawn mobs

This commit is contained in:
Mordred 2022-01-24 11:06:34 +01:00
parent 198e641420
commit 8a55a8b42c
5 changed files with 48 additions and 1 deletions

View file

@ -39,6 +39,7 @@
#include <Manager/RNGMgr.h>
#include <Manager/PlayerMgr.h>
#include <Manager/TaskMgr.h>
#include <Script/ScriptMgr.h>
#include <Task/RemoveBNpcTask.h>
#include <Task/FadeBNpcTask.h>
#include <Task/DelayedEmnityTask.h>
@ -574,6 +575,13 @@ void Sapphire::Entity::BNpc::deaggro( const Sapphire::Entity::CharaPtr& pChara )
sendToInRangeSet( makeActorControl( getId(), ActorControlType::ToggleWeapon, 0, 1, 1 ) );
sendToInRangeSet( makeActorControl( getId(), ActorControlType::SetBattle, 0, 0, 0 ) );
tmpPlayer->onMobDeaggro( *this );
if( getTriggerOwnerId() == pChara->getId() )
{
auto pScript = std::make_shared< Scripting::ScriptMgr >();
pScript->onTriggerOwnerDeaggro( *pChara->getAsPlayer(), getLayoutId(), getId() );
}
}
}

View file

@ -150,6 +150,10 @@ namespace Sapphire::ScriptAPI
{
}
void QuestScript::onTriggerOwnerDeaggro( World::Quest& quest, uint32_t layoutId, uint32_t entityId, Sapphire::Entity::Player& player )
{
}
void QuestScript::onEmote( World::Quest& quest, uint64_t actorId, uint32_t emoteId, Entity::Player& player )
{
}

View file

@ -220,6 +220,8 @@ namespace Sapphire::ScriptAPI
virtual void onBNpcKill( World::Quest& quest, uint16_t nameId, uint32_t entityId, Sapphire::Entity::Player& player );
virtual void onTriggerOwnerDeaggro( World::Quest& quest, uint32_t layoutId, uint32_t entityId, Sapphire::Entity::Player& player );
virtual void onEmote( World::Quest& quest, uint64_t actorId, uint32_t emoteId, Sapphire::Entity::Player& player );
virtual void onEnterTerritory( World::Quest& quest, Sapphire::Entity::Player& player, uint16_t param1, uint16_t param2 );

View file

@ -410,6 +410,37 @@ bool Sapphire::Scripting::ScriptMgr::onEventItem( Entity::Player& player, uint32
return false;
}
bool Sapphire::Scripting::ScriptMgr::onTriggerOwnerDeaggro( Entity::Player& player, uint32_t layoutId, uint32_t entityId )
{
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
// loop through all active quests and try to call available onBNpcKill callbacks
for( size_t i = 0; i < 30; i++ )
{
auto quest = player.getQuestByIndex( static_cast< uint16_t >( i ) );
if( quest.getId() == 0 )
continue;
uint32_t questId = quest.getId() | Event::EventHandler::EventHandlerType::Quest << 16;
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestScript >( questId );
if( script )
{
std::string objName = eventMgr.getEventName( questId );
PlayerMgr::sendDebug( player, "Calling: {0}.onTriggerOwnerDeaggro layoutId#{1}", objName, layoutId );
World::Quest preQ = quest;
script->onTriggerOwnerDeaggro( quest, layoutId, entityId, player );
if( quest != preQ )
player.updateQuest( quest );
}
}
return true;
}
bool Sapphire::Scripting::ScriptMgr::onBNpcKill( Entity::Player& player, uint16_t nameId, uint32_t layoutId )
{
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();

View file

@ -66,7 +66,9 @@ namespace Sapphire::Scripting
bool onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint64_t targetId );
bool onBNpcKill( Entity::Player& player, uint16_t nameId, uint32_t lyoutId );
bool onBNpcKill( Entity::Player& player, uint16_t nameId, uint32_t layoutId );
bool onTriggerOwnerDeaggro( Entity::Player& player, uint32_t layoutId, uint32_t entityId );
bool onEObjHit( Entity::Player& player, uint64_t actorId, uint32_t actionId );