Editing
Module:Products
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function p._main(frame) local args = frame:getParent().args args.item = mw.title.getCurrentTitle().text local mw = require('mw') local products = p.getProducts(args) local recipeNames = p.extractRecipeNames(products) local prodprices = p.getShopBuyPrices(products) -- Generate and return a table containing the product information local output = p.displayProductTable(prodprices) return output end function p.extractRecipeNames(products) local recipeNames = {} for _, recipeInfo in ipairs(products) do local recipeLink = recipeInfo["Recipe"] if recipeLink then local displayName = recipeLink:match("%[%[.-|(.+)%]%]") if displayName then table.insert(recipeNames, displayName) end end end return recipeNames end function p.getProducts(args) local item = mw.smw.ask('[[:+]][[Uses item::' .. args.item .. ']]|?Uses item |?Profession A |?Profession Level A|?Value |mainlabel=Recipe') or 0 return item end function p.getShopBuyPrices(products) local mw = require('mw') for _, product in ipairs(products) do local usesItems = product["Uses item"] if type(usesItems) == "table" then for _, item in ipairs(usesItems) do -- Extract item name from the link local itemName = item:match("%[%[.-|(.+)%]%]") or item:match("%[%[(.-)%]%]") if itemName then -- Query for the shop buy price of the item local shopPriceQuery = '[[:+]][[Sold item::' .. itemName .. ']]|?Shop buy price|mainlabel=' .. itemName local shopPriceResult = mw.smw.ask(shopPriceQuery) or {} if shopPriceResult[1] and shopPriceResult[1]["Shop buy price"] then product[itemName .. "_Shop_buy_price"] = shopPriceResult[1]["Shop buy price"] else product[itemName .. "_Shop_buy_price"] = "N/A" end end end elseif type(usesItems) == "string" then -- Handle single uses item (not a table) local itemName = usesItems:match("%[%[.-|(.+)%]%]") or usesItems:match("%[%[(.-)%]%]") if itemName then -- Query for the shop buy price of the item local shopPriceQuery = '[[:+]][[Sold item::' .. itemName .. ']]|?Shop buy price|mainlabel=' .. itemName local shopPriceResult = mw.smw.ask(shopPriceQuery) or {} if shopPriceResult[1] and shopPriceResult[1]["Shop buy price"] then product[itemName .. "_Shop_buy_price"] = shopPriceResult[1]["Shop buy price"] else product[itemName .. "_Shop_buy_price"] = "N/A" end end end end return products end function p.displayProductTable(products) local currency = require('Module:Currency').parse local out = {} table.insert(out, '{| class="wikitable"') table.insert(out, '! Recipe !! Level !! Value !! Ingredients !! Price') for _, product in ipairs(products) do local recipe = product["Recipe"] or "Unknown" local professionName = product["Profession A"]:match("%[%[.-|(.+)%]%]") or product["Profession A"]:match("%[%[(.-)%]%]") or product["Profession A"] or "Unknown" local professionLevel = "[[File:" .. professionName .. " small icon.png|30px]] " .. (product["Profession Level A"] or "Unknown") local usesItems = product["Uses item"] or {} local value = currency(product["Value"]) or "Unknown" -- Concatenate uses items and their shop buy prices in unordered lists local usesItemStr = "<ul style='list-style:none; margin:0; padding-left:0;'>" local shopBuyPriceStr = "<ul style='list-style:none; margin:0; padding-left:0; text-align:right;'>" if type(usesItems) == "table" then for _, item in ipairs(usesItems) do local itemName = item:match("%[%[.-|(.+)%]%]") or item:match("%[%[(.-)%]%]") or item usesItemStr = usesItemStr .. "<li>" .. item .. "</li>" local shopBuyPrice = product[itemName .. "_Shop_buy_price"] or 0 if shopBuyPrice == "N/A" then shopBuyPrice = 0 end shopBuyPriceStr = shopBuyPriceStr .. "<li>" .. currency(shopBuyPrice) .. "</li>" end elseif type(usesItems) == "string" then usesItemStr = usesItemStr .. "<li>" .. usesItems .. "</li>" local itemName = usesItems:match("%[%[.-|(.+)%]%]") or usesItems:match("%[%[(.-)%]%]") or usesItems local shopBuyPrice = product[itemName .. "_Shop_buy_price"] or 0 if shopBuyPrice == "N/A" then shopBuyPrice = 0 end shopBuyPriceStr = shopBuyPriceStr .. "<li>" .. currency(shopBuyPrice) .. "</li>" end usesItemStr = usesItemStr .. "</ul>" shopBuyPriceStr = shopBuyPriceStr .. "</ul>" table.insert(out, '|-') table.insert(out, '| ' .. recipe .. ' || ' .. professionLevel .. ' || ' .. value .. ' || ' .. usesItemStr .. ' || ' .. shopBuyPriceStr) end table.insert(out, '|}') return table.concat(out, '\n') end return p
Summary:
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
Brighter Shores:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Template used on this page:
Module:Products/doc
(
view source
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Refresh
Search
Discord
Discord
Navigation
About us
User help
Random page
Recent changes
Gray Jellied Eel Stew
1m
ago
-
Mudscape
8% Preparation XP Hopeport
1m
ago
-
Fyri
Purple Hoggberries
2m
ago
-
Mudscape
Hand Saw
3m
ago
-
Mudscape
Show more...
Brighter Shores
Professions
Factions
Episodes
Premium Pass
Monsters
Quests
Community
Policies
Tools
What links here
Related changes
Special pages
Page information