From b84c7a01d0a999c3d7515a040afbca6075655748 Mon Sep 17 00:00:00 2001 From: omarcopires Date: Tue, 11 Feb 2025 22:09:35 -0300 Subject: [PATCH 1/3] fix: unintended depot message and improve code --- data/libs/functions/player.lua | 23 +++++++++++++++++++++++ data/scripts/movements/special_tiles.lua | 22 ---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index 8dae1cb7fe5..d5e6b27e01e 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -855,3 +855,26 @@ function Player.findItemInInbox(self, itemId, name) end return nil end + +function Player.checkAndSendDepotMessage(self) + for _, direction in ipairs(DIRECTIONS_TABLE) do + local playerPosition = self:getPosition() + playerPosition:getNextPosition(direction) + + local tile = playerPosition:getTile() + if tile then + local depotItem = tile:getItemByType(ITEM_TYPE_DEPOT) + if depotItem then + local depotItems = 0 + for id = 1, configManager.getNumber(configKeys.DEPOT_BOXES) do + depotItems = depotItems + self:getDepotChest(id, true):getItemHoldingCount() + end + + self:sendTextMessage(MESSAGE_STATUS, string.format("Your depot contains %d item%s Your supply stash contains %d item%s", depotItems, depotItems ~= 1 and "s." or ".", self:getStashCount(), self:getStashCount() ~= 1 and "s." or ".")) + self:setSpecialContainersAvailable(true, true, true) + return true + end + end + end + return true +end diff --git a/data/scripts/movements/special_tiles.lua b/data/scripts/movements/special_tiles.lua index eed5e6400b6..c57440e6b55 100644 --- a/data/scripts/movements/special_tiles.lua +++ b/data/scripts/movements/special_tiles.lua @@ -1,24 +1,6 @@ local increasing = { [419] = 420, [431] = 430, [452] = 453, [563] = 564, [549] = 562, [10145] = 10146 } local decreasing = { [420] = 419, [430] = 431, [453] = 452, [564] = 563, [562] = 549, [10146] = 10145 } -function Player:checkAndSendDepotMessage() - for _, direction in ipairs(DIRECTIONS_TABLE) do - local playerPosition = self:getPosition() - playerPosition:getNextPosition(direction) - local depotItem = playerPosition:getTile():getItemByType(ITEM_TYPE_DEPOT) - if depotItem ~= nil or self:getGroup():getAccess() then - local depotItems = 0 - for id = 1, configManager.getNumber(configKeys.DEPOT_BOXES) do - depotItems = depotItems + self:getDepotChest(id, true):getItemHoldingCount() - end - self:sendTextMessage(MESSAGE_STATUS, string.format("Your depot contains %d item%s Your supply stash contains %d item%s", depotItems, depotItems > 1 and "s." or ".", self:getStashCount(), self:getStashCount() > 1 and "s." or ".")) - self:setSpecialContainersAvailable(true, true, true) - return true - end - end - return false -end - local tile = MoveEvent() function tile.onStepIn(creature, item, position, fromPosition) @@ -27,10 +9,6 @@ function tile.onStepIn(creature, item, position, fromPosition) return true end - if player:isInGhostMode() then - return player:checkAndSendDepotMessage() - end - if not increasing[item.itemid] then return true end From 3d0f596ec3c26c248b06f4e7539965abd3fc692c Mon Sep 17 00:00:00 2001 From: omarcopires Date: Tue, 11 Feb 2025 22:15:43 -0300 Subject: [PATCH 2/3] improve: readability of depot message --- data/libs/functions/player.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index d5e6b27e01e..8fce4d12e23 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -870,7 +870,10 @@ function Player.checkAndSendDepotMessage(self) depotItems = depotItems + self:getDepotChest(id, true):getItemHoldingCount() end - self:sendTextMessage(MESSAGE_STATUS, string.format("Your depot contains %d item%s Your supply stash contains %d item%s", depotItems, depotItems ~= 1 and "s." or ".", self:getStashCount(), self:getStashCount() ~= 1 and "s." or ".")) + local depotMessage = string.format("Your depot contains %d item%s", depotItems, depotItems ~= 1 and "s." or ".") + local stashMessage = string.format("Your supply stash contains %d item%s", self:getStashCount(), self:getStashCount() ~= 1 and "s." or ".") + + self:sendTextMessage(MESSAGE_STATUS, string.format("%s %s", depotMessage, stashMessage)) self:setSpecialContainersAvailable(true, true, true) return true end From 4b861d76983c7a0febecdcdcc764514e4dc803e2 Mon Sep 17 00:00:00 2001 From: omarcopires Date: Thu, 20 Feb 2025 19:43:36 -0300 Subject: [PATCH 3/3] refactor: make checkAndSendDepotMessage a local function --- data/libs/functions/player.lua | 26 ----------------------- data/scripts/movements/special_tiles.lua | 27 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index 8fce4d12e23..8dae1cb7fe5 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -855,29 +855,3 @@ function Player.findItemInInbox(self, itemId, name) end return nil end - -function Player.checkAndSendDepotMessage(self) - for _, direction in ipairs(DIRECTIONS_TABLE) do - local playerPosition = self:getPosition() - playerPosition:getNextPosition(direction) - - local tile = playerPosition:getTile() - if tile then - local depotItem = tile:getItemByType(ITEM_TYPE_DEPOT) - if depotItem then - local depotItems = 0 - for id = 1, configManager.getNumber(configKeys.DEPOT_BOXES) do - depotItems = depotItems + self:getDepotChest(id, true):getItemHoldingCount() - end - - local depotMessage = string.format("Your depot contains %d item%s", depotItems, depotItems ~= 1 and "s." or ".") - local stashMessage = string.format("Your supply stash contains %d item%s", self:getStashCount(), self:getStashCount() ~= 1 and "s." or ".") - - self:sendTextMessage(MESSAGE_STATUS, string.format("%s %s", depotMessage, stashMessage)) - self:setSpecialContainersAvailable(true, true, true) - return true - end - end - end - return true -end diff --git a/data/scripts/movements/special_tiles.lua b/data/scripts/movements/special_tiles.lua index c57440e6b55..bccdf5b82f0 100644 --- a/data/scripts/movements/special_tiles.lua +++ b/data/scripts/movements/special_tiles.lua @@ -1,6 +1,31 @@ local increasing = { [419] = 420, [431] = 430, [452] = 453, [563] = 564, [549] = 562, [10145] = 10146 } local decreasing = { [420] = 419, [430] = 431, [453] = 452, [564] = 563, [562] = 549, [10146] = 10145 } +local function checkAndSendDepotMessage(player) + for _, direction in ipairs(DIRECTIONS_TABLE) do + local playerPosition = player:getPosition() + playerPosition:getNextPosition(direction) + + local tile = playerPosition:getTile() + if tile then + local depotItem = tile:getItemByType(ITEM_TYPE_DEPOT) + if depotItem then + local depotItems = 0 + for id = 1, configManager.getNumber(configKeys.DEPOT_BOXES) do + depotItems = depotItems + player:getDepotChest(id, true):getItemHoldingCount() + end + + local depotMessage = string.format("Your depot contains %d item%s", depotItems, depotItems ~= 1 and "s." or ".") + local stashMessage = string.format("Your supply stash contains %d item%s", player:getStashCount(), player:getStashCount() ~= 1 and "s." or ".") + + player:sendTextMessage(MESSAGE_STATUS, string.format("%s %s", depotMessage, stashMessage)) + player:setSpecialContainersAvailable(true, true, true) + end + end + end + return true +end + local tile = MoveEvent() function tile.onStepIn(creature, item, position, fromPosition) @@ -25,7 +50,7 @@ function tile.onStepIn(creature, item, position, fromPosition) end if Tile(position):hasFlag(TILESTATE_PROTECTIONZONE) then - return player:checkAndSendDepotMessage() + return checkAndSendDepotMessage(player) end if item.actionid ~= 0 and player:getStorageValue(item.actionid) <= 0 then