[Commands] Cleanup #task Command. (#2071)

* [Commands] Cleanup #task Command.
- Cleanup messages.
- Add #task uncomplete [Task ID] to uncomplete a completed task without having to go in the database manually.

* Message cleanup.
This commit is contained in:
Kinglykrab 2022-04-13 23:11:20 -04:00 committed by GitHub
parent 9dba6a6680
commit a6814d46de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 294 additions and 99 deletions

View File

@ -4,11 +4,12 @@
extern WorldServer worldserver; extern WorldServer worldserver;
#include "../../common/shared_tasks.h" #include "../../common/shared_tasks.h"
#include "../../common/repositories/completed_tasks_repository.h"
void command_task(Client *c, const Seperator *sep) void command_task(Client *c, const Seperator *sep)
{ {
//super-command for managing tasks int arguments = sep->argnum;
if (sep->arg[1][0] == '\0' || !strcasecmp(sep->arg[1], "help")) { if (!arguments) {
c->Message(Chat::White, "Syntax: #task [subcommand]"); c->Message(Chat::White, "Syntax: #task [subcommand]");
c->Message(Chat::White, "------------------------------------------------"); c->Message(Chat::White, "------------------------------------------------");
c->Message(Chat::White, "# Task System Commands"); c->Message(Chat::White, "# Task System Commands");
@ -22,6 +23,7 @@ void command_task(Client *c, const Seperator *sep)
); );
c->Message(Chat::White, "--- update <task_id> <activity_id> [count] | Updates task"); c->Message(Chat::White, "--- update <task_id> <activity_id> [count] | Updates task");
c->Message(Chat::White, "--- assign <task_id> | Assigns task to client"); c->Message(Chat::White, "--- assign <task_id> | Assigns task to client");
c->Message(Chat::White, "--- uncomplete <task_id> | Uncompletes a task if a client has completed it");
c->Message( c->Message(
Chat::White, Chat::White,
fmt::format( fmt::format(
@ -75,7 +77,6 @@ void command_task(Client *c, const Seperator *sep)
EQ::SayLinkEngine::GenerateQuestSaylink("#task sharedpurge", false, "sharedpurge") EQ::SayLinkEngine::GenerateQuestSaylink("#task sharedpurge", false, "sharedpurge")
).c_str() ).c_str()
); );
return; return;
} }
@ -84,53 +85,190 @@ void command_task(Client *c, const Seperator *sep)
client_target = c->GetTarget()->CastToClient(); client_target = c->GetTarget()->CastToClient();
} }
if (!strcasecmp(sep->arg[1], "show")) { bool is_assign = !strcasecmp(sep->arg[1], "assign");
c->ShowClientTasks(client_target); bool is_purgetimers = !strcasecmp(sep->arg[1], "purgetimers");
bool is_reload = !strcasecmp(sep->arg[1], "reload");
bool is_reloadall = !strcasecmp(sep->arg[1], "reloadall");
bool is_sharedpurge = !strcasecmp(sep->arg[1], "sharedpurge");
bool is_show = !strcasecmp(sep->arg[1], "show");
bool is_uncomplete = !strcasecmp(sep->arg[1], "uncomplete");
bool is_update = !strcasecmp(sep->arg[1], "update");
if (
!is_assign &&
!is_purgetimers &&
!is_reload &&
!is_reloadall &&
!is_sharedpurge &&
!is_show &&
!is_uncomplete &&
!is_update
) {
c->Message(Chat::White, "Syntax: #task [subcommand]");
c->Message(Chat::White, "------------------------------------------------");
c->Message(Chat::White, "# Task System Commands");
c->Message(Chat::White, "------------------------------------------------");
c->Message(
Chat::White,
fmt::format(
"--- [{}] List active tasks for a client",
EQ::SayLinkEngine::GenerateQuestSaylink("#task show", false, "show")
).c_str()
);
c->Message(Chat::White, "--- update <task_id> <activity_id> [count] | Updates task");
c->Message(Chat::White, "--- assign <task_id> | Assigns task to client");
c->Message(Chat::White, "--- uncomplete <task_id> | Uncompletes a task if a client has completed it");
c->Message(
Chat::White,
fmt::format(
"--- [{}] Reload all Task information from the database",
EQ::SayLinkEngine::GenerateQuestSaylink("#task reloadall", false, "reloadall")
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"--- [{}] <task_id> Reload Task and Activity information for a single task",
EQ::SayLinkEngine::GenerateQuestSaylink("#task reload task", false, "reload task")
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"--- [{}] Reload goal/reward list information",
EQ::SayLinkEngine::GenerateQuestSaylink("#task reload lists", false, "reload lists")
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"--- [{}] Reload proximity information",
EQ::SayLinkEngine::GenerateQuestSaylink("#task reload prox", false, "reload prox")
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"--- [{}] Reload task set information",
EQ::SayLinkEngine::GenerateQuestSaylink("#task reload sets", false, "reload sets")
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"--- [{}] Purges targeted characters task timers",
EQ::SayLinkEngine::GenerateQuestSaylink("#task purgetimers", false, "purgetimers")
).c_str()
);
c->Message(Chat::White, "------------------------------------------------");
c->Message(Chat::White, "# Shared Task System Commands");
c->Message(Chat::White, "------------------------------------------------");
c->Message(
Chat::White,
fmt::format(
"--- [{}] Purges all active Shared Tasks in memory and database ",
EQ::SayLinkEngine::GenerateQuestSaylink("#task sharedpurge", false, "sharedpurge")
).c_str()
);
return; return;
} }
if (!strcasecmp(sep->arg[1], "purgetimers")) { if (is_assign) {
c->Message(15, fmt::format("{}'s task timers have been purged", client_target->GetCleanName()).c_str()); auto task_id = std::stoul(sep->arg[2]);
if (client_target != c) { if (task_id && task_id < MAXTASKS) {
client_target->Message(15, "[GM] Your task timers have been purged by a GM"); client_target->AssignTask(task_id, 0, false);
}
client_target->PurgeTaskTimers();
return;
}
if (!strcasecmp(sep->arg[1], "update")) {
if (sep->argnum >= 3) {
int task_id = atoi(sep->arg[2]);
int activity_id = atoi(sep->arg[3]);
int count = 1;
if (sep->argnum >= 4) {
count = atoi(sep->arg[4]);
if (count <= 0) {
count = 1;
}
}
c->Message( c->Message(
Chat::Yellow, Chat::Yellow,
"Updating Task [%i] Activity [%i] Count [%i] for client [%s]", fmt::format(
task_id, "Assigned task ID {} to {}.",
activity_id, task_id,
count, (
client_target->GetCleanName() client_target == c ?
"yourself" :
fmt::format(
"{} ({})",
client_target->GetCleanName(),
client_target->GetID()
)
)
).c_str()
); );
client_target->UpdateTaskActivity(task_id, activity_id, count);
c->ShowClientTasks(client_target);
} }
return; return;
} } else if (is_purgetimers) {
c->Message(
Chat::Yellow,
fmt::format(
"Task timers have been purged for {}.",
(
client_target == c ?
"yourself" :
fmt::format(
"{} ({})",
client_target->GetCleanName(),
client_target->GetID()
)
)
).c_str()
);
if (!strcasecmp(sep->arg[1], "sharedpurge")) { if (client_target != c) {
client_target->Message(Chat::Yellow, "Your task timers have been purged by a GM.");
}
client_target->PurgeTaskTimers();
return;
} else if (is_reload) {
if (arguments >= 2) {
if (!strcasecmp(sep->arg[2], "lists")) {
c->Message(Chat::Yellow, "Attempting to reload goal lists.");
worldserver.SendReloadTasks(RELOADTASKGOALLISTS);
c->Message(Chat::Yellow, "Successfully reloaded goal lists.");
return;
} else if (!strcasecmp(sep->arg[2], "prox")) {
c->Message(Chat::Yellow, "Attempting to reload task proximites.");
worldserver.SendReloadTasks(RELOADTASKPROXIMITIES);
c->Message(Chat::Yellow, "Successfully reloaded task proximites.");
return;
} else if (!strcasecmp(sep->arg[2], "sets")) {
c->Message(Chat::Yellow, "Attempting to reload task sets.");
worldserver.SendReloadTasks(RELOADTASKSETS);
c->Message(Chat::Yellow, "Successfully reloaded task sets.");
return;
} else if (!strcasecmp(sep->arg[2], "task") && arguments == 3) {
int task_id = std::stoul(sep->arg[3]);
if (task_id && task_id < MAXTASKS) {
c->Message(
Chat::Yellow,
fmt::format(
"Attempted to reload task ID {}.",
task_id
).c_str()
);
worldserver.SendReloadTasks(RELOADTASKS, task_id);
c->Message(
Chat::Yellow,
fmt::format(
"Successfully reloaded task ID {}.",
task_id
).c_str()
);
return;
}
}
}
} else if (is_reloadall) {
c->Message(Chat::Yellow, "Attempting to reload tasks.");
worldserver.SendReloadTasks(RELOADTASKS);
c->Message(Chat::Yellow, "Successfully reloaded tasks.");
return;
} else if (is_sharedpurge) {
if (!strcasecmp(sep->arg[2], "confirm")) { if (!strcasecmp(sep->arg[2], "confirm")) {
LogTasksDetail("Sending purge request"); LogTasksDetail("Sending purge request");
auto pack = new ServerPacket(ServerOP_SharedTaskPurgeAllCommand, 0); auto pack = new ServerPacket(ServerOP_SharedTaskPurgeAllCommand, 0);
worldserver.SendPacket(pack); worldserver.SendPacket(pack);
safe_delete(pack); safe_delete(pack);
return; return;
} }
@ -143,56 +281,99 @@ void command_task(Client *c, const Seperator *sep)
); );
return; return;
} } else if (is_show) {
c->ShowClientTasks(client_target);
if (!strcasecmp(sep->arg[1], "assign")) {
int task_id = atoi(sep->arg[2]);
if ((task_id > 0) && (task_id < MAXTASKS)) {
client_target->AssignTask(task_id, 0, false);
c->Message(Chat::Yellow, "Assigned task [%i] to [%s]", task_id, client_target->GetCleanName());
}
return; return;
} } else if (is_uncomplete) {
if (sep->IsNumber(2)) {
if (!strcasecmp(sep->arg[1], "reloadall")) { auto task_id = std::stoul(sep->arg[2]);
c->Message(Chat::Yellow, "Sending reloadtasks to world"); if (task_id && task_id < MAXTASKS) {
worldserver.SendReloadTasks(RELOADTASKS); if (
c->Message(Chat::Yellow, "Back again"); CompletedTasksRepository::DeleteWhere(
return; database,
} fmt::format(
"charid = {} AND taskid = {}",
if (!strcasecmp(sep->arg[1], "reload")) { client_target->CharacterID(),
if (sep->arg[2][0] != '\0') { task_id
if (!strcasecmp(sep->arg[2], "lists")) { )
c->Message(Chat::Yellow, "Sending reload lists to world"); )
worldserver.SendReloadTasks(RELOADTASKGOALLISTS); ) {
c->Message(Chat::Yellow, "Reloaded"); c->Message(
return; Chat::Yellow,
} fmt::format(
if (!strcasecmp(sep->arg[2], "prox")) { "Successfully uncompleted task ID {} for {}.",
c->Message(Chat::Yellow, "Sending reload proximities to world"); task_id,
worldserver.SendReloadTasks(RELOADTASKPROXIMITIES); (
c->Message(Chat::Yellow, "Reloaded"); client_target == c ?
return; "yourself" :
} fmt::format(
if (!strcasecmp(sep->arg[2], "sets")) { "{} ({})",
c->Message(Chat::Yellow, "Sending reload task sets to world"); client_target->GetCleanName(),
worldserver.SendReloadTasks(RELOADTASKSETS); client_target->GetID()
c->Message(Chat::Yellow, "Reloaded"); )
return; )
} ).c_str()
if (!strcasecmp(sep->arg[2], "task") && (sep->arg[3][0] != '\0')) { );
int task_id = atoi(sep->arg[3]); return;
if ((task_id > 0) && (task_id < MAXTASKS)) { } else {
c->Message(Chat::Yellow, "Sending reload task %i to world", task_id); c->Message(
worldserver.SendReloadTasks(RELOADTASKS, task_id); Chat::Yellow,
c->Message(Chat::Yellow, "Reloaded"); fmt::format(
"{} not completed task ID {}.",
(
client_target == c ?
"You have" :
fmt::format(
"{} ({}) has",
client_target->GetCleanName(),
client_target->GetID()
)
),
task_id
).c_str()
);
return; return;
} }
} else {
c->Message(Chat::White, "Invalid task ID specified.");
return;
} }
} }
} else if (is_update) {
if (arguments >= 3) {
auto task_id = std::stoul(sep->arg[2]);
auto activity_id = std::stoul(sep->arg[3]);
int count = 1;
if (arguments >= 4) {
count = std::stoi(sep->arg[4]);
if (count <= 0) {
count = 1;
}
}
c->Message(
Chat::Yellow,
fmt::format(
"Updating task ID {}, activity {} with a count of {} for {}.",
task_id,
activity_id,
count,
(
client_target == c ?
"yourself" :
fmt::format(
"{} ({})",
client_target->GetCleanName(),
client_target->GetID()
)
)
).c_str()
);
client_target->UpdateTaskActivity(task_id, activity_id, count);
c->ShowClientTasks(client_target);
}
return;
} }
c->Message(Chat::White, "Unable to interpret command. Type #task help");
} }

View File

@ -1682,22 +1682,27 @@ void ClientTaskState::ShowClientTaskInfoMessage(ClientTaskInformation *task, Cli
c->Message(Chat::White, "------------------------------------------------"); c->Message(Chat::White, "------------------------------------------------");
c->Message( c->Message(
Chat::White, "# [%s] | task_id [%i] title [%s] slot (%i)", Chat::White,
Tasks::GetTaskTypeDescription(task_data->type).c_str(), fmt::format(
task->task_id, "Task {} | Title: {} ID: {} Type: {}",
task_data->title.c_str(), task->slot,
task->slot task_data->title,
task->task_id,
Tasks::GetTaskTypeDescription(task_data->type)
).c_str()
); );
c->Message(Chat::White, "------------------------------------------------"); c->Message(Chat::White, "------------------------------------------------");
c->Message( c->Message(
Chat::White, Chat::White,
" -- Description [%s]\n", fmt::format(
task_data->description.c_str() "Description | {}",
task_data->description
).c_str()
); );
for (int activity_id = 0; activity_id < task_manager->GetActivityCount(task->task_id); activity_id++) { for (int activity_id = 0; activity_id < task_manager->GetActivityCount(task->task_id); activity_id++) {
std::vector<std::string> update_increments = {"1", "5", "50"}; std::vector<std::string> update_increments = { "1", "5", "10", "20", "50" };
std::string update_saylinks; std::vector<std::string> update_saylinks;
for (auto &increment: update_increments) { for (auto &increment: update_increments) {
auto task_update_saylink = EQ::SayLinkEngine::GenerateQuestSaylink( auto task_update_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
@ -1711,17 +1716,19 @@ void ClientTaskState::ShowClientTaskInfoMessage(ClientTaskInformation *task, Cli
increment increment
); );
update_saylinks += "[" + task_update_saylink + "] "; update_saylinks.push_back(task_update_saylink);
} }
c->Message( c->Message(
Chat::White, Chat::White,
" --- Update %s activity_id [%i] done_count [%i] state [%d] (%s)", fmt::format(
update_saylinks.c_str(), "Activity {} | Count: {} State: {} ({}) [{}]",
task->activity[activity_id].activity_id, task->activity[activity_id].activity_id,
task->activity[activity_id].done_count, task->activity[activity_id].done_count,
task->activity[activity_id].activity_state, task->activity[activity_id].activity_state,
Tasks::GetActivityStateDescription(task->activity[activity_id].activity_state).c_str() Tasks::GetActivityStateDescription(task->activity[activity_id].activity_state),
implode(" | ", update_saylinks)
).c_str()
); );
} }
} }
@ -1729,8 +1736,15 @@ void ClientTaskState::ShowClientTaskInfoMessage(ClientTaskInformation *task, Cli
void ClientTaskState::ShowClientTasks(Client *client) void ClientTaskState::ShowClientTasks(Client *client)
{ {
client->Message(Chat::White, "------------------------------------------------"); client->Message(Chat::White, "------------------------------------------------");
client->Message(Chat::White, "# Task Information | Client [%s]", client->GetCleanName()); client->Message(
// client->Message(Chat::White, "------------------------------------------------"); Chat::White,
fmt::format(
"Task Information for {} ({})",
client->GetCleanName(),
client->GetID()
).c_str()
);
if (m_active_task.task_id != TASKSLOTEMPTY) { if (m_active_task.task_id != TASKSLOTEMPTY) {
ShowClientTaskInfoMessage(&m_active_task, client); ShowClientTaskInfoMessage(&m_active_task, client);
} }