Module:GetEffect
Appearance
local p = {}
function p.getEffect(frame)
local pageName = frame.args[1] or mw.title.getCurrentTitle().text
local booleanParam = frame.args[2] or '0' -- default to full effect
local page = mw.title.new(pageName)
if not page then
return 'Page not found'
end
local content = page:getContent()
local effect = content:match('|%s*effects%s*=%s*(.-)\n%s*|') or content:match('|%s*effects%s*=%s*(.-)%s*}}') or ''
effect = mw.text.trim(effect)
effect = effect:gsub("<", "<")
local debugOutput = 'Debug Info:\n'
debugOutput = debugOutput .. 'Extracted effect: ' .. effect .. '\n'
if booleanParam ~= '1' then
-- Return full effect string if boolean is not '1'
return effect
end
-- Parse stats into a map
local statsMap = {}
local parts = mw.text.split(effect, ',')
for _, part in ipairs(parts) do
part = mw.text.trim(part)
debugOutput = debugOutput .. 'Part: ' .. part .. '\n'
local num, percent, key = part:match('^([+-]?[%d%.]+)(%%?)%s+(.*)$')
if num and key then
debugOutput = debugOutput .. 'Standard match: num=' .. num .. ', percent=' .. (percent or '') .. ', key=' .. key .. '\n'
local normKey = mw.text.trim(key):lower()
local value = num .. percent
if num:sub(1,1) == '+' then
value = value:sub(2)
end
-- Handle range formats in key
local range_stat, range_part, condition = key:match('^([%w%.]+)%s+(to%s*(<)?%s*[%w%.]+)%s*(%b()|[%w%.]+)?$')
if range_stat then
debugOutput = debugOutput .. 'Range match in key: range_stat=' .. range_stat .. ', range_part=' .. range_part .. ', condition=' .. (condition or '') .. '\n'
local normRangeStat = range_stat:lower()
value = num .. percent .. ' ' .. range_part
statsMap[normRangeStat] = mw.text.trim(value)
else
statsMap[normKey] = mw.text.trim(value)
end
else
debugOutput = debugOutput .. 'Standard match: no match\n'
end
end
-- Output all 6 stats separated by ||
local allStats = {'w.pwr', 'def', 'crit', 'durability', 'gather speed', 'speed'}
local results = {}
for _, s in ipairs(allStats) do
local val = statsMap[s] or ''
table.insert(results, val)
end
local output = table.concat(results, '||')
-- If no values were found for any stat, return debug to diagnose
if output == '|||||' then
return debugOutput .. '\nNo stats matched - full output would be empty'
end
return output
end
return p