mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +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:
@@ -1274,6 +1274,7 @@ public:
|
||||
}
|
||||
void PurgeTaskTimers();
|
||||
void LockSharedTask(bool lock) { if (task_state) { task_state->LockSharedTask(this, lock); } }
|
||||
void EndSharedTask(bool fail = false) { if (task_state) { task_state->EndSharedTask(this, fail); } }
|
||||
|
||||
// shared task shims / middleware
|
||||
// these variables are used as a shim to intercept normal localized task functionality
|
||||
|
||||
@@ -1257,6 +1257,21 @@ std::string Perl__gettaskname(uint32 task_id)
|
||||
return quest_manager.gettaskname(task_id);
|
||||
}
|
||||
|
||||
int Perl__get_dz_task_id()
|
||||
{
|
||||
return quest_manager.GetCurrentDzTaskID();
|
||||
}
|
||||
|
||||
void Perl__end_dz_task()
|
||||
{
|
||||
quest_manager.EndCurrentDzTask();
|
||||
}
|
||||
|
||||
void Perl__end_dz_task(bool send_fail)
|
||||
{
|
||||
quest_manager.EndCurrentDzTask(send_fail);
|
||||
}
|
||||
|
||||
void Perl__popup(const char* window_title, const char* message)
|
||||
{
|
||||
quest_manager.popup(window_title, message, 0, 0, 0);
|
||||
@@ -4078,6 +4093,8 @@ void perl_register_quest()
|
||||
package.add("enablerecipe", &Perl__enablerecipe);
|
||||
package.add("enabletask", &Perl__enabletask);
|
||||
package.add("enabletitle", &Perl__enabletitle);
|
||||
package.add("end_dz_task", (void(*)())&Perl__end_dz_task);
|
||||
package.add("end_dz_task", (void(*)(bool))&Perl__end_dz_task);
|
||||
package.add("exp", &Perl__exp);
|
||||
package.add("faction", (void(*)(int, int))&Perl__faction);
|
||||
package.add("faction", (void(*)(int, int, int))&Perl__faction);
|
||||
@@ -4101,6 +4118,7 @@ void perl_register_quest()
|
||||
package.add("getconsiderlevelname", &Perl__getconsiderlevelname);
|
||||
package.add("gethexcolorcode", &Perl__gethexcolorcode);
|
||||
package.add("getcurrencyid", &Perl__getcurrencyid);
|
||||
package.add("get_dz_task_id", &Perl__get_dz_task_id);
|
||||
package.add("getexpmodifierbycharid", (double(*)(uint32, uint32))&Perl__getexpmodifierbycharid);
|
||||
package.add("getexpmodifierbycharid", (double(*)(uint32, uint32, int16))&Perl__getexpmodifierbycharid);
|
||||
package.add("get_expedition", &Perl__get_expedition);
|
||||
|
||||
@@ -1445,6 +1445,16 @@ void Lua_Client::LockSharedTask(bool lock) {
|
||||
return self->LockSharedTask(lock);
|
||||
}
|
||||
|
||||
void Lua_Client::EndSharedTask() {
|
||||
Lua_Safe_Call_Void();
|
||||
self->EndSharedTask();
|
||||
}
|
||||
|
||||
void Lua_Client::EndSharedTask(bool send_fail) {
|
||||
Lua_Safe_Call_Void();
|
||||
self->EndSharedTask(send_fail);
|
||||
}
|
||||
|
||||
int Lua_Client::GetCorpseCount() {
|
||||
Lua_Safe_Call_Int();
|
||||
return self->GetCorpseCount();
|
||||
@@ -2657,6 +2667,8 @@ luabind::scope lua_register_client() {
|
||||
.def("EnableAreaHPRegen", &Lua_Client::EnableAreaHPRegen)
|
||||
.def("EnableAreaManaRegen", &Lua_Client::EnableAreaManaRegen)
|
||||
.def("EnableAreaRegens", &Lua_Client::EnableAreaRegens)
|
||||
.def("EndSharedTask", (void(Lua_Client::*)(void))&Lua_Client::EndSharedTask)
|
||||
.def("EndSharedTask", (void(Lua_Client::*)(bool))&Lua_Client::EndSharedTask)
|
||||
.def("Escape", (void(Lua_Client::*)(void))&Lua_Client::Escape)
|
||||
.def("FailTask", (void(Lua_Client::*)(int))&Lua_Client::FailTask)
|
||||
.def("FilteredMessage", &Lua_Client::FilteredMessage)
|
||||
|
||||
@@ -348,6 +348,8 @@ public:
|
||||
bool IsTaskActive(int task);
|
||||
bool IsTaskActivityActive(int task, int activity);
|
||||
void LockSharedTask(bool lock);
|
||||
void EndSharedTask();
|
||||
void EndSharedTask(bool send_fail);
|
||||
int GetCorpseCount();
|
||||
int GetCorpseID(int corpse);
|
||||
int GetCorpseItemAt(int corpse, int slot);
|
||||
|
||||
@@ -760,6 +760,18 @@ std::string lua_get_task_name(uint32 task_id) {
|
||||
return quest_manager.gettaskname(task_id);
|
||||
}
|
||||
|
||||
int lua_get_dz_task_id() {
|
||||
return quest_manager.GetCurrentDzTaskID();
|
||||
}
|
||||
|
||||
void lua_end_dz_task() {
|
||||
quest_manager.EndCurrentDzTask();
|
||||
}
|
||||
|
||||
void lua_end_dz_task(bool send_fail) {
|
||||
quest_manager.EndCurrentDzTask(send_fail);
|
||||
}
|
||||
|
||||
void lua_popup(const char *title, const char *text, uint32 id, uint32 buttons, uint32 duration) {
|
||||
quest_manager.popup(title, text, id, buttons, duration);
|
||||
}
|
||||
@@ -3759,6 +3771,9 @@ luabind::scope lua_register_general() {
|
||||
luabind::def("completed_tasks_in_set", &lua_completed_tasks_in_set),
|
||||
luabind::def("is_task_appropriate", &lua_is_task_appropriate),
|
||||
luabind::def("get_task_name", (std::string(*)(uint32))&lua_get_task_name),
|
||||
luabind::def("get_dz_task_id", &lua_get_dz_task_id),
|
||||
luabind::def("end_dz_task", (void(*)())&lua_end_dz_task),
|
||||
luabind::def("end_dz_task", (void(*)(bool))&lua_end_dz_task),
|
||||
luabind::def("popup", &lua_popup),
|
||||
luabind::def("clear_spawn_timers", &lua_clear_spawn_timers),
|
||||
luabind::def("zone_emote", &lua_zone_emote),
|
||||
|
||||
@@ -1423,6 +1423,16 @@ void Perl_Client_LockSharedTask(Client* self, bool lock)
|
||||
return self->LockSharedTask(lock);
|
||||
}
|
||||
|
||||
void Perl_Client_EndSharedTask(Client* self)
|
||||
{
|
||||
return self->EndSharedTask();
|
||||
}
|
||||
|
||||
void Perl_Client_EndSharedTask(Client* self, bool send_fail)
|
||||
{
|
||||
return self->EndSharedTask(send_fail);
|
||||
}
|
||||
|
||||
uint32_t Perl_Client_GetCorpseCount(Client* self) // @categories Account and Character, Corpse
|
||||
{
|
||||
return self->GetCorpseCount();
|
||||
@@ -2548,6 +2558,8 @@ void perl_register_client()
|
||||
package.add("Duck", &Perl_Client_Duck);
|
||||
package.add("DyeArmorBySlot", (void(*)(Client*, uint8, uint8, uint8, uint8))&Perl_Client_DyeArmorBySlot);
|
||||
package.add("DyeArmorBySlot", (void(*)(Client*, uint8, uint8, uint8, uint8, uint8))&Perl_Client_DyeArmorBySlot);
|
||||
package.add("EndSharedTask", (void(*)(Client*))&Perl_Client_EndSharedTask);
|
||||
package.add("EndSharedTask", (void(*)(Client*, bool))&Perl_Client_EndSharedTask);
|
||||
package.add("Escape", &Perl_Client_Escape);
|
||||
package.add("ExpeditionMessage", &Perl_Client_ExpeditionMessage);
|
||||
package.add("FailTask", &Perl_Client_FailTask);
|
||||
|
||||
@@ -2480,6 +2480,24 @@ std::string QuestManager::gettaskname(uint32 task_id) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int QuestManager::GetCurrentDzTaskID() {
|
||||
QuestManagerCurrentQuestVars();
|
||||
|
||||
if (RuleB(TaskSystem, EnableTaskSystem) && zone && task_manager) {
|
||||
return task_manager->GetCurrentDzTaskID();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QuestManager::EndCurrentDzTask(bool send_fail) {
|
||||
QuestManagerCurrentQuestVars();
|
||||
|
||||
if (RuleB(TaskSystem, EnableTaskSystem) && zone && task_manager) {
|
||||
task_manager->EndCurrentDzTask(send_fail);
|
||||
}
|
||||
}
|
||||
|
||||
void QuestManager::clearspawntimers() {
|
||||
if (!zone) {
|
||||
return;
|
||||
|
||||
@@ -234,6 +234,8 @@ public:
|
||||
int completedtasksinset(int taskset);
|
||||
bool istaskappropriate(int task);
|
||||
std::string gettaskname(uint32 task_id);
|
||||
int GetCurrentDzTaskID();
|
||||
void EndCurrentDzTask(bool send_fail = false);
|
||||
void clearspawntimers();
|
||||
void ze(int type, const char *str);
|
||||
void we(int type, const char *str);
|
||||
|
||||
@@ -169,6 +169,15 @@ void SharedTaskZoneMessaging::HandleWorldMessage(ServerPacket *pack)
|
||||
|
||||
break;
|
||||
}
|
||||
case ServerOP_SharedTaskFailed: {
|
||||
auto buf = reinterpret_cast<ServerSharedTaskCharacterTask_Struct*>(pack->pBuffer);
|
||||
Client* client = entity_list.GetClientByCharID(buf->character_id);
|
||||
if (client)
|
||||
{
|
||||
client->SendTaskFailed(buf->task_id, TASKSLOTSHAREDTASK, TaskType::Shared);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
+10
-21
@@ -1122,16 +1122,12 @@ void ClientTaskState::FailTask(Client *client, int task_id)
|
||||
return;
|
||||
}
|
||||
|
||||
// type: Shared Task
|
||||
// type: Shared Task (failed via world for all members)
|
||||
if (m_active_shared_task.task_id == task_id) {
|
||||
client->SendTaskFailed(task_id, TASKSLOTSHAREDTASK, TaskType::Shared);
|
||||
// Remove the task from the client
|
||||
client->CancelTask(TASKSLOTSHAREDTASK, TaskType::Shared);
|
||||
task_manager->EndSharedTask(*client, task_id, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: shared tasks
|
||||
|
||||
if (m_active_task_count == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -1146,7 +1142,6 @@ void ClientTaskState::FailTask(Client *client, int task_id)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Shared tasks
|
||||
bool ClientTaskState::IsTaskActivityActive(int task_id, int activity_id)
|
||||
{
|
||||
LogTasks("[IsTaskActivityActive] task_id [{}] activity_id [{}]", task_id, activity_id);
|
||||
@@ -1566,6 +1561,7 @@ bool ClientTaskState::TaskOutOfTime(TaskType task_type, int index)
|
||||
|
||||
void ClientTaskState::TaskPeriodicChecks(Client *client)
|
||||
{
|
||||
// shared task expiration is handled by world
|
||||
|
||||
// type "task"
|
||||
if (m_active_task.task_id != TASKSLOTEMPTY) {
|
||||
@@ -1581,20 +1577,6 @@ void ClientTaskState::TaskPeriodicChecks(Client *client)
|
||||
}
|
||||
}
|
||||
|
||||
// type "shared"
|
||||
if (m_active_shared_task.task_id != TASKSLOTEMPTY) {
|
||||
if (TaskOutOfTime(TaskType::Shared, TASKSLOTSHAREDTASK)) {
|
||||
// Send Red Task Failed Message
|
||||
client->SendTaskFailed(m_active_shared_task.task_id, TASKSLOTSHAREDTASK, TaskType::Shared);
|
||||
// Remove the task from the client
|
||||
client->CancelTask(TASKSLOTSHAREDTASK, TaskType::Shared);
|
||||
// It is a conscious decision to only fail one task per call to this method,
|
||||
// otherwise the player will not see all the failed messages where multiple
|
||||
// tasks fail at the same time.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_active_task_count == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -2434,6 +2416,13 @@ void ClientTaskState::LockSharedTask(Client* client, bool lock)
|
||||
}
|
||||
}
|
||||
|
||||
void ClientTaskState::EndSharedTask(Client* client, bool send_fail)
|
||||
{
|
||||
if (task_manager && m_active_shared_task.task_id != TASKSLOTEMPTY)
|
||||
{
|
||||
task_manager->EndSharedTask(*client, m_active_shared_task.task_id, send_fail);
|
||||
}
|
||||
}
|
||||
bool ClientTaskState::CanAcceptNewTask(Client* client, int task_id, int npc_entity_id) const
|
||||
{
|
||||
auto it = std::find_if(m_last_offers.begin(), m_last_offers.end(),
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
void ClearLastOffers() { m_last_offers.clear(); }
|
||||
bool CanAcceptNewTask(Client* client, int task_id, int npc_entity_id) const;
|
||||
bool HasExploreTask(Client* client) const;
|
||||
void EndSharedTask(Client* client, bool send_fail);
|
||||
|
||||
inline bool HasFreeTaskSlot() { return m_active_task.task_id == TASKSLOTEMPTY; }
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ public:
|
||||
int NextTaskInSet(int task_set, int task_id);
|
||||
bool IsTaskRepeatable(int task_id);
|
||||
bool IsActiveTaskComplete(ClientTaskInformation& client_task);
|
||||
int GetCurrentDzTaskID();
|
||||
void EndCurrentDzTask(bool send_fail);
|
||||
void EndSharedTask(Client& client, int task_id, bool send_fail);
|
||||
void EndSharedTask(uint32_t dz_id, bool send_fail);
|
||||
|
||||
friend class ClientTaskState;
|
||||
|
||||
|
||||
@@ -3291,6 +3291,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
|
||||
case ServerOP_SharedTaskMemberChange:
|
||||
case ServerOP_SharedTaskInvitePlayer:
|
||||
case ServerOP_SharedTaskPurgeAllCommand:
|
||||
case ServerOP_SharedTaskFailed:
|
||||
{
|
||||
SharedTaskZoneMessaging::HandleWorldMessage(pack);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user