m (-wrappers) |
mNo edit summary |
||
Line 70: | Line 70: | ||
local temp = round(args[key] * data[key].val, 2) |
local temp = round(args[key] * data[key].val, 2) |
||
out[#out+1] = string.format( |
out[#out+1] = string.format( |
||
− | + | "* %s%s %s = %s", |
|
args[key], |
args[key], |
||
data[key].percent and '%' or '', |
data[key].percent and '%' or '', |
Revision as of 04:29, 20 January 2020
Documentation for this module may be created at Module:Sandbox/BryghtShadow/Gold value math/doc
-- <pre>
-- Libraries and modules
local ImageLink_createList = require('Module:ImageLink')._createLink
local Fd_get = require('Module:fd').get
local data = mw.loadData('Module:Gold value math/data')
-- Helpers
local function fd(s)
return Fd_get{args={tostring(s)}}
end
local function gold(value)
value = value or ''
-- TODO: Make ImageLink accept Boolean false.
local link, img, label = ImageLink_createList{
link = 'Gold',
text = fd(value),
image = 'Gold.png',
alttext = value .. ' Gold',
border = 'false',
style = 'color:gold;white-space:pre',
labellink = 'false',
}
return tostring(link)
end
local function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
-- Export
local p = {}
function p.main(frame)
local args = require('Dev:Arguments').getArgs(frame, {
parentFirst = true,
})
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, 2)
out[#out+1] = string.format(
"* %s%s %s = %s",
args[key],
data[key].percent and '%' or '',
data[key].name,
gold(tostring(temp)))
total = total + temp
end
end
out[#out+1] = "** '''Total Gold Value''' = " .. gold(tostring(round(total, 2)))
return table.concat(out, '\n')
end
return p
-- </pre>
-- [[Category:Lua]]