From febf8903a26ab2629b13fa94895189f218fc6388 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 6 Sep 2024 06:18:26 -0300 Subject: [PATCH 1/3] Update player.lua --- data/events/scripts/player.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index ec1a92f3528..3a62c18e66f 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -279,8 +279,17 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, local toTile = Tile(toCylinder:getPosition()) if toTile then local topDownItem = toTile:getTopDownItem() - if topDownItem and table.contains({ BATHTUB_EMPTY, BATHTUB_FILLED }, topDownItem:getId()) then - return false + if topDownItem then + local topDownItemItemId = topDownItem:getId() + -- Bath tube + if table.contains({ BATHTUB_EMPTY, BATHTUB_FILLED }, topDownItemItemId) then + return false + -- Podium + elseif ItemType(topDownItemItemId):isPodium() then + self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + self:getPosition():sendMagicEffect(CONST_ME_POFF) + return false + end end end From 7ebb6a638e36d95473654ae1cf4378f3008906a0 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 6 Sep 2024 06:28:05 -0300 Subject: [PATCH 2/3] update --- data/events/scripts/player.lua | 47 ++----------------- data/libs/functions/player.lua | 12 +++-- .../functions/items/item_type_functions.cpp | 11 +++++ .../functions/items/item_type_functions.hpp | 2 + 4 files changed, 24 insertions(+), 48 deletions(-) diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 3a62c18e66f..72e5402263f 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -275,17 +275,14 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, return true end - -- Bath tube local toTile = Tile(toCylinder:getPosition()) if toTile then local topDownItem = toTile:getTopDownItem() if topDownItem then local topDownItemItemId = topDownItem:getId() - -- Bath tube - if table.contains({ BATHTUB_EMPTY, BATHTUB_FILLED }, topDownItemItemId) then + if table.contains({ BATHTUB_EMPTY, BATHTUB_FILLED }, topDownItemItemId) then -- Bath tube return false - -- Podium - elseif ItemType(topDownItemItemId):isPodium() then + elseif ItemType(topDownItemItemId):isPodium() then -- Podium self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) self:getPosition():sendMagicEffect(CONST_ME_POFF) return false @@ -324,45 +321,7 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, end -- Reward System - if toPosition.x == CONTAINER_POSITION then - local containerId = toPosition.y - 64 - local container = self:getContainerById(containerId) - if not container then - return true - end - - -- Do not let the player insert items into either the Reward Container or the Reward Chest - local itemId = container:getId() - if itemId == ITEM_REWARD_CONTAINER or itemId == ITEM_REWARD_CHEST then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - - -- The player also shouldn't be able to insert items into the boss corpse - local tileCorpse = Tile(container:getPosition()) - if tileCorpse then - for index, value in ipairs(tileCorpse:getItems() or {}) do - if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - end - end - end - - -- Do not let the player move the boss corpse. - if item:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - - -- Players cannot throw items on reward chest - local tileChest = Tile(toPosition) - if tileChest and tileChest:getItemById(ITEM_REWARD_CHEST) then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - self:getPosition():sendMagicEffect(CONST_ME_POFF) - return false - end + self:executeRewardEvents(item, toPosition) if tile and tile:getItemById(370) then -- Trapdoor diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index a2fb8bc0de6..8c86349c0be 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -877,18 +877,22 @@ function Player:executeRewardEvents(item, toPosition) -- The player also shouldn't be able to insert items into the boss corpse local tileCorpse = Tile(container:getPosition()) - for index, value in ipairs(tileCorpse:getItems() or {}) do - if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false + if tileCorpse then + for index, value in ipairs(tileCorpse:getItems() or {}) do + if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then + self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + return false + end end end end + -- Do not let the player move the boss corpse. if item:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 then self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return false end + -- Players cannot throw items on reward chest local tileChest = Tile(toPosition) if tileChest and tileChest:getItemById(ITEM_REWARD_CHEST) then diff --git a/src/lua/functions/items/item_type_functions.cpp b/src/lua/functions/items/item_type_functions.cpp index b528795a050..c186913f055 100644 --- a/src/lua/functions/items/item_type_functions.cpp +++ b/src/lua/functions/items/item_type_functions.cpp @@ -215,6 +215,17 @@ int ItemTypeFunctions::luaItemTypeIsQuiver(lua_State* L) { return 1; } +int ItemTypeFunctions::luaItemTypeIsPodium(lua_State* L) { + // itemType:isPodium() + const ItemType* itemType = getUserdata(L, 1); + if (itemType) { + pushBoolean(L, itemType->isPodium); + } else { + lua_pushnil(L); + } + return 1; +} + int ItemTypeFunctions::luaItemTypeGetType(lua_State* L) { // itemType:getType() const ItemType* itemType = getUserdata(L, 1); diff --git a/src/lua/functions/items/item_type_functions.hpp b/src/lua/functions/items/item_type_functions.hpp index ce53d429804..d283609d947 100644 --- a/src/lua/functions/items/item_type_functions.hpp +++ b/src/lua/functions/items/item_type_functions.hpp @@ -35,6 +35,7 @@ class ItemTypeFunctions final : LuaScriptInterface { registerMethod(L, "ItemType", "isPickupable", ItemTypeFunctions::luaItemTypeIsPickupable); registerMethod(L, "ItemType", "isKey", ItemTypeFunctions::luaItemTypeIsKey); registerMethod(L, "ItemType", "isQuiver", ItemTypeFunctions::luaItemTypeIsQuiver); + registerMethod(L, "ItemType", "isPodium", ItemTypeFunctions::luaItemTypeIsPodium); registerMethod(L, "ItemType", "getType", ItemTypeFunctions::luaItemTypeGetType); registerMethod(L, "ItemType", "getId", ItemTypeFunctions::luaItemTypeGetId); @@ -102,6 +103,7 @@ class ItemTypeFunctions final : LuaScriptInterface { static int luaItemTypeIsPickupable(lua_State* L); static int luaItemTypeIsKey(lua_State* L); static int luaItemTypeIsQuiver(lua_State* L); + static int luaItemTypeIsPodium(lua_State* L); static int luaItemTypeGetType(lua_State* L); static int luaItemTypeGetId(lua_State* L); From ea86060977bfbb77af0670b399c75e22563aa8e3 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 6 Sep 2024 06:33:31 -0300 Subject: [PATCH 3/3] update --- data/events/scripts/player.lua | 47 +++++++++++++++++++++++++++++++--- data/libs/functions/player.lua | 43 ------------------------------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 72e5402263f..39219822bf1 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -321,15 +321,54 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, end -- Reward System - self:executeRewardEvents(item, toPosition) + if toPosition.x == CONTAINER_POSITION then + local containerId = toPosition.y - 64 + local container = self:getContainerById(containerId) + if not container then + return true + end - if tile and tile:getItemById(370) then - -- Trapdoor + -- Do not let the player insert items into either the Reward Container or the Reward Chest + local itemId = container:getId() + if itemId == ITEM_REWARD_CONTAINER or itemId == ITEM_REWARD_CHEST then + self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + return false + end + + -- The player also shouldn't be able to insert items into the boss corpse + local tileCorpse = Tile(container:getPosition()) + if tileCorpse then + for index, value in ipairs(tileCorpse:getItems() or {}) do + if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then + self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + return false + end + end + end + end + + -- Do not let the player move the boss corpse. + if item:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 then self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - self:getPosition():sendMagicEffect(CONST_ME_POFF) return false end + if tile then + -- Players cannot throw items on reward chest + if tile:getItemById(ITEM_REWARD_CHEST) then + self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + self:getPosition():sendMagicEffect(CONST_ME_POFF) + return false + end + + -- Trapdoor + if tile:getItemById(370) then + self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + self:getPosition():sendMagicEffect(CONST_ME_POFF) + return false + end + end + if not antiPush(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) then return false end diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index 8c86349c0be..dccf92c340d 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -859,49 +859,6 @@ function Player.inBossFight(self) return false end --- For use of data/events/scripts/player.lua -function Player:executeRewardEvents(item, toPosition) - if toPosition.x == CONTAINER_POSITION then - local containerId = toPosition.y - 64 - local container = self:getContainerById(containerId) - if not container then - return true - end - - -- Do not let the player insert items into either the Reward Container or the Reward Chest - local itemId = container:getId() - if itemId == ITEM_REWARD_CONTAINER or itemId == ITEM_REWARD_CHEST then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - - -- The player also shouldn't be able to insert items into the boss corpse - local tileCorpse = Tile(container:getPosition()) - if tileCorpse then - for index, value in ipairs(tileCorpse:getItems() or {}) do - if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - end - end - end - - -- Do not let the player move the boss corpse. - if item:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - - -- Players cannot throw items on reward chest - local tileChest = Tile(toPosition) - if tileChest and tileChest:getItemById(ITEM_REWARD_CHEST) then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - self:getPosition():sendMagicEffect(CONST_ME_POFF) - return false - end -end - do local loyaltySystem = { enable = configManager.getBoolean(configKeys.LOYALTY_ENABLED),