diff --git a/src/scripts/instances/questbattles/ChasingShadows.cpp b/src/scripts/instances/questbattles/ChasingShadows.cpp index 01324df4..91fe7d9c 100644 --- a/src/scripts/instances/questbattles/ChasingShadows.cpp +++ b/src/scripts/instances/questbattles/ChasingShadows.cpp @@ -52,6 +52,12 @@ public: } + void onDutyComplete( QuestBattle& instance, Entity::Player& player ) override + { + player.updateQuest( instance.getQuestId(), 2 ); + player.exitInstance(); + } + }; EXPOSE_SCRIPT( ChasingShadows ); \ No newline at end of file diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 77b7dd0c..b37943b7 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -2102,3 +2102,8 @@ void Sapphire::Entity::Player::updateHuntingLog( uint16_t id ) sendHuntingLog(); } +Sapphire::World::SessionPtr Sapphire::Entity::Player::getSession() +{ + return m_pSession; +} + diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 314c055e..b7becacb 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -972,6 +972,8 @@ namespace Sapphire::Entity void updateHuntingLog( uint16_t id ); + World::SessionPtr getSession(); + ////////////////////////////////////////////////////////////////////////////////////////////////////// uint64_t m_lastMoveTime; @@ -982,6 +984,8 @@ namespace Sapphire::Entity uint32_t m_lastWrite; uint32_t m_lastPing; + World::SessionPtr m_pSession; + bool m_bIsLogin; uint64_t m_contentId; // This id will be the name of the folder for character settings in "My Games" diff --git a/src/world/Actor/PlayerSql.cpp b/src/world/Actor/PlayerSql.cpp index 1fe30904..784c970b 100644 --- a/src/world/Actor/PlayerSql.cpp +++ b/src/world/Actor/PlayerSql.cpp @@ -31,6 +31,7 @@ bool Sapphire::Entity::Player::load( uint32_t charId, World::SessionPtr pSession { auto pDb = m_pFw->get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pTeriMgr = m_pFw->get< TerritoryMgr >(); + m_pSession = pSession; const std::string char_id_str = std::to_string( charId ); diff --git a/src/world/Manager/DebugCommandMgr.cpp b/src/world/Manager/DebugCommandMgr.cpp index 27000355..c4ac0789 100644 --- a/src/world/Manager/DebugCommandMgr.cpp +++ b/src/world/Manager/DebugCommandMgr.cpp @@ -1030,6 +1030,26 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: else player.sendDebug( "Failed to create instance with id#{0}", contentFinderConditionId ); } + else if( subCommand == "complete" ) + { + + auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentZone() ); + if( !instance ) + return; + + instance->success(); + + } + else if( subCommand == "fail" ) + { + + auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentZone() ); + if( !instance ) + return; + + instance->fail(); + + } else if( subCommand == "createzone" || subCommand == "crz" ) { uint32_t zoneId; diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index 103051f5..1f16ae03 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -222,6 +222,7 @@ void Sapphire::Network::GameConnection::handleZonePacket( Sapphire::Network::Pac else { Logger::debug( "[{0}] Undefined Zone IPC : Unknown ( {1:04X} )", m_pSession->getId(), opcode ); + Logger::debug( "Dump:\n{0}", Util::binaryToHexDump( const_cast< uint8_t* >( &pPacket.data[ 0 ] ), pPacket.segHdr.size ) ); } diff --git a/src/world/Script/NativeScriptApi.cpp b/src/world/Script/NativeScriptApi.cpp index 33fcfb60..661a1923 100644 --- a/src/world/Script/NativeScriptApi.cpp +++ b/src/world/Script/NativeScriptApi.cpp @@ -201,6 +201,11 @@ namespace Sapphire::ScriptAPI { } + void QuestBattleScript::onDutyComplete( Sapphire::QuestBattle& instance, Entity::Player& player ) + { + + } + void QuestBattleScript::onPlayerSetup( Sapphire::QuestBattle& instance, Entity::Player& player ) { } diff --git a/src/world/Script/NativeScriptApi.h b/src/world/Script/NativeScriptApi.h index 073a5d63..7a2f5ba5 100644 --- a/src/world/Script/NativeScriptApi.h +++ b/src/world/Script/NativeScriptApi.h @@ -239,6 +239,8 @@ namespace Sapphire::ScriptAPI public: explicit QuestBattleScript( uint32_t questBattleId ); + virtual void onDutyComplete( Sapphire::QuestBattle& instance, Entity::Player& player ); + virtual void onPlayerSetup( Sapphire::QuestBattle& instance, Entity::Player& player ); virtual void onInit( Sapphire::QuestBattle& instance ); diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index 260f196a..e6e71352 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -516,3 +516,16 @@ Sapphire::Scripting::NativeScriptMgr& Sapphire::Scripting::ScriptMgr::getNativeS { return *m_nativeScriptMgr; } + +bool +Sapphire::Scripting::ScriptMgr::onDutyComplete( Sapphire::QuestBattlePtr instance, Sapphire::Entity::Player& player ) +{ + auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestBattleScript >( instance->getDirectorId() ); + if( script ) + { + script->onDutyComplete( *instance, player ); + return true; + } + + return false; +} diff --git a/src/world/Script/ScriptMgr.h b/src/world/Script/ScriptMgr.h index ce05c052..e333a39f 100644 --- a/src/world/Script/ScriptMgr.h +++ b/src/world/Script/ScriptMgr.h @@ -109,6 +109,8 @@ namespace Sapphire::Scripting bool onInstanceEnterTerritory( QuestBattlePtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ); + bool onDutyComplete( QuestBattlePtr instance, Entity::Player& player ); + bool loadDir( const std::string& dirname, std::set< std::string >& files, const std::string& ext ); NativeScriptMgr& getNativeScriptHandler(); diff --git a/src/world/Territory/Cell.cpp b/src/world/Territory/Cell.cpp index 2ac8da95..d4ea8bf0 100644 --- a/src/world/Territory/Cell.cpp +++ b/src/world/Territory/Cell.cpp @@ -39,7 +39,7 @@ void Sapphire::Cell::addActor( Entity::ActorPtr pAct ) m_actors.insert( pAct ); } -void Sapphire::Cell::removeActor( Entity::ActorPtr pAct ) +void Sapphire::Cell::removeActorFromCell( Entity::ActorPtr pAct ) { if( pAct->isPlayer() ) --m_playerCount; diff --git a/src/world/Territory/Cell.h b/src/world/Territory/Cell.h index f414451a..c1cf413d 100644 --- a/src/world/Territory/Cell.h +++ b/src/world/Territory/Cell.h @@ -36,7 +36,7 @@ public: void addActor( Entity::ActorPtr pAct ); - void removeActor( Entity::ActorPtr pAct ); + void removeActorFromCell( Entity::ActorPtr pAct ); bool hasActor( Entity::ActorPtr pAct ) { diff --git a/src/world/Territory/QuestBattle.cpp b/src/world/Territory/QuestBattle.cpp index 227d82ba..097266c6 100644 --- a/src/world/Territory/QuestBattle.cpp +++ b/src/world/Territory/QuestBattle.cpp @@ -333,3 +333,33 @@ void Sapphire::QuestBattle::clearDirector( Entity::Player& player ) // remove "bound by duty" state player.unsetStateFlag( PlayerStateFlag::BoundByDuty ); } + +void Sapphire::QuestBattle::success() +{ + + m_pPlayer->eventStart( m_pPlayer->getId(), getDirectorId(), Event::EventHandler::GameProgress, 1, 0 ); + m_pPlayer->playScene( getDirectorId(), 60001, 0x40000, + [ & ]( Entity::Player& player, const Event::SceneResult& result ) + { + player.eventFinish( getDirectorId(), 1 ); + player.eventStart( player.getId(), getDirectorId(), Event::EventHandler::GameProgress, 1, 0 ); + player.playScene( getDirectorId(), 6, HIDE_HOTBAR | NO_DEFAULT_CAMERA, + [ & ]( Entity::Player& player, const Event::SceneResult& result ) + { + player.eventFinish( getDirectorId(), 1 ); + auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >(); + pScriptMgr->onDutyComplete( getAsQuestBattle(), *m_pPlayer ); + } ); + + } ); +} + +void Sapphire::QuestBattle::fail() +{ + +} + +uint32_t Sapphire::QuestBattle::getQuestId() const +{ + return m_pBattleDetails->quest; +} diff --git a/src/world/Territory/QuestBattle.h b/src/world/Territory/QuestBattle.h index 67495c65..4667d5ce 100644 --- a/src/world/Territory/QuestBattle.h +++ b/src/world/Territory/QuestBattle.h @@ -61,6 +61,11 @@ namespace Sapphire void endEventCutscene(); + uint32_t getQuestId() const; + + void fail(); + void success(); + void clearDirector( Entity::Player& player ); Event::Director::DirectorState getState() const; diff --git a/src/world/Territory/Zone.cpp b/src/world/Territory/Zone.cpp index be66bcc4..2632cf2e 100644 --- a/src/world/Territory/Zone.cpp +++ b/src/world/Territory/Zone.cpp @@ -234,9 +234,6 @@ void Sapphire::Zone::pushActor( Entity::ActorPtr pActor ) auto pPlayer = pActor->getAsPlayer(); auto pServerZone = m_pFw->get< World::ServerMgr >(); - auto pSession = pServerZone->getSession( pPlayer->getId() ); - if( pSession ) - m_sessionSet.insert( pSession ); m_playerMap[ pPlayer->getId() ] = pPlayer; updateCellActivity( cx, cy, 2 ); } @@ -259,7 +256,7 @@ void Sapphire::Zone::removeActor( Entity::ActorPtr pActor ) Cell* pCell = getCellPtr( cx, cy ); if( pCell && pCell->hasActor( pActor ) ) - pCell->removeActor( pActor ); + pCell->removeActorFromCell( pActor ); if( pActor->isPlayer() ) { @@ -459,26 +456,22 @@ bool Sapphire::Zone::update( uint64_t tickCount ) void Sapphire::Zone::updateSessions( uint64_t tickCount, bool changedWeather ) { // update sessions in this zone - for( auto it = m_sessionSet.begin(); it != m_sessionSet.end(); ++it ) + for( auto it = m_playerMap.begin(); it != m_playerMap.end(); ++it ) { - auto pSession = *it; + auto pPlayer = it->second; - if( !pSession ) + if( !pPlayer ) { - it = m_sessionSet.erase( it ); - continue; + m_playerMap.erase( it ); + return; } - auto pPlayer = pSession->getPlayer(); - // this session is not linked to this area anymore, remove it from zone session list if( ( !pPlayer->getCurrentZone() ) || ( pPlayer->getCurrentZone() != shared_from_this() ) ) { - removeActor( pSession->getPlayer() ); - - it = m_sessionSet.erase( it ); - continue; + removeActor( pPlayer ); + return; } m_lastUpdate = tickCount; @@ -488,11 +481,15 @@ void Sapphire::Zone::updateSessions( uint64_t tickCount, bool changedWeather ) auto weatherChangePacket = makeZonePacket< FFXIVIpcWeatherChange >( pPlayer->getId() ); weatherChangePacket->data().weatherId = static_cast< uint8_t >( m_currentWeather ); weatherChangePacket->data().delay = 5.0f; - pSession->getPlayer()->queuePacket( weatherChangePacket ); + pPlayer->queuePacket( weatherChangePacket ); } // perform session duties - pSession->update(); + pPlayer->getSession()->update(); + + // this session is not linked to this area anymore, remove it from zone session list + if( ( !pPlayer->getCurrentZone() ) || ( pPlayer->getCurrentZone() != shared_from_this() ) ) + return; } } @@ -599,7 +596,7 @@ void Sapphire::Zone::updateActorPosition( Entity::Actor& actor ) if( pOldCell ) { - pOldCell->removeActor( actor.shared_from_this() ); + pOldCell->removeActorFromCell( actor.shared_from_this() ); } pCell->addActor( actor.shared_from_this() ); diff --git a/src/world/Territory/Zone.h b/src/world/Territory/Zone.h index bd91d0be..88927be5 100644 --- a/src/world/Territory/Zone.h +++ b/src/world/Territory/Zone.h @@ -21,7 +21,6 @@ namespace Sapphire class ZonePosition; - using SessionSet = std::set< World::SessionPtr >; using FestivalPair = std::pair< uint16_t, uint16_t >; namespace Data @@ -44,8 +43,6 @@ namespace Sapphire std::unordered_map< int32_t, Entity::BNpcPtr > m_bNpcMap; std::unordered_map< int32_t, Entity::EventObjectPtr > m_eventObjects; - SessionSet m_sessionSet; - Common::Weather m_currentWeather; Common::Weather m_weatherOverride; std::map< uint8_t, int32_t > m_weatherRateMap; diff --git a/src/world/Util/ActorFilter.cpp b/src/world/Util/ActorFilter.cpp index ec7fee56..db5ab81a 100644 --- a/src/world/Util/ActorFilter.cpp +++ b/src/world/Util/ActorFilter.cpp @@ -14,7 +14,7 @@ Sapphire::World::Util::ActorFilterInRange::ActorFilterInRange( Common::FFXIVARR_ bool Sapphire::World::Util::ActorFilterInRange::conditionApplies( const Entity::Actor& actor ) { return Sapphire::Util::distance( m_startPos.x, m_startPos.y, m_startPos.z, - actor.getPos().x, actor.getPos().y, actor.getPos().z ) <= m_range; + actor.getPos().x, actor.getPos().y, actor.getPos().z ) <= m_range; } ///////////////////////////////////////////////////////////////////////////////////////////////////////