2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Common.h>
|
2018-01-31 11:43:22 +01:00
|
|
|
#include <common/Exd/ExdDataGenerated.h>
|
2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Network/CommonNetwork.h>
|
|
|
|
#include <common/Network/GamePacketNew.h>
|
|
|
|
#include <common/Network/PacketContainer.h>
|
|
|
|
#include <common/Network/PacketDef/Zone/ServerZoneDef.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Network/GameConnection.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Network/PacketWrappers/ServerNoticePacket.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket142.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket143.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket144.h"
|
|
|
|
#include "Network/PacketWrappers/EventStartPacket.h"
|
|
|
|
#include "Network/PacketWrappers/EventFinishPacket.h"
|
|
|
|
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
|
|
|
|
#include "Script/ScriptManager.h"
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
#include "Forwards.h"
|
|
|
|
#include "Event/EventHelper.h"
|
2018-02-25 17:23:52 +11:00
|
|
|
#include "Zone/InstanceContent.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-01-31 11:43:22 +01:00
|
|
|
extern Core::Data::ExdDataGenerated g_exdDataGen;
|
2017-08-17 17:36:40 +02:00
|
|
|
extern Core::Scripting::ScriptManager g_scriptMgr;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
using namespace Core::Common;
|
|
|
|
using namespace Core::Network::Packets;
|
|
|
|
using namespace Core::Network::Packets::Server;
|
|
|
|
|
2018-01-14 23:54:26 +01:00
|
|
|
void Core::Network::GameConnection::eventHandlerTalk( const Packets::GamePacket& inPacket, Entity::Player& player )
|
|
|
|
{
|
|
|
|
auto actorId = inPacket.getValAt< uint64_t >( 0x20 );
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x28 );
|
|
|
|
auto eventType = static_cast< uint16_t >( eventId >> 16 );
|
|
|
|
|
|
|
|
std::string eventName = "onTalk";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
|
2018-02-20 22:46:44 +01:00
|
|
|
player.sendDebug( "Chara: " +
|
2018-01-14 23:54:26 +01:00
|
|
|
std::to_string( actorId ) + " -> " +
|
|
|
|
std::to_string( Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ) ) +
|
|
|
|
" \neventId: " +
|
|
|
|
std::to_string( eventId ) +
|
|
|
|
" (0x" + boost::str( boost::format( "%|08X|" )
|
|
|
|
% static_cast< uint64_t >( eventId & 0xFFFFFFF ) ) + ")" );
|
|
|
|
|
|
|
|
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName );
|
|
|
|
player.eventStart( actorId, eventId, Event::EventHandler::Talk, 0, 0 );
|
|
|
|
|
2018-02-25 17:23:52 +11:00
|
|
|
|
|
|
|
if( auto instance = player.getCurrentInstance() )
|
|
|
|
{
|
|
|
|
instance->onTalk( player, eventId, actorId );
|
|
|
|
}
|
|
|
|
else if( !g_scriptMgr.onTalk( player, actorId, eventId ) &&
|
2018-01-16 02:16:48 +01:00
|
|
|
eventType == Event::EventHandler::EventHandlerType::Quest )
|
2018-01-14 23:54:26 +01:00
|
|
|
{
|
2018-02-14 12:31:47 +01:00
|
|
|
auto questInfo = g_exdDataGen.get< Core::Data::Quest >( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
if ( questInfo )
|
2018-01-31 11:43:22 +01:00
|
|
|
player.sendUrgent( "Quest not implemented: " + questInfo->name + " (" + questInfo->id + ")" );
|
2018-01-14 23:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-16 02:16:48 +01:00
|
|
|
void Core::Network::GameConnection::eventHandlerEmote( const Packets::GamePacket& inPacket, Entity::Player& player )
|
|
|
|
{
|
|
|
|
|
|
|
|
auto actorId = inPacket.getValAt< uint64_t >( 0x20 );
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x28 );
|
|
|
|
auto emoteId = inPacket.getValAt< uint16_t >( 0x2C );
|
|
|
|
auto eventType = static_cast< uint16_t >( eventId >> 16 );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-01-16 02:16:48 +01:00
|
|
|
std::string eventName = "onEmote";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
|
2018-02-20 22:46:44 +01:00
|
|
|
player.sendDebug( "Chara: " +
|
2018-01-16 02:16:48 +01:00
|
|
|
std::to_string( actorId ) + " -> " +
|
|
|
|
std::to_string( Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ) ) +
|
|
|
|
" \neventId: " +
|
|
|
|
std::to_string( eventId ) +
|
|
|
|
" (0x" + boost::str( boost::format( "%|08X|" )
|
|
|
|
% static_cast< uint64_t >( eventId & 0xFFFFFFF ) ) + ")" );
|
|
|
|
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName );
|
|
|
|
|
|
|
|
player.eventStart( actorId, eventId, Event::EventHandler::Emote, 0, emoteId );
|
|
|
|
|
|
|
|
if( !g_scriptMgr.onEmote( player, actorId, eventId, static_cast< uint8_t >( emoteId ) ) &&
|
|
|
|
eventType == Event::EventHandler::EventHandlerType::Quest )
|
|
|
|
{
|
2018-02-14 12:31:47 +01:00
|
|
|
auto questInfo = g_exdDataGen.get< Core::Data::Quest >( eventId );
|
2018-01-16 02:16:48 +01:00
|
|
|
if( questInfo )
|
|
|
|
player.sendUrgent( "Quest not implemented: " + questInfo->name );
|
|
|
|
}
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Network::GameConnection::eventHandlerWithinRange( const Packets::GamePacket& inPacket,
|
|
|
|
Entity::Player& player )
|
|
|
|
{
|
|
|
|
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x24 );
|
|
|
|
auto param1 = inPacket.getValAt< uint32_t >( 0x20 );
|
|
|
|
auto x = inPacket.getValAt< float >( 0x28 );
|
|
|
|
auto y = inPacket.getValAt< float >( 0x2C );
|
|
|
|
auto z = inPacket.getValAt< float >( 0x30 );
|
|
|
|
|
|
|
|
std::string eventName = "onWithinRange";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) +
|
|
|
|
" p1: " + std::to_string( param1 ) );
|
|
|
|
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
|
|
|
|
|
|
|
|
g_scriptMgr.onWithinRange( player, eventId, param1, x, y, z );
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Network::GameConnection::eventHandlerOutsideRange( const Packets::GamePacket& inPacket,
|
|
|
|
Entity::Player& player )
|
|
|
|
{
|
|
|
|
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x24 );
|
|
|
|
auto param1 = inPacket.getValAt< uint32_t >( 0x20 );
|
|
|
|
auto x = inPacket.getValAt< float >( 0x28 );
|
|
|
|
auto y = inPacket.getValAt< float >( 0x2C );
|
|
|
|
auto z = inPacket.getValAt< float >( 0x30 );
|
|
|
|
|
|
|
|
std::string eventName = "onOutsideRange";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) +
|
|
|
|
" p1: " + std::to_string( param1 ) );
|
|
|
|
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
|
|
|
|
|
|
|
|
g_scriptMgr.onOutsideRange( player, eventId, param1, x, y, z );
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Network::GameConnection::eventHandlerEnterTerritory( const Packets::GamePacket &inPacket,
|
|
|
|
Entity::Player &player )
|
|
|
|
{
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x20 );
|
|
|
|
auto param1 = inPacket.getValAt< uint16_t >( 0x24 );
|
|
|
|
auto param2 = inPacket.getValAt< uint16_t >( 0x26 );
|
|
|
|
|
2018-02-03 01:51:46 +01:00
|
|
|
std::string eventName = "onEnterTerritory";
|
2018-01-16 02:16:48 +01:00
|
|
|
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
|
|
|
|
|
2018-03-05 22:40:11 +11:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId(), 0 );
|
2018-01-16 02:16:48 +01:00
|
|
|
|
2018-03-05 22:10:14 +11:00
|
|
|
if( auto instance = player.getCurrentInstance() )
|
2018-03-05 22:40:11 +11:00
|
|
|
{
|
|
|
|
// param2 of eventStart
|
|
|
|
// 0 = default state?
|
|
|
|
// 1 = restore state?
|
|
|
|
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId(), instance->getDirectorId() & 0xFFFF );
|
2018-03-05 22:10:14 +11:00
|
|
|
instance->onEnterTerritory( player, eventId, param1, param2 );
|
2018-03-05 22:40:11 +11:00
|
|
|
}
|
2018-03-05 22:10:14 +11:00
|
|
|
else
|
2018-03-05 22:40:11 +11:00
|
|
|
{
|
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId() );
|
2018-03-05 22:10:14 +11:00
|
|
|
g_scriptMgr.onEnterTerritory( player, eventId, param1, param2 );
|
2018-03-05 22:40:11 +11:00
|
|
|
}
|
2018-01-16 02:16:48 +01:00
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-01-18 21:49:12 +01:00
|
|
|
void Core::Network::GameConnection::eventHandlerReturn( const Packets::GamePacket &inPacket,
|
|
|
|
Entity::Player &player )
|
|
|
|
{
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x20 );
|
|
|
|
auto scene = inPacket.getValAt< uint16_t >( 0x24 );
|
|
|
|
auto param1 = inPacket.getValAt< uint16_t >( 0x26 );
|
|
|
|
auto param2 = inPacket.getValAt< uint16_t >( 0x28 );
|
|
|
|
auto param3 = inPacket.getValAt< uint16_t >( 0x2C );
|
|
|
|
|
|
|
|
std::string eventName = Event::getEventName( eventId );
|
|
|
|
|
|
|
|
player.sendDebug( "eventId: " +
|
|
|
|
std::to_string( eventId ) +
|
|
|
|
" ( 0x" + boost::str( boost::format( "%|08X|" ) % ( uint64_t ) ( eventId & 0xFFFFFFF ) ) + " ) " +
|
|
|
|
" scene: " + std::to_string( scene ) +
|
|
|
|
" p1: " + std::to_string( param1 ) +
|
|
|
|
" p2: " + std::to_string( param2 ) +
|
|
|
|
" p3: " + std::to_string( param3 ) );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
eventCallback( player, eventId, param1, param2, param3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Network::GameConnection::eventHandlerLinkshell( const Packets::GamePacket &inPacket,
|
|
|
|
Entity::Player &player )
|
|
|
|
{
|
|
|
|
auto eventId = inPacket.getValAt< uint32_t >( 0x20 );
|
|
|
|
auto scene = inPacket.getValAt< uint16_t >( 0x24 );
|
|
|
|
auto lsName = inPacket.getStringAt( 0x27 );
|
|
|
|
|
|
|
|
ZoneChannelPacket< FFXIVIpcEventLinkshell > linkshellEvent( player.getId() );
|
|
|
|
linkshellEvent.data().eventId = eventId;
|
|
|
|
linkshellEvent.data().scene = static_cast< uint8_t >( scene );
|
|
|
|
linkshellEvent.data().param3 = 1;
|
|
|
|
linkshellEvent.data().unknown1 = 0x15a;
|
|
|
|
player.queuePacket( linkshellEvent );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
|