1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 08:57:44 +00:00

Added dynamic event notice function which takes a vector for its params. Supports up to 32 params. Can be omitted.

This commit is contained in:
Mordred 2023-02-05 21:29:55 +01:00
parent 9eaa423c23
commit 6e9d47b6a3
4 changed files with 186 additions and 35 deletions

View file

@ -18,7 +18,7 @@
#include "Network/PacketWrappers/EventPlayPacket.h" #include "Network/PacketWrappers/EventPlayPacket.h"
#include "Network/PacketWrappers/EventFinishPacket.h" #include "Network/PacketWrappers/EventFinishPacket.h"
#include "Network/PacketWrappers/EventResumePacket.h" #include "Network/PacketWrappers/EventResumePacket.h"
#include "Network/PacketWrappers/Notice2Packet.h" #include "Network/PacketWrappers/EventNoticePacket.h"
#include "Territory/InstanceObjectCache.h" #include "Territory/InstanceObjectCache.h"
@ -843,7 +843,31 @@ Sapphire::Event::EventHandlerPtr EventMgr::bootstrapSceneEvent( Entity::Player&
void EventMgr::sendEventNotice( Entity::Player& player, uint32_t questId, int8_t noticeId, uint8_t numOfArgs, uint32_t var1, uint32_t var2 ) void EventMgr::sendEventNotice( Entity::Player& player, uint32_t questId, int8_t noticeId, uint8_t numOfArgs, uint32_t var1, uint32_t var2 )
{ {
auto noticePacket = std::make_shared< Notice2Packet >( player.getId(), questId, noticeId, numOfArgs, var1, var2 ); std::vector< uint32_t > args{ var1, var2 };
auto noticePacket = std::make_shared< EventNotice2Packet >( player, questId, noticeId, args );
auto& server = Common::Service< World::WorldServer >::ref(); auto& server = Common::Service< World::WorldServer >::ref();
server.queueForPlayer( player.getCharacterId(), noticePacket ); server.queueForPlayer( player.getCharacterId(), noticePacket );
} }
void EventMgr::sendEventNotice( Entity::Player& player, uint32_t questId, int8_t noticeId, std::vector< uint32_t > args )
{
FFXIVPacketBasePtr pPacket = nullptr;
size_t paramCount = args.size();
assert( paramCount <= 32 );
if( paramCount < 2 )
pPacket = std::move( std::make_shared< EventNotice2Packet >( player, questId, noticeId, args ) );
else if( paramCount < 4 )
pPacket = std::move( std::make_shared< EventNotice4Packet >( player, questId, noticeId, args ) );
else if( paramCount < 8 )
pPacket = std::move( std::make_shared< EventNotice8Packet >( player, questId, noticeId, args ) );
else if( paramCount < 16 )
pPacket = std::move( std::make_shared< EventNotice16Packet >( player, questId, noticeId, args ) );
else if( paramCount < 32 )
pPacket = std::move( std::make_shared< EventNotice32Packet >( player, questId, noticeId, args ) );
auto& server = Common::Service< World::WorldServer >::ref();
server.queueForPlayer( player.getCharacterId(), pPacket );
}

View file

@ -73,6 +73,7 @@ namespace Sapphire::World::Manager
bool sendEventPlay( Entity::Player& player, uint32_t eventid, uint32_t scene, uint32_t flags ); bool sendEventPlay( Entity::Player& player, uint32_t eventid, uint32_t scene, uint32_t flags );
void sendEventNotice( Entity::Player& player, uint32_t eventId, int8_t noticeId, uint8_t numOfArgs = 0, uint32_t var1 = 0, uint32_t var2 = 0 ); void sendEventNotice( Entity::Player& player, uint32_t eventId, int8_t noticeId, uint8_t numOfArgs = 0, uint32_t var1 = 0, uint32_t var2 = 0 );
void sendEventNotice( Entity::Player& player, uint32_t questId, int8_t noticeId, std::vector< uint32_t > args = {} );
/*! setup the event and return a ptr to it */ /*! setup the event and return a ptr to it */
Event::EventHandlerPtr bootstrapSceneEvent( Entity::Player& player, uint32_t eventId, uint32_t flags ); Event::EventHandlerPtr bootstrapSceneEvent( Entity::Player& player, uint32_t eventId, uint32_t flags );

View file

@ -0,0 +1,159 @@
#pragma once
#include <Network/GamePacket.h>
#include <Actor/Player.h>
#include <Event/EventHandler.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include "Forwards.h"
namespace Sapphire::Network::Packets::WorldPackets::Server
{
/**
* @brief The packet sent to resume an event and fill it with additional data.
*/
class EventNoticePacketHeader : public ZoneChannelPacket< FFXIVIpcNoticeHeader >
{
public:
EventNoticePacketHeader( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args = {} ) :
ZoneChannelPacket< FFXIVIpcNoticeHeader >( player.getId(), player.getId() )
{
initialize( player, handlerId, noticeId, args );
};
private:
void initialize( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args )
{
m_data.handlerId = handlerId;
m_data.noticeId = noticeId;
m_data.numOfArgs = static_cast< uint8_t >( args.size() );
if( !args.empty() )
{
int i = 0;
for( auto& val : args )
m_data.args[ i++ ] = val;
}
}
};
class EventNotice2Packet : public ZoneChannelPacket< FFXIVIpcNotice2 >
{
public:
EventNotice2Packet( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args = {} ) :
ZoneChannelPacket< FFXIVIpcNotice2 >( player.getId(), player.getId() )
{
initialize( player, handlerId, noticeId, args );
};
private:
void initialize( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args )
{
m_data.handlerId = handlerId;
m_data.noticeId = noticeId;
m_data.numOfArgs = static_cast< uint8_t >( args.size() );
if( !args.empty() )
{
int i = 0;
for( auto& val : args )
m_data.args[ i++ ] = val;
}
}
};
class EventNotice4Packet : public ZoneChannelPacket< FFXIVIpcNotice4 >
{
public:
EventNotice4Packet( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args = {} ) :
ZoneChannelPacket< FFXIVIpcNotice4 >( player.getId(), player.getId() )
{
initialize( player, handlerId, noticeId, args );
};
private:
void initialize( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args )
{
m_data.handlerId = handlerId;
m_data.noticeId = noticeId;
m_data.numOfArgs = static_cast< uint8_t >( args.size() );
if( !args.empty() )
{
int i = 0;
for( auto& val : args )
m_data.args[ i++ ] = val;
}
}
};
class EventNotice8Packet : public ZoneChannelPacket< FFXIVIpcNotice8 >
{
public:
EventNotice8Packet( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args = {} ) :
ZoneChannelPacket< FFXIVIpcNotice8 >( player.getId(), player.getId() )
{
initialize( player, handlerId, noticeId, args );
};
private:
void initialize( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args )
{
m_data.handlerId = handlerId;
m_data.noticeId = noticeId;
m_data.numOfArgs = static_cast< uint8_t >( args.size() );
if( !args.empty() )
{
int i = 0;
for( auto& val : args )
m_data.args[ i++ ] = val;
}
}
};
class EventNotice16Packet : public ZoneChannelPacket< FFXIVIpcNotice16 >
{
public:
EventNotice16Packet( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args = {} ) :
ZoneChannelPacket< FFXIVIpcNotice16 >( player.getId(), player.getId() )
{
initialize( player, handlerId, noticeId, args );
};
private:
void initialize( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args )
{
m_data.handlerId = handlerId;
m_data.noticeId = noticeId;
m_data.numOfArgs = static_cast< uint8_t >( args.size() );
if( !args.empty() )
{
int i = 0;
for( auto& val : args )
m_data.args[ i++ ] = val;
}
}
};
class EventNotice32Packet : public ZoneChannelPacket< FFXIVIpcNotice32 >
{
public:
EventNotice32Packet( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args = {} ) :
ZoneChannelPacket< FFXIVIpcNotice32 >( player.getId(), player.getId() )
{
initialize( player, handlerId, noticeId, args );
};
private:
void initialize( const Entity::Player& player, uint32_t handlerId, uint8_t noticeId, std::vector< uint32_t > args )
{
m_data.handlerId = handlerId;
m_data.noticeId = noticeId;
m_data.numOfArgs = static_cast< uint8_t >( args.size() );
if( !args.empty() )
{
int i = 0;
for( auto& val : args )
m_data.args[ i++ ] = val;
}
}
};
}

View file

@ -1,33 +0,0 @@
#pragma once
#include <Network/GamePacket.h>
#include "Forwards.h"
namespace Sapphire::Network::Packets::WorldPackets::Server
{
/**
* @brief Packet to display a quest specific info message.
*/
class Notice2Packet : public ZoneChannelPacket< FFXIVIpcNotice2 >
{
public:
Notice2Packet( uint32_t entityId, uint32_t questId, int8_t msgId, uint8_t numOfArgs = 0, uint32_t var1 = 0, uint32_t var2 = 0 ) :
ZoneChannelPacket< FFXIVIpcNotice2 >( entityId, entityId )
{
initialize( questId, msgId, numOfArgs, var1, var2 );
};
private:
void initialize( uint32_t questId, int8_t msgId, uint8_t numOfArgs, uint32_t var1, uint32_t var2 )
{
m_data.handlerId = questId;
m_data.noticeId = msgId;
// todo: not correct
m_data.numOfArgs = numOfArgs;
m_data.args[0] = var1;
m_data.args[1] = var2;
};
};
}