From f7fe10fc98ef03a89cb23d1330183c35bd920846 Mon Sep 17 00:00:00 2001 From: regneq Date: Fri, 27 Apr 2018 16:31:35 -0700 Subject: [PATCH] =?UTF-8?q?Implemented=20lua=20methods=20eq.pause=5Ftimer(?= =?UTF-8?q?"timername")=20and=20eq.resume=5Ftim=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …er("timername"). This allows developers to pause and resume the given timer on the current NPC. Added lua method eq.is_paused_timer("timername") to check to see if y… …ou have a paused timer or not. Example usage: if(eq.is_paused_timer("test"))then e.self:Say("You have a paused timer."); else e.self:Say("You do not have a paused timer."); end (credit goes to Cavedude) --- zone/lua_general.cpp | 16 +++++++ zone/questmgr.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++ zone/questmgr.h | 10 +++++ 3 files changed, 127 insertions(+) diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 55f00bcf1..3d309c542 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -341,6 +341,19 @@ void lua_stop_all_timers(Lua_Encounter enc) { quest_manager.stopalltimers(enc); } +void lua_pause_timer(const char *timer) { + quest_manager.pausetimer(timer); + +} + +void lua_resume_timer(const char *timer) { + quest_manager.resumetimer(timer); +} + +bool lua_is_paused_timer(const char *timer) { + return quest_manager.ispausedtimer(timer); +} + void lua_depop() { quest_manager.depop(0); } @@ -1543,6 +1556,9 @@ luabind::scope lua_register_general() { luabind::def("stop_timer", (void(*)(const char*, Lua_ItemInst))&lua_stop_timer), luabind::def("stop_timer", (void(*)(const char*, Lua_Mob))&lua_stop_timer), luabind::def("stop_timer", (void(*)(const char*, Lua_Encounter))&lua_stop_timer), + luabind::def("pause_timer", (void(*)(const char*))&lua_pause_timer), + luabind::def("resume_timer", (void(*)(const char*))&lua_resume_timer), + luabind::def("is_paused_timer", (bool(*)(const char*))&lua_is_paused_timer), luabind::def("stop_all_timers", (void(*)(void))&lua_stop_all_timers), luabind::def("stop_all_timers", (void(*)(Lua_ItemInst))&lua_stop_all_timers), luabind::def("stop_all_timers", (void(*)(Lua_Mob))&lua_stop_all_timers), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index f0276e25b..d6e8a004c 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -555,6 +555,107 @@ void QuestManager::stopalltimers(Mob *mob) { } } +void QuestManager::pausetimer(const char *timer_name) { + QuestManagerCurrentQuestVars(); + + std::list::iterator cur = QTimerList.begin(), end; + std::list::iterator pcur = PTimerList.begin(), pend; + PausedTimer pt; + uint32 milliseconds = 0; + + pend = PTimerList.end(); + while (pcur != pend) + { + if (pcur->owner && pcur->owner == owner && pcur->name == timer_name) + { + Log(Logs::General, Logs::Quests, "Timer %s is already paused for %s. Returning...", timer_name, owner->GetName()); + return; + } + ++pcur; + } + + end = QTimerList.end(); + while (cur != end) + { + if (cur->mob && cur->mob == owner && cur->name == timer_name) + { + milliseconds = cur->Timer_.GetRemainingTime(); + QTimerList.erase(cur); + break; + } + ++cur; + } + + std::string timername = timer_name; + pt.name = timername; + pt.owner = owner; + pt.time = milliseconds; + Log(Logs::General, Logs::Quests, "Pausing timer %s for %s with %d ms remaining.", timer_name, owner->GetName(), milliseconds); + PTimerList.push_back(pt); +} + +void QuestManager::resumetimer(const char *timer_name) { + QuestManagerCurrentQuestVars(); + + std::list::iterator cur = QTimerList.begin(), end; + std::list::iterator pcur = PTimerList.begin(), pend; + PausedTimer pt; + uint32 milliseconds = 0; + + pend = PTimerList.end(); + while (pcur != pend) + { + if (pcur->owner && pcur->owner == owner && pcur->name == timer_name) + { + milliseconds = pcur->time; + PTimerList.erase(pcur); + break; + } + ++pcur; + } + + if (milliseconds == 0) + { + Log(Logs::General, Logs::Quests, "Paused timer %s not found or has expired. Returning...", timer_name); + return; + } + + end = QTimerList.end(); + while (cur != end) + { + if (cur->mob && cur->mob == owner && cur->name == timer_name) + { + cur->Timer_.Enable(); + cur->Timer_.Start(milliseconds, false); + Log(Logs::General, Logs::Quests, "Resuming timer %s for %s with %d ms remaining.", timer_name, owner->GetName(), milliseconds); + return; + } + ++cur; + } + + QTimerList.push_back(QuestTimer(milliseconds, owner, timer_name)); + Log(Logs::General, Logs::Quests, "Creating a new timer and resuming %s for %s with %d ms remaining.", timer_name, owner->GetName(), milliseconds); + +} + +bool QuestManager::ispausedtimer(const char *timer_name) { + QuestManagerCurrentQuestVars(); + + std::list::iterator pcur = PTimerList.begin(), pend; + + pend = PTimerList.end(); + while (pcur != pend) + { + if (pcur->owner && pcur->owner == owner && pcur->name == timer_name) + { + return true; + } + ++pcur; + } + + return false; +} + void QuestManager::emote(const char *str) { QuestManagerCurrentQuestVars(); if (!owner) { diff --git a/zone/questmgr.h b/zone/questmgr.h index df0f0b669..93ba8267d 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -41,6 +41,12 @@ class QuestManager { bool depop_npc; std::string encounter; }; + + struct PausedTimer { + Mob * owner; + std::string name; + uint32 time; + }; public: QuestManager(); virtual ~QuestManager(); @@ -82,6 +88,9 @@ public: void stopalltimers(); void stopalltimers(EQEmu::ItemInstance *inst); void stopalltimers(Mob *mob); + void pausetimer(const char *timer_name); + void resumetimer(const char *timer_name); + bool ispausedtimer(const char *timer_name); void emote(const char *str); void shout(const char *str); void shout2(const char *str); @@ -304,6 +313,7 @@ private: }; std::list QTimerList; std::list STimerList; + std::list PTimerList; size_t item_timers; };