[Tasks] Extend IsTaskCompleted to also be aware of shared task completion (#4714)

* [Tasks] Extend IsTaskCompleted to also be aware of shared task completion

* Fix my stupidity

* Update client.h
This commit is contained in:
Chris Miles 2025-02-24 16:31:35 -06:00 committed by GitHub
parent 80e8634a48
commit fa2ab11676
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 4 deletions

View File

@ -1289,6 +1289,27 @@ public:
void SendSpellTypePrompts(bool commanded_types = false, bool client_only_types = false);
// Task System Methods
inline void LoadClientSharedCompletedTasks()
{
std::string query = fmt::format(R"(
SELECT
cst.task_id
FROM completed_shared_task_members cstm
JOIN completed_shared_tasks cst ON cstm.shared_task_id = cst.id
WHERE cstm.character_id = {}
GROUP BY cst.task_id;
)", CharacterID());
auto results = database.QueryDatabase(query);
if (!results.Success()) {
return;
}
for (auto row = results.begin(); row != results.end(); ++row) {
m_completed_shared_tasks.push_back(std::stoi(row[0]));
}
};
inline std::vector<uint32_t> GetCompletedSharedTasks() const { return m_completed_shared_tasks; };
void LoadClientTaskState();
void RemoveClientTaskState();
void SendTaskActivityComplete(int task_id, int activity_id, int task_index, TaskType task_type, int task_incomplete=1);
@ -1459,7 +1480,10 @@ public:
{
return (task_state ? task_state->EnabledTaskCount(task_set_id) : -1);
}
inline bool IsTaskCompleted(int task_id) { return (task_state ? task_state->IsTaskCompleted(task_id) : false); }
inline bool IsTaskCompleted(int task_id)
{
return (task_state ? task_state->IsTaskCompleted(task_id, this) : false);
}
inline bool AreTasksCompleted(std::vector<int> task_ids)
{
return (task_state ? task_state->AreTasksCompleted(task_ids) : false);
@ -2290,6 +2314,8 @@ private:
bool m_has_quest_compass = false;
std::vector<uint32_t> m_dynamic_zone_ids;
std::vector<uint32_t> m_completed_shared_tasks;
public:
enum BotOwnerOption : size_t {
booDeathMarquee,

View File

@ -952,6 +952,8 @@ int ClientTaskState::IncrementDoneCount(
client->CancelTask(task_index, task_data->type);
}
client->LoadClientSharedCompletedTasks();
}
}
else {
@ -1561,7 +1563,7 @@ int ClientTaskState::TaskTimeLeft(int task_id)
return -1;
}
bool ClientTaskState::IsTaskCompleted(int task_id)
bool ClientTaskState::IsTaskCompleted(int task_id, Client *c)
{
if (!RuleB(TaskSystem, RecordCompletedTasks)) {
return false;
@ -1574,6 +1576,14 @@ bool ClientTaskState::IsTaskCompleted(int task_id)
}
}
if (c) {
for (auto &e: c->GetCompletedSharedTasks()) {
if (e == task_id) {
return true;
}
}
}
return false;
}

View File

@ -45,7 +45,7 @@ public:
void AcceptNewTask(Client *client, int task_id, int npc_type_id, time_t accept_time, bool enforce_level_requirement = false);
void FailTask(Client *client, int task_id);
int TaskTimeLeft(int task_id);
bool IsTaskCompleted(int task_id);
bool IsTaskCompleted(int task_id, Client *c = nullptr);
bool AreTasksCompleted(const std::vector<int>& task_ids);
bool IsTaskActive(int task_id);
bool IsTaskActivityActive(int task_id, int activity_id);

View File

@ -15,8 +15,9 @@ extern QueryServ *QServ;
void Client::LoadClientTaskState()
{
if (RuleB(TaskSystem, EnableTaskSystem) && task_manager) {
safe_delete(task_state);
LoadClientSharedCompletedTasks();
safe_delete(task_state);
task_state = new ClientTaskState();
if (!task_manager->LoadClientState(this, task_state)) {
safe_delete(task_state);