Skip to content

Commit

Permalink
fix: npc submenu shop window (#2852)
Browse files Browse the repository at this point in the history
• Fixed to open submenus even after having a shop window open
• Fixed so that when saying "trade" it informs the other available
categories
  • Loading branch information
dudantas authored Oct 10, 2024
1 parent 5b55f96 commit ad56722
Show file tree
Hide file tree
Showing 31 changed files with 150 additions and 239 deletions.
8 changes: 2 additions & 6 deletions data-otservbr-global/npc/alaistar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,11 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/alexander.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]
local itemId = items[player:getVocation():getBaseId()]
if MsgContains(message, "first rod") or MsgContains(message, "first wand") then
Expand All @@ -163,7 +158,8 @@ local function creatureSayCallback(npc, creature, type, message)
npcHandler:say("Ok then.", npc, creature)
npcHandler:setTopic(playerId, 0)
elseif categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -175,7 +171,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hi there |PLAYERNAME|, and welcome to the {magic} store.")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {runes} or {wands}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
9 changes: 3 additions & 6 deletions data-otservbr-global/npc/asima.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]
local itemId = items[player:getVocation():getBaseId()]
if MsgContains(message, "first rod") or MsgContains(message, "first wand") then
Expand All @@ -174,12 +169,14 @@ local function creatureSayCallback(npc, creature, type, message)
npcHandler:say("Ok then.", npc, creature)
npcHandler:setTopic(playerId, 0)
elseif categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
end

npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

Expand Down
11 changes: 4 additions & 7 deletions data-otservbr-global/npc/battlemart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,20 @@ local itemsTable = {
}

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)
npcHandler:say("I sell a selection of " .. npc:getFormattedCategoryNames(itemsTable), npc, player)
elseif categoryTable then
npcHandler:say("Here are the items for the category " .. message, npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", 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:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)
Expand Down
9 changes: 3 additions & 6 deletions data-otservbr-global/npc/chuckles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,17 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
end

npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/fenech.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]
local itemId = items[player:getVocation():getBaseId()]
if MsgContains(message, "first rod") or MsgContains(message, "first wand") then
Expand All @@ -163,7 +158,8 @@ local function creatureSayCallback(npc, creature, type, message)
npcHandler:say("Ok then.", npc, creature)
npcHandler:setTopic(playerId, 0)
elseif categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -173,7 +169,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Be mourned pilgrim in flesh and welcome to the magic store.")
npcHandler:setMessage(MESSAGE_FAREWELL, "May enlightenment be your path.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "May enlightenment be your path.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/frans.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,11 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -134,7 +130,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Beeee greeeeted, Simula! What is your neeeed?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
11 changes: 3 additions & 8 deletions data-otservbr-global/npc/frederik.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,10 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -158,7 +153,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hi there and welcome to my little magic shop.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Yeah, bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Yeah, bye.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions}, {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/ghorza.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,11 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -141,7 +137,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hello, scraggy human.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Take care of evil spirits.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Take care of evil spirits.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/gnomegica.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,11 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -154,7 +150,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Greetings! You came to the right gnome to buy {potions}, {runes} or {wands}. So let's talk about a {trade}.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye and come again.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {potions}, {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
10 changes: 4 additions & 6 deletions data-otservbr-global/npc/hamish.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]
if MsgContains(message, "dawnport") then
npcHandler:say({
Expand All @@ -191,7 +186,8 @@ local function creatureSayCallback(npc, creature, type, message)
He even has a crush on lady Oressa. Cute. <chuckles>",
}, npc, creature, 200)
elseif categoryTable then
npcHandler:say("Take your pick!", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -203,6 +199,8 @@ npcHandler:setMessage(
"Hi there, fellow adventurer. \z
What's your need? Say {trade} and we'll soon get you fixed up. Or ask me about {potions}, {wands}, or {runes}."
)

npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:setMessage(MESSAGE_FAREWELL, "Use your runes wisely!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Use your runes wisely!")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Take your pick! Or maybe you want to look only at {potions}, {wands} or {runes}?")
Expand Down
3 changes: 2 additions & 1 deletion data-otservbr-global/npc/hireling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ function createHirelingType(HirelingName)

local categoryTable = itemsTable[message:lower()]
if categoryTable then
npcHandler:say("Here are the items for the category " .. message .. ".", npc, creature)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
end
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/khanna.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]
local itemId = items[player:getVocation():getBaseId()]
if MsgContains(message, "first rod") or MsgContains(message, "first wand") then
Expand All @@ -202,14 +197,15 @@ local function creatureSayCallback(npc, creature, type, message)
npcHandler:say("Ok then.", npc, creature)
npcHandler:setTopic(playerId, 0)
elseif categoryTable then
npcHandler:say("Take your pick!", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/mordecai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,11 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Choose wisely!", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -161,7 +157,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Welcome to the magic emporium, child. Ask me for a trade if you need {runes}, {wands}, or spellbooks.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Take care, child.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Ah, the impetuosity of youth.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Choose wisely! Or maybe you want to look only at {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Choose wisely! Or maybe you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
10 changes: 3 additions & 7 deletions data-otservbr-global/npc/nelly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,11 @@ local function creatureSayCallback(npc, creature, type, message)
return false
end

local formattedCategoryNames = {}
for categoryName, _ in pairs(itemsTable) do
table.insert(formattedCategoryNames, "{" .. categoryName .. "}")
end

local categoryTable = itemsTable[message:lower()]

if categoryTable then
npcHandler:say("Of course, just browse through my wares.", npc, player)
local remainingCategories = npc:getRemainingShopCategories(message:lower(), itemsTable)
npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player)
npc:openShopWindowTable(player, categoryTable)
end
return true
Expand All @@ -170,7 +166,7 @@ npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, What can I do for you? I'm working for the post office, but I also trade with important {potions}, {runes} and other magical equipment.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Ah, the impetuosity of youth.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at {post stuff}, {potions}, {wands} or {runes}?")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares. Or do you want to look only at " .. GetFormattedShopCategoryNames(itemsTable) .. ".")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- On buy npc shop message
Expand Down
Loading

0 comments on commit ad56722

Please sign in to comment.