Module:RatKetBuying

From Fallen London Wiki

Documentation for this module may be created at Module:RatKetBuying/doc

p = {}

-- Editable, demands list.
-- Each new demand is a key-value pair
-- key - name of the demand
-- value - list of lists that represent items sold
-- -- each list has two values
-- -- [0] - name of the item (wiki page)
-- -- [1] - name of the item as shown in-text
demands = {
	Intricate = {{"Unlawful Device", "Unlawful Devices"}, {"Corresponding Sounder", "Corresponding Sounders"}},
	Saintly = {{"Ratty Reliquary", "Ratty Reliquaries"}, {"False Hagiotoponym", "False Hagiotoponyms"}},
	Soft = {{"Parabola-Linen Scrap", "Parabola-Linen"}, {"Scrap of Ivory Organza", "Ivory Organza"}},
	Inscrutable = {{"Uncanny Incunabulum", "Uncanny Incunabula"}, {"Cartographer's Hoard", "Cartographer's Hoards"}},
	Maudlin = {{"Captivating Ballad", "Captivating Ballads"}, {"Parabolan Parable", "Parabolan Parables"}},
	Tempestuous = {{"Storm-Threnody", "Storm-Threnodies"}, {"Night-Whisper", "Night-Whispers"}}
}

function p.currentDemands()
	local out = "Presently, the Rat Market is buying:\n"
	for demandName, demandInfo in pairs(demands) do
		local demandValue = p.getDemand(demandName)
		local run = true
		if demandValue == "1" then
			out = out .. "* Newly-available"
		elseif demandValue == "2" then
			out = out .. "* Leaving after"
		else
			run = false
		end
		if run then
			out = out .. " this week: "
			for k, itemInfo in pairs(demandInfo) do
				out = out .. "[[" .. itemInfo[1] .. "|" .. itemInfo[2] .. "]] and "
			end
			out = out:sub(0, -6) .. ".\n"
		end
	end
	return out
end

function p.getDemand(name)
	return mw.smw.ask("[[" .. name .. " Demand]]|?Has current value")[1]["Has current value"]
end

return p