mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-14 07:48:21 +00:00
Add Buff infrastructure to go through different logic paths from different patches (#5073)
This commit is contained in:
+90
-43
@@ -1,26 +1,50 @@
|
||||
//
|
||||
// Created by dannu on 4/21/2026.
|
||||
//
|
||||
/* EQEmu: EQEmulator
|
||||
|
||||
Copyright (C) 2001-2026 EQEmu Development Team
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "common/emu_versions.h"
|
||||
#include "common/patches/client_version.h"
|
||||
#include "common/patches/IBuff.h"
|
||||
#include "common/patches/IMessage.h"
|
||||
|
||||
#include "zone/client.h"
|
||||
#include "zone/mob.h"
|
||||
|
||||
#include <ranges>
|
||||
|
||||
// store all _generic_ static functions for the different patches here
|
||||
namespace ClientPatch {
|
||||
|
||||
using ClientList = std::unordered_map<uint16, Client*>;
|
||||
template<typename Obj> using ComponentGetter = std::function<Obj*(const Client*)>;
|
||||
template<typename Obj> using ComponentGetter = Obj*(*)(const Client*);
|
||||
using SendPredicate = std::function<bool(Client*)>;
|
||||
using MutatePacket = std::function<void(std::unique_ptr<EQApplicationPacket>&, Client*)>;
|
||||
|
||||
template <typename Component>
|
||||
Component* GetClientComponent(const Client* client)
|
||||
{
|
||||
return GetComponent<Component>(client->GetClientVersion()).get();
|
||||
}
|
||||
|
||||
template <typename Fun, typename Obj, typename... Args>
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
static void QueuePacket(Client* c, Fun fun, Obj* obj, Args&&... args)
|
||||
void QueuePacket(Client* c, Fun fun, Obj* obj, Args&&... args)
|
||||
{
|
||||
if (obj != nullptr) {
|
||||
std::unique_ptr<EQApplicationPacket> app = std::invoke(fun, obj, std::forward<Args>(args)...);
|
||||
@@ -30,15 +54,14 @@ static void QueuePacket(Client* c, Fun fun, Obj* obj, Args&&... args)
|
||||
}
|
||||
|
||||
// packet generator queue functions
|
||||
static auto QueueClients(Mob* sender, bool ignore_sender = false, bool ackreq = true)
|
||||
inline auto QueueClients(Mob* sender, bool ignore_sender = false, bool ackreq = true)
|
||||
{
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, const ComponentGetter<Obj>& component, Args&&... args)
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, ComponentGetter<Obj> component, Args&&... args)
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
{
|
||||
std::array<std::unique_ptr<EQApplicationPacket>, EQ::versions::ClientVersionCount> build_packets;
|
||||
std::unordered_map<uint16, Client*> client_list = entity_list.GetClientList();
|
||||
|
||||
for (auto [_, ent] : client_list) {
|
||||
for (auto ent : entity_list.GetClientList() | std::views::values) {
|
||||
if (!ignore_sender || ent != sender) {
|
||||
auto& packet = build_packets.at(static_cast<uint32_t>(ent->ClientVersion()));
|
||||
if (!packet)
|
||||
@@ -52,14 +75,14 @@ static auto QueueClients(Mob* sender, bool ignore_sender = false, bool ackreq =
|
||||
};
|
||||
}
|
||||
|
||||
static auto QueueCloseClients(
|
||||
inline auto QueueCloseClients(
|
||||
Mob* sender, bool ignore_sender = false, float distance = 200,
|
||||
Mob* skipped_mob = nullptr, bool is_ack_required = true,
|
||||
eqFilterType filter = FilterNone)
|
||||
{
|
||||
if (distance <= 0) distance = static_cast<float>(zone->GetClientUpdateRange());
|
||||
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, const ComponentGetter<Obj>& component, Args&&... args)
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, ComponentGetter<Obj> component, Args&&... args)
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
{
|
||||
if (sender == nullptr) {
|
||||
@@ -68,14 +91,14 @@ static auto QueueCloseClients(
|
||||
float distance_squared = distance * distance;
|
||||
std::array<std::unique_ptr<EQApplicationPacket>, EQ::versions::ClientVersionCount> build_packets;
|
||||
|
||||
for (auto& [_, mob] : sender->GetCloseMobList(distance)) {
|
||||
for (auto mob : sender->GetCloseMobList(distance) | std::views::values) {
|
||||
if (mob && mob->IsClient()) {
|
||||
Client* client = mob->CastToClient();
|
||||
if ((!ignore_sender || client != sender)
|
||||
&& client != skipped_mob
|
||||
&& DistanceSquared(client->GetPosition(), sender->GetPosition()) < distance_squared
|
||||
&& client->Connected()
|
||||
&& client->ShouldGetPacket(sender, filter))
|
||||
&& client->ShouldGetPacket(sender, filter)
|
||||
&& DistanceSquared(client->GetPosition(), sender->GetPosition()) < distance_squared)
|
||||
{
|
||||
auto& packet = build_packets.at(static_cast<uint32_t>(client->ClientVersion()));
|
||||
if (!packet)
|
||||
@@ -91,30 +114,60 @@ static auto QueueCloseClients(
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace ClientPatch
|
||||
template <typename Fun, typename Obj, typename... Args>
|
||||
void FastQueuePacket(Client* c, Fun fun, Obj* obj, Args&&... args)
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
{
|
||||
if (obj != nullptr) {
|
||||
std::unique_ptr<EQApplicationPacket> app = std::invoke(fun, obj, std::forward<Args>(args)...);
|
||||
if (app) {
|
||||
// FastQueuePacket specifically takes lifetime management of packet, so release here
|
||||
EQApplicationPacket* packet = app.release();
|
||||
c->FastQueuePacket(&packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers for the Message interface to send message packets
|
||||
namespace Message {
|
||||
inline auto QueueClientsByTarget(Mob* sender, bool ackreq, const SendPredicate& should_send, const MutatePacket& mutate)
|
||||
{
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, ComponentGetter<Obj> component, Args&&... args)
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
{
|
||||
if (sender != nullptr) {
|
||||
std::array<std::unique_ptr<EQApplicationPacket>, EQ::versions::ClientVersionCount> build_packets;
|
||||
|
||||
// this can return nullptr when the component doesn't exist for the version
|
||||
static std::function GetComponent = [](const Client* c) -> IMessage* {
|
||||
return GetMessageComponent(c->GetClientVersion()).get();
|
||||
};
|
||||
for (auto c : entity_list.GetClientList() | std::views::values) {
|
||||
Mob* Target = c->GetTarget();
|
||||
if (Target == sender && should_send(c)) {
|
||||
auto& packet = build_packets.at(static_cast<uint32_t>(c->ClientVersion()));
|
||||
if (!packet)
|
||||
if (auto comp = component(c); comp != nullptr)
|
||||
packet = std::invoke(fun, comp, std::forward<Args>(args)...);
|
||||
|
||||
mutate(packet, c);
|
||||
|
||||
if (packet)
|
||||
c->QueuePacket(packet.get(), ackreq, Client::CLIENT_CONNECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Helper functions to wrap the packet construction in sends
|
||||
template <AllConstChar... Args>
|
||||
requires (sizeof...(Args) <= 9)
|
||||
void MessageString(Client* c, uint32_t type, uint32_t id, Args&&... args)
|
||||
void SendMessageString(Client* c, uint32_t type, uint32_t id, Args&&... args)
|
||||
{
|
||||
if constexpr (sizeof...(Args) == 0) {
|
||||
ClientPatch::QueuePacket(c, &IMessage::Simple, GetComponent(c), type, id);
|
||||
QueuePacket(c, &IMessage::Simple, GetClientComponent<IMessage>(c), type, id);
|
||||
} else {
|
||||
std::array<const char*, 9> a = {args...};
|
||||
ClientPatch::QueuePacket(c, &IMessage::Formatted, GetComponent(c), type, id, a);
|
||||
IMessage::FormattedArgs a = {args...};
|
||||
QueuePacket(c, &IMessage::Formatted, GetClientComponent<IMessage>(c), type, id, a);
|
||||
}
|
||||
}
|
||||
|
||||
static auto CloseMessageString(
|
||||
inline auto BroadcastMessageStringInRadius(
|
||||
Mob* sender, bool ignore_sender = false, float distance = 200.f,
|
||||
Mob* skipped_mob = nullptr, bool is_ack_required = true,
|
||||
eqFilterType filter = FilterNone)
|
||||
@@ -122,29 +175,23 @@ static auto CloseMessageString(
|
||||
return [=]<AllConstChar... Args>(uint32_t type, uint32_t id, Args&&... args)
|
||||
requires (sizeof...(Args) <= 9)
|
||||
{
|
||||
auto queue_close_clients = ClientPatch::QueueCloseClients(sender, ignore_sender, distance, skipped_mob,
|
||||
auto queue_close_clients = QueueCloseClients(sender, ignore_sender, distance, skipped_mob,
|
||||
is_ack_required, filter);
|
||||
|
||||
if constexpr (sizeof...(Args) == 0) {
|
||||
return queue_close_clients(&IMessage::Simple, GetComponent, type, id);
|
||||
return queue_close_clients(&IMessage::Simple, GetClientComponent<IMessage>, type, id);
|
||||
} else {
|
||||
std::array<const char*, 9> a = {args...};
|
||||
return queue_close_clients(&IMessage::Formatted, GetComponent, type, id, a);
|
||||
IMessage::FormattedArgs a = {args...};
|
||||
return queue_close_clients(&IMessage::Formatted, GetClientComponent<IMessage>, type, id, a);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline void InterruptSpell(Client* c, uint32_t message, uint32_t spawn_id, const char* spell_link)
|
||||
{
|
||||
ClientPatch::QueuePacket(c, &IMessage::InterruptSpell, GetComponent(c), message, spawn_id, spell_link);
|
||||
}
|
||||
void InterruptSpell(Client* c, uint32_t message, uint32_t spawn_id, const char* spell_link);
|
||||
void InterruptSpellOther(Mob* sender, uint32_t message, uint32_t spawn_id, const char* name,
|
||||
const char* spell_link);
|
||||
|
||||
inline void InterruptSpellOther(Mob* sender, uint32_t message, uint32_t spawn_id, const char* name,
|
||||
const char* spell_link)
|
||||
{
|
||||
ClientPatch::QueueCloseClients(sender, true, RuleI(Range, SongMessages), nullptr, true,
|
||||
sender->IsClient() ? FilterPCSpells : FilterNPCSpells)(
|
||||
&IMessage::InterruptSpellOther, GetComponent, sender, message, spawn_id, name, spell_link);
|
||||
}
|
||||
void SendFullBuffRefresh(Mob* sender, bool remove = false, bool ackreq = true);
|
||||
void SendSingleBuffChange(Mob* sender, const Buffs_Struct& buff, int slot, bool remove = false, bool ackreq = true);
|
||||
|
||||
} // namespace Message
|
||||
} // namespace ClientPatch
|
||||
|
||||
Reference in New Issue
Block a user