Module:Weapon Upgrades

--Module:LuaWeaponUpgrades --Table local p = {}

function p.weaponupgrades(frame) --Test values stats = --{["rounds"]=1,["reload-time"]=1,["unload-time"]=1,["cycle-time"]=1,   ["level-02-damage"]=1,["level-02-cost"]="1k"} --Get one-time arguments frame:getParent.args rounds = formatnum(stats["rounds"]) reload = formatnum(stats["reload-time"]) unload = formatnum(stats["unload-time"]) cyclet = formatnum(stats["cycle-time"]) --write table header local tab = "{| class=\"article-table weapon-upgrades\"\n! Level\n! Damage\n! Cost (Ag)\n! Time\n! Burst DPS\n! Cycle Damage\n! Cycle DPS\n" --Loop across all levels for n=1,12 do       tab = tab ..row(n) end --Write table end return tab .."|}" end

function row(n) --convert n to the level for reading arguments local lvl = string.format( "%02d", n ) --read in damage per particle local dmg = stats["level-" ..lvl .."-damage"] or "" --if no value, skip level if dmg == "" then return "" end --change dmg to a number dmg = formatnum(stats["level-" ..lvl .."-damage"]) --also read damage of previous level local prevdmg = stats["level-" ..string.format( "%02d", n-1 ) .."-damage"] or "" --calculate percent increase, empty string if no previous level local dmginc if prevdmg == "" then dmginc = "" else prevdmg = formatnum(prevdmg) dmginc = " (+" ..round(100*dmg/prevdmg -100) .."%)" end --read in upgrade cost local cst = stats["level-" ..lvl .."-cost"] or "" --read in upgrade time local tme = stats["level-" ..lvl .."-time"] or "" --Calculate output local cycdmg = dmg*rounds local brstdps = round(cycdmg/unload) local cycdps = round(cycdmg/cyclet) --return output return "|-\n! " ..n .."\n| " ..dmg ..dmginc .."\n| " ..cst .."\n| " ..tme .."\n| " ..brstdps .."\n| " ..cycdmg .."\n| " ..cycdps .."\n" end

function round(x) return math.floor(x+.5) end

function formatnum(str) return tonumber(string.gsub(str,",",""),10) end

return p