Module:Reforge

require('Module:LoadLib')(_G)

local p = {} - -- Template:Reforge stone table -- -- Creates a table that formats the cost of a reforge stone - function p.reforgeStoneTable(frame) local args = getArgs(frame)

local rTiers = { 'common', 'uncommon', 'rare', 'epic', 'legendary', 'mythic', }	local rTiersShort = { 'c', 'u', 'r', 'e', 'l', 'm', }	local statsMap = { 'damage', 'strength', 'crit_chance', 'crit_damage', 'bonus_attack_speed', 'sea_creature_chance', 'health', 'defense', 'speed', 'intelligence', 'magic_find', 'true_defense', 'ferocity', 'mining_speed', 'mining_fortune', 'foraging_fortune', 'farming_fortune', }	local statsMapShort = { 'dmg', 'str', 'cc', 'cd', 'bas', 'scc', 'hp', 'def', 'spd', 'int', 'mf', 'td', 'fer', 'mns', 'mnf', 'frf', 'fmf', }	local statsListShowPerc = { false, -- damage false, -- strength true, -- crit_chance true, -- crit_damage true, -- bonus_attack_speed true, -- sea_creature_chance false, -- health false, -- defense false, -- speed false, -- intelligence false, -- magic_find false, -- true_defense false, -- ferocity false, -- mining_speed false, -- mining_fortune false, -- foraging_fortune false, -- farming_fortune }	--Configuration for the size of the table local config = { lenX = #rTiers or 6, lenY = #statsMapShort or 10, }	local infoNeededVals = { ['in']=1, ['infoneeded']=1, ['ineeded']=1, ['infon']=1, ['moreinfoneeded']=1, ['moreinfo']=1, ['info needed']=1, ['more info needed']=1, ['more info']=1, ['info n']=1, ['?']=1,	}	local confirmVals = { ['confirm']=1, ['c']=1, ['con']=1, ['conf']=1, ['check']=1, ['not confirmed']=1, ['unconfirmed']=1, ['notconfirmed']=1, }	local srcNeededVals = { ['source needed']=1, ['src needed']=1, ['src n']=1, ['sn']=1, ['source n']=1, ['source?']=1, ['souce']=1, ['s?']=1, ['s']=1, }	local blankCellVals = { ['n/a']=1, ['no']=1, ['n']=1, ['none']=1, ['f']=1, ['fal']=1, ['false']=1, ['0']=1,		['-0']=1,		['+0']=1,		['-0%']=1,		['+0%']=1,		['0%']=1,		['']=1,		['unapplicable']=1, }	local function isNormal(arg) if not infoNeededVals[arg:lower] and not blankCellVals[arg:lower] then return true else return false end end

local function processOtherArg(arg) if infoNeededVals[arg:lower] then ret = string.infoNeeded elseif blankCellVals[arg:lower] then ret = string.blankCell

else ret = arg end return ret end local function extractEndNotice(arg) if arg:match('%s*;%s*') then arg, endNotice = arg:match('(.+)%s*;%s*(.*)') else endNotice = '' end if endNotice ~= '' then if confirmVals[endNotice:lower] then endNotice = '' elseif srcNeededVals[endNotice:lower] then endNotice = '' else endNotice = '' end end return arg, endNotice end local function processCostArgs(i) local argCase1 = args["cost_"..rTiers[i]] local argCase2 = args["cost_"..rTiersShort[i]] local argStorage = argCase1 or argCase2 if args["cost"] then local tmp = mw.text.split(args["cost"], '%s*,%s*') arg = tmp[i] else arg = argStorage or "" end return arg end local function processStatArgs(i) local argShort = args['stats_'..statsMap[i]] local argNormal = args['stats_'..statsMapShort[i]] if argNormal then tmp = argNormal elseif argShort then tmp = argShort else tmp = '' end if tmp ~= '' then ret = (mw.text.split(tmp, '%s*\,%s*')) for j=1, config.lenX, 1 do						if not ret[j] or ret[j] == '' then ret[j] = string.blankCell end end else ret = {} for j=1, config.lenX ,1 do					local argCase1 = args[statsMapShort[i]..'_'..rTiers[j]] local argCase2 = args[statsMapShort[i]..'_'..rTiersShort[j]] local argCase3 = args[statsMap[i]..'_'..rTiers[j]] local argCase4 = args[statsMap[i]..'_'..rTiersShort[j]] local argRet = argCase2 or argCase1 or argCase3 or argCase4 ret[j] = argRet if not ret[j] then ret[j] = string.blankCell end end end return ret end local wikitable = mw.html.create('table'):addClass('wikitable') local row = wikitable:tag('tr') row:tag('th') :attr({ rowspan=2 }) :wikitext(string.centerText('Stat Bonus')) :done row:tag('th') :attr({ colspan=config.lenX, }) :wikitext(string.centerText('Rarity')) :done row:done local row = wikitable:tag('tr') for i=1, config.lenX, 1 do

row:tag('th'):wikitext(string.centerText(makeRarity(rTiers[i]))):done if i == config.lenX then row:done end end for i=1, config.lenY, 1 do		argsList = processStatArgs(i) local rowIsEmpty = (argsList[1] == string.blankCell 			and argsList[2] == string.blankCell 			and argsList[3] == string.blankCell 			and argsList[4] == string.blankCell 			and argsList[5] == string.blankCell 			and argsList[6] == string.blankCell) local row = not rowIsEmpty and wikitable:tag('tr'):tag('td'):wikitext(string.centerText(makeStat(statsMap[i]))):done or '' if not rowIsEmpty then for j=1, config.lenX, 1 do 				local arg, endNotice = extractEndNotice(argsList[j]) if isNormal(arg) and arg:match('([^%d%%%-%+%.%,]+)') then arg = arg end

row:tag('td') :wikitext(string.centerText( (isNormal(arg) and not arg:match('([^%d%%%-%+%.%,]+)')) and makeColor(							'green', 							arg:gsub('^([%+%-]*)(%d+)(%%?)$', function(prep, d)									local pattern = tostring(d) if statsListShowPerc[i] then pattern = pattern..'%' end return (prep == '-' and prep or '+')..pattern end )						)..endNotice or processOtherArg(arg) )):done end row:done end end local row = wikitable:tag('tr') row:tag('th'):wikitext(table.concat{'Cost to apply (in ', tostring(coins), ')'}):done for i=1, config.lenX, 1 do		local arg, endNotice = extractEndNotice(processCostArgs(i)) row:tag('td'):wikitext(			((arg and isNormal(arg)) and string.centerText(				tostring(coins{ arg, nil, true })..endNotice			) or processOtherArg(arg) ))	end local specialEffect = args["special effect"] or args["specialeff"] or args["special"] or args["eff"] or args["se"] if specialEffect then local name, desc = specialEffect:match('([%a ]+)%s*;%s*(.+)') local varStrs = desc:match(';\n') and mw.text.split(desc:match('.+;\n(.+)'), '%s*,%s*') local desc = varStrs and desc:match('(.+);\n.+') or desc local desc = desc :gsub('\n', ' ') local copy if varStrs then local showPerc = table.some(varStrs, 					function(_, v) 						return v:match('%%')					end				) if showPerc then copy = table.from(varStrs) table.each(varStrs, function(v, i, t)					t[i] = v:gsub('%%', '')				end) else copy = table.from(varStrs) end desc = desc:gsub('$VALUES', function				return makeColor('Green', { '+', 					table.concat(varStrs, '/'), showPerc and '%' or '', })			end) end local row = wikitable:tag('tr') row:tag('th') :wikitext('Reforge Special Effect') :done row:tag('td') :attr({ colspan=config.lenX }) :wikitext(table.concat{					makeColor('Blue', name),					': ',					desc,				}) :done row:done if varStrs then local row = wikitable:tag('tr') row:tag('th') :wikitext('Reforge Special effect values') :done for i = 1, table.length(varStrs), 1 do				mw.log(varStrs[i]) end for i, v in pairs(varStrs) do				local t = varStrs if infoNeededVals[v:lower] then t[i] = string.infoNeeded end end for i, v in ipairs(copy) do				row:tag('td') :wikitext((v ~= string.blankCell and v ~= string.infoNeeded) and makeColor('Green', v) or v)				:done end row:done end end wikitable:done return frame:preprocess(tostring(wikitable)) end

--Finish Module return p