[Quest API] (Performance) Check event exists before export and execute area events (#2888)

* [Quest API] Optionally parse area events

# Notes
- Optionally parse these events instead of always doing so.

* Update entity.cpp
This commit is contained in:
Alex King 2023-02-12 23:01:28 -05:00 committed by GitHub
parent 5ac5beb456
commit cfec31457c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3992,29 +3992,43 @@ void EntityList::ProcessMove(Client *c, const glm::vec3& location)
for (auto iter = events.begin(); iter != events.end(); ++iter) {
quest_proximity_event& evt = (*iter);
std::vector<std::any> args;
args.push_back(&evt.area_id);
args.push_back(&evt.area_type);
std::vector<std::any> args = { &evt.area_id, &evt.area_type };
if (evt.npc) {
if (evt.event_id == EVENT_ENTER) {
parse->EventNPC(EVENT_ENTER, evt.npc, evt.client, "", 0);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_ENTER)) {
parse->EventNPC(EVENT_ENTER, evt.npc, evt.client, "", 0);
}
} else if (evt.event_id == EVENT_EXIT) {
parse->EventNPC(EVENT_EXIT, evt.npc, evt.client, "", 0);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_EXIT)) {
parse->EventNPC(EVENT_EXIT, evt.npc, evt.client, "", 0);
}
} else if (evt.event_id == EVENT_ENTER_AREA) {
parse->EventNPC(EVENT_ENTER_AREA, evt.npc, evt.client, "", 0, &args);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_ENTER_AREA)) {
parse->EventNPC(EVENT_ENTER_AREA, evt.npc, evt.client, "", 0, &args);
}
} else if (evt.event_id == EVENT_LEAVE_AREA) {
parse->EventNPC(EVENT_LEAVE_AREA, evt.npc, evt.client, "", 0, &args);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_LEAVE_AREA)) {
parse->EventNPC(EVENT_LEAVE_AREA, evt.npc, evt.client, "", 0, &args);
}
}
} else {
if (evt.event_id == EVENT_ENTER) {
parse->EventPlayer(EVENT_ENTER, evt.client, "", 0);
if (parse->PlayerHasQuestSub(EVENT_ENTER)) {
parse->EventPlayer(EVENT_ENTER, evt.client, "", 0);
}
} else if (evt.event_id == EVENT_EXIT) {
parse->EventPlayer(EVENT_EXIT, evt.client, "", 0);
if (parse->PlayerHasQuestSub(EVENT_EXIT)) {
parse->EventPlayer(EVENT_EXIT, evt.client, "", 0);
}
} else if (evt.event_id == EVENT_ENTER_AREA) {
parse->EventPlayer(EVENT_ENTER_AREA, evt.client, "", 0, &args);
if (parse->PlayerHasQuestSub(EVENT_ENTER_AREA)) {
parse->EventPlayer(EVENT_ENTER_AREA, evt.client, "", 0, &args);
}
} else if (evt.event_id == EVENT_LEAVE_AREA) {
parse->EventPlayer(EVENT_LEAVE_AREA, evt.client, "", 0, &args);
if (parse->PlayerHasQuestSub(EVENT_LEAVE_AREA)) {
parse->EventPlayer(EVENT_LEAVE_AREA, evt.client, "", 0, &args);
}
}
}
}
@ -4027,20 +4041,22 @@ void EntityList::ProcessMove(NPC *n, float x, float y, float z) {
std::list<quest_proximity_event> events;
for (auto iter = area_list.begin(); iter != area_list.end(); ++iter) {
Area &a = (*iter);
for (const auto& a : area_list) {
bool old_in = true;
bool new_in = true;
if (last_x < a.min_x || last_x > a.max_x ||
last_y < a.min_y || last_y > a.max_y ||
last_z < a.min_z || last_z > a.max_z) {
if (
!EQ::ValueWithin(last_x, a.min_x, a.max_x) ||
!EQ::ValueWithin(last_y, a.min_y, a.max_y) ||
!EQ::ValueWithin(last_z, a.min_z, a.max_z)
) {
old_in = false;
}
if (x < a.min_x || x > a.max_x ||
y < a.min_y || y > a.max_y ||
z < a.min_z || z > a.max_z) {
if (
!EQ::ValueWithin(x, a.min_x, a.max_x) ||
!EQ::ValueWithin(y, a.min_y, a.max_y) ||
!EQ::ValueWithin(z, a.min_z, a.max_z)
) {
new_in = false;
}
@ -4052,7 +4068,7 @@ void EntityList::ProcessMove(NPC *n, float x, float y, float z) {
evt.npc = n;
evt.area_id = a.id;
evt.area_type = a.type;
events.push_back(evt);
events.emplace_back(evt);
}
else if (!old_in && new_in) {
//were not in but now are
@ -4062,25 +4078,29 @@ void EntityList::ProcessMove(NPC *n, float x, float y, float z) {
evt.npc = n;
evt.area_id = a.id;
evt.area_type = a.type;
events.push_back(evt);
events.emplace_back(evt);
}
}
for (auto iter = events.begin(); iter != events.end(); ++iter) {
quest_proximity_event &evt = (*iter);
std::vector<std::any> args;
args.push_back(&evt.area_id);
args.push_back(&evt.area_type);
for (const auto& evt : events) {
std::vector<std::any> args = { &evt.area_id, &evt.area_type };
if (evt.event_id == EVENT_ENTER) {
parse->EventNPC(EVENT_ENTER, evt.npc, evt.client, "", 0);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_ENTER)) {
parse->EventNPC(EVENT_ENTER, evt.npc, evt.client, "", 0);
}
} else if (evt.event_id == EVENT_EXIT) {
parse->EventNPC(EVENT_EXIT, evt.npc, evt.client, "", 0);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_EXIT)) {
parse->EventNPC(EVENT_EXIT, evt.npc, evt.client, "", 0);
}
} else if (evt.event_id == EVENT_ENTER_AREA) {
parse->EventNPC(EVENT_ENTER_AREA, evt.npc, evt.client, "", 0, &args);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_ENTER_AREA)) {
parse->EventNPC(EVENT_ENTER_AREA, evt.npc, evt.client, "", 0, &args);
}
} else if (evt.event_id == EVENT_LEAVE_AREA) {
parse->EventNPC(EVENT_LEAVE_AREA, evt.npc, evt.client, "", 0, &args);
if (parse->HasQuestSub(evt.npc->GetNPCTypeID(), EVENT_LEAVE_AREA)) {
parse->EventNPC(EVENT_LEAVE_AREA, evt.npc, evt.client, "", 0, &args);
}
}
}
}