ElEditors, Interface administrators, Administrators
70,866
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- pystart | |||
require('Module:CommonFunctions'); | require('Module:CommonFunctions'); | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
Line 262: | Line 263: | ||
else | else | ||
DAMAGE_CONFIG = BASE_DAMAGE_CONFIG | DAMAGE_CONFIG = BASE_DAMAGE_CONFIG | ||
end | |||
-- Helper function to check if a table is not empty | |||
local function isTableNotEmpty(tbl) | |||
return next(tbl) ~= nil | |||
end | |||
-- Function to apply inheritance for a specific damage type and argument | |||
local function applyInheritance(mainArgValues, inheritArg, mainArgValue, inheritValue) | |||
if mainArgValue == '' then | |||
return inheritValue | |||
elseif mainArgValue and string.find(mainArgValue, 'i') and inheritValue then | |||
return eval(mainArgValue:gsub('i', inheritValue)) | |||
end | |||
return mainArgValue | |||
end | |||
-- Function to apply inheritance for a specific argument key | |||
local function applyInheritanceForKey(args, prefix, mainKey, argTable, damageTypeIndex) | |||
local mainKeyPrefixed = prefix .. mainKey | |||
local mainArgValues = args[mainKeyPrefixed] | |||
if mainArgValues then | |||
local i = 1 | |||
local cancelDmgLen = args.cancel_dmg and #args.cancel_dmg or 0 | |||
while i <= (#args.dmg + cancelDmgLen) do | |||
local mainArgValue = mainArgValues[i] | |||
for ix, inheritKey in ipairs(argTable) do | |||
local inheritArg = args[prefix .. inheritKey] or args[inheritKey] | |||
if inheritArg and inheritArg[i] and inheritArg[i] ~= '' and | |||
(damageTypeIndex == 1 and ix ~= 1 or damageTypeIndex ~= 1) | |||
then | |||
mainArgValues[i] = applyInheritance(mainArgValues, inheritArg, mainArgValue, inheritArg[i]) | |||
break | |||
end | |||
end | |||
i = i + 1 | |||
end | |||
end | |||
end | end | ||
Line 267: | Line 311: | ||
function inherit(mode) | function inherit(mode) | ||
local prefix = mode == 'PvE' and '' or string.lower(mode .. '_') | local prefix = mode == 'PvE' and '' or string.lower(mode .. '_') | ||
for configKey, configValue in pairs(DAMAGE_CONFIG) do | |||
for argTableKey, argTable in pairs(configValue) do | |||
if argTableKey ~= 'provided' and isTableNotEmpty(argTable) then | |||
for damageTypeIndex, damageType in ipairs({ '', '_min', '_max' }) do | |||
applyInheritanceForKey(args, prefix, argTable[1] .. damageType, argTable, damageTypeIndex) | |||
end | end | ||
end | end | ||
Line 889: | Line 902: | ||
if OPTIONS.do_table then | if OPTIONS.do_table then | ||
doTable() | doTable() | ||
end | end | ||
-- Dump all values if wanted. | -- Dump all values if wanted. | ||
Line 919: | Line 932: | ||
return p | return p | ||
-- pyend |