Module:Sandbox/BryghtShadow/Gold value math

-- -- Libraries and modules local imagelink = require('Module:ImageLink') local data = mw.loadData('Module:Gold value math/data')

-- Helpers local function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end

local function gold(value) value = value or '' -- TODO: Make ImageLink accept Boolean false. local link, img, label = imagelink._createLink{ link = 'Gold', text = value, image = 'Gold.png', alttext = value .. ' Gold', border = 'false', style = 'color:gold;white-space:pre', labellink = 'false', }	return tostring(link) end

-- Export

local p = {}

function p.main(frame) local args = require('Dev:Arguments').getArgs(frame, {	   parentFirst = true,	    wrappers = {	        "Template:Gold value math",        },	}) return p._main(args) end

function p._main(args) local total = 0 local out = {} local keys = { 'ap', 'ad', 'as', 'armor', 'rpen', 'cdr', 'cdrunique', 'crit', 'critunique', 'hsp', 'health', 'hp5', 'hp5flat', 'lifesteal', 'mr', 'mana', 'mp5', 'mp5flat', 'mpen', 'msflat', 'ms', }	for i, key in ipairs(keys) do		if args[key] and data[key] then local temp = round(args[key] * data[key].val) out[#out+1] = string.format(	           "* %s%s %s = %s",				args[key],				data[key].percent and '%' or '',				data[key].name,				gold(temp)) total = total + temp end end out[#out+1] = "** Total Gold Value = " .. gold(round(total, 2)) return table.concat(out, '\n') end

return p -- --