diff --git a/data-otservbr-global/lib/lib.lua b/data-otservbr-global/lib/lib.lua index 2e9ead889eb..1416c15ead8 100644 --- a/data-otservbr-global/lib/lib.lua +++ b/data-otservbr-global/lib/lib.lua @@ -9,3 +9,6 @@ dofile(DATA_DIRECTORY .. "/lib/quests/quest.lua") -- Tables library dofile(DATA_DIRECTORY .. "/lib/tables/load.lua") + +-- Tasks Library +dofile(DATA_DIRECTORY .. "/lib/others/task_lib.lua") diff --git a/data-otservbr-global/lib/others/task_lib.lua b/data-otservbr-global/lib/others/task_lib.lua deleted file mode 100644 index 5391d6e8c4f..00000000000 --- a/data-otservbr-global/lib/others/task_lib.lua +++ /dev/null @@ -1,453 +0,0 @@ -taskConfiguration = { -{name = "Rotworm", color = 40, total = 200, type = "repeatable", storage = 200000, storagecount = 200001, -rewards = { -{3043, 10}, -{"exp", 240000}, - }, -}, - -{name = "Minotaur", color = 40, total = 300, type = "repeatable", storage = 200002, storagecount = 200003, -rewards = { -{5804, 1}, -{"exp", 450000}, - }, -}, - -{name = "Dragon", color = 40, total = 200, type = "repeatable", storage = 200004, storagecount = 200005, -rewards = { -{3043, 10}, -{"exp", 2100000}, - }, -}, - -{name = "Dragon Lord", color = 40, total = 750, type = "once", storage = 200006, storagecount = 200007, -rewards = { -{5919, 1}, -{"exp", 11812500}, - }, -}, - -{name = "Amazon", color = 40, total = 5000, type = "once", storage = 200008, storagecount = 200009, -rewards = { -{3437, 1}, -{3393, 1}, -{3437, 1}, -{"exp", 1500000}, - }, -}, - -{name = "Weakened Frazzlemaw", color = 40, total = 500, type = "once", storage = 200010, storagecount = 200011, -rewards = { -{22721, 25}, - }, -}, - -{name = "Enfeebled Silencer", color = 40, total = 500, type = "once", storage = 200012, storagecount = 200013, -rewards = { -{22721, 25}, - }, -}, - -{name = "Hero", color = 40, total = 500, type = "repeatable", storage = 200014, storagecount = 200015, -rewards = { -{3043, 25}, -{"exp", 3000000}, - }, -}, - -{name = "Vicious Squire", color = 40, total = 500, type = "repeatable", storage = 200016, storagecount = 200017, -rewards = { -{"exp", 2250000}, - }, -}, - -{name = "Vile Grandmaster", color = 40, total = 500, type = "repeatable", storage = 200032, storagecount = 200033, -rewards = { -{"exp", 3750000}, - }, -}, - - -{name = "Crazed Winter Rearguard", color = 40, total = 1000, type = "repeatable", storage = 200018, storagecount = 200019, -rewards = { -{"exp", 9400000}, - }, -}, - -{name = "Crazed Winter Vanguard", color = 40, total = 1000, type = "repeatable", storage = 200020, storagecount = 200021, -rewards = { -{"exp", 10800000}, - }, -}, - -{name = "Crazed Summer Rearguard", color = 40, total = 1000, type = "repeatable", storage = 200022, storagecount = 200023, -rewards = { -{"exp", 9400000}, - }, -}, - -{name = "Insane Siren", color = 40, total = 1000, type = "repeatable", storage = 200024, storagecount = 200025, -rewards = { -{"exp", 10000000}, - }, -}, - -{name = "Cobra Vizier", color = 40, total = 1000, type = "repeatable", storage = 200026, storagecount = 200027, -rewards = { -{3043, 50}, -{"exp", 10000000}, - }, -}, - -{name = "Cobra Assassin", color = 40, total = 500, type = "repeatable", storage = 200028, storagecount = 200029, -rewards = { -{"exp", 1500000}, - }, -}, - -{name = "Cobra Scout", color = 40, total = 500, type = "repeatable", storage = 200030, storagecount = 200031, -rewards = { -{"exp", 1500000}, - }, -}, - -{name = "Dawnfire Asura", color = 40, total = 1000, type = "repeatable", storage = 200034, storagecount = 200035, -rewards = { -{"exp", 11480000}, - }, -}, - -{name = "Midnight Asura", color = 40, total = 1000, type = "repeatable", storage = 200100, storagecount = 200101, -rewards = { -{"exp", 11480000}, - }, -}, - -{name = "Guzzlemaw", color = 40, total = 1500, type = "repeatable", storage = 200036, storagecount = 200037, -rewards = { -{20270, 1}, -{"exp", 20015000}, - }, -}, - -{name = "Frazzlemaw", color = 40, total = 1500, type = "repeatable", storage = 200038, storagecount = 200039, -rewards = { -{20272, 1}, -{"exp", 17022000}, - }, -}, - -{name = "Silencer", color = 40, total = 1500, type = "repeatable", storage = 200040, storagecount = 200041, -rewards = { -{20271, 1}, -{"exp", 16030000}, - }, -}, - -{name = "Demon", color = 40, total = 66666, type = "once", storage = 200042, storagecount = 200043, -rewards = { -{3365, 1}, - }, -}, - -{name = "Cloak Of Terror", color = 40, total = 2000, type = "repeatable", storage = 200044, storagecount = 200045, -rewards = { -{"exp", 59904000}, - }, -}, - -{name = "Vibrant Phantom", color = 40, total = 2000, type = "repeatable", storage = 200046, storagecount = 200047, -rewards = { -{"exp", 59904000}, - }, -}, - -{name = "Courage Leech", color = 40, total = 2000, type = "repeatable", storage = 200048, storagecount = 200049, -rewards = { -{34109, 1}, -{"exp", 45360000}, - }, -}, - -{name = "Brachiodemon", color = 40, total = 2000, type = "repeatable", storage = 200050, storagecount = 200051, -rewards = { -{"exp", 11440000}, - }, -}, - -{name = "Infernal Demon", color = 40, total = 2000, type = "repeatable", storage = 200052, storagecount = 200053, -rewards = { -{34109, 1}, -{"exp", 68640000}, - }, -}, - -{name = "Infernal Phantom", color = 40, total = 2000, type = "repeatable", storage = 200054, storagecount = 200055, -rewards = { -{"exp", 68640000}, - }, -}, - -{name = "Retching Horror", color = 40, total = 1000, type = "repeatable", storage = 200056, storagecount = 200057, -rewards = { -{"exp", 18900000}, - }, -}, - -{name = "Choking Fear", color = 40, total = 1000, type = "repeatable", storage = 200058, storagecount = 200059, -rewards = { -{"exp", 20700000}, - }, -}, - -{name = "Burning Book", color = 40, total = 2000, type = "repeatable", storage = 200060, storagecount = 200061, -rewards = { -{"exp", 45349299}, - }, -}, - -{name = "Rage Squid", color = 40, total = 2000, type = "repeatable", storage = 200062, storagecount = 200063, -rewards = { -{"exp", 35349299}, -{3043, 1000}, - }, -}, - -{name = "Dark Torturer", color = 40, total = 1000, type = "repeatable", storage = 200064, storagecount = 200065, -rewards = { -{"exp", 8500781}, -{19083, 1}, - }, -}, - -{name = "Silencer", color = 40, total = 1000, type = "repeatable", storage = 200070, storagecount = 200071, -rewards = { -{"exp", 6630000}, - }, -}, - -{name = "Flimsy Lost Soul", color = 40, total = 1000, type = "repeatable", storage = 200072, storagecount = 200073, -rewards = { -{"exp", 7865000}, - }, -}, - -{name = "Mean Lost Soul", color = 40, total = 1000, type = "repeatable", storage = 200074, storagecount = 200075, -rewards = { -{"exp", 8060000}, -{19083, 1}, - }, -}, - -{name = "Falcon Paladin", color = 40, total = 1000, type = "repeatable", storage = 200076, storagecount = 200077, -rewards = { -{"exp", 20664000}, - }, -}, - -{name = "Falcon Knight", color = 40, total = 1000, type = "repeatable", storage = 200078, storagecount = 200079, -rewards = { -{"exp", 18900000}, - }, -}, - -{name = "Wyrm", color = 40, total = 500, type = "repeatable", storage = 200080, storagecount = 200081, -rewards = { -{"exp", 1550000}, - }, -}, - -{name = "Elder Wyrm", color = 40, total = 500, type = "repeatable", storage = 200082, storagecount = 200083, -rewards = { -{"exp", 2500000}, - }, -}, - -{name = "Vexclaw", color = 40, total = 1000, type = "repeatable", storage = 200084, storagecount = 200085, -rewards = { -{"exp", 23763600}, -{19083, 1}, - }, -}, - -{name = "Grimeleech", color = 40, total = 1000, type = "repeatable", storage = 200086, storagecount = 200087, -rewards = { -{"exp", 28516320}, - }, -}, - -{name = "Hellflayer", color = 40, total = 1000, type = "repeatable", storage = 200088, storagecount = 200089, -rewards = { -{"exp", 29516320}, - }, -}, - -{name = "Bony Sea Devil", color = 40, total = 2000, type = "repeatable", storage = 200090, storagecount = 200091, -rewards = { -{"exp", 59904000}, - }, -}, - -{name = "Turbulent Elemental", color = 40, total = 2000, type = "repeatable", storage = 200092, storagecount = 2000093, -rewards = { -{34109, 1}, -{"exp", 45360000}, - }, -}, - -{name = "Capricious Phantom", color = 40, total = 2000, type = "repeatable", storage = 200094, storagecount = 2000095, -rewards = { -{34109, 1}, -{"exp", 59904000}, - }, -}, - -{name = "Gore Horn", color = 40, total = 2000, type = "repeatable", storage = 200094, storagecount = 2000095, -rewards = { -{39546, 1}, -{"exp", 59904000}, - }, -}, -} - - - - -squareWaitTime = 5000 -taskQuestLog = 65000 -- A storage so you get the quest log -dailyTaskWaitTime = 10 * 60 * 60 - -function Player.getCustomActiveTasksName(self) -local player = self - if not player then - return false - end -local tasks = {} - for i, data in pairs(taskConfiguration) do - if player:getStorageValue(data.storagecount) ~= -1 then - tasks[#tasks + 1] = data.name - end - end - return #tasks > 0 and tasks or false -end - - -function getTaskByStorage(storage) - for i, data in pairs(taskConfiguration) do - if data.storage == tonumber(storage) then - return data - end - end - return false -end - -function getTaskByMonsterName(name) - for i, data in pairs(taskConfiguration) do - if data.name:lower() == name:lower() then - return data - end - end - return false -end - -function Player.startTask(self, storage) -local player = self - if not player then - return false - end -local data = getTaskByStorage(storage) - if data == false then - return false - end - if player:getStorageValue(taskQuestLog) == -1 then - player:setStorageValue(taskQuestLog, 1) - end - player:setStorageValue(storage, player:getStorageValue(storage) + 1) - player:setStorageValue(data.storagecount, 0) - return true -end - -function Player.canStartCustomTask(self, storage) -local player = self - if not player then - return false - end -local data = getTaskByStorage(storage) - if data == false then - return false - end - if data.type == "daily" then - return os.time() >= player:getStorageValue(storage) - elseif data.type == "once" then - return player:getStorageValue(storage) == -1 - elseif data.type[1] == "repeatable" and data.type[2] ~= -1 then - return player:getStorageValue(storage) < (data.type[2] - 1) - else - return true - end -end - -function Player.endTask(self, storage, prematurely) -local player = self - if not player then - return false - end -local data = getTaskByStorage(storage) - if data == false then - return false -end - if prematurely then - if data.type == "daily" then - player:setStorageValue(storage, -1) - else - player:setStorageValue(storage, player:getStorageValue(storage) - 1) - end - else - if data.type == "daily" then - player:setStorageValue(storage, os.time() + dailyTaskWaitTime) - end - end - player:setStorageValue(data.storagecount, -1) - return true -end - -function Player.hasStartedTask(self, storage) -local player = self - if not player then - return false - end -local data = getTaskByStorage(storage) - if data == false then - return false - end - return player:getStorageValue(data.storagecount) ~= -1 -end - - -function Player.getTaskKills(self, storage) -local player = self - if not player then - return false - end - return player:getStorageValue(storage) -end - -function Player.addTaskKill(self, storage, count) -local player = self - if not player then - return false - end -local data = getTaskByStorage(storage) - if data == false then - return false - end - local kills = player:getTaskKills(data.storagecount) - if kills >= data.total then - return false - end - if kills + count >= data.total then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[Task System] You finished this task! to take your rewards use !task") - return player:setStorageValue(data.storagecount, data.total) - end - return player:setStorageValue(data.storagecount, kills + count) -end diff --git a/data/scripts/talkactions/player/task_talkaction.lua b/data/scripts/talkactions/player/task_talkaction.lua deleted file mode 100644 index 6974f229710..00000000000 --- a/data/scripts/talkactions/player/task_talkaction.lua +++ /dev/null @@ -1,153 +0,0 @@ -function endTaskModalWindow(player, storage) -local data = getTaskByStorage(storage) -local newmessage -local completion = false - if player:getTaskKills(data.storagecount) < data.total then - newmessage = "You have already completed, or are in progress on this task." - else - player:endTask(storage, false) - completion = true - newmessage = "You completed the task" .. (data.rewards and "\nHere are your rewards:" or "") - end -local window = ModalWindow{ - title = "Task System", - message = newmessage - } - if completion and data.rewards then - for _, info in pairs (data.rewards) do - if info[1] == "exp" then - player:addExperience(info[2]) - window:addChoice("- Experience: "..info[2]) - elseif tonumber(info[1]) then - window:addChoice("- ".. info[2] .." "..ItemType(info[1]):getName()) - player:addItem(info[1], info[2]) - end - end -end - window:addButton("Back", function() sendTaskModalWindow(player) end) - window:sendToPlayer(player) -end -function acceptedTaskModalWindow(player) -local window = ModalWindow{ - title = "Task System", - message = "You accepted this task!" - } - window:addButton("Back", function() sendTaskModalWindow(player) end) - window:sendToPlayer(player) -end - -function confirmTaskModalWindow(player, storage) -local window = ModalWindow{ - title = "Task System", - message = "Here are the details of your task:" - } -local data = getTaskByStorage(storage) - window:addChoice("Monster name: "..data.name) - window:addChoice("Necessary deaths: "..data.total) - if data.type == "daily" then - window:addChoice("You can repeat: Every day!") - elseif data.type[1] == "repeatable" then - window:addChoice("You can repeat: ".. (data.type[2] == -1 and "Always." or data.type[2] .." times.")) - elseif data.type[1] == "once" then - window:addChoice("You can repeat: Only once!") - end - if data.rewards then - window:addChoice("Rewards:") - for _, info in pairs(data.rewards) do - if info[1] == "exp" then - window:addChoice("- Experience: "..info[2]) - elseif tonumber(info[1]) then - window:addChoice("- " .. info[2] .. " ".. ItemType(info[1]):getName()) - end - end -end -local function confirmCallback(player, button, choice) - if player:hasStartedTask(storage) or not player:canStartCustomTask(storage) then - errorModalWindow(player) - else - acceptedTaskModalWindow(player) - player:startTask(storage) - end -end - window:addButton("Choose", confirmCallback) - window:addButton("Back", function() sendTaskModalWindow(player) end) - window:sendToPlayer(player) -end - -function errorModalWindow(player) -local window = ModalWindow{ - title = "Task System", - message = "You have already completed this task." - } - window:addButton("Back", function() sendTaskModalWindow(player) end) - window:sendToPlayer(player) -end - -function cancelTaskModalWindow(player, managed) -local newmessage - if managed then - newmessage = "You canceled this task." - else - newmessage = "You cannot cancel this task, because it is already completed or not started." - end -local window = ModalWindow{ - title = "Task System", - message = newmessage - } - window:addButton("Back", function() sendTaskModalWindow(player) end) - window:sendToPlayer(player) -end - -function sendTaskModalWindow(player) -local window = ModalWindow{ - title = "Task System", - message = "Choose a task and use the buttons below:" - } -local temptasks = {} - for _, data in pairs (taskConfiguration) do - temptasks[#temptasks+1] = data.storage - if player:hasStartedTask(data.storage) then - window:addChoice(data.name .. " ["..(player:getTaskKills(data.storagecount) >= data.total and "Reward on Hold]" or player:getTaskKills(data.storagecount).."/"..data.total.."]")) - elseif player:canStartCustomTask(data.storage) == false then - if data.type == "daily" then - window:addChoice(data.name .. ", [Concluded Daily]") - else - window:addChoice(data.name ..", [Concluded]") - end - else - window:addChoice(data.name ..", "..data.total) - end -end -local function confirmCallback(player, button, choice) -local id = choice.id - if player:hasStartedTask(temptasks[id]) then - endTaskModalWindow(player, temptasks[id]) - elseif not player:canStartCustomTask(temptasks[id]) then - errorModalWindow(player) - else - confirmTaskModalWindow(player, temptasks[id]) - end -end -local function cancelCallback(player, button, choice) -local id = choice.id - if player:hasStartedTask(temptasks[id]) then - cancelTaskModalWindow(player, true) - player:endTask(temptasks[id], true) - else - cancelTaskModalWindow(player, false) - end -end - window:addButton("Choose", confirmCallback) - window:addButton("Cancel", cancelCallback) - window:addButton("Exit") - window:sendToPlayer(player) -end - -local task = TalkAction("!task") - -function task.onSay(player, words, param) - sendTaskModalWindow(player) - return false -end -task:groupType("normal") -task:register()