From 0e2d7fd0fa28cadf995e6ead6f669f9dca3ee87c Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 1 Dec 2023 13:33:21 -0300 Subject: [PATCH] feat: custom npc shop items from lua table (#1947) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This introduces a new feature that allows for the creation of NPC shop items from lua dynamic tables. It is now possible to associate specific items with keywords/storage and other methods, and when a player interacts with an NPC shop, the items related to those methods will be displayed in the shop's inventory. Key changes included in this pull request: • Added support for associating items custom tables in the NPC shop system. • Implemented the logic to display items from hireling based on keywords when opening an NPC shop. --- data-otservbr-global/npc/battlemart.lua | 294 ++++---- data-otservbr-global/npc/hireling.lua | 643 ++++++++++-------- src/creatures/npcs/npc.cpp | 16 +- src/creatures/npcs/npc.hpp | 13 +- src/creatures/players/player.cpp | 5 +- .../functions/creatures/npc/npc_functions.cpp | 65 +- .../functions/creatures/npc/npc_functions.hpp | 2 + src/server/network/protocol/protocolgame.cpp | 2 +- 8 files changed, 598 insertions(+), 442 deletions(-) diff --git a/data-otservbr-global/npc/battlemart.lua b/data-otservbr-global/npc/battlemart.lua index 2461fc91129..b4b99993411 100644 --- a/data-otservbr-global/npc/battlemart.lua +++ b/data-otservbr-global/npc/battlemart.lua @@ -50,137 +50,173 @@ npcType.onCloseChannel = function(npc, creature) npcHandler:onCloseChannel(npc, creature) end -npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) - -npcConfig.shop = { - { itemName = "animate dead rune", clientId = 3203, buy = 375 }, - { itemName = "arrow", clientId = 3447, buy = 3 }, - { itemName = "assassin star", clientId = 7368, buy = 100 }, - { itemName = "avalanche rune", clientId = 3161, buy = 57 }, - { itemName = "backpack", clientId = 2854, buy = 20 }, - { itemName = "blank rune", clientId = 3147, buy = 10 }, - { itemName = "blue quiver", clientId = 35848, buy = 400 }, - { itemName = "bolt", clientId = 3446, buy = 4 }, - { itemName = "bow", clientId = 3350, buy = 400 }, - { itemName = "brown mushroom", clientId = 3725, buy = 10 }, - { itemName = "chameleon rune", clientId = 3178, buy = 210 }, - { itemName = "collar of blue plasma", clientId = 23542, buy = 60000 }, - { itemName = "collar of green plasma", clientId = 23543, buy = 60000 }, - { itemName = "collar of red plasma", clientId = 23544, buy = 60000 }, - { itemName = "convince creature rune", clientId = 3177, buy = 80 }, - { itemName = "crowbar", clientId = 3304, buy = 260 }, - { itemName = "crystalline arrow", clientId = 15793, buy = 20 }, - { itemName = "cure poison rune", clientId = 3153, buy = 65 }, - { itemName = "desintegrate rune", clientId = 3197, buy = 26 }, - { itemName = "destroy field rune", clientId = 3148, buy = 15 }, - { itemName = "diamond arrow", clientId = 35901, buy = 100 }, - { itemName = "drill bolt", clientId = 16142, buy = 12 }, - { itemName = "dwarven ring", clientId = 3097, buy = 2000 }, - { itemName = "earth arrow", clientId = 774, buy = 5 }, - { itemName = "enchanted spear", clientId = 7367, buy = 30 }, - { itemName = "energy bomb rune", clientId = 3149, buy = 203 }, - { itemName = "energy field rune", clientId = 3164, buy = 38 }, - { itemName = "energy ring", clientId = 3051, buy = 2000 }, - { itemName = "energy wall rune", clientId = 3166, buy = 85 }, - { itemName = "enhanced exercise axe", clientId = 35280, buy = 2340000 }, - { itemName = "enhanced exercise bow", clientId = 35282, buy = 2340000 }, - { itemName = "enhanced exercise club", clientId = 35281, buy = 2340000 }, - { itemName = "enhanced exercise rod", clientId = 35283, buy = 2340000 }, - { itemName = "enhanced exercise shield", clientId = 44066, buy = 2340000 }, - { itemName = "enhanced exercise sword", clientId = 35279, buy = 2340000 }, - { itemName = "enhanced exercise wand", clientId = 35284, buy = 2340000 }, - { itemName = "envenomed arrow", clientId = 16143, buy = 12 }, - { itemName = "exercise axe", clientId = 28553, buy = 1800000 }, - { itemName = "exercise bow", clientId = 28555, buy = 1800000 }, - { itemName = "exercise club", clientId = 28554, buy = 1800000 }, - { itemName = "exercise rod", clientId = 28556, buy = 1800000 }, - { itemName = "exercise sword", clientId = 28552, buy = 1800000 }, - { itemName = "exercise wand", clientId = 28557, buy = 1800000 }, - { itemName = "explosion rune", clientId = 3200, buy = 31 }, - { itemName = "fire bomb rune", clientId = 3192, buy = 147 }, - { itemName = "fire field rune", clientId = 3188, buy = 28 }, - { itemName = "fire mushroom", clientId = 3731, buy = 300 }, - { itemName = "fire wall rune", clientId = 3190, buy = 61 }, - { itemName = "fireball rune", clientId = 3189, buy = 30 }, - { itemName = "fishing rod", clientId = 3483, buy = 150 }, - { itemName = "flaming arrow", clientId = 763, buy = 5 }, - { itemName = "flash arrow", clientId = 761, buy = 5 }, - { itemName = "flask of rust remover", clientId = 9016, buy = 50 }, - { itemName = "gill necklace", clientId = 16108, buy = 20000 }, - { itemName = "glacier amulet", clientId = 815, buy = 15000 }, - { itemName = "great fireball rune", clientId = 3191, buy = 57 }, - { itemName = "great health potion", clientId = 239, buy = 225 }, - { itemName = "great mana potion", clientId = 238, buy = 144 }, - { itemName = "great spirit potion", clientId = 7642, buy = 228 }, - { itemName = "health potion", clientId = 266, buy = 50 }, - { itemName = "heavy magic missile rune", clientId = 3198, buy = 12 }, - { itemName = "holy missile rune", clientId = 3182, buy = 16 }, - { itemName = "hunting spear", clientId = 3347, buy = 25 }, - { itemName = "icicle rune", clientId = 3158, buy = 30 }, - { itemName = "intense healing rune", clientId = 3152, buy = 95 }, - { itemName = "leviathan's amulet", clientId = 9303, buy = 30000 }, - { itemName = "life ring", clientId = 3052, buy = 900 }, - { itemName = "light magic missile rune", clientId = 3174, buy = 4 }, - { itemName = "lightning pendant", clientId = 816, buy = 15000 }, - { itemName = "magic wall rune", clientId = 3180, buy = 116 }, - { itemName = "magma amulet", clientId = 817, buy = 15000 }, - { itemName = "mana potion", clientId = 268, buy = 56 }, - { itemName = "mana shield potion", clientId = 35563, buy = 200000 }, - { itemName = "masterful exercise axe", clientId = 35286, buy = 2700000 }, - { itemName = "masterful exercise bow", clientId = 35288, buy = 2700000 }, - { itemName = "masterful exercise club", clientId = 35287, buy = 2700000 }, - { itemName = "masterful exercise rod", clientId = 35289, buy = 2700000 }, - { itemName = "masterful exercise shield", clientId = 44067, buy = 2700000 }, - { itemName = "masterful exercise sword", clientId = 35285, buy = 2700000 }, - { itemName = "masterful exercise wand", clientId = 35290, buy = 2700000 }, - { itemName = "might ring", clientId = 3048, buy = 5000 }, - { itemName = "onyx arrow", clientId = 7365, buy = 7 }, - { itemName = "paralyze rune", clientId = 3165, buy = 700 }, - { itemName = "piercing bolt", clientId = 7363, buy = 5 }, - { itemName = "poison bomb rune", clientId = 3173, buy = 85 }, - { itemName = "poison field rune", clientId = 3172, buy = 21 }, - { itemName = "poison wall rune", clientId = 3176, buy = 52 }, - { itemName = "power bolt", clientId = 3450, buy = 7 }, - { itemName = "prismatic bolt", clientId = 16141, buy = 20 }, - { itemName = "prismatic necklace", clientId = 16113, buy = 20000 }, - { itemName = "prismatic ring", clientId = 16114, buy = 100000 }, - { itemName = "quiver", clientId = 35562, buy = 400 }, - { itemName = "red quiver", clientId = 35849, buy = 400 }, - { itemName = "ring of blue plasma", clientId = 23529, buy = 80000 }, - { itemName = "ring of green plasma", clientId = 23531, buy = 80000 }, - { itemName = "ring of healing", clientId = 3098, buy = 2000 }, - { itemName = "ring of red plasma", clientId = 23533, buy = 80000 }, - { itemName = "royal star", clientId = 25759, buy = 110 }, - { itemName = "sacred tree amulet", clientId = 9302, buy = 30000 }, - { itemName = "shiver arrow", clientId = 762, buy = 5 }, - { itemName = "shockwave amulet", clientId = 9304, buy = 30000 }, - { itemName = "sniper arrow", clientId = 7364, buy = 5 }, - { itemName = "soulfire rune", clientId = 3195, buy = 46 }, - { itemName = "spear", clientId = 3277, buy = 5 }, - { itemName = "spectral bolt", clientId = 35902, buy = 70 }, - { itemName = "stalagmite rune", clientId = 3179, buy = 12 }, - { itemName = "stealth ring", clientId = 3049, buy = 5000 }, - { itemName = "stone shower rune", clientId = 3175, buy = 37 }, - { itemName = "stone skin amulet", clientId = 3081, buy = 5000 }, - { itemName = "strong health potion", clientId = 236, buy = 115 }, - { itemName = "strong mana potion", clientId = 237, buy = 93 }, - { itemName = "sudden death rune", clientId = 3155, buy = 135 }, - { itemName = "supreme health potion", clientId = 23375, buy = 625 }, - { itemName = "tarsal arrow", clientId = 14251, buy = 6 }, - { itemName = "terra amulet", clientId = 814, buy = 15000 }, - { itemName = "throwing star", clientId = 3287, buy = 42 }, - { itemName = "thunderstorm rune", clientId = 3202, buy = 47 }, - { itemName = "time ring", clientId = 3053, buy = 2000 }, - { itemName = "torch", clientId = 2920, buy = 2 }, - { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, - { itemName = "ultimate health potion", clientId = 7643, buy = 379 }, - { itemName = "ultimate mana potion", clientId = 23373, buy = 438 }, - { itemName = "ultimate spirit potion", clientId = 23374, buy = 438 }, - { itemName = "vortex bolt", clientId = 14252, buy = 6 }, - { itemName = "wild growth rune", clientId = 3156, buy = 160 }, - { itemName = "worm", clientId = 3492, buy = 1 }, +local itemsTable = { + ["foods"] = { + { itemName = "brown mushroom", clientId = 3725, buy = 10 }, + { itemName = "fire mushroom", clientId = 3731, buy = 300 }, + }, + ["exercise weapons"] = { + { itemName = "enhanced exercise axe", clientId = 35280, buy = 2340000 }, + { itemName = "enhanced exercise bow", clientId = 35282, buy = 2340000 }, + { itemName = "enhanced exercise club", clientId = 35281, buy = 2340000 }, + { itemName = "enhanced exercise rod", clientId = 35283, buy = 2340000 }, + { itemName = "enhanced exercise shield", clientId = 44066, buy = 2340000 }, + { itemName = "enhanced exercise sword", clientId = 35279, buy = 2340000 }, + { itemName = "enhanced exercise wand", clientId = 35284, buy = 2340000 }, + { itemName = "exercise axe", clientId = 28553, buy = 1800000 }, + { itemName = "exercise bow", clientId = 28555, buy = 1800000 }, + { itemName = "exercise club", clientId = 28554, buy = 1800000 }, + { itemName = "exercise rod", clientId = 28556, buy = 1800000 }, + { itemName = "exercise sword", clientId = 28552, buy = 1800000 }, + { itemName = "exercise wand", clientId = 28557, buy = 1800000 }, + { itemName = "masterful exercise axe", clientId = 35286, buy = 2700000 }, + { itemName = "masterful exercise bow", clientId = 35288, buy = 2700000 }, + { itemName = "masterful exercise club", clientId = 35287, buy = 2700000 }, + { itemName = "masterful exercise rod", clientId = 35289, buy = 2700000 }, + { itemName = "masterful exercise shield", clientId = 44067, buy = 2700000 }, + { itemName = "masterful exercise sword", clientId = 35285, buy = 2700000 }, + { itemName = "masterful exercise wand", clientId = 35290, buy = 2700000 }, + }, + ["distance equipments"] = { + { itemName = "envenomed arrow", clientId = 16143, buy = 12 }, + { itemName = "diamond arrow", clientId = 35901, buy = 100 }, + { itemName = "drill bolt", clientId = 16142, buy = 12 }, + { itemName = "crystalline arrow", clientId = 15793, buy = 20 }, + { itemName = "blue quiver", clientId = 35848, buy = 400 }, + { itemName = "bolt", clientId = 3446, buy = 4 }, + { itemName = "bow", clientId = 3350, buy = 400 }, + { itemName = "arrow", clientId = 3447, buy = 3 }, + { itemName = "assassin star", clientId = 7368, buy = 100 }, + { itemName = "earth arrow", clientId = 774, buy = 5 }, + { itemName = "enchanted spear", clientId = 7367, buy = 30 }, + { itemName = "flaming arrow", clientId = 763, buy = 5 }, + { itemName = "flash arrow", clientId = 761, buy = 5 }, + { itemName = "royal star", clientId = 25759, buy = 110 }, + { itemName = "quiver", clientId = 35562, buy = 400 }, + { itemName = "red quiver", clientId = 35849, buy = 400 }, + { itemName = "power bolt", clientId = 3450, buy = 7 }, + { itemName = "piercing bolt", clientId = 7363, buy = 5 }, + { itemName = "onyx arrow", clientId = 7365, buy = 7 }, + { itemName = "prismatic bolt", clientId = 16141, buy = 20 }, + { itemName = "shiver arrow", clientId = 762, buy = 5 }, + { itemName = "sniper arrow", clientId = 7364, buy = 5 }, + { itemName = "spear", clientId = 3277, buy = 5 }, + { itemName = "spectral bolt", clientId = 35902, buy = 70 }, + { itemName = "throwing star", clientId = 3287, buy = 42 }, + { itemName = "tarsal arrow", clientId = 14251, buy = 6 }, + { itemName = "vortex bolt", clientId = 14252, buy = 6 }, + { itemName = "hunting spear", clientId = 3347, buy = 25 }, + }, + ["runes"] = { + { itemName = "avalanche rune", clientId = 3161, buy = 57 }, + { itemName = "blank rune", clientId = 3147, buy = 10 }, + { itemName = "chameleon rune", clientId = 3178, buy = 210 }, + { itemName = "animate dead rune", clientId = 3203, buy = 375 }, + { itemName = "convince creature rune", clientId = 3177, buy = 80 }, + { itemName = "cure poison rune", clientId = 3153, buy = 65 }, + { itemName = "desintegrate rune", clientId = 3197, buy = 26 }, + { itemName = "destroy field rune", clientId = 3148, buy = 15 }, + { itemName = "energy wall rune", clientId = 3166, buy = 85 }, + { itemName = "energy bomb rune", clientId = 3149, buy = 203 }, + { itemName = "energy field rune", clientId = 3164, buy = 38 }, + { itemName = "explosion rune", clientId = 3200, buy = 31 }, + { itemName = "fire bomb rune", clientId = 3192, buy = 147 }, + { itemName = "fire field rune", clientId = 3188, buy = 28 }, + { itemName = "fire wall rune", clientId = 3190, buy = 61 }, + { itemName = "fireball rune", clientId = 3189, buy = 30 }, + { itemName = "great fireball rune", clientId = 3191, buy = 57 }, + { itemName = "heavy magic missile rune", clientId = 3198, buy = 12 }, + { itemName = "holy missile rune", clientId = 3182, buy = 16 }, + { itemName = "icicle rune", clientId = 3158, buy = 30 }, + { itemName = "intense healing rune", clientId = 3152, buy = 95 }, + { itemName = "light magic missile rune", clientId = 3174, buy = 4 }, + { itemName = "magic wall rune", clientId = 3180, buy = 116 }, + { itemName = "paralyze rune", clientId = 3165, buy = 700 }, + { itemName = "poison bomb rune", clientId = 3173, buy = 85 }, + { itemName = "poison field rune", clientId = 3172, buy = 21 }, + { itemName = "poison wall rune", clientId = 3176, buy = 52 }, + { itemName = "stone shower rune", clientId = 3175, buy = 37 }, + { itemName = "stalagmite rune", clientId = 3179, buy = 12 }, + { itemName = "sudden death rune", clientId = 3155, buy = 135 }, + { itemName = "soulfire rune", clientId = 3195, buy = 46 }, + { itemName = "thunderstorm rune", clientId = 3202, buy = 47 }, + { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, + { itemName = "wild growth rune", clientId = 3156, buy = 160 }, + }, + ["tools"] = { + { itemName = "fishing rod", clientId = 3483, buy = 150 }, + { itemName = "flask of rust remover", clientId = 9016, buy = 50 }, + { itemName = "torch", clientId = 2920, buy = 2 }, + { itemName = "worm", clientId = 3492, buy = 1 }, + { itemName = "crowbar", clientId = 3304, buy = 260 }, + { itemName = "backpack", clientId = 2854, buy = 20 }, + }, + ["amulets"] = { + { itemName = "gill necklace", clientId = 16108, buy = 20000 }, + { itemName = "glacier amulet", clientId = 815, buy = 15000 }, + { itemName = "leviathan's amulet", clientId = 9303, buy = 30000 }, + { itemName = "magma amulet", clientId = 817, buy = 15000 }, + { itemName = "lightning pendant", clientId = 816, buy = 15000 }, + { itemName = "prismatic necklace", clientId = 16113, buy = 20000 }, + { itemName = "sacred tree amulet", clientId = 9302, buy = 30000 }, + { itemName = "shockwave amulet", clientId = 9304, buy = 30000 }, + { itemName = "stone skin amulet", clientId = 3081, buy = 5000 }, + { itemName = "collar of blue plasma", clientId = 23542, buy = 60000 }, + { itemName = "collar of green plasma", clientId = 23543, buy = 60000 }, + { itemName = "collar of red plasma", clientId = 23544, buy = 60000 }, + { itemName = "terra amulet", clientId = 814, buy = 15000 }, + }, + ["rings"] = { + { itemName = "life ring", clientId = 3052, buy = 900 }, + { itemName = "might ring", clientId = 3048, buy = 5000 }, + { itemName = "ring of blue plasma", clientId = 23529, buy = 80000 }, + { itemName = "ring of green plasma", clientId = 23531, buy = 80000 }, + { itemName = "ring of healing", clientId = 3098, buy = 2000 }, + { itemName = "prismatic ring", clientId = 16114, buy = 100000 }, + { itemName = "ring of red plasma", clientId = 23533, buy = 80000 }, + { itemName = "stealth ring", clientId = 3049, buy = 5000 }, + { itemName = "time ring", clientId = 3053, buy = 2000 }, + { itemName = "dwarven ring", clientId = 3097, buy = 2000 }, + { itemName = "energy ring", clientId = 3051, buy = 2000 }, + }, + ["potions"] = { + { itemName = "great health potion", clientId = 239, buy = 225 }, + { itemName = "great mana potion", clientId = 238, buy = 144 }, + { itemName = "great spirit potion", clientId = 7642, buy = 228 }, + { itemName = "health potion", clientId = 266, buy = 50 }, + { itemName = "mana potion", clientId = 268, buy = 56 }, + { itemName = "mana shield potion", clientId = 35563, buy = 200000 }, + { itemName = "ultimate health potion", clientId = 7643, buy = 379 }, + { itemName = "ultimate mana potion", clientId = 23373, buy = 438 }, + { itemName = "ultimate spirit potion", clientId = 23374, buy = 438 }, + { itemName = "supreme health potion", clientId = 23375, buy = 625 }, + { itemName = "strong health potion", clientId = 236, buy = 115 }, + { itemName = "strong mana potion", clientId = 237, buy = 93 }, + }, } +local function creatureSayCallback(npc, player, type, message) + local formattedCategoryNames = {} + for categoryName, _ in pairs(itemsTable) do + table.insert(formattedCategoryNames, "{" .. categoryName .. "}") + end + + local categoryTable = itemsTable[message:lower()] + if MsgContains(message, "shop options") then + npcHandler:say("I sell a selection of " .. table.concat(formattedCategoryNames, ", "), npc, player) + elseif categoryTable then + npcHandler:say("Here are the items for the category " .. message, npc, player) + npc:openShopWindowTable(player, categoryTable) + end +end + +npcHandler:setMessage(MESSAGE_GREET, "It is good to see you. I'm always at your {shop options}") +npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, |PLAYERNAME|, I'll be here if you need me again.") +npcHandler:setMessage(MESSAGE_WALKAWAY, "Come back soon!") + +npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) +npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) + -- On buy npc shop message npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost) npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks) diff --git a/data-otservbr-global/npc/hireling.lua b/data-otservbr-global/npc/hireling.lua index 519ff32773a..8ee39c5e391 100644 --- a/data-otservbr-global/npc/hireling.lua +++ b/data-otservbr-global/npc/hireling.lua @@ -30,300 +30,342 @@ function createHirelingType(HirelingName) floorchange = false, } - npcConfig.shop = { - { itemName = "amphora", clientId = 2893, buy = 4 }, - { itemName = "animate dead rune", clientId = 3203, buy = 377 }, - { itemName = "armor rack kit", clientId = 6111, buy = 90 }, - { itemName = "arrow", clientId = 3447, buy = 2 }, - { itemName = "avalanche rune", clientId = 3161, buy = 57 }, - { itemName = "axe", clientId = 3274, sell = 7 }, - { itemName = "bamboo drawer kit", clientId = 2465, buy = 20 }, - { itemName = "bamboo table kit", clientId = 2350, buy = 25 }, - { itemName = "barrel kit", clientId = 2523, buy = 12 }, - { itemName = "basket", clientId = 2855, buy = 6 }, - { itemName = "battle axe", clientId = 3266, sell = 80 }, - { itemName = "battle hammer", clientId = 3305, sell = 120 }, - { itemName = "big table kit", clientId = 2314, buy = 30 }, - { itemName = "birdcage kit", clientId = 2976, buy = 50 }, - { itemName = "blank rune", clientId = 3147, buy = 10 }, - { itemName = "blue footboard", clientId = 32482, buy = 40 }, - { itemName = "blue headboard", clientId = 32473, buy = 40 }, - { itemName = "blue pillow", clientId = 2394, buy = 25 }, - { itemName = "blue quiver", clientId = 35848, buy = 400 }, - { itemName = "blue tapestry", clientId = 2659, buy = 25 }, - { itemName = "bolt", clientId = 3446, buy = 4 }, - { itemName = "bone sword", clientId = 3338, sell = 20 }, - { itemName = "bookcase kit", clientId = 6370, buy = 70 }, - { itemName = "bottle", clientId = 2875, buy = 3 }, - { itemName = "bow", clientId = 3350, sell = 100 }, - { itemName = "box", clientId = 2469, buy = 10 }, - { itemName = "brass armor", clientId = 3359, sell = 150 }, - { itemName = "brass helmet", clientId = 3354, sell = 30 }, - { itemName = "brass legs", clientId = 3372, sell = 49 }, - { itemName = "brass shield", clientId = 3411, sell = 25 }, - { itemName = "brown mushroom", clientId = 3725, buy = 10 }, - { itemName = "bucket", clientId = 2873, buy = 4 }, - { itemName = "candelabrum", clientId = 2911, buy = 8 }, - { itemName = "candlestick", clientId = 2917, buy = 2 }, - { itemName = "canopy footboard", clientId = 32490, buy = 40 }, - { itemName = "canopy headboard", clientId = 32481, buy = 40 }, - { itemName = "carlin sword", clientId = 3283, sell = 118 }, - { itemName = "chain armor", clientId = 3358, sell = 70 }, - { itemName = "chain helmet", clientId = 3352, sell = 17 }, - { itemName = "chain legs", clientId = 3558, sell = 25 }, - { itemName = "chameleon rune", clientId = 3178, buy = 210 }, - { itemName = "chest of drawers", clientId = 2433, buy = 18 }, - { itemName = "chest", clientId = 2472, buy = 10 }, - { itemName = "chimney kit", clientId = 7860, buy = 200 }, - { itemName = "closed trap", clientId = 3481, sell = 75 }, - { itemName = "club", clientId = 3270, sell = 1 }, - { itemName = "coal basin kit", clientId = 3513, buy = 25 }, - { itemName = "coat", clientId = 3562, sell = 1 }, - { itemName = "convince creature rune", clientId = 3177, buy = 80 }, - { itemName = "cookie", clientId = 3598, buy = 2 }, - { itemName = "cot footboard", clientId = 32486, buy = 40 }, - { itemName = "cot headboard", clientId = 32477, buy = 40 }, - { itemName = "crate", clientId = 2471, buy = 10 }, - { itemName = "crossbow", clientId = 3349, sell = 120 }, - { itemName = "crowbar", clientId = 3304, sell = 50 }, - { itemName = "crystalline arrow", clientId = 15793, buy = 20 }, - { itemName = "cuckoo clock", clientId = 2664, buy = 40 }, - { itemName = "cure poison rune", clientId = 3153, buy = 65 }, - { itemName = "dagger", clientId = 3267, sell = 2 }, - { itemName = "destroy field rune", clientId = 3148, buy = 15 }, - { itemName = "diamond arrow", clientId = 35901, buy = 100 }, - { itemName = "disintegrate rune", clientId = 3197, buy = 26 }, - { itemName = "doublet", clientId = 3379, sell = 3 }, - { itemName = "dresser kit", clientId = 2441, buy = 25 }, - { itemName = "drill bolt", clientId = 16142, buy = 12 }, - { itemName = "dwarven shield", clientId = 3425, sell = 100 }, - { itemName = "earth arrow", clientId = 774, buy = 5 }, - { itemName = "empty potion flask", clientId = 283, sell = 5 }, - { itemName = "empty potion flask", clientId = 284, sell = 5 }, - { itemName = "empty potion flask", clientId = 285, sell = 5 }, - { itemName = "energy bomb rune", clientId = 3149, buy = 203 }, - { itemName = "energy field rune", clientId = 3164, buy = 38 }, - { itemName = "energy wall rune", clientId = 3166, buy = 85 }, - { itemName = "envenomed arrow", clientId = 16143, buy = 12 }, - { itemName = "exercise axe", clientId = 28553, buy = 262500 }, - { itemName = "exercise bow", clientId = 28555, buy = 262500 }, - { itemName = "exercise club", clientId = 28554, buy = 262500 }, - { itemName = "exercise rod", clientId = 28556, buy = 262500 }, - { itemName = "exercise shield", clientId = 44065, buy = 262500 }, - { itemName = "exercise sword", clientId = 28552, buy = 262500 }, - { itemName = "exercise wand", clientId = 28557, buy = 262500 }, - { itemName = "durable exercise axe", clientId = 35280, buy = 945000 }, - { itemName = "durable exercise bow", clientId = 35282, buy = 945000 }, - { itemName = "durable exercise club", clientId = 35281, buy = 945000 }, - { itemName = "durable exercise rod", clientId = 35283, buy = 945000 }, - { itemName = "durable exercise shield", clientId = 44066, buy = 945000 }, - { itemName = "durable exercise sword", clientId = 35279, buy = 945000 }, - { itemName = "durable exercise wand", clientId = 35284, buy = 945000 }, - { itemName = "lasting exercise axe", clientId = 35286, buy = 7560000 }, - { itemName = "lasting exercise bow", clientId = 35288, buy = 7560000 }, - { itemName = "lasting exercise club", clientId = 35287, buy = 7560000 }, - { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000 }, - { itemName = "lasting exercise shield", clientId = 44067, buy = 7560000 }, - { itemName = "lasting exercise sword", clientId = 35285, buy = 7560000 }, - { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000 }, - { itemName = "explosion rune", clientId = 3200, buy = 31 }, - { itemName = "fire bomb rune", clientId = 3192, buy = 147 }, - { itemName = "fire field rune", clientId = 3188, buy = 28 }, - { itemName = "fire wall rune", clientId = 3190, buy = 61 }, - { itemName = "fireball rune", clientId = 3189, buy = 30 }, - { itemName = "fireworks rocket", clientId = 6576, buy = 100 }, - { itemName = "fishing rod", clientId = 3483, sell = 40 }, - { itemName = "flaming arrow", clientId = 763, buy = 5 }, - { itemName = "flash arrow", clientId = 761, buy = 5 }, - { itemName = "flower bowl", clientId = 2983, buy = 6 }, - { itemName = "globe", clientId = 2979, buy = 50 }, - { itemName = "goblin statue kit", clientId = 2030, buy = 50 }, - { itemName = "god flowers", clientId = 2981, buy = 5 }, - { itemName = "goldfish bowl", clientId = 5928, buy = 50 }, - { itemName = "great fireball rune", clientId = 3191, buy = 57 }, - { itemName = "great health potion", clientId = 239, buy = 225 }, - { itemName = "great mana potion", clientId = 238, buy = 144 }, - { itemName = "great spirit potion", clientId = 7642, buy = 228 }, - { itemName = "green balloons", clientId = 6577, buy = 500 }, - { itemName = "green cushioned chair kit", clientId = 2378, buy = 40 }, - { itemName = "green footboard", clientId = 32483, buy = 40 }, - { itemName = "green headboard", clientId = 32474, buy = 40 }, - { itemName = "green pillow", clientId = 2396, buy = 25 }, - { itemName = "green tapestry", clientId = 2647, buy = 25 }, - { itemName = "hailstorm rod", clientId = 3067, buy = 13526 }, - { itemName = "ham", clientId = 3582, buy = 10 }, - { itemName = "hammock foot section", clientId = 32487, buy = 40 }, - { itemName = "hammock head section", clientId = 32478, buy = 40 }, - { itemName = "hand axe", clientId = 3268, sell = 4 }, - { itemName = "harp kit", clientId = 2963, buy = 50 }, - { itemName = "health potion", clientId = 266, buy = 50 }, - { itemName = "heart pillow", clientId = 2393, buy = 30 }, - { itemName = "heavy magic missile rune", clientId = 3198, buy = 12 }, - { itemName = "holy missile rune", clientId = 3182, buy = 16 }, - { itemName = "honey flower", clientId = 2984, buy = 5 }, - { itemName = "icicle rune", clientId = 3158, buy = 30 }, - { itemName = "indoor plant kit", clientId = 2982, buy = 8 }, - { itemName = "intense healing rune", clientId = 3152, buy = 95 }, - { itemName = "iron helmet", clientId = 3353, sell = 150 }, - { itemName = "ivory chair kit", clientId = 2422, buy = 25 }, - { itemName = "jacket", clientId = 3561, sell = 1 }, - { itemName = "knight statue kit", clientId = 2025, buy = 50 }, - { itemName = "label", clientId = 3507, buy = 1 }, - { itemName = "large amphora kit", clientId = 2904, buy = 50 }, - { itemName = "large trunk", clientId = 2483, buy = 10 }, - { itemName = "leather armor", clientId = 3361, sell = 12 }, - { itemName = "leather boots", clientId = 3552, sell = 2 }, - { itemName = "leather helmet", clientId = 3355, sell = 4 }, - { itemName = "leather legs", clientId = 3559, sell = 9 }, - { itemName = "letter", clientId = 3505, buy = 8 }, - { itemName = "light magic missile rune", clientId = 3174, buy = 4 }, - { itemName = "locker kit", clientId = 2449, buy = 30 }, - { itemName = "longsword", clientId = 3285, sell = 51 }, - { itemName = "mace", clientId = 3286, sell = 30 }, - { itemName = "machete", clientId = 3308, sell = 6 }, - { itemName = "magic wall rune", clientId = 3180, buy = 116 }, - { itemName = "mana potion", clientId = 268, buy = 56 }, - { itemName = "meat", clientId = 3577, buy = 5 }, - { itemName = "minotaur statue kit", clientId = 2029, buy = 50 }, - { itemName = "moonlight rod", clientId = 3070, buy = 1245 }, - { itemName = "morning star", clientId = 3282, sell = 100 }, - { itemName = "necrotic rod", clientId = 3069, buy = 4999 }, - { itemName = "northwind rod", clientId = 8083, buy = 7500 }, - { itemName = "onyx arrow", clientId = 7365, buy = 7 }, - { itemName = "orange tapestry", clientId = 2653, buy = 25 }, - { itemName = "oven kit", clientId = 6355, buy = 80 }, - { itemName = "paralyse rune", clientId = 3165, buy = 700 }, - { itemName = "parcel", clientId = 3503, buy = 15 }, - { itemName = "party hat", clientId = 6578, buy = 800 }, - { itemName = "party trumpet", clientId = 6572, buy = 500 }, - { itemName = "pendulum clock kit", clientId = 2445, buy = 75 }, - { itemName = "piano kit", clientId = 2959, buy = 200 }, - { itemName = "pick", clientId = 3456, sell = 15 }, - { itemName = "piercing bolt", clientId = 7363, buy = 5 }, - { itemName = "plate armor", clientId = 3357, sell = 400 }, - { itemName = "plate shield", clientId = 3410, sell = 45 }, - { itemName = "poison bomb rune", clientId = 3173, buy = 85 }, - { itemName = "poison field rune", clientId = 3172, buy = 21 }, - { itemName = "poison wall rune", clientId = 3176, buy = 52 }, - { itemName = "potted flower", clientId = 2985, buy = 5 }, - { itemName = "power bolt", clientId = 3450, buy = 7 }, - { itemName = "present", clientId = 2856, buy = 10 }, - { itemName = "prismatic bolt", clientId = 16141, buy = 20 }, - { itemName = "purple tapestry", clientId = 2644, buy = 25 }, - { itemName = "quiver", clientId = 35562, buy = 400 }, - { itemName = "rapier", clientId = 3272, sell = 5 }, - { itemName = "red balloons", clientId = 6575, buy = 500 }, - { itemName = "red cushioned chair kit", clientId = 2374, buy = 40 }, - { itemName = "red footboard", clientId = 32484, buy = 40 }, - { itemName = "red headboard", clientId = 32475, buy = 40 }, - { itemName = "red pillow", clientId = 2395, buy = 25 }, - { itemName = "red quiver", clientId = 35849, buy = 400 }, - { itemName = "red tapestry", clientId = 2656, buy = 25 }, - { itemName = "rocking horse", clientId = 2998, buy = 30 }, - { itemName = "rope", clientId = 3003, sell = 15 }, - { itemName = "round blue pillow", clientId = 2398, buy = 25 }, - { itemName = "round purple pillow", clientId = 2400, buy = 25 }, - { itemName = "round red pillow", clientId = 2399, buy = 25 }, - { itemName = "round turquoise pillow", clientId = 2401, buy = 25 }, - { itemName = "royal spear", clientId = 7378, buy = 15 }, - { itemName = "sabre", clientId = 3273, sell = 12 }, - { itemName = "scale armor", clientId = 3377, sell = 75 }, - { itemName = "scythe", clientId = 3453, sell = 10 }, - { itemName = "shiver arrow", clientId = 762, buy = 5 }, - { itemName = "short sword", clientId = 3294, sell = 10 }, - { itemName = "shovel", clientId = 3457, sell = 8 }, - { itemName = "sickle", clientId = 3293, sell = 3 }, - { itemName = "simple footboard", clientId = 32488, buy = 40 }, - { itemName = "simple headboard", clientId = 32479, buy = 40 }, - { itemName = "small blue pillow", clientId = 2389, buy = 20 }, - { itemName = "small green pillow", clientId = 2387, buy = 20 }, - { itemName = "small ice statue", clientId = 7448, buy = 50 }, - { itemName = "small orange pillow", clientId = 2390, buy = 20 }, - { itemName = "small purple pillow", clientId = 2386, buy = 20 }, - { itemName = "small red pillow", clientId = 2388, buy = 20 }, - { itemName = "small round table", clientId = 2316, buy = 25 }, - { itemName = "small table kit", clientId = 2319, buy = 20 }, - { itemName = "small trunk", clientId = 2426, buy = 20 }, - { itemName = "small turquoise pillow", clientId = 2391, buy = 20 }, - { itemName = "small white pillow", clientId = 2392, buy = 20 }, - { itemName = "snakebite rod", clientId = 3066, buy = 500 }, - { itemName = "sniper arrow", clientId = 7364, buy = 5 }, - { itemName = "sofa chair kit", clientId = 2366, buy = 55 }, - { itemName = "soldier helmet", clientId = 3375, sell = 16 }, - { itemName = "soulfire rune", clientId = 3195, buy = 46 }, - { itemName = "spear", clientId = 3277, sell = 3 }, - { itemName = "spectral bolt", clientId = 35902, buy = 70 }, - { itemName = "spellwand", clientId = 651, sell = 299 }, - { itemName = "spike sword", clientId = 3271, sell = 240 }, - { itemName = "springsprout rod", clientId = 8084, buy = 15468 }, - { itemName = "square table kit", clientId = 2315, buy = 25 }, - { itemName = "stalagmite rune", clientId = 3179, buy = 12 }, - { itemName = "steel helmet", clientId = 3351, sell = 293 }, - { itemName = "steel shield", clientId = 3409, sell = 80 }, - { itemName = "stone shower rune", clientId = 3175, buy = 37 }, - { itemName = "stone table kit", clientId = 2347, buy = 30 }, - { itemName = "straw mat foot section", clientId = 32489, buy = 40 }, - { itemName = "straw mat head section", clientId = 32480, buy = 40 }, - { itemName = "strong health potion", clientId = 236, buy = 115 }, - { itemName = "strong mana potion", clientId = 237, buy = 93 }, - { itemName = "studded armor", clientId = 3378, sell = 25 }, - { itemName = "studded helmet", clientId = 3376, sell = 20 }, - { itemName = "studded legs", clientId = 3362, sell = 15 }, - { itemName = "studded shield", clientId = 3426, sell = 16 }, - { itemName = "sudden death rune", clientId = 3155, buy = 135 }, - { itemName = "supreme health potion", clientId = 23375, buy = 625 }, - { itemName = "sword", clientId = 3264, sell = 25 }, - { itemName = "table lamp kit", clientId = 2934, buy = 35 }, - { itemName = "tarsal arrow", clientId = 14251, buy = 6 }, - { itemName = "telescope kit", clientId = 3485, buy = 70 }, - { itemName = "terra rod", clientId = 3065, buy = 10000 }, - { itemName = "thick trunk", clientId = 2352, buy = 20 }, - { itemName = "throwing knife", clientId = 3298, sell = 2 }, - { itemName = "throwing star", clientId = 3287, buy = 42 }, - { itemName = "thunderstorm rune", clientId = 3202, buy = 47 }, - { itemName = "torch", clientId = 2920, buy = 2 }, - { itemName = "treasure chest", clientId = 2478, buy = 1245 }, - { itemName = "trophy stand", clientId = 872, buy = 50 }, - { itemName = "trough kit", clientId = 2524, buy = 7 }, - { itemName = "tusk chair kit", clientId = 2418, buy = 25 }, - { itemName = "tusk table kit", clientId = 2348, buy = 25 }, - { itemName = "two handed sword", clientId = 3265, sell = 456 }, - { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, - { itemName = "ultimate health potion", clientId = 7643, buy = 381 }, - { itemName = "ultimate mana potion", clientId = 23373, buy = 443 }, - { itemName = "ultimate spirit potion", clientId = 23374, buy = 443 }, - { itemName = "underworld rod", clientId = 8082, buy = 19666 }, - { itemName = "vase", clientId = 2876, buy = 3 }, - { itemName = "venorean cabinet", clientId = 18015, buy = 90 }, - { itemName = "venorean drawer", clientId = 18019, buy = 40 }, - { itemName = "venorean wardrobe", clientId = 18017, buy = 50 }, - { itemName = "vial", clientId = 2874, sell = 5 }, - { itemName = "viking helmet", clientId = 3367, sell = 66 }, - { itemName = "viking shield", clientId = 3431, sell = 85 }, - { itemName = "vortex bolt", clientId = 14252, buy = 6 }, - { itemName = "wall mirror", clientId = 2632, buy = 40 }, - { itemName = "wand of cosmic energy", clientId = 3073, buy = 9087 }, - { itemName = "wand of decay", clientId = 3072, buy = 4999 }, - { itemName = "wand of draconia", clientId = 8093, buy = 7500 }, - { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, - { itemName = "wand of inferno", clientId = 3071, buy = 13526 }, - { itemName = "wand of starstorm", clientId = 8092, buy = 15468 }, - { itemName = "wand of voodoo", clientId = 8094, buy = 19666 }, - { itemName = "wand of vortex", clientId = 3074, buy = 500 }, - { itemName = "war hammer", clientId = 3279, sell = 595 }, - { itemName = "watch", clientId = 2906, sell = 6 }, - { itemName = "water pipe", clientId = 2980, buy = 40 }, - { itemName = "weapon rack kit", clientId = 6109, buy = 90 }, - { itemName = "white tapestry", clientId = 2667, buy = 25 }, - { itemName = "wild growth rune", clientId = 3156, buy = 160 }, - { itemName = "wooden chair kit", clientId = 2360, buy = 15 }, - { itemName = "wooden shield", clientId = 3412, sell = 5 }, - { itemName = "worm", clientId = 3492, buy = 1 }, - { itemName = "yellow footboard", clientId = 32485, buy = 40 }, - { itemName = "yellow headboard", clientId = 32476, buy = 40 }, - { itemName = "yellow pillow", clientId = 900, buy = 25 }, - { itemName = "yellow tapestry", clientId = 2650, buy = 25 }, + local itemsTable = { + ["various"] = { + { itemName = "blue footboard", clientId = 32482, buy = 40 }, + { itemName = "blue headboard", clientId = 32473, buy = 40 }, + { itemName = "cot footboard", clientId = 32486, buy = 40 }, + { itemName = "cot headboard", clientId = 32477, buy = 40 }, + { itemName = "green footboard", clientId = 32483, buy = 40 }, + { itemName = "green headboard", clientId = 32474, buy = 40 }, + { itemName = "hammock foot section", clientId = 32487, buy = 40 }, + { itemName = "hammock head section", clientId = 32478, buy = 40 }, + { itemName = "red footboard", clientId = 32484, buy = 40 }, + { itemName = "red headboard", clientId = 32475, buy = 40 }, + { itemName = "simple footboard", clientId = 32488, buy = 40 }, + { itemName = "simple headboard", clientId = 32479, buy = 40 }, + { itemName = "straw mat foot section", clientId = 32489, buy = 40 }, + { itemName = "straw mat head section", clientId = 32480, buy = 40 }, + { itemName = "yellow footboard", clientId = 32485, buy = 40 }, + { itemName = "yellow headboard", clientId = 32476, buy = 40 }, + { itemName = "amphora", clientId = 2893, buy = 4 }, + { itemName = "armor rack kit", clientId = 6114, buy = 90 }, + { itemName = "bamboo drawer kit", clientId = 2795, buy = 20 }, + { itemName = "bamboo table kit", clientId = 2788, buy = 25 }, + { itemName = "barrel kit", clientId = 2793, buy = 12 }, + { itemName = "big table kit", clientId = 2785, buy = 30 }, + { itemName = "birdcage kit", clientId = 2796, buy = 50 }, + { itemName = "blue pillow", clientId = 2394, buy = 25 }, + { itemName = "blue tapestry", clientId = 2659, buy = 25 }, + { itemName = "bookcase kit", clientId = 6372, buy = 70 }, + { itemName = "box", clientId = 2469, buy = 10 }, + { itemName = "chest", clientId = 2472, buy = 10 }, + { itemName = "chest of drawers", clientId = 2789, buy = 18 }, + { itemName = "chimney kit", clientId = 7864, buy = 200 }, + { itemName = "coal basin kit", clientId = 2806, buy = 25 }, + { itemName = "cookie", clientId = 3598, buy = 2 }, + { itemName = "crate", clientId = 2471, buy = 10 }, + { itemName = "cuckoo clock", clientId = 2664, buy = 40 }, + { itemName = "dresser kit", clientId = 2790, buy = 25 }, + { itemName = "goldfish bowl", clientId = 5928, buy = 50 }, + { itemName = "fireworks rocket", clientId = 6576, buy = 100 }, + { itemName = "flower bowl", clientId = 2983, buy = 6 }, + { itemName = "globe", clientId = 2797, buy = 50 }, + { itemName = "goblin statue kit", clientId = 2804, buy = 50 }, + { itemName = "god flowers", clientId = 2981, buy = 5 }, + { itemName = "green balloons", clientId = 6577, buy = 500 }, + { itemName = "green cushioned chair kit", clientId = 2776, buy = 40 }, + { itemName = "green pillow", clientId = 2396, buy = 25 }, + { itemName = "green tapestry", clientId = 2647, buy = 25 }, + { itemName = "harp kit", clientId = 2808, buy = 50 }, + { itemName = "heart pillow", clientId = 2393, buy = 30 }, + { itemName = "honey flower", clientId = 2984, buy = 5 }, + { itemName = "indoor plant kit", clientId = 2811, buy = 8 }, + { itemName = "ivory chair kit", clientId = 2781, buy = 25 }, + { itemName = "knight statue kit", clientId = 2802, buy = 50 }, + { itemName = "large amphora kit", clientId = 2805, buy = 50 }, + { itemName = "large trunk", clientId = 2794, buy = 10 }, + { itemName = "locker kit", clientId = 2791, buy = 30 }, + { itemName = "minotaur statue kit", clientId = 2803, buy = 50 }, + { itemName = "orange tapestry", clientId = 2653, buy = 25 }, + { itemName = "oven kit", clientId = 6371, buy = 80 }, + { itemName = "party hat", clientId = 6578, buy = 800 }, + { itemName = "party trumpet", clientId = 6572, buy = 500 }, + { itemName = "pendulum clock kit", clientId = 2801, buy = 75 }, + { itemName = "piano kit", clientId = 2807, buy = 200 }, + { itemName = "potted flower", clientId = 2985, buy = 5 }, + { itemName = "present", clientId = 2856, buy = 10 }, + { itemName = "purple tapestry", clientId = 2644, buy = 25 }, + { itemName = "red balloons", clientId = 6575, buy = 500 }, + { itemName = "red cushioned chair kit", clientId = 2775, buy = 40 }, + { itemName = "red pillow", clientId = 2395, buy = 25 }, + { itemName = "red tapestry", clientId = 2656, buy = 25 }, + { itemName = "rocking horse", clientId = 2800, buy = 30 }, + { itemName = "round blue pillow", clientId = 2398, buy = 25 }, + { itemName = "round purple pillow", clientId = 2400, buy = 25 }, + { itemName = "round red pillow", clientId = 2399, buy = 25 }, + { itemName = "round turquoise pillow", clientId = 2401, buy = 25 }, + { itemName = "small blue pillow", clientId = 2389, buy = 20 }, + { itemName = "small green pillow", clientId = 2387, buy = 20 }, + { itemName = "small ice statue", clientId = 7447, buy = 50 }, + { itemName = "small ice statue", clientId = 7448, buy = 50 }, + { itemName = "small orange pillow", clientId = 2390, buy = 20 }, + { itemName = "small purple pillow", clientId = 2386, buy = 20 }, + { itemName = "small red pillow", clientId = 2388, buy = 20 }, + { itemName = "small round table", clientId = 2783, buy = 25 }, + { itemName = "small table kit", clientId = 2782, buy = 20 }, + { itemName = "small trunk", clientId = 2426, buy = 20 }, + { itemName = "small turquoise pillow", clientId = 2391, buy = 20 }, + { itemName = "small white pillow", clientId = 2392, buy = 20 }, + { itemName = "sofa chair kit", clientId = 2779, buy = 55 }, + { itemName = "square table kit", clientId = 2784, buy = 25 }, + { itemName = "stone table kit", clientId = 2786, buy = 30 }, + { itemName = "table lamp kit", clientId = 2798, buy = 35 }, + { itemName = "telescope kit", clientId = 2799, buy = 70 }, + { itemName = "thick trunk", clientId = 2352, buy = 20 }, + { itemName = "treasure chest", clientId = 2478, buy = 1000 }, + { itemName = "trophy stand", clientId = 872, buy = 50 }, + { itemName = "trough kit", clientId = 2792, buy = 7 }, + { itemName = "tusk chair kit", clientId = 2780, buy = 25 }, + { itemName = "tusk table kit", clientId = 2787, buy = 25 }, + { itemName = "vase", clientId = 2876, buy = 3 }, + { itemName = "venorean cabinet", clientId = 17974, buy = 90 }, + { itemName = "venorean drawer", clientId = 17977, buy = 40 }, + { itemName = "venorean wardrobe", clientId = 17975, buy = 50 }, + { itemName = "wall mirror", clientId = 2638, buy = 40 }, + { itemName = "wall mirror", clientId = 2635, buy = 40 }, + { itemName = "wall mirror", clientId = 2632, buy = 40 }, + { itemName = "water pipe", clientId = 2980, buy = 40 }, + { itemName = "weapon rack kit", clientId = 6115, buy = 90 }, + { itemName = "white tapestry", clientId = 2667, buy = 25 }, + { itemName = "wooden chair kit", clientId = 2777, buy = 15 }, + { itemName = "yellow pillow", clientId = 900, buy = 25 }, + { itemName = "yellow tapestry", clientId = 2650, buy = 25 }, + }, + ["exercise weapons"] = { + { itemName = "exercise axe", clientId = 28553, buy = 262500, subType = 500 }, + { itemName = "exercise bow", clientId = 28555, buy = 262500, subType = 500 }, + { itemName = "exercise club", clientId = 28554, buy = 262500, subType = 500 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, subType = 500 }, + { itemName = "exercise sword", clientId = 28552, buy = 262500, subType = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, subType = 500 }, + { itemName = "durable exercise axe", clientId = 35280, buy = 945000, subType = 1800 }, + { itemName = "durable exercise bow", clientId = 35282, buy = 945000, subType = 1800 }, + { itemName = "durable exercise club", clientId = 35281, buy = 945000, subType = 1800 }, + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, subType = 1800 }, + { itemName = "durable exercise sword", clientId = 35279, buy = 945000, subType = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, subType = 1800 }, + { itemName = "lasting exercise axe", clientId = 35286, buy = 7560000, subType = 14400 }, + { itemName = "lasting exercise bow", clientId = 35288, buy = 7560000, subType = 14400 }, + { itemName = "lasting exercise club", clientId = 35287, buy = 7560000, subType = 14400 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, subType = 14400 }, + { itemName = "lasting exercise sword", clientId = 35285, buy = 7560000, subType = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, subType = 14400 }, + }, + ["equipment"] = { + { itemName = "axe", clientId = 3274, buy = 20, sell = 7 }, + { itemName = "battle axe", clientId = 3266, buy = 235, sell = 80 }, + { itemName = "battle hammer", clientId = 3305, buy = 350, sell = 120 }, + { itemName = "bone sword", clientId = 3338, buy = 75, sell = 20 }, + { itemName = "brass armor", clientId = 3359, buy = 450, sell = 150 }, + { itemName = "brass helmet", clientId = 3354, buy = 120, sell = 30 }, + { itemName = "brass legs", clientId = 3372, buy = 195, sell = 49 }, + { itemName = "brass shield", clientId = 3411, buy = 65, sell = 25 }, + { itemName = "carlin sword", clientId = 3283, buy = 473, sell = 118 }, + { itemName = "chain armor", clientId = 3358, buy = 200, sell = 70 }, + { itemName = "chain helmet", clientId = 3352, buy = 52, sell = 17 }, + { itemName = "chain legs", clientId = 3558, buy = 80, sell = 25 }, + { itemName = "club", clientId = 3270, buy = 5, sell = 1 }, + { itemName = "coat", clientId = 3562, buy = 8, sell = 1 }, + { itemName = "crowbar", clientId = 3304, buy = 260, sell = 50 }, + { itemName = "dagger", clientId = 3267, buy = 5, sell = 2 }, + { itemName = "doublet", clientId = 3379, buy = 16, sell = 3 }, + { itemName = "dwarven shield", clientId = 3425, buy = 500, sell = 100 }, + { itemName = "hand axe", clientId = 3268, buy = 8, sell = 4 }, + { itemName = "iron helmet", clientId = 3353, buy = 390, sell = 150 }, + { itemName = "jacket", clientId = 3561, buy = 12, sell = 1 }, + { itemName = "leather armor", clientId = 3361, buy = 35, sell = 12 }, + { itemName = "leather boots", clientId = 3552, buy = 10, sell = 2 }, + { itemName = "leather helmet", clientId = 3355, buy = 12, sell = 4 }, + { itemName = "leather legs", clientId = 3559, buy = 10, sell = 9 }, + { itemName = "longsword", clientId = 3285, buy = 160, sell = 51 }, + { itemName = "mace", clientId = 3286, buy = 90, sell = 30 }, + { itemName = "morning star", clientId = 3282, buy = 430, sell = 100 }, + { itemName = "plate armor", clientId = 3357, buy = 1200, sell = 400 }, + { itemName = "plate shield", clientId = 3410, buy = 125, sell = 45 }, + { itemName = "rapier", clientId = 3272, buy = 15, sell = 5 }, + { itemName = "sabre", clientId = 3273, buy = 35, sell = 12 }, + { itemName = "scale armor", clientId = 3377, buy = 260, sell = 75 }, + { itemName = "short sword", clientId = 3294, buy = 26, sell = 10 }, + { itemName = "sickle", clientId = 3293, buy = 7, sell = 3 }, + { itemName = "soldier helmet", clientId = 3375, buy = 110, sell = 16 }, + { itemName = "spike sword", clientId = 3271, buy = 8000, sell = 240 }, + { itemName = "steel helmet", clientId = 3351, buy = 580, sell = 293 }, + { itemName = "steel shield", clientId = 3409, buy = 240, sell = 80 }, + { itemName = "studded armor", clientId = 3378, buy = 90, sell = 25 }, + { itemName = "studded helmet", clientId = 3376, buy = 63, sell = 20 }, + { itemName = "studded legs", clientId = 3362, buy = 50, sell = 15 }, + { itemName = "studded shield", clientId = 3426, buy = 50, sell = 16 }, + { itemName = "sword", clientId = 3264, buy = 85, sell = 25 }, + { itemName = "throwing knife", clientId = 3298, buy = 25, sell = 2 }, + { itemName = "two handed sword", clientId = 3265, buy = 950, sell = 450 }, + { itemName = "viking helmet", clientId = 3367, buy = 265, sell = 66 }, + { itemName = "viking shield", clientId = 3431, buy = 260, sell = 85 }, + { itemName = "war hammer", clientId = 3279, buy = 10000, sell = 470 }, + { itemName = "wooden shield", clientId = 3412, buy = 15, sell = 5 }, + }, + ["distance"] = { + { itemName = "arrow", clientId = 3447, buy = 2 }, + { itemName = "bolt", clientId = 3483, buy = 4 }, + { itemName = "bow", clientId = 3350, buy = 400, sell = 100 }, + { itemName = "crossbow", clientId = 3349, buy = 500, sell = 120 }, + { itemName = "crystalline arrow", clientId = 15793, buy = 450 }, + { itemName = "drill bolt", clientId = 16142, buy = 12 }, + { itemName = "diamond arrow", clientId = 35901, buy = 100 }, + { itemName = "earth arrow", clientId = 774, buy = 5 }, + { itemName = "envenomed arrow", clientId = 16143, buy = 12 }, + { itemName = "flaming arrow", clientId = 763, buy = 5 }, + { itemName = "flash arrow", clientId = 761, buy = 5 }, + { itemName = "onyx arrow", clientId = 7365, buy = 7 }, + { itemName = "piercing bolt", clientId = 7363, buy = 5 }, + { itemName = "power bolt", clientId = 3450, buy = 7 }, + { itemName = "prismatic bolt", clientId = 16141, buy = 20 }, + { itemName = "quiver", clientId = 35562, buy = 400 }, + { itemName = "royal spear", clientId = 7378, buy = 15 }, + { itemName = "shiver arrow", clientId = 762, buy = 5 }, + { itemName = "sniper arrow", clientId = 7364, buy = 5 }, + { itemName = "spear", clientId = 3277, buy = 9, sell = 3 }, + { itemName = "spectral bolt", clientId = 35902, buy = 70 }, + { itemName = "tarsal arrow", clientId = 14251, buy = 6 }, + { itemName = "throwing star", clientId = 3287, buy = 42 }, + { itemName = "vortex bolt", clientId = 14252, buy = 6 }, + }, + ["wands"] = { + { itemName = "exercise rod", clientId = 28556, buy = 236250, subType = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 236250, subType = 500 }, + { itemName = "hailstorm rod", clientId = 3067, buy = 15000 }, + { itemName = "moonlight rod", clientId = 3070, buy = 1000 }, + { itemName = "necrotic rod", clientId = 3069, buy = 5000 }, + { itemName = "northwind rod", clientId = 8083, buy = 7500 }, + { itemName = "snakebite rod", clientId = 3066, buy = 500 }, + { itemName = "spellwand", clientId = 651, sell = 299 }, + { itemName = "springsprout rod", clientId = 8084, buy = 18000 }, + { itemName = "terra rod", clientId = 3065, buy = 10000 }, + { itemName = "underworld rod", clientId = 8082, buy = 22000 }, + { itemName = "wand of cosmic energy", clientId = 3073, buy = 10000 }, + { itemName = "wand of decay", clientId = 3072, buy = 5000 }, + { itemName = "wand of draconia", clientId = 8093, buy = 7500 }, + { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, + { itemName = "wand of inferno", clientId = 3071, buy = 15000 }, + { itemName = "wand of starstorm", clientId = 8092, buy = 18000 }, + { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, + { itemName = "wand of vortex", clientId = 3074, buy = 500 }, + }, + ["rods"] = { + { itemName = "exercise rod", clientId = 28556, buy = 236250, subType = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 236250, subType = 500 }, + { itemName = "hailstorm rod", clientId = 3067, buy = 15000 }, + { itemName = "moonlight rod", clientId = 3070, buy = 1000 }, + { itemName = "necrotic rod", clientId = 3069, buy = 5000 }, + { itemName = "northwind rod", clientId = 8083, buy = 7500 }, + { itemName = "snakebite rod", clientId = 3066, buy = 500 }, + { itemName = "springsprout rod", clientId = 8084, buy = 18000 }, + { itemName = "terra rod", clientId = 3065, buy = 10000 }, + { itemName = "underworld rod", clientId = 8082, buy = 22000 }, + { itemName = "wand of cosmic energy", clientId = 3073, buy = 10000 }, + { itemName = "wand of decay", clientId = 3072, buy = 5000 }, + { itemName = "wand of draconia", clientId = 8093, buy = 7500 }, + { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, + { itemName = "wand of inferno", clientId = 3071, buy = 15000 }, + { itemName = "wand of starstorm", clientId = 8092, buy = 18000 }, + { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, + { itemName = "wand of vortex", clientId = 3074, buy = 500 }, + }, + ["potions"] = { + { itemName = "great health potion", clientId = 239, buy = 225 }, + { itemName = "great mana potion", clientId = 238, buy = 144 }, + { itemName = "great spirit potion", clientId = 7642, buy = 228 }, + { itemName = "health potion", clientId = 266, buy = 50 }, + { itemName = "mana potion", clientId = 268, buy = 56 }, + { itemName = "strong health potion", clientId = 236, buy = 115 }, + { itemName = "strong mana potion", clientId = 237, buy = 93 }, + { itemName = "supreme health potion", clientId = 23375, buy = 625 }, + { itemName = "ultimate health potion", clientId = 7643, buy = 379 }, + { itemName = "ultimate mana potion", clientId = 23373, buy = 438 }, + { itemName = "ultimate spirit potion", clientId = 23374, buy = 438 }, + { itemName = "empty potion flask", clientId = 283, sell = 5 }, + { itemName = "empty potion flask", clientId = 284, sell = 5 }, + { itemName = "empty potion flask", clientId = 285, sell = 5 }, + { itemName = "vial", clientId = 2874, sell = 5 }, + }, + ["runes"] = { + { itemName = "animate dead rune", clientId = 3203, buy = 375 }, + { itemName = "avalanche rune", clientId = 3161, buy = 57 }, + { itemName = "blank rune", clientId = 3147, buy = 10 }, + { itemName = "chameleon rune", clientId = 3178, buy = 210 }, + { itemName = "convince creature rune", clientId = 3177, buy = 80 }, + { itemName = "cure poison rune", clientId = 3153, buy = 65 }, + { itemName = "destroy field rune", clientId = 3148, buy = 15 }, + { itemName = "disintegrate rune", clientId = 3197, buy = 26 }, + { itemName = "energy bomb rune", clientId = 3149, buy = 203 }, + { itemName = "energy field rune", clientId = 3164, buy = 38 }, + { itemName = "energy wall rune", clientId = 3166, buy = 85 }, + { itemName = "explosion rune", clientId = 3200, buy = 31 }, + { itemName = "fire bomb rune", clientId = 3192, buy = 147 }, + { itemName = "fire field rune", clientId = 3188, buy = 28 }, + { itemName = "fire wall rune", clientId = 3190, buy = 61 }, + { itemName = "fireball rune", clientId = 3189, buy = 30 }, + { itemName = "great fireball rune", clientId = 3191, buy = 57 }, + { itemName = "heavy magic missile rune", clientId = 3198, buy = 12 }, + { itemName = "holy missile rune", clientId = 3182, buy = 16 }, + { itemName = "icicle rune", clientId = 3158, buy = 30 }, + { itemName = "intense healing rune", clientId = 3152, buy = 95 }, + { itemName = "light magic missile rune", clientId = 3174, buy = 4 }, + { itemName = "magic wall rune", clientId = 3180, buy = 116 }, + { itemName = "paralyse rune", clientId = 3165, buy = 700 }, + { itemName = "poison bomb rune", clientId = 3173, buy = 85 }, + { itemName = "poison field rune", clientId = 3172, buy = 21 }, + { itemName = "poison wall rune", clientId = 3176, buy = 52 }, + { itemName = "soulfire rune", clientId = 3195, buy = 46 }, + { itemName = "stalagmite rune", clientId = 3179, buy = 12 }, + { itemName = "stone shower rune", clientId = 3175, buy = 37 }, + { itemName = "sudden death rune", clientId = 3155, buy = 135 }, + { itemName = "thunderstorm rune", clientId = 3202, buy = 47 }, + { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, + { itemName = "wild growth rune", clientId = 3156, buy = 160 }, + }, + ["supplies"] = { + { itemName = "brown mushroom", clientId = 3725, buy = 10 }, + { itemName = "ham", clientId = 3582, buy = 10 }, + { itemName = "meat", clientId = 3577, buy = 5 }, + { itemName = "shapeshifter ring", clientId = 907, buy = 5500, subType = 15 }, + }, + ["tools"] = { + { itemName = "basket", clientId = 2855, buy = 6 }, + { itemName = "bottle", clientId = 2875, buy = 3 }, + { itemName = "bucket", clientId = 2873, buy = 4 }, + { itemName = "candelabrum", clientId = 2911, buy = 8 }, + { itemName = "candlestick", clientId = 2917, buy = 2 }, + { itemName = "closed trap", clientId = 3481, buy = 280, sell = 75 }, + { itemName = "crowbar", clientId = 3304, buy = 260, sell = 50 }, + { itemName = "fishing rod", clientId = 3483, buy = 150, sell = 40 }, + { itemName = "machete", clientId = 3308, buy = 35, sell = 6 }, + { itemName = "pick", clientId = 3456, buy = 50, sell = 15 }, + { itemName = "rope", clientId = 3003, buy = 50, sell = 15 }, + { itemName = "scythe", clientId = 3453, buy = 50, sell = 10 }, + { itemName = "shovel", clientId = 3457, buy = 50, sell = 8 }, + { itemName = "spellwand", clientId = 651, sell = 299 }, + { itemName = "torch", clientId = 2920, buy = 2 }, + { itemName = "watch", clientId = 2906, buy = 20, sell = 6 }, + { itemName = "worm", clientId = 3492, buy = 1 }, + }, + ["postal"] = { + { itemName = "label", clientId = 3507, buy = 1 }, + { itemName = "letter", clientId = 3505, buy = 8 }, + { itemName = "parcel", clientId = 3503, buy = 15 }, + }, } + -- On buy npc shop message npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost) npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks) @@ -596,7 +638,14 @@ function createHirelingType(HirelingName) sendSkillNotLearned(npc, creature, HIRELING_SKILLS.STEWARD) end elseif MsgContains(message, "goods") then - npcHandler:say("I sell a selection of various items. Just ask {trade}!", npc, creature) + local string + if not hireling:hasSkill(HIRELING_SKILLS.TRADER) then + string = "While I'm not a trader, I still have a collection of {various} items to sell if you like!" + else + string = "I sell a selection of {various} items, {exercise weapons}, {equipment}, " .. "{distance} weapons, {wands} and {rods}, {potions}, {runes}, " .. "{supplies}, {tools} and {postal} goods. Just ask!" + end + npcHandler:setTopic(playerId, TOPIC.GOODS) + npcHandler:say(string, npc, creature) elseif MsgContains(message, "lamp") then npcHandler:setTopic(playerId, TOPIC.LAMP) if player:getGuid() == hireling:getOwnerId() then @@ -623,6 +672,12 @@ function createHirelingType(HirelingName) enableBankSystem[playerId] = true elseif npcHandler:getTopic(playerId) >= TOPIC.FOOD and npcHandler:getTopic(playerId) < TOPIC.GOODS then handleFoodActions(npc, creature, message) + elseif npcHandler:getTopic(playerId) == TOPIC.GOODS then + local categoryTable = itemsTable[message:lower()] + if categoryTable then + npcHandler:say("Here are the items for the category " .. message, npc, creature) + npc:openShopWindowTable(player, categoryTable) + end end if enableBankSystem[playerId] then -- Parse bank diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 648ce4da4c2..3991d01c1c1 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -261,7 +261,7 @@ void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8 } uint32_t buyPrice = 0; - const std::vector &shopVector = getShopItemVector(); + const std::vector &shopVector = getShopItemVector(player->getGUID()); for (ShopBlock shopBlock : shopVector) { if (itemType.id == shopBlock.itemId && shopBlock.itemBuyPrice != 0) { buyPrice = shopBlock.itemBuyPrice; @@ -370,7 +370,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint uint32_t sellPrice = 0; const ItemType &itemType = Item::items[itemId]; - const std::vector &shopVector = getShopItemVector(); + const std::vector &shopVector = getShopItemVector(player->getGUID()); for (ShopBlock shopBlock : shopVector) { if (itemType.id == shopBlock.itemId && shopBlock.itemSellPrice != 0) { sellPrice = shopBlock.itemSellPrice; @@ -642,23 +642,25 @@ bool Npc::getRandomStep(Direction &moveDirection) { return false; } -void Npc::addShopPlayer(const std::shared_ptr &player) { +void Npc::addShopPlayer(const std::shared_ptr &player, const std::vector &shopItems /* = {}*/) { if (!player) { return; } - shopPlayerMap.try_emplace(player->getID(), player); + + shopPlayerMap.try_emplace(player->getGUID(), shopItems); } void Npc::removeShopPlayer(const std::shared_ptr &player) { if (!player) { return; } - shopPlayerMap.erase(player->getID()); + + shopPlayerMap.erase(player->getGUID()); } void Npc::closeAllShopWindows() { - for (auto &[_, playerPtr] : shopPlayerMap) { - auto shopPlayer = playerPtr.lock(); + for (const auto &[playerGUID, playerPtr] : shopPlayerMap) { + auto shopPlayer = g_game().getPlayerByGUID(playerGUID); if (shopPlayer) { shopPlayer->closeShopWindow(); } diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 5f118360528..393b24867a1 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -96,7 +96,14 @@ class Npc final : public Creature { npcType->info.currencyId = currency; } - std::vector getShopItemVector() { + std::vector getShopItemVector(uint32_t playerGUID) { + if (playerGUID != 0) { + auto it = shopPlayerMap.find(playerGUID); + if (it != shopPlayerMap.end() && !it->second.empty()) { + return it->second; + } + } + return npcType->info.shopItemVector; } @@ -159,7 +166,7 @@ class Npc final : public Creature { internalLight = npcType->info.light; } - void addShopPlayer(const std::shared_ptr &player); + void addShopPlayer(const std::shared_ptr &player, const std::vector &shopItems = {}); void removeShopPlayer(const std::shared_ptr &player); void closeAllShopWindows(); @@ -178,7 +185,7 @@ class Npc final : public Creature { std::map playerInteractions; - phmap::flat_hash_map> shopPlayerMap; + phmap::flat_hash_map> shopPlayerMap; std::shared_ptr npcType; std::shared_ptr spawnNpc; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 44bf33d09b1..0c68ec3a659 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1474,7 +1474,7 @@ void Player::openImbuementWindow(std::shared_ptr item) { void Player::sendSaleItemList(const std::map &inventoryMap) const { if (client && shopOwner) { - client->sendSaleItemList(shopOwner->getShopItemVector(), inventoryMap); + client->sendSaleItemList(shopOwner->getShopItemVector(getGUID()), inventoryMap); } } @@ -1781,7 +1781,6 @@ bool Player::openShopWindow(std::shared_ptr npc) { } setShopOwner(npc); - npc->addShopPlayer(static_self_cast()); sendShop(npc); std::map inventoryMap; @@ -4130,7 +4129,7 @@ bool Player::hasShopItemForSale(uint16_t itemId, uint8_t subType) const { } const ItemType &itemType = Item::items[itemId]; - std::vector shoplist = shopOwner->getShopItemVector(); + std::vector shoplist = shopOwner->getShopItemVector(getGUID()); return std::any_of(shoplist.begin(), shoplist.end(), [&](const ShopBlock &shopBlock) { return shopBlock.itemId == itemId && shopBlock.itemBuyPrice != 0 && (!itemType.isFluidContainer() || shopBlock.itemSubType == subType); }); diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index d24ed978ac8..0df0b55041a 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -354,6 +354,60 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { return 1; } + npc->addShopPlayer(player); + pushBoolean(L, player->openShopWindow(npc)); + return 1; +} + +int NpcFunctions::luaNpcOpenShopWindowTable(lua_State* L) { + // npc:openShopWindowTable(player, items) + const auto &npc = getUserdataShared(L, 1); + if (!npc) { + reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + pushBoolean(L, false); + return 1; + } + + const auto &player = getUserdataShared(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + + if (lua_istable(L, 3) == 0) { + reportError(__FUNCTION__, "item list is not a table."); + pushBoolean(L, false); + return 1; + } + + std::vector items; + lua_pushnil(L); + while (lua_next(L, 3) != 0) { + const auto tableIndex = lua_gettop(L); + ShopBlock item; + + auto itemId = getField(L, tableIndex, "clientId"); + auto subType = getField(L, tableIndex, "subType"); + if (subType == 0) { + subType = getField(L, tableIndex, "subtype"); + lua_pop(L, 1); + } + + auto buyPrice = getField(L, tableIndex, "buy"); + auto sellPrice = getField(L, tableIndex, "sell"); + auto storageKey = getField(L, tableIndex, "storageKey"); + auto storageValue = getField(L, tableIndex, "storageValue"); + auto realName = getFieldString(L, tableIndex, "name"); + g_logger().debug("[{}] item '{}' sell price '{}', buyprice '{}'", __FUNCTION__, realName, sellPrice, buyPrice); + + items.emplace_back(itemId, subType, buyPrice, sellPrice, storageKey, storageValue, std::move(realName)); + lua_pop(L, 8); + } + lua_pop(L, 3); + + // Close any eventual other shop window currently open. + player->closeShopWindow(true); + npc->addShopPlayer(player, items); pushBoolean(L, player->openShopWindow(npc)); return 1; } @@ -391,8 +445,8 @@ int NpcFunctions::luaNpcIsMerchant(lua_State* L) { return 1; } - const std::vector shopItems = npc->getShopItemVector(); - + auto playerGUID = getNumber(L, 2, 0); + const auto &shopItems = npc->getShopItemVector(playerGUID); if (shopItems.empty()) { pushBoolean(L, false); return 1; @@ -411,8 +465,9 @@ int NpcFunctions::luaNpcGetShopItem(lua_State* L) { return 1; } - const std::vector &shopVector = npc->getShopItemVector(); - for (ShopBlock shopBlock : shopVector) { + auto playerGUID = getNumber(L, 2, 0); + const auto &shopItems = npc->getShopItemVector(playerGUID); + for (ShopBlock shopBlock : shopItems) { setField(L, "id", shopBlock.itemId); setField(L, "name", shopBlock.itemName); setField(L, "subType", shopBlock.itemSubType); @@ -522,7 +577,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { } uint64_t pricePerUnit = 0; - const std::vector &shopVector = npc->getShopItemVector(); + const std::vector &shopVector = npc->getShopItemVector(player->getGUID()); for (ShopBlock shopBlock : shopVector) { if (itemId == shopBlock.itemId && shopBlock.itemBuyPrice != 0) { pricePerUnit = shopBlock.itemBuyPrice; diff --git a/src/lua/functions/creatures/npc/npc_functions.hpp b/src/lua/functions/creatures/npc/npc_functions.hpp index 7671780e720..ef3371a54fb 100644 --- a/src/lua/functions/creatures/npc/npc_functions.hpp +++ b/src/lua/functions/creatures/npc/npc_functions.hpp @@ -36,6 +36,7 @@ class NpcFunctions final : LuaScriptInterface { registerMethod(L, "Npc", "isInTalkRange", NpcFunctions::luaNpcIsInTalkRange); registerMethod(L, "Npc", "isPlayerInteractingOnTopic", NpcFunctions::luaNpcIsPlayerInteractingOnTopic); registerMethod(L, "Npc", "openShopWindow", NpcFunctions::luaNpcOpenShopWindow); + registerMethod(L, "Npc", "openShopWindowTable", NpcFunctions::luaNpcOpenShopWindowTable); registerMethod(L, "Npc", "closeShopWindow", NpcFunctions::luaNpcCloseShopWindow); registerMethod(L, "Npc", "getShopItem", NpcFunctions::luaNpcGetShopItem); registerMethod(L, "Npc", "isMerchant", NpcFunctions::luaNpcIsMerchant); @@ -73,6 +74,7 @@ class NpcFunctions final : LuaScriptInterface { static int luaNpcIsInTalkRange(lua_State* L); static int luaNpcIsPlayerInteractingOnTopic(lua_State* L); static int luaNpcOpenShopWindow(lua_State* L); + static int luaNpcOpenShopWindowTable(lua_State* L); static int luaNpcCloseShopWindow(lua_State* L); static int luaNpcGetShopItem(lua_State* L); static int luaNpcIsMerchant(lua_State* L); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 38014a3a511..958d19f2a71 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -4360,7 +4360,7 @@ void ProtocolGame::sendShop(std::shared_ptr npc) { msg.addString(std::string()); // Currency name } - std::vector shoplist = npc->getShopItemVector(); + std::vector shoplist = npc->getShopItemVector(player->getGUID()); uint16_t itemsToSend = std::min(shoplist.size(), std::numeric_limits::max()); msg.add(itemsToSend);