From f9a87e26c9bf5056b4cdec7d8668858d9a002450 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sun, 12 Feb 2023 22:54:20 -0500 Subject: [PATCH] [Quest API] (Performance) Check event exists before export and execute EVENT_AGGRO_SAY, EVENT_SAY, and EVENT_PROXIMITY_SAY (#2882) * [Quest API] Add optional parsing to EVENT_AGGRO_SAY and EVENT_SAY # Notes - Optionally parse these events instead of always doing so. * Optionally parse EVENT_PROXIMITY_SAY --- zone/client.cpp | 23 ++++++++++++++++------- zone/entity.cpp | 29 ++++++++++++++++++----------- zone/entity.h | 2 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 5a4bdcc2f..efd944d21 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -1199,7 +1199,9 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s entity_list.ChannelMessage(sender, chan_num, language, lang_skill, message); } - parse->EventPlayer(EVENT_SAY, this, message, language); + if (parse->PlayerHasQuestSub(EVENT_SAY)) { + parse->EventPlayer(EVENT_SAY, this, message, language); + } if (sender != this) { break; @@ -1220,8 +1222,9 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s CheckEmoteHail(t, message); if (DistanceNoZ(m_Position, t->GetPosition()) <= RuleI(Range, Say)) { - - parse->EventNPC(EVENT_SAY, t, this, message, language); + if (parse->HasQuestSub(t->GetNPCTypeID(), EVENT_SAY)) { + parse->EventNPC(EVENT_SAY, t, this, message, language); + } if (RuleB(TaskSystem, EnableTaskSystem)) { if (UpdateTasksOnSpeakWith(t)) { @@ -1230,8 +1233,10 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s } } } else { - if (DistanceSquaredNoZ(m_Position, t->GetPosition()) <= RuleI(Range, Say)) { - parse->EventNPC(EVENT_AGGRO_SAY, t, this, message, language); + if (parse->HasQuestSub(t->GetNPCTypeID(), EVENT_AGGRO_SAY)) { + if (DistanceSquaredNoZ(m_Position, t->GetPosition()) <= RuleI(Range, Say)) { + parse->EventNPC(EVENT_AGGRO_SAY, t, this, message, language); + } } } @@ -1239,9 +1244,13 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s else if (GetTarget() && GetTarget()->IsBot() && !IsInvisible(GetTarget())) { if (DistanceNoZ(m_Position, GetTarget()->GetPosition()) <= RuleI(Range, Say)) { if (GetTarget()->IsEngaged()) { - parse->EventBot(EVENT_AGGRO_SAY, GetTarget()->CastToBot(), this, message, language); + if (parse->BotHasQuestSub(EVENT_AGGRO_SAY)) { + parse->EventBot(EVENT_AGGRO_SAY, GetTarget()->CastToBot(), this, message, language); + } } else { - parse->EventBot(EVENT_SAY, GetTarget()->CastToBot(), this, message, language); + if (parse->BotHasQuestSub(EVENT_SAY)) { + parse->EventBot(EVENT_SAY, GetTarget()->CastToBot(), this, message, language); + } } } } diff --git a/zone/entity.cpp b/zone/entity.cpp index c141d392f..449c1febc 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -4134,24 +4134,31 @@ void EntityList::ClearAreas() area_list.clear(); } -void EntityList::ProcessProximitySay(const char *Message, Client *c, uint8 language) +void EntityList::ProcessProximitySay(const char *message, Client *c, uint8 language) { - if (!Message || !c) + if (!message || !c) { return; + } - auto iter = proximity_list.begin(); - for (; iter != proximity_list.end(); ++iter) { - NPC *d = (*iter); - NPCProximity *l = d->proximity; - if (l == nullptr || !l->say) + for (const auto& n : proximity_list) { + auto* p = n->proximity; + if (!p || !p->say) { continue; + } - if (c->GetX() < l->min_x || c->GetX() > l->max_x - || c->GetY() < l->min_y || c->GetY() > l->max_y - || c->GetZ() < l->min_z || c->GetZ() > l->max_z) + if (!parse->HasQuestSub(n->GetNPCTypeID(), EVENT_PROXIMITY_SAY)) { continue; + } - parse->EventNPC(EVENT_PROXIMITY_SAY, d, c, Message, language); + if ( + !EQ::ValueWithin(c->GetX(), p->min_x, p->max_x) || + !EQ::ValueWithin(c->GetY(), p->min_y, p->max_y) || + !EQ::ValueWithin(c->GetZ(), p->min_z, p->max_z) + ) { + continue; + } + + parse->EventNPC(EVENT_PROXIMITY_SAY, n, c, message, language); } } diff --git a/zone/entity.h b/zone/entity.h index cb04bf619..ffd6c4c39 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -263,7 +263,7 @@ public: void RemoveArea(int id); void ClearAreas(); void ReloadMerchants(); - void ProcessProximitySay(const char *Message, Client *c, uint8 language = 0); + void ProcessProximitySay(const char *message, Client *c, uint8 language = 0); void SendAATimer(uint32 charid,UseAA_Struct* uaa); Doors *FindDoor(uint8 door_id); Object *FindObject(uint32 object_id);