mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[Quest API] Add apis to end shared tasks (#2521)
This required some minor shared task refactoring - Shared task expiration handling was moved to world. Previously this was handled by zone and had clients self remove when a shared task expired. This resulted in wrong messages when a task ended. - FailTask is now implemented for shared tasks which previously only made the client quit the shared task. It now fails the task for all members by ending the shared task. The `Client::EndSharedTask` api will end the client's current shared task (removing all members). This is similiar to the `FailTask` api except it doesn't require a `task_id` and the red task fail banner is optional (live doesn't use it for shared tasks). The global `end_dz_task` api was added for when a client context isn't available. This will end a shared task if the current zone is a dynamic zone for a shared task mission. Currently only shared tasks use dynamic zones but this api can be expanded if support is added for tasks/quests. The global `get_dz_task_id` was added to conveniently get the task id for the current dynamic zone if it's used for a mission. Note this is a database hit since that information is not available at zone level.
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
#include "../common/repositories/tasks_repository.h"
|
||||
#include "../common/repositories/tasksets_repository.h"
|
||||
#include "client.h"
|
||||
#include "dynamic_zone.h"
|
||||
#include "string_ids.h"
|
||||
#include "task_manager.h"
|
||||
#include "../common/repositories/shared_task_activity_state_repository.h"
|
||||
#include "../common/repositories/shared_task_dynamic_zones_repository.h"
|
||||
#include "../common/repositories/shared_task_members_repository.h"
|
||||
#include "../common/shared_tasks.h"
|
||||
#include "worldserver.h"
|
||||
@@ -1833,3 +1835,48 @@ bool TaskManager::IsActiveTaskComplete(ClientTaskInformation& client_task)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int TaskManager::GetCurrentDzTaskID()
|
||||
{
|
||||
auto dz = zone->GetDynamicZone();
|
||||
if (dz)
|
||||
{
|
||||
// currently only supports shared tasks
|
||||
auto res = SharedTasksRepository::GetWhere(database, fmt::format(
|
||||
"id = (SELECT shared_task_id FROM shared_task_dynamic_zones WHERE dynamic_zone_id = {})", dz->GetID()));
|
||||
|
||||
if (!res.empty())
|
||||
{
|
||||
return res.front().task_id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TaskManager::EndCurrentDzTask(bool send_fail)
|
||||
{
|
||||
auto dz = zone->GetDynamicZone();
|
||||
if (dz)
|
||||
{
|
||||
EndSharedTask(dz->GetID(), send_fail);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskManager::EndSharedTask(uint32_t dz_id, bool send_fail)
|
||||
{
|
||||
ServerPacket pack(ServerOP_SharedTaskEndByDz, sizeof(ServerSharedTaskEnd_Struct));
|
||||
auto buf = reinterpret_cast<ServerSharedTaskEnd_Struct*>(pack.pBuffer);
|
||||
buf->dz_id = dz_id;
|
||||
buf->send_fail = send_fail;
|
||||
worldserver.SendPacket(&pack);
|
||||
}
|
||||
|
||||
void TaskManager::EndSharedTask(Client& client, int task_id, bool send_fail)
|
||||
{
|
||||
ServerPacket pack(ServerOP_SharedTaskEnd, sizeof(ServerSharedTaskEnd_Struct));
|
||||
auto buf = reinterpret_cast<ServerSharedTaskEnd_Struct*>(pack.pBuffer);
|
||||
buf->character_id = client.CharacterID();
|
||||
buf->task_id = task_id;
|
||||
buf->send_fail = send_fail;
|
||||
worldserver.SendPacket(&pack);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user