From 91c451b6c588338357e86b85f003401b336dcca6 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Fri, 1 Oct 2021 18:42:02 -0500 Subject: [PATCH] Shared task kill update fix --- zone/task_client_state.cpp | 178 ++++++++++++++++++++----------------- 1 file changed, 98 insertions(+), 80 deletions(-) diff --git a/zone/task_client_state.cpp b/zone/task_client_state.cpp index e00960238..e3ed80637 100644 --- a/zone/task_client_state.cpp +++ b/zone/task_client_state.cpp @@ -2739,110 +2739,128 @@ void ClientTaskState::SyncSharedTaskZoneClientDoneCountState( void ClientTaskState::HandleUpdateTasksOnKill(Client *client, uint32 npc_type_id) { - if (!HasActiveTasks()) { - return; + + // get clients to update + std::vector clients_to_update = {}; + + // raid + Raid *raid = entity_list.GetRaidByClient(client); + if (raid) { + for (auto &e : raid->members) { + if (e.member && e.member->IsClient()) { + clients_to_update.push_back(e.member->CastToClient()); + } + } } - // loop over the union of tasks and quests - for (auto &active_task : m_active_tasks) { - auto current_task = &active_task; - if (current_task->task_id == TASKSLOTEMPTY) { + // group + if (!clients_to_update.empty()) { + Group *group = entity_list.GetGroupByClient(client); + if (group) { + for (auto &m : group->members) { + if (m && m->IsClient()) { + clients_to_update.push_back(m->CastToClient()); + } + } + } + } + + // solo + if (!clients_to_update.empty()) { + clients_to_update.push_back(client); + } + + for (auto &c: clients_to_update) { + if (c->ClientDataLoaded()) { continue; } - // Check if there are any active kill activities for this p_task_data - auto p_task_data = task_manager->m_task_data[current_task->task_id]; - if (p_task_data == nullptr) { - return; - } + LogTasksDetail("[HandleUpdateTasksOnKill] Looping through client [{}]", c->GetCleanName()); - for (int activity_id = 0; activity_id < p_task_data->activity_count; activity_id++) { - ClientActivityInformation *client_activity = ¤t_task->activity[activity_id]; - ActivityInformation *activity_info = &p_task_data->activity_information[activity_id]; - - // We are not interested in completed or hidden activities - if (client_activity->activity_state != ActivityActive) { + // loop over the union of tasks and quests + for (auto &active_task : c->GetTaskState()->m_active_tasks) { + auto current_task = &active_task; + if (current_task->task_id == TASKSLOTEMPTY) { continue; } - // We are only interested in Kill activities - if (activity_info->activity_type != TaskActivityType::Kill) { - continue; + // Check if there are any active kill activities for this p_task_data + auto p_task_data = task_manager->m_task_data[current_task->task_id]; + if (p_task_data == nullptr) { + return; } - // Is there a zone restriction on the activity_information ? - if (!activity_info->CheckZone(zone->GetZoneID())) { - LogTasks( - "[HandleUpdateTasksOnKill] character [{}] task_id [{}] activity_id [{}] activity_type [{}] for NPC [{}] failed zone check", - client->GetName(), - current_task->task_id, - activity_id, - static_cast(TaskActivityType::Kill), - npc_type_id - ); - continue; - } - // Is the activity_information to kill this type of NPC ? - switch (activity_info->goal_method) { - case METHODSINGLEID: - if (activity_info->goal_id != npc_type_id) { - LogTasksDetail("[HandleUpdateTasksOnKill] Matched single goal"); - continue; - } - break; + for (int activity_id = 0; activity_id < p_task_data->activity_count; activity_id++) { + ClientActivityInformation *client_activity = ¤t_task->activity[activity_id]; + ActivityInformation *activity_info = &p_task_data->activity_information[activity_id]; - case METHODLIST: - if (!task_manager->m_goal_list_manager.IsInList( - activity_info->goal_id, - (int) npc_type_id - )) { - LogTasksDetail("[HandleUpdateTasksOnKill] Matched list goal"); - continue; - } - break; - - default: - // If METHODQUEST, don't updated the activity_information here + // We are not interested in completed or hidden activities + if (client_activity->activity_state != ActivityActive) { continue; - } + } - LogTasksDetail("[HandleUpdateTasksOnKill] passed checks"); + // We are only interested in Kill activities + if (activity_info->activity_type != TaskActivityType::Kill) { + continue; + } - // handle actual update - // legacy eqemu task update logic loops through group on kill of npc to update a single task - if (p_task_data->type != TaskType::Shared) { - LogTasksDetail("[HandleUpdateTasksOnKill] Non-Shared Update"); - - Raid *raid = entity_list.GetRaidByClient(client); - if (raid) { - for (auto &e : raid->members) { - if (e.member && e.member->IsClient()) { - Client *c = e.member->CastToClient(); - c->UpdateTasksOnKill(npc_type_id); + // Is there a zone restriction on the activity_information ? + if (!activity_info->CheckZone(zone->GetZoneID())) { + LogTasks( + "[HandleUpdateTasksOnKill] character [{}] task_id [{}] activity_id [{}] activity_type [{}] for NPC [{}] failed zone check", + client->GetName(), + current_task->task_id, + activity_id, + static_cast(TaskActivityType::Kill), + npc_type_id + ); + continue; + } + // Is the activity_information to kill this type of NPC ? + switch (activity_info->goal_method) { + case METHODSINGLEID: + if (activity_info->goal_id != npc_type_id) { + LogTasksDetail("[HandleUpdateTasksOnKill] Matched single goal"); + continue; } - } + break; + + case METHODLIST: + if (!task_manager->m_goal_list_manager.IsInList( + activity_info->goal_id, + (int) npc_type_id + )) { + LogTasksDetail("[HandleUpdateTasksOnKill] Matched list goal"); + continue; + } + break; + + default: + // If METHODQUEST, don't updated the activity_information here + continue; + } + + LogTasksDetail("[HandleUpdateTasksOnKill] passed checks"); + + // handle actual update + // legacy eqemu task update logic loops through group on kill of npc to update a single task + if (p_task_data->type != TaskType::Shared) { + LogTasksDetail("[HandleUpdateTasksOnKill] Non-Shared Update"); + IncrementDoneCount(c, p_task_data, current_task->slot, activity_id); return; } - Group *group = entity_list.GetGroupByClient(client); - if (group) { - for (auto &m : group->members) { - if (m && m->IsClient()) { - Client *c = m->CastToClient(); - c->UpdateTasksOnKill(npc_type_id); - } - } - return; + LogTasksDetail("[HandleUpdateTasksOnKill] Shared update"); + + // shared tasks only require one client to receive an update to propagate + if (c == client) { + IncrementDoneCount(c, p_task_data, current_task->slot, activity_id); } } - - LogTasksDetail("[HandleUpdateTasksOnKill] Shared update"); - - // shared tasks only require one client to receive an update to propagate - client->UpdateTasksOnKill(npc_type_id); } } } + bool ClientTaskState::HasActiveTasks() { if (!task_manager) {