From 444a4f67440706ec1c01323f8cbb430a46ad1695 Mon Sep 17 00:00:00 2001 From: hg <4683435+hgtw@users.noreply.github.com> Date: Sat, 29 Oct 2022 20:46:08 -0400 Subject: [PATCH] [Tasks] Add pre-task update event (#2512) This adds the player EVENT_TASK_BEFORE_UPDATE event which will allow quests to prevent a source controlled task update by returning non-zero. --- zone/embparser.cpp | 2 ++ zone/event_codes.h | 1 + zone/lua_general.cpp | 3 ++- zone/lua_parser.cpp | 2 ++ zone/task_client_state.cpp | 9 +++++++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 14c0c7dc4..c866e47ca 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -160,6 +160,7 @@ const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_MERCHANT_BUY", "EVENT_MERCHANT_SELL", "EVENT_INSPECT", + "EVENT_TASK_BEFORE_UPDATE", }; PerlembParser::PerlembParser() : perl(nullptr) @@ -1465,6 +1466,7 @@ void PerlembParser::ExportEventVariables( } case EVENT_TASK_COMPLETE: + case EVENT_TASK_BEFORE_UPDATE: case EVENT_TASK_UPDATE: { Seperator sep(data); ExportVar(package_name.c_str(), "donecount", sep.arg[0]); diff --git a/zone/event_codes.h b/zone/event_codes.h index 9230f9fa4..7c469527e 100644 --- a/zone/event_codes.h +++ b/zone/event_codes.h @@ -103,6 +103,7 @@ typedef enum { EVENT_MERCHANT_BUY, EVENT_MERCHANT_SELL, EVENT_INSPECT, + EVENT_TASK_BEFORE_UPDATE, _LargestEventID } QuestEventID; diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index a705f245e..24012687e 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -4307,7 +4307,8 @@ luabind::scope lua_register_events() { luabind::value("alt_currency_merchant_sell", static_cast(EVENT_ALT_CURRENCY_MERCHANT_SELL)), luabind::value("merchant_buy", static_cast(EVENT_MERCHANT_BUY)), luabind::value("merchant_sell", static_cast(EVENT_MERCHANT_SELL)), - luabind::value("inspect", static_cast(EVENT_INSPECT)) + luabind::value("inspect", static_cast(EVENT_INSPECT)), + luabind::value("task_before_update", static_cast(EVENT_TASK_BEFORE_UPDATE)) ]; } diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 91aaad096..42f62c967 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -147,6 +147,7 @@ const char *LuaEvents[_LargestEventID] = { "event_merchant_buy", "event_merchant_sell", "event_inspect", + "event_task_before_update", }; extern Zone *zone; @@ -222,6 +223,7 @@ LuaParser::LuaParser() { PlayerArgumentDispatch[EVENT_TASK_STAGE_COMPLETE] = handle_player_task_stage_complete; PlayerArgumentDispatch[EVENT_TASK_COMPLETE] = handle_player_task_update; PlayerArgumentDispatch[EVENT_TASK_UPDATE] = handle_player_task_update; + PlayerArgumentDispatch[EVENT_TASK_BEFORE_UPDATE] = handle_player_task_update; PlayerArgumentDispatch[EVENT_COMMAND] = handle_player_command; PlayerArgumentDispatch[EVENT_COMBINE_SUCCESS] = handle_player_combine; PlayerArgumentDispatch[EVENT_COMBINE_FAILURE] = handle_player_combine; diff --git a/zone/task_client_state.cpp b/zone/task_client_state.cpp index 9f9c06bf5..7923af74b 100644 --- a/zone/task_client_state.cpp +++ b/zone/task_client_state.cpp @@ -564,6 +564,15 @@ int ClientTaskState::UpdateTasks(Client* client, const TaskUpdateFilter& filter, if (CanUpdate(client, filter, client_task.task_id, activity, client_activity)) { + auto args = fmt::format("{} {} {}", count, client_activity.activity_id, client_task.task_id); + if (parse->EventPlayer(EVENT_TASK_BEFORE_UPDATE, client, args, 0) != 0) + { + LogTasks("[UpdateTasks] client [{}] task [{}]-[{}] update prevented by quest", + client->GetName(), client_task.task_id, client_activity.activity_id); + + continue; + } + LogTasks("[UpdateTasks] client [{}] task [{}] activity [{}] increment [{}]", client->GetName(), client_task.task_id, client_activity.activity_id, count);