Module:DropsLine

-- local p = {}

local yesno = require('Module:Yesno') local uclc = require('Module:Paramtest').ucflc local commas = require('Module:Addcommas') local geprice = require('Module:Exchange')._price

local raritybg = { ['always'] = '#AFEEEE', ['common'] = '#56E156', ['uncommon'] = '#FFED4C', ['rare'] = '#FF863C', ['very rare'] = '#FF6262', ['random'] = '#FFA3FF', ['varies'] = '#FFA3FF', ['discontinued'] = '#DBFF4C' }

local raritysort = { ['always'] = '1', ['common'] = '2', ['uncommon'] = '3', ['rare'] = '4', ['very rare'] = '5', ['varies'] = '6', ['random'] = '6', ['discontinued'] = '7' }

function p._main(frame) local args = frame:getParent.args -- Params and defaults local name = args.Name or 'item' local namenotes = args.Namenotes or '' local quantity = string.lower(args.Quantity or 'Unknown') local quantitynotes = args.Quantitynotes or '' local rarity = uclc(args.Rarity) or 'Unknown' local raritynotes = args.Raritynotes or '' local gemw = args.gemw or 'yes' gemw = yesno(gemw) local price local alt = false if gemw then -- Default to leet while we're still using templates for gemw -- Need raw numbers, can only get template expansion price = '1337' -- price = geprice(name) elseif args.AltValue then price = args.AltValue alt = true else price = 'Not sold' end -- Clean up price price = commas._strip(price) price = tonumber(price) or false -- Use 'File: .png' if no image param -- User 'File: ' if image param; image param will include extension local image = 'File:' .. (args.Image or (name .. '.png'))

-- Table row local ret = main(name,namenotes,quantity,quantitynotes,rarity,raritynotes,price,alt,image,gemw)

-- categories for mainspace local cats = '' local ns = mw.title.getCurrentTitle.nsText if ns == '' then cats = categories(name,quantity,rarity) end return ret..cats end

function main(name,namenotes,quantity,quantitynotes,rarity,raritynotes,price,alt,image,gemw) local rare_bg = raritybg[rarity:lower] or '#FFFFFF' local rare_sort = raritysort[rarity:lower] or '8' local cleanqty = qty(price,quantity) quantity = cleanqty[1] local total = cleanqty[2] -- Table row creation local ret = '|- style="text-align:center;"' .. '\n| ' .. image .. '' .. '\n| style="text-align:left;" | ' .. name .. ' ' .. namenotes .. '\n| ' .. quantity .. ' ' .. quantitynotes .. '\n| style="background:' .. rare_bg .. ';"' .. -- display none is used to create a sort key to let -- rarity sorting work properly ' | ' .. rare_sort .. '; ' .. rarity .. ' ' .. raritynotes if gemw and not alt then ret = ret .. '\n| title="'			.. commas._add(price) .. ' coins each" | ' .. total elseif alt then ret = ret .. '\n| ' .. total .. ' '	else ret = ret .. '\n| Not sold' end return ret end

function qty(price,quantity) -- if no quantity is given, return unknown and the price if not quantity or quantity == 'unknown' then return { 'Unknown', price } end -- en dashes are the proper dash for number ranges -- replace all hyphens and em dashes with en	-- strip *all* whitespace -- change '(noted)' to 'n' for parsing quantity = quantity:gsub('[-—]','–') :gsub('%s','') :gsub('%(noted%)','n') -- split list into table local vals = mw.text.split(quantity,',') -- All prices ranges will be a range -- e.g. if items valued at 100 coins are dropped in quantities of 1, 3, 5 -- the price will be 100–500 rather than 100; 300; 500 -- if low and high vars are the same in the end, only 1 price is displayed local low = 2147483648 local high = 0 local ret = {} -- recreate the quantity string to ensure consistent formatting local numstr = '' for i, v in ipairs(vals) do		local clean = v:gsub('n','') -- if list element contain an en dash (indicating range) -- Find the smaller/larger number (just in case) -- Compare them to the current min/max -- put them in order with desired format if v:find('–') then local noted = v:find('n') local splitvals = mw.text.split(clean,'–') local a = tonumber(splitvals[1]) local b = tonumber(splitvals[2]) local smaller,larger if a > b then smaller = b				larger = a			else smaller = a				larger = b			end if smaller < low then low = smaller end if larger > high then high = larger end numstr = numstr .. commas._add(smaller) .. '–' .. commas._add(larger) if noted then numstr = numstr .. ' (noted)' end else local a = tonumber(clean) if a < low then low = a			end if a > high then high = a			end numstr = numstr .. commas._add(a) if v:find('n') then numstr = numstr .. ' (noted)' end end -- To prevent any possible confusion with formatted numbers -- elements should be separated with semicolons followed by a space numstr = numstr .. '; '	end -- removes the final separator, because it's redundant numstr = numstr:sub(1,-3) ret[1] = numstr local qtys if high == low then qtys = {['low'] = nil, ['high'] = high} else qtys = {['low'] = low, ['high'] = high} end ret[2] = get_price(price,qtys) return ret end

-- function to parse the quantity ranges and give a price range -- also returns the desired format function get_price(price,quantity) local ttl if not price then ttl = 'Not sold' elseif not quantity.low then ttl = price * quantity.high ttl = commas._add(ttl) else local lower = price * quantity.low local higher = price * quantity.high ttl = commas._add(lower) .. '–' .. commas._add(higher) end return ttl end

-- adding categories to mainspace function categories(name,quantity,rarity) local ret = '' name = name:lower quantity = quantity:lower if name:find('effigy') then ret = ret .. ''	elseif name:find('clue scroll') then ret = ret .. ''	end if not raritysort[rarity:lower] then ret = ret .. ''	end if quantity:find('Unknown') then ret = ret .. ''	end return ret end

return p