diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index a9cfc049..1c04247b 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -524,7 +524,7 @@ void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network:: auto pe4 = std::make_shared< FFXIVRawPacket >( 0x08, 0x18, 0, 0 ); *reinterpret_cast< unsigned int* >( &pe4->data()[ 0 ] ) = id; - *reinterpret_cast< unsigned int* >( &pe4->data()[ 4 ] ) = timeStamp; + *reinterpret_cast< unsigned int* >( &pe4->data()[ 4 ] ) = Util::getTimeSeconds(); sendSinglePacket( pe4 ); break; diff --git a/src/world/Script/NativeScriptApi.cpp b/src/world/Script/NativeScriptApi.cpp index 4fd16292..8cfeab68 100644 --- a/src/world/Script/NativeScriptApi.cpp +++ b/src/world/Script/NativeScriptApi.cpp @@ -158,11 +158,11 @@ namespace Sapphire::ScriptAPI { } - void QuestScript::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) + void QuestScript::onWithinRange( World::Quest& quest, Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) { } - void QuestScript::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) + void QuestScript::onOutsideRange( World::Quest& quest, Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) { } diff --git a/src/world/Script/NativeScriptApi.h b/src/world/Script/NativeScriptApi.h index b229801a..9bf38233 100644 --- a/src/world/Script/NativeScriptApi.h +++ b/src/world/Script/NativeScriptApi.h @@ -223,9 +223,9 @@ namespace Sapphire::ScriptAPI virtual void onEnterTerritory( World::Quest& quest, Sapphire::Entity::Player& player, uint16_t param1, uint16_t param2 ); - virtual void onWithinRange( Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); + virtual void onWithinRange( World::Quest& quest, Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); - virtual void onOutsideRange( Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); + virtual void onOutsideRange( World::Quest& quest, Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); virtual void onEventHandlerTradeReturn( Sapphire::Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, uint32_t catalogId ); diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index e133a6aa..189d6262 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -264,19 +264,63 @@ bool Sapphire::Scripting::ScriptMgr::onEnterTerritory( Entity::Player& player, u bool Sapphire::Scripting::ScriptMgr::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) { - auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventScript >( eventId ); - if( !script ) - return false; - script->onWithinRange( player, eventId, param1, x, y, z ); + const auto eventType = static_cast< uint16_t >( eventId >> 16 ); + auto& pEventMgr = Common::Service< World::Manager::EventMgr >::ref(); + + if( eventType == Event::EventHandler::EventHandlerType::Quest ) + { + auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestScript >( eventId ); + if( !script ) + return false; + if( player.hasQuest( eventId ) ) + { + auto idx = player.getQuestIndex( eventId ); + auto& quest = player.getQuestByIndex( idx ); + World::Quest preQ = quest; + script->onWithinRange( quest, player, eventId, param1, x, y, z ); + if( quest != preQ ) + player.updateQuest( quest ); + } + } + else + { + auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventScript >( eventId ); + if( !script ) + return false; + script->onWithinRange( player, eventId, param1, x, y, z ); + } + return true; } bool Sapphire::Scripting::ScriptMgr::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) { - auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventScript >( eventId ); - if( !script ) - return false; - script->onOutsideRange( player, eventId, param1, x, y, z ); + const auto eventType = static_cast< uint16_t >( eventId >> 16 ); + auto& pEventMgr = Common::Service< World::Manager::EventMgr >::ref(); + + if( eventType == Event::EventHandler::EventHandlerType::Quest ) + { + auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestScript >( eventId ); + if( !script ) + return false; + if( player.hasQuest( eventId ) ) + { + auto idx = player.getQuestIndex( eventId ); + auto& quest = player.getQuestByIndex( idx ); + World::Quest preQ = quest; + script->onOutsideRange( quest, player, eventId, param1, x, y, z ); + if( quest != preQ ) + player.updateQuest( quest ); + } + } + else + { + auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventScript >( eventId ); + if( !script ) + return false; + script->onOutsideRange( player, eventId, param1, x, y, z ); + } + return true; } @@ -295,7 +339,10 @@ bool Sapphire::Scripting::ScriptMgr::onEmote( Entity::Player& player, uint64_t a { auto idx = player.getQuestIndex( eventId ); auto& quest = player.getQuestByIndex( idx ); + World::Quest preQ = quest; script->onEmote( quest, actor, emoteId, player ); + if( quest != preQ ) + player.updateQuest( quest ); } } else