From 6e9d47b6a3551f6e48702c677490b481f21329e3 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 5 Feb 2023 21:29:55 +0100 Subject: [PATCH] Added dynamic event notice function which takes a vector for its params. Supports up to 32 params. Can be omitted. --- src/world/Manager/EventMgr.cpp | 28 ++- src/world/Manager/EventMgr.h | 1 + .../PacketWrappers/EventNoticePacket.h | 159 ++++++++++++++++++ .../Network/PacketWrappers/Notice2Packet.h | 33 ---- 4 files changed, 186 insertions(+), 35 deletions(-) create mode 100644 src/world/Network/PacketWrappers/EventNoticePacket.h delete mode 100644 src/world/Network/PacketWrappers/Notice2Packet.h diff --git a/src/world/Manager/EventMgr.cpp b/src/world/Manager/EventMgr.cpp index a6e6310d..1c36b4c6 100644 --- a/src/world/Manager/EventMgr.cpp +++ b/src/world/Manager/EventMgr.cpp @@ -18,7 +18,7 @@ #include "Network/PacketWrappers/EventPlayPacket.h" #include "Network/PacketWrappers/EventFinishPacket.h" #include "Network/PacketWrappers/EventResumePacket.h" -#include "Network/PacketWrappers/Notice2Packet.h" +#include "Network/PacketWrappers/EventNoticePacket.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 ) { - 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(); 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 ); + +} diff --git a/src/world/Manager/EventMgr.h b/src/world/Manager/EventMgr.h index 58dec99f..3db61b97 100644 --- a/src/world/Manager/EventMgr.h +++ b/src/world/Manager/EventMgr.h @@ -73,6 +73,7 @@ namespace Sapphire::World::Manager 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 questId, int8_t noticeId, std::vector< uint32_t > args = {} ); /*! setup the event and return a ptr to it */ Event::EventHandlerPtr bootstrapSceneEvent( Entity::Player& player, uint32_t eventId, uint32_t flags ); diff --git a/src/world/Network/PacketWrappers/EventNoticePacket.h b/src/world/Network/PacketWrappers/EventNoticePacket.h new file mode 100644 index 00000000..750057c0 --- /dev/null +++ b/src/world/Network/PacketWrappers/EventNoticePacket.h @@ -0,0 +1,159 @@ +#pragma once + +#include +#include +#include +#include +#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; + } + } + }; + +} diff --git a/src/world/Network/PacketWrappers/Notice2Packet.h b/src/world/Network/PacketWrappers/Notice2Packet.h deleted file mode 100644 index f0ea6f7c..00000000 --- a/src/world/Network/PacketWrappers/Notice2Packet.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#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; - }; - }; - -} \ No newline at end of file