mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-09 17:32:29 +00:00
More refactors
This commit is contained in:
parent
fac75a3ae0
commit
65f2f823a8
164
zone/tasks.cpp
164
zone/tasks.cpp
@ -46,6 +46,7 @@ Copyright (C) 2001-2008 EQEMu Development Team (http://eqemulator.net)
|
|||||||
#include "../common/repositories/task_activities_repository.h"
|
#include "../common/repositories/task_activities_repository.h"
|
||||||
#include "../common/repositories/character_activities_repository.h"
|
#include "../common/repositories/character_activities_repository.h"
|
||||||
#include "../common/repositories/character_tasks_repository.h"
|
#include "../common/repositories/character_tasks_repository.h"
|
||||||
|
#include "../common/repositories/proximities_repository.h"
|
||||||
|
|
||||||
extern QueryServ *QServ;
|
extern QueryServ *QServ;
|
||||||
|
|
||||||
@ -3745,8 +3746,8 @@ void ClientTaskState::AcceptNewTask(Client *client, int task_id, int npc_type_id
|
|||||||
|
|
||||||
// only Quests can have more than one, so don't need to check others
|
// only Quests can have more than one, so don't need to check others
|
||||||
if (task->type == TaskType::Quest) {
|
if (task->type == TaskType::Quest) {
|
||||||
for (int i = 0; i < MAXACTIVEQUESTS; i++) {
|
for (auto &active_quest : active_quests) {
|
||||||
if (active_quests[i].task_id == task_id) {
|
if (active_quest.task_id == task_id) {
|
||||||
client->Message(Chat::Red, "You have already been assigned this task.");
|
client->Message(Chat::Red, "You have already been assigned this task.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3805,11 +3806,11 @@ void ClientTaskState::AcceptNewTask(Client *client, int task_id, int npc_type_id
|
|||||||
active_slot->updated = true;
|
active_slot->updated = true;
|
||||||
active_slot->current_step = -1;
|
active_slot->current_step = -1;
|
||||||
|
|
||||||
for (int i = 0; i < p_task_manager->p_task_data[task_id]->activity_count; i++) {
|
for (int activity_id = 0; activity_id < p_task_manager->p_task_data[task_id]->activity_count; activity_id++) {
|
||||||
active_slot->activity[i].activity_id = i;
|
active_slot->activity[activity_id].activity_id = activity_id;
|
||||||
active_slot->activity[i].done_count = 0;
|
active_slot->activity[activity_id].done_count = 0;
|
||||||
active_slot->activity[i].activity_state = ActivityHidden;
|
active_slot->activity[activity_id].activity_state = ActivityHidden;
|
||||||
active_slot->activity[i].updated = true;
|
active_slot->activity[activity_id].updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnlockActivities(client->CharacterID(), *active_slot);
|
UnlockActivities(client->CharacterID(), *active_slot);
|
||||||
@ -3822,7 +3823,8 @@ void ClientTaskState::AcceptNewTask(Client *client, int task_id, int npc_type_id
|
|||||||
client->Message(
|
client->Message(
|
||||||
Chat::White,
|
Chat::White,
|
||||||
"You have been assigned the task '%s'.",
|
"You have been assigned the task '%s'.",
|
||||||
p_task_manager->p_task_data[task_id]->title.c_str());
|
p_task_manager->p_task_data[task_id]->title.c_str()
|
||||||
|
);
|
||||||
p_task_manager->SaveClientState(client, this);
|
p_task_manager->SaveClientState(client, this);
|
||||||
std::string buf = std::to_string(task_id);
|
std::string buf = std::to_string(task_id);
|
||||||
|
|
||||||
@ -3834,25 +3836,26 @@ void ClientTaskState::AcceptNewTask(Client *client, int task_id, int npc_type_id
|
|||||||
|
|
||||||
void ClientTaskState::ProcessTaskProximities(Client *client, float x, float y, float z)
|
void ClientTaskState::ProcessTaskProximities(Client *client, float x, float y, float z)
|
||||||
{
|
{
|
||||||
|
float last_x = client->ProximityX();
|
||||||
|
float last_y = client->ProximityY();
|
||||||
|
float last_z = client->ProximityZ();
|
||||||
|
|
||||||
float LastX = client->ProximityX();
|
if ((last_x == x) && (last_y == y) && (last_z == z)) {
|
||||||
float LastY = client->ProximityY();
|
return;
|
||||||
float LastZ = client->ProximityZ();
|
}
|
||||||
|
|
||||||
if ((LastX == x) && (LastY == y) && (LastZ == z)) { return; }
|
LogTasksDetail("[ProcessTaskProximities] Checking proximities for Position x[{}] y[{}] z[{}]", x, y, z);
|
||||||
|
int explore_id = p_task_manager->proximity_manager.CheckProximities(x, y, z);
|
||||||
Log(Logs::General, Logs::Tasks, "[PROXIMITY] Checking proximities for Position %8.3f, %8.3f, %8.3f", x, y, z);
|
if (explore_id > 0) {
|
||||||
int ExploreID = p_task_manager->proximity_manager.CheckProximities(x, y, z);
|
LogTasksDetail(
|
||||||
|
"[ProcessTaskProximities] Position x[{}] y[{}] z[{}] is within proximity explore_id [{}]",
|
||||||
if (ExploreID > 0) {
|
|
||||||
Log(Logs::General,
|
|
||||||
Logs::Tasks,
|
|
||||||
"[PROXIMITY] Position %8.3f, %8.3f, %8.3f is within proximity %i",
|
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z,
|
z,
|
||||||
ExploreID);
|
explore_id
|
||||||
UpdateTasksOnExplore(client, ExploreID);
|
);
|
||||||
|
|
||||||
|
UpdateTasksOnExplore(client, explore_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3866,14 +3869,9 @@ TaskGoalListManager::~TaskGoalListManager() {}
|
|||||||
bool TaskGoalListManager::LoadLists()
|
bool TaskGoalListManager::LoadLists()
|
||||||
{
|
{
|
||||||
task_goal_lists.clear();
|
task_goal_lists.clear();
|
||||||
|
|
||||||
const char *ERR_MYSQLERROR = "Error in TaskGoalListManager::LoadLists: %s %s";
|
|
||||||
|
|
||||||
goal_lists_count = 0;
|
goal_lists_count = 0;
|
||||||
|
|
||||||
std::string query = "SELECT `listid`, COUNT(`entry`) "
|
std::string query = "SELECT `listid`, COUNT(`entry`) FROM `goallists` GROUP by `listid` ORDER BY `listid`";
|
||||||
"FROM `goallists` GROUP by `listid` "
|
|
||||||
"ORDER BY `listid`";
|
|
||||||
auto results = content_db.QueryDatabase(query);
|
auto results = content_db.QueryDatabase(query);
|
||||||
if (!results.Success()) {
|
if (!results.Success()) {
|
||||||
return false;
|
return false;
|
||||||
@ -3886,12 +3884,12 @@ bool TaskGoalListManager::LoadLists()
|
|||||||
|
|
||||||
int list_index = 0;
|
int list_index = 0;
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
int listID = atoi(row[0]);
|
int list_id = atoi(row[0]);
|
||||||
int listSize = atoi(row[1]);
|
int list_size = atoi(row[1]);
|
||||||
|
|
||||||
task_goal_lists.push_back({listID, 0, 0});
|
task_goal_lists.push_back({list_id, 0, 0});
|
||||||
|
|
||||||
task_goal_lists[list_index].GoalItemEntries.reserve(listSize);
|
task_goal_lists[list_index].GoalItemEntries.reserve(list_size);
|
||||||
|
|
||||||
list_index++;
|
list_index++;
|
||||||
}
|
}
|
||||||
@ -3946,51 +3944,56 @@ int TaskGoalListManager::GetListByID(int list_id)
|
|||||||
|
|
||||||
int TaskGoalListManager::GetFirstEntry(int list_id)
|
int TaskGoalListManager::GetFirstEntry(int list_id)
|
||||||
{
|
{
|
||||||
int ListIndex = GetListByID(list_id);
|
int list_by_id = GetListByID(list_id);
|
||||||
|
|
||||||
if ((ListIndex < 0) || (ListIndex >= goal_lists_count)) { return -1; }
|
if ((list_by_id < 0) || (list_by_id >= goal_lists_count)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (task_goal_lists[ListIndex].GoalItemEntries.empty()) { return -1; }
|
if (task_goal_lists[list_by_id].GoalItemEntries.empty()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return task_goal_lists[ListIndex].GoalItemEntries[0];
|
return task_goal_lists[list_by_id].GoalItemEntries[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> TaskGoalListManager::GetListContents(int list_index)
|
std::vector<int> TaskGoalListManager::GetListContents(int list_index)
|
||||||
{
|
{
|
||||||
std::vector<int> ListContents;
|
std::vector<int> list_contents;
|
||||||
int ListIndex = GetListByID(list_index);
|
int list_by_id = GetListByID(list_index);
|
||||||
|
|
||||||
if ((ListIndex < 0) || (ListIndex >= goal_lists_count)) { return ListContents; }
|
if ((list_by_id < 0) || (list_by_id >= goal_lists_count)) {
|
||||||
|
return list_contents;
|
||||||
|
}
|
||||||
|
|
||||||
ListContents = task_goal_lists[ListIndex].GoalItemEntries;
|
list_contents = task_goal_lists[list_by_id].GoalItemEntries;
|
||||||
|
|
||||||
return ListContents;
|
return list_contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskGoalListManager::IsInList(int list_id, int entry)
|
bool TaskGoalListManager::IsInList(int list_id, int entry)
|
||||||
{
|
{
|
||||||
Log(Logs::General, Logs::Tasks, "[UPDATE] TaskGoalListManager::IsInList(%i, %i)", list_id, entry);
|
Log(Logs::General, Logs::Tasks, "[UPDATE] TaskGoalListManager::IsInList(%i, %i)", list_id, entry);
|
||||||
|
|
||||||
int ListIndex = GetListByID(list_id);
|
int list_index = GetListByID(list_id);
|
||||||
|
|
||||||
if ((ListIndex < 0) || (ListIndex >= goal_lists_count)) {
|
if ((list_index < 0) || (list_index >= goal_lists_count)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((entry < task_goal_lists[ListIndex].Min) || (entry > task_goal_lists[ListIndex].Max)) {
|
if ((entry < task_goal_lists[list_index].Min) || (entry > task_goal_lists[list_index].Max)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FirstEntry = 0;
|
int first_entry = 0;
|
||||||
auto &task = task_goal_lists[ListIndex];
|
auto &task = task_goal_lists[list_index];
|
||||||
|
auto it = std::find(task.GoalItemEntries.begin(), task.GoalItemEntries.end(), entry);
|
||||||
auto it = std::find(task.GoalItemEntries.begin(), task.GoalItemEntries.end(), entry);
|
|
||||||
|
|
||||||
if (it == task.GoalItemEntries.end()) {
|
if (it == task.GoalItemEntries.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(Logs::General, Logs::Tasks, "[UPDATE] TaskGoalListManager::IsInList(%i, %i) returning true", ListIndex,
|
Log(Logs::General, Logs::Tasks, "[UPDATE] TaskGoalListManager::IsInList(%i, %i) returning true", list_index,
|
||||||
entry);
|
entry);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -4009,65 +4012,58 @@ TaskProximityManager::~TaskProximityManager()
|
|||||||
|
|
||||||
bool TaskProximityManager::LoadProximities(int zone_id)
|
bool TaskProximityManager::LoadProximities(int zone_id)
|
||||||
{
|
{
|
||||||
TaskProximity proximity;
|
TaskProximity proximity{};
|
||||||
|
|
||||||
Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] TaskProximityManager::LoadProximities Called for zone %i", zone_id);
|
|
||||||
task_proximities.clear();
|
task_proximities.clear();
|
||||||
|
|
||||||
std::string query = StringFormat(
|
auto proximities = ProximitiesRepository::GetWhere(
|
||||||
"SELECT `exploreid`, `minx`, `maxx`, "
|
content_db,
|
||||||
"`miny`, `maxy`, `minz`, `maxz` "
|
fmt::format("zoneid = {} ORDER BY `zoneid` ASC", zone_id)
|
||||||
"FROM `proximities` WHERE `zoneid` = %i "
|
|
||||||
"ORDER BY `zoneid` ASC", zone_id
|
|
||||||
);
|
);
|
||||||
auto results = content_db.QueryDatabase(query);
|
|
||||||
if (!results.Success()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
for (auto &row: proximities) {
|
||||||
proximity.explore_id = atoi(row[0]);
|
proximity.explore_id = row.exploreid;
|
||||||
proximity.min_x = atof(row[1]);
|
proximity.min_x = row.minx;
|
||||||
proximity.max_x = atof(row[2]);
|
proximity.max_x = row.maxx;
|
||||||
proximity.min_y = atof(row[3]);
|
proximity.min_y = row.miny;
|
||||||
proximity.max_y = atof(row[4]);
|
proximity.max_y = row.maxy;
|
||||||
proximity.min_z = atof(row[5]);
|
proximity.min_z = row.minz;
|
||||||
proximity.max_z = atof(row[6]);
|
proximity.max_z = row.maxz;
|
||||||
|
|
||||||
task_proximities.push_back(proximity);
|
task_proximities.push_back(proximity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
LogTasks("Loaded [{}] Task Proximities", proximities.size());
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TaskProximityManager::CheckProximities(float x, float y, float z)
|
int TaskProximityManager::CheckProximities(float x, float y, float z)
|
||||||
{
|
{
|
||||||
|
for (auto &task_proximity : task_proximities) {
|
||||||
|
|
||||||
for (unsigned int i = 0; i < task_proximities.size(); i++) {
|
TaskProximity *p_proximity = &task_proximity;
|
||||||
|
|
||||||
TaskProximity *P = &task_proximities[i];
|
Log(
|
||||||
|
Logs::General,
|
||||||
Log(Logs::General,
|
|
||||||
Logs::Tasks,
|
Logs::Tasks,
|
||||||
"[PROXIMITY] Checking %8.3f, %8.3f, %8.3f against %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f",
|
"[PROXIMITY] Checking %8.3f, %8.3f, %8.3f against %8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f",
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z,
|
z,
|
||||||
P->min_x,
|
p_proximity->min_x,
|
||||||
P->max_x,
|
p_proximity->max_x,
|
||||||
P->min_y,
|
p_proximity->min_y,
|
||||||
P->max_y,
|
p_proximity->max_y,
|
||||||
P->min_z,
|
p_proximity->min_z,
|
||||||
P->max_z);
|
p_proximity->max_z
|
||||||
|
);
|
||||||
|
|
||||||
if (x < P->min_x || x > P->max_x || y < P->min_y || y > P->max_y ||
|
if (x < p_proximity->min_x || x > p_proximity->max_x || y < p_proximity->min_y || y > p_proximity->max_y ||
|
||||||
z < P->min_z || z > P->max_z) {
|
z < p_proximity->min_z || z > p_proximity->max_z) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return P->explore_id;
|
return p_proximity->explore_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user