2018-03-06 22:22:19 +01:00
|
|
|
#include <Common.h>
|
2018-11-22 00:04:26 +01:00
|
|
|
#include <Logging/Logger.h>
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Exd/ExdDataGenerated.h>
|
|
|
|
#include <Network/CommonNetwork.h>
|
2019-03-08 15:34:38 +01:00
|
|
|
#include <Network/GamePacket.h>
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Network/PacketContainer.h>
|
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
2018-07-06 23:36:50 +10:00
|
|
|
#include <Network/PacketDef/Zone/ClientZoneDef.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Network/GameConnection.h"
|
|
|
|
#include "Network/PacketWrappers/ServerNoticePacket.h"
|
|
|
|
#include "Network/PacketWrappers/EventStartPacket.h"
|
|
|
|
#include "Network/PacketWrappers/EventFinishPacket.h"
|
|
|
|
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
|
2018-03-02 07:22:25 -03:00
|
|
|
|
|
|
|
#include "Script/ScriptMgr.h"
|
|
|
|
|
2018-10-26 08:25:20 +02:00
|
|
|
#include <Util/Util.h>
|
2020-03-01 01:00:57 +11:00
|
|
|
#include <Service.h>
|
2018-10-26 08:25:20 +02:00
|
|
|
|
2018-09-20 23:31:38 +02:00
|
|
|
#include "Event/EventHandler.h"
|
2018-12-23 03:53:08 +01:00
|
|
|
#include "Manager/EventMgr.h"
|
2018-03-06 00:10:36 +01:00
|
|
|
|
2018-12-01 00:27:16 +11:00
|
|
|
#include "Territory/InstanceContent.h"
|
2019-03-31 23:45:03 +02:00
|
|
|
#include "Territory/QuestBattle.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-03-02 07:22:25 -03:00
|
|
|
#include "Session.h"
|
2018-06-02 15:52:35 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Common;
|
|
|
|
using namespace Sapphire::Network::Packets;
|
|
|
|
using namespace Sapphire::Network::Packets::Server;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerTalk( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-11-29 16:55:48 +01:00
|
|
|
Entity::Player& player )
|
2018-01-14 23:54:26 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
|
|
|
|
auto& exdData = Common::Service< Data::ExdDataGenerated >::ref();
|
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
2018-06-18 23:03:39 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerTalk >( inPacket );
|
2018-07-06 23:36:50 +10:00
|
|
|
|
2018-10-14 23:31:52 +11:00
|
|
|
const auto actorId = packet.data().actorId;
|
|
|
|
const auto eventId = packet.data().eventId;
|
2018-07-06 23:36:50 +10:00
|
|
|
|
2020-05-11 06:43:07 +09:00
|
|
|
auto eventType = static_cast< Event::EventHandler::EventHandlerType >( eventId >> 16 );
|
2018-01-14 23:54:26 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::string eventName = "onTalk";
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string objName = eventMgr.getEventName( eventId );
|
2018-01-14 23:54:26 +01:00
|
|
|
|
2019-01-15 18:20:21 +11:00
|
|
|
player.sendDebug( "Chara: {0} -> {1} \neventId: {2} ({3:08X})",
|
2020-03-01 01:00:57 +11:00
|
|
|
actorId, eventMgr.mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ),
|
2019-01-05 12:32:10 +01:00
|
|
|
eventId, eventId );
|
2018-01-14 23:54:26 +01:00
|
|
|
|
|
|
|
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Calling: {0}.{1}", objName, eventName );
|
2018-08-29 21:40:59 +02:00
|
|
|
player.eventStart( actorId, eventId, Event::EventHandler::Talk, 0, 0 );
|
2018-01-14 23:54:26 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( auto instance = player.getCurrentInstance() )
|
|
|
|
{
|
|
|
|
instance->onTalk( player, eventId, actorId );
|
|
|
|
}
|
2020-03-01 01:00:57 +11:00
|
|
|
else if( !scriptMgr.onTalk( player, actorId, eventId ) &&
|
2018-08-29 21:40:59 +02:00
|
|
|
eventType == Event::EventHandler::EventHandlerType::Quest )
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto questInfo = exdData.get< Sapphire::Data::Quest >( eventId );
|
2018-08-29 21:40:59 +02:00
|
|
|
if( questInfo )
|
2019-01-06 00:26:26 +01:00
|
|
|
player.sendUrgent( "Quest not implemented: {0} ({1})", questInfo->name, questInfo->id );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-01-14 23:54:26 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.checkEvent( eventId );
|
2018-01-14 23:54:26 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerEmote( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-01-16 02:16:48 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
|
|
|
|
auto& exdData = Common::Service< Data::ExdDataGenerated >::ref();
|
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
2018-06-18 23:03:39 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerEmote >( inPacket );
|
2018-07-06 23:36:50 +10:00
|
|
|
|
2018-10-14 23:31:52 +11:00
|
|
|
const auto actorId = packet.data().actorId;
|
|
|
|
const auto eventId = packet.data().eventId;
|
|
|
|
const auto emoteId = packet.data().emoteId;
|
2020-05-11 06:43:07 +09:00
|
|
|
const auto eventType = static_cast< Event::EventHandler::EventHandlerType >( eventId >> 16 );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::string eventName = "onEmote";
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string objName = eventMgr.getEventName( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2019-01-15 18:20:21 +11:00
|
|
|
player.sendDebug( "Chara: {0} -> {1} \neventId: {2} ({3:08X})",
|
2020-03-01 01:00:57 +11:00
|
|
|
actorId, eventMgr.mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ),
|
2019-01-05 12:32:10 +01:00
|
|
|
eventId, eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Calling: {0}.{1}", objName, eventName );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.eventStart( actorId, eventId, Event::EventHandler::Emote, 0, emoteId );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
if( !scriptMgr.onEmote( player, actorId, eventId, static_cast< uint8_t >( emoteId ) ) &&
|
2018-08-29 21:40:59 +02:00
|
|
|
eventType == Event::EventHandler::EventHandlerType::Quest )
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto questInfo = exdData.get< Sapphire::Data::Quest >( eventId );
|
2018-08-29 21:40:59 +02:00
|
|
|
if( questInfo )
|
2019-01-06 00:26:26 +01:00
|
|
|
player.sendUrgent( "Quest not implemented: {0}", questInfo->name );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.checkEvent( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerWithinRange( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-01-16 02:16:48 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
|
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
2018-06-18 23:03:39 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerWithinRange >( inPacket );
|
2018-06-18 23:03:39 +02:00
|
|
|
|
2018-10-14 23:31:52 +11:00
|
|
|
const auto eventId = packet.data().eventId;
|
|
|
|
const auto param1 = packet.data().param1;
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto& pos = packet.data().position;
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::string eventName = "onWithinRange";
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string objName = eventMgr.getEventName( eventId );
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Calling: {0}.{1} - {2} p1: {3}", objName, eventName, eventId, param1 );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
scriptMgr.onWithinRange( player, eventId, param1, pos.x, pos.y, pos.z );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.checkEvent( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerOutsideRange( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-01-16 02:16:48 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
|
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
2018-06-18 23:03:39 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerOutsideRange >( inPacket );
|
2018-10-14 23:31:52 +11:00
|
|
|
const auto eventId = packet.data().eventId;
|
|
|
|
const auto param1 = packet.data().param1;
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto& pos = packet.data().position;
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::string eventName = "onOutsideRange";
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string objName = eventMgr.getEventName( eventId );
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Calling: {0}.{1} - {2} p1: {3}", objName, eventName, eventId, param1 );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
scriptMgr.onOutsideRange( player, eventId, param1, pos.x, pos.y, pos.z );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.checkEvent( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerEnterTerritory( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-01-16 02:16:48 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
|
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
2018-06-18 23:03:39 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEnterTerritoryHandler >( inPacket );
|
2018-07-06 23:36:50 +10:00
|
|
|
|
2018-10-14 23:31:52 +11:00
|
|
|
const auto eventId = packet.data().eventId;
|
|
|
|
const auto param1 = packet.data().param1;
|
|
|
|
const auto param2 = packet.data().param2;
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::string eventName = "onEnterTerritory";
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string objName = eventMgr.getEventName( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2019-04-02 00:00:58 +02:00
|
|
|
player.sendDebug( "Calling: {0}.{1} - {2}", objName, eventName, eventId & 0xFFFF );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( auto instance = player.getCurrentInstance() )
|
|
|
|
{
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 1, player.getZoneId() );
|
|
|
|
instance->onEnterTerritory( player, eventId, param1, param2 );
|
|
|
|
}
|
2019-03-31 23:45:03 +02:00
|
|
|
else if( auto instance = player.getCurrentQuestBattle() )
|
|
|
|
{
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 1, player.getZoneId() );
|
|
|
|
instance->onEnterTerritory( player, eventId, param1, param2 );
|
|
|
|
}
|
2018-08-29 21:40:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId() );
|
2020-03-01 01:00:57 +11:00
|
|
|
scriptMgr.onEnterTerritory( player, eventId, param1, param2 );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.checkEvent( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerReturn( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-01-18 21:49:12 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
2018-12-23 03:53:08 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerReturn >( inPacket );
|
2018-10-14 23:31:52 +11:00
|
|
|
const auto eventId = packet.data().eventId;
|
|
|
|
const auto scene = packet.data().scene;
|
|
|
|
const auto param1 = packet.data().param1;
|
|
|
|
const auto param2 = packet.data().param2;
|
|
|
|
const auto param3 = packet.data().param3;
|
|
|
|
const auto param4 = packet.data().param4;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string eventName = eventMgr.getEventName( eventId );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2020-05-11 06:25:25 +09:00
|
|
|
player.sendDebug( "eventId: {0} ({0:08X}) scene: {1}, p1: {2}, p2: {3}, p3: {4}, p4: {5}",
|
|
|
|
eventId, scene, param1, param2, param3, param4 );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
auto pEvent = player.getEvent( eventId );
|
|
|
|
if( pEvent )
|
|
|
|
{
|
|
|
|
pEvent->setPlayedScene( false );
|
|
|
|
// try to retrieve a stored callback
|
|
|
|
auto eventCallback = pEvent->getEventReturnCallback();
|
|
|
|
// if there is one, proceed to call it
|
|
|
|
if( eventCallback )
|
|
|
|
{
|
|
|
|
Event::SceneResult result;
|
2018-11-25 23:20:56 +11:00
|
|
|
result.actorId = pEvent->getActorId();
|
2018-08-29 21:40:59 +02:00
|
|
|
result.eventId = eventId;
|
|
|
|
result.param1 = param1;
|
|
|
|
result.param2 = param2;
|
|
|
|
result.param3 = param3;
|
|
|
|
result.param4 = param4;
|
|
|
|
eventCallback( player, result );
|
|
|
|
}
|
2018-03-20 22:08:25 +11:00
|
|
|
// we might have a scene chain callback instead so check for that too
|
2018-08-29 21:40:59 +02:00
|
|
|
else if( auto chainCallback = pEvent->getSceneChainCallback() )
|
|
|
|
chainCallback( player );
|
2018-03-20 00:05:54 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-01-18 21:49:12 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.checkEvent( eventId );
|
2018-01-18 21:49:12 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerLinkshell( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-01-18 21:49:12 +01:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcLinkshellEventHandler >( inPacket );
|
|
|
|
|
|
|
|
auto linkshellEvent = makeZonePacket< Server::FFXIVIpcEventLinkshell >( player.getId() );
|
|
|
|
linkshellEvent->data().eventId = packet.data().eventId;
|
|
|
|
linkshellEvent->data().scene = static_cast< uint8_t >( packet.data().scene );
|
|
|
|
linkshellEvent->data().param3 = 1;
|
|
|
|
linkshellEvent->data().unknown1 = 0x15a;
|
|
|
|
player.queuePacket( linkshellEvent );
|
2018-01-18 21:49:12 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
void Sapphire::Network::GameConnection::eventHandlerShop( const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-12-23 03:53:08 +01:00
|
|
|
Entity::Player& player )
|
2018-11-22 00:04:26 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
|
|
|
|
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
|
2018-12-23 03:53:08 +01:00
|
|
|
|
2018-11-22 00:04:26 +01:00
|
|
|
const auto packet = ZoneChannelPacket< Client::FFXIVIpcShopEventHandler >( inPacket );
|
|
|
|
|
|
|
|
|
|
|
|
const auto eventId = packet.data().eventId;
|
|
|
|
|
|
|
|
auto eventType = static_cast< uint16_t >( eventId >> 16 );
|
|
|
|
|
2018-11-22 23:59:42 +01:00
|
|
|
std::string eventName = "onOpen";
|
2020-03-01 01:00:57 +11:00
|
|
|
std::string objName = eventMgr.getEventName( eventId );
|
2018-11-22 00:04:26 +01:00
|
|
|
|
2019-01-15 18:20:21 +11:00
|
|
|
player.sendDebug( "EventId: {0} ({0:08X})", eventId );
|
2018-11-22 00:04:26 +01:00
|
|
|
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Calling: {0}.{1}", objName, eventName );
|
2018-11-24 15:17:18 +11:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::UI, 0, packet.data().param );
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
scriptMgr.onTalk( player, player.getId(), eventId );
|
2018-11-22 00:04:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
|