Module:Charm log

-- -- Module to be required by data pages -- Will handle all functions for /Monster modules --

local p = {}

function p.view( frame ) local view_arg = string.lower( frame.args[1] ) local monster = frame.args[2] local page = 'Charm:Module test' local data = mw.loadData( page )

local kills = data.kills local charms = data.charms local gold = data.gold local green = data.green local crimson = data.crimson local blue = data.blue

-- view variables to pull right from the table -- log, charms, kills, gold, green, crimson, blue data_views = { ['log'] = true, charms = true, kills = true, gold = true, green = true, crimson = true, blue = true }   if data_views[view_arg] then return data[view_arg] end

if view_arg == "none" then return kills - ( gold + green + crimson + blue ) end

if view_arg == "nonepercent" then if kills == 0 then return 0 else return ( kills - ( ( gold + green + crimson + blue ) / charms ) ) / kills end end

if view_arg == "charmpercent" then if kills == 0 then return 0 else return ( ( gold + green + crimson + blue ) / charms ) / kills end end

-- little helper function for individual char percentages local function percent( charm, kills ) if kills == 0 then return 0 else return ( charm / charms ) / kills end end

if view_arg == "goldpercent" then return percent( gold, kills ) end

if view_arg == "greenpercent" then return percent( green, kills ) end

if view_arg == "crimsonpercent" then return percent( crimson, kills ) end

if view_arg == "bluepercent" then return percent( blue, kills ) end end

return p