From ded4bf702d3ad43ce0e8f455679a9a5d36ba34f8 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Nov 2024 08:44:05 -0300 Subject: [PATCH 1/5] chore: vortex tamer achievement logic --- data/lib/core/storages.lua | 2 +- data/scripts/actions/others/usable_mount_items.lua | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/data/lib/core/storages.lua b/data/lib/core/storages.lua index 601e5ee419..bd67ee9d97 100644 --- a/data/lib/core/storages.lua +++ b/data/lib/core/storages.lua @@ -33,7 +33,7 @@ PlayerStorageKeys = { nailCaseUseCount = 30031, swampDigging = 30032, insectoidCell = 30033, - vortexTamer = 30034, + -- empty: 30034 mutatedPumpkin = 30035, -- Achievements: diff --git a/data/scripts/actions/others/usable_mount_items.lua b/data/scripts/actions/others/usable_mount_items.lua index 3865b7c41f..7f902f8f45 100644 --- a/data/scripts/actions/others/usable_mount_items.lua +++ b/data/scripts/actions/others/usable_mount_items.lua @@ -42,11 +42,7 @@ function usableItemMounts.onUse(player, item, fromPosition, target, toPosition, end if table.contains({26194, 26340, 26341}, item.itemid) then - local storage = player:getStorageValue(PlayerStorageKeys.vortexTamer) - player:setStorageValue(PlayerStorageKeys.vortexTamer, storage + 1) - if storage == 1 then - player:addAchievement("Vortex Tamer") - end + player:addAchievementProgress("Vortex Tamer", 3) end if useItem.achievement then From 712c9f7aa7acd5102c92430871e3457b1d37f558 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Nov 2024 08:51:37 -0300 Subject: [PATCH 2/5] refactor: simplify and improve mount item usage logic --- .../actions/others/usable_mount_items.lua | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/data/scripts/actions/others/usable_mount_items.lua b/data/scripts/actions/others/usable_mount_items.lua index 7f902f8f45..7c9d265849 100644 --- a/data/scripts/actions/others/usable_mount_items.lua +++ b/data/scripts/actions/others/usable_mount_items.lua @@ -2,17 +2,20 @@ local config = { [26194] = { -- vibrant egg name = "vortexion", mountId = 94, - tameMessage = "You receive the permission to ride a sparkion." + tameMessage = "You receive the permission to ride a sparkion.", + achievementProgress = { name = "Vortex Tamer", progress = 3 } }, [26340] = { -- crackling egg name = "neon sparkid", mountId = 98, - tameMessage = "You receive the permission to ride a neon sparkid." + tameMessage = "You receive the permission to ride a neon sparkid.", + achievementProgress = { name = "Vortex Tamer", progress = 3 } }, [26341] = { -- menacing egg name = "vortexion", mountId = 99, - tameMessage = "You receive the permission to ride a vortexion." + tameMessage = "You receive the permission to ride a vortexion.", + achievementProgress = { name = "Vortex Tamer", progress = 3 } }, [25521] = { -- mysterious scroll name = "rift runner", @@ -31,18 +34,22 @@ local config = { local usableItemMounts = Action() function usableItemMounts.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local useItem = config[item.itemid] + if not useItem then + return true + end + if not player:isPremium() then player:sendCancelMessage(RETURNVALUE_YOUNEEDPREMIUMACCOUNT) return true end - local useItem = config[item.itemid] if player:hasMount(useItem.mountId) then - return false + return true end - if table.contains({26194, 26340, 26341}, item.itemid) then - player:addAchievementProgress("Vortex Tamer", 3) + if useItem.achievementProgress then + player:addAchievementProgress(useItem.achievementProgress.name, useItem.achievementProgress.progress) end if useItem.achievement then @@ -56,8 +63,8 @@ function usableItemMounts.onUse(player, item, fromPosition, target, toPosition, return true end -for k, v in pairs(config) do - usableItemMounts:id(k) +for itemId in pairs(config) do + usableItemMounts:id(itemId) end usableItemMounts:register() From 01abf503433e899af5051b7edff7ebf594f1b447 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Nov 2024 09:10:51 -0300 Subject: [PATCH 3/5] improvement: enable custom duration and simplify expiration calculation --- data/scripts/talkactions/ban.lua | 50 ++++++++++++++++++++++++++++++++ data/talkactions/scripts/ban.lua | 39 ------------------------- data/talkactions/talkactions.xml | 1 - 3 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 data/scripts/talkactions/ban.lua delete mode 100644 data/talkactions/scripts/ban.lua diff --git a/data/scripts/talkactions/ban.lua b/data/scripts/talkactions/ban.lua new file mode 100644 index 0000000000..8a34f55e6d --- /dev/null +++ b/data/scripts/talkactions/ban.lua @@ -0,0 +1,50 @@ +local talk = TalkAction("/ban") + +function talk.onSay(player, words, param) + if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GAMEMASTER then + return true + end + + local params = param:split(",") + if #params < 3 then + player:sendCancelMessage("Command requires 3 parameters: /ban , , ") + return true + end + + local name = params[1]:trim() + local banDuration = tonumber(params[2]:trim()) + local banReason = params[3]:trim() + + if not banDuration or banDuration <= 0 then + player:sendCancelMessage("Ban duration must be a positive number.") + return true + end + + local accountId = getAccountNumberByPlayerName(name) + if accountId == 0 then + return true + end + + local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId) + if resultId then + result.free(resultId) + return true + end + + local currentTime = os.time() + local expirationTime = currentTime + (banDuration * 24 * 60 * 60) + db.query(string.format("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (%d, %s, %d, %d, %d)", accountId, db.escapeString(banReason), currentTime, expirationTime, player:getGuid())) + + local target = Player(name) + if target then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has been banned for %d days.", target:getName(), banDuration)) + target:remove() + else + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has been banned for %d days.", name, banDuration)) + end + return true +end + +talk:separator(" ") +talk:groupType("gamemaster") +talk:register() diff --git a/data/talkactions/scripts/ban.lua b/data/talkactions/scripts/ban.lua deleted file mode 100644 index 44b9231456..0000000000 --- a/data/talkactions/scripts/ban.lua +++ /dev/null @@ -1,39 +0,0 @@ -local banDays = 7 - -function onSay(player, words, param) - if not player:getGroup():getAccess() then - return true - end - - local name = param - local reason = '' - - local separatorPos = param:find(',') - if separatorPos then - name = param:sub(0, separatorPos - 1) - reason = string.trim(param:sub(separatorPos + 1)) - end - - local accountId = getAccountNumberByPlayerName(name) - if accountId == 0 then - return false - end - - local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId) - if resultId then - result.free(resultId) - return false - end - - local timeNow = os.time() - db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" .. - accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")") - - local target = Player(name) - if target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.") - target:remove() - else - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.") - end -end diff --git a/data/talkactions/talkactions.xml b/data/talkactions/talkactions.xml index b3990d6636..fd89ea6125 100644 --- a/data/talkactions/talkactions.xml +++ b/data/talkactions/talkactions.xml @@ -2,7 +2,6 @@ - From ebc84ce3a747cdc376ab5ee734fde3d0944d32f0 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Nov 2024 09:11:45 -0300 Subject: [PATCH 4/5] Revert "refactor: simplify and improve mount item usage logic" This reverts commit 712c9f7aa7acd5102c92430871e3457b1d37f558. --- .../actions/others/usable_mount_items.lua | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/data/scripts/actions/others/usable_mount_items.lua b/data/scripts/actions/others/usable_mount_items.lua index 7c9d265849..7f902f8f45 100644 --- a/data/scripts/actions/others/usable_mount_items.lua +++ b/data/scripts/actions/others/usable_mount_items.lua @@ -2,20 +2,17 @@ local config = { [26194] = { -- vibrant egg name = "vortexion", mountId = 94, - tameMessage = "You receive the permission to ride a sparkion.", - achievementProgress = { name = "Vortex Tamer", progress = 3 } + tameMessage = "You receive the permission to ride a sparkion." }, [26340] = { -- crackling egg name = "neon sparkid", mountId = 98, - tameMessage = "You receive the permission to ride a neon sparkid.", - achievementProgress = { name = "Vortex Tamer", progress = 3 } + tameMessage = "You receive the permission to ride a neon sparkid." }, [26341] = { -- menacing egg name = "vortexion", mountId = 99, - tameMessage = "You receive the permission to ride a vortexion.", - achievementProgress = { name = "Vortex Tamer", progress = 3 } + tameMessage = "You receive the permission to ride a vortexion." }, [25521] = { -- mysterious scroll name = "rift runner", @@ -34,22 +31,18 @@ local config = { local usableItemMounts = Action() function usableItemMounts.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local useItem = config[item.itemid] - if not useItem then - return true - end - if not player:isPremium() then player:sendCancelMessage(RETURNVALUE_YOUNEEDPREMIUMACCOUNT) return true end + local useItem = config[item.itemid] if player:hasMount(useItem.mountId) then - return true + return false end - if useItem.achievementProgress then - player:addAchievementProgress(useItem.achievementProgress.name, useItem.achievementProgress.progress) + if table.contains({26194, 26340, 26341}, item.itemid) then + player:addAchievementProgress("Vortex Tamer", 3) end if useItem.achievement then @@ -63,8 +56,8 @@ function usableItemMounts.onUse(player, item, fromPosition, target, toPosition, return true end -for itemId in pairs(config) do - usableItemMounts:id(itemId) +for k, v in pairs(config) do + usableItemMounts:id(k) end usableItemMounts:register() From d8194eb5f346905e0565583b678057345aa35cb8 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Nov 2024 09:11:49 -0300 Subject: [PATCH 5/5] Revert "chore: vortex tamer achievement logic" This reverts commit ded4bf702d3ad43ce0e8f455679a9a5d36ba34f8. --- data/lib/core/storages.lua | 2 +- data/scripts/actions/others/usable_mount_items.lua | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/lib/core/storages.lua b/data/lib/core/storages.lua index bd67ee9d97..601e5ee419 100644 --- a/data/lib/core/storages.lua +++ b/data/lib/core/storages.lua @@ -33,7 +33,7 @@ PlayerStorageKeys = { nailCaseUseCount = 30031, swampDigging = 30032, insectoidCell = 30033, - -- empty: 30034 + vortexTamer = 30034, mutatedPumpkin = 30035, -- Achievements: diff --git a/data/scripts/actions/others/usable_mount_items.lua b/data/scripts/actions/others/usable_mount_items.lua index 7f902f8f45..3865b7c41f 100644 --- a/data/scripts/actions/others/usable_mount_items.lua +++ b/data/scripts/actions/others/usable_mount_items.lua @@ -42,7 +42,11 @@ function usableItemMounts.onUse(player, item, fromPosition, target, toPosition, end if table.contains({26194, 26340, 26341}, item.itemid) then - player:addAchievementProgress("Vortex Tamer", 3) + local storage = player:getStorageValue(PlayerStorageKeys.vortexTamer) + player:setStorageValue(PlayerStorageKeys.vortexTamer, storage + 1) + if storage == 1 then + player:addAchievement("Vortex Tamer") + end end if useItem.achievement then