ElEditors, Interface administrators, Administrators
70,868
edits
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
end | end | ||
-- Implement sorted loop through array. | |||
function spairs(t) | function spairs(t) | ||
local keys = {} | local keys = {} | ||
Line 18: | Line 19: | ||
end | end | ||
-- Implement merging tables | |||
function tableMerge(first_table, second_table) | function tableMerge(first_table, second_table) | ||
for k,v in spairs(second_table) do first_table[k] = v end | for k,v in spairs(second_table) do first_table[k] = v end | ||
end | end | ||
-- Implement rounding. | |||
function round(num, numDecimalPlaces) | |||
if numDecimalPlaces == nil then | |||
numDecimalPlaces = 2 | |||
end | |||
local mult = 10^(numDecimalPlaces or 0) | |||
return math.floor(num * mult + 0.5) / mult | |||
end | |||
-- Implement splitting string to a table. | |||
function split (inputstr, sep) | function split (inputstr, sep) | ||
if sep == nil then | if sep == nil then | ||
Line 33: | Line 45: | ||
end | end | ||
-- Function wrapper for vardefine notation in MW. | |||
function var(name, dmg) | function var(name, dmg) | ||
return '{{#vardefine:'..name..'|'..dmg..'}}' | return '{{#vardefine:'..name..'|'..dmg..'}}' | ||
end | end | ||
-- Main process | |||
function p.list(frame) | function p.list(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
Line 54: | Line 68: | ||
end | end | ||
-- Define tables that hold the subsequent damage values. | |||
-- I know this isn't the best, but I don't want to work with nested tables in this language. | |||
local fvals = {} | local fvals = {} | ||
local tvals = {} | local tvals = {} | ||
Line 60: | Line 76: | ||
local pvals23 = {} | local pvals23 = {} | ||
local vars = {} | local vars = {} | ||
local traits = { | |||
heavy = 1.44 | -- Handle trait table | ||
local traits = {} | |||
if (inArgs('heavy')) then | |||
traits.heavy = 1.44 | |||
end | |||
if (inArgs('enhanced')) then | |||
traits.enhanced = 0.8 | |||
end | |||
if inArgs('empowered') | -- Customizable for empowered, it had to be special lol. | ||
traits.empowered = args.empowered | if (inArgs('empowered')) then | ||
if (args.empowered == 'true') then | |||
traits.empowered = 1.2 | |||
else | |||
traits.empowered = args.empowered | |||
end | |||
end | end | ||
-- Define total/average damage calculation based on damage per hit and hit amount. | |||
function getTotal(dmg, hits, fval) | function getTotal(dmg, hits, fval) | ||
local i = 1 | local i = 1 | ||
Line 79: | Line 107: | ||
end | end | ||
end | end | ||
-- But not for useful because I don't want it overcomplicated. | |||
if not string.find(fval, 'useful') then | if not string.find(fval, 'useful') then | ||
table.insert(vars, var(fval, fvals[fval])) | table.insert(vars, var(fval, fvals[fval])) | ||
else | |||
table.insert(vars, var('total_damage_useful', fvals.total_damage_useful * args.useful_penalty)) | |||
end | end | ||
end | end | ||
-- | -- Actually generate the values depending on arguments provided. | ||
getTotal('dmg', 'hits', 'total_damage') | getTotal('dmg', 'hits', 'total_damage') | ||
Line 99: | Line 130: | ||
end | end | ||
-- traits | -- Handling traits | ||
-- Useful handled separately | |||
if inArgs('useful_penalty') then | if inArgs('useful_penalty') then | ||
getTotal('dmg', 'hits_useful', 'total_damage_useful') | getTotal('dmg', 'hits_useful', 'total_damage_useful') | ||
end | end | ||