From 52b7971f12a526bb0529a16e11865100b29d8a6c Mon Sep 17 00:00:00 2001
From: Jesusaves <cpntb1@ymail.com>
Date: Sat, 25 Apr 2020 00:38:24 -0300
Subject: Handle quest end by cooldown expired in Main Gate

---
 npc/014-4/kamelot.txt | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/npc/014-4/kamelot.txt b/npc/014-4/kamelot.txt
index b95d4b720..401d8532c 100644
--- a/npc/014-4/kamelot.txt
+++ b/npc/014-4/kamelot.txt
@@ -26,6 +26,15 @@
 // $KAMELOT_KEYMASK [ guild_id ] = Which bit was assigned as the key
 // $KAMELOT_COOLDOWN [ guild_id ] = Last attempt (weekly attempts)
 
+// KamelotCleanup(guildid)
+function	script	KamelotCleanup	{
+    .@g=getarg(0);
+    //$KAMELOT_ID[.@g]=0;
+    $KAMELOT_QUEST[.@g]=0;
+    $KAMELOT_KEYMASK[.@g]=0;
+    return;
+}
+
 014-4,67,26,0	script	#KamelotEnter	NPC_HIDDEN,0,0,{
     end;
 
@@ -43,13 +52,16 @@ OnTouch:
     // Save your GID for reference
     .@g=getcharid(2);
 
-    // TODO: Quest started, Cooldown expired
-    // Needs to cleanup - wipe all variables
-
     // Quest already started
     if ($KAMELOT_QUEST[.@g] & 1) {
-        dispbottom l("The gates are firmly shut by some weird magical power.");
-        end;
+        // Quest started but Cooldown expired
+        // Needs to cleanup - wipe all variables
+        if ($KAMELOT_COOLDOWN[.@g] < gettimeparam(GETTIME_WEEKDAY)) {
+            KamelotCleanup();
+        } else {
+            dispbottom l("The gates are firmly shut by some weird magical power.");
+            end;
+        }
     }
 
     // Build instance if it doesn't exists or has been reallocated
-- 
cgit v1.2.3-70-g09d2