Module:Kat

-- local p = {} --Get Required Modules local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local table = require('Module:Table') local string = require('Module:String')

--Define Rarity Tiers local TIERS = {"common", "uncommon", "rare", "epic", 'legendary', "mythic"} local TIERSshort, upgrades = {}, {}

table.each(TIERS, function(v, i)	TIERSshort[i] = TIERS[i]:sub(1, 1)	end)

for i = 2, #TIERS do	upgrades[i-1] = table.concat{ ,		"  → ",		,	} end

--Shorten number function local function shortenNum(num) --If input is null, return 0 if num == nil then return 0 end --Shorten if over 10k if num >= 10000 then return math.ceil(num) --Else return normal else return math.ceil(num*10)/10 end end - -- Template:Kat Cost table -- -- Takes inputs from template and formats it in a nice table with formatted text - function p.katTable(frame) local args = getArgs(frame) --Process Arguments local function processArgs(j, num) if args[j..'_'..TIERS[num]] then s = args[j..'_'..TIERS[num]] elseif args[j..'_'..TIERSshort[num]] then s = args[j..'_'..TIERSshort[num]] end return s	end --Process Cost arguments local function costProcess(d) return processArgs('cost', d)	end --Process Materials arguments local function matsProcess(k) return processArgs('mats', k)	end --Process Time arguments local function timeProcess(g) return processArgs('time', g)	end --Create the Table local katTable = mw.html.create('table'):attr({ class="wikitable" }) --Header local row = katTable:tag("tr") row:tag("th"):attr({ rowspan=2 }):wikitext("Rarity Upgrade"):done row:tag("th"):attr({ colspan=2 }):wikitext("Cost"):done row:tag("th"):attr({ rowspan=2 }):wikitext("Time"):done row:done --Header 2 local row = katTable:tag("tr") row:tag("th"):wikitext("Coins"):done row:tag("th"):wikitext("Materials"):done row:done --Iterator Function to create the table rows for i = 1,#TIERS-1,1 do			--Check for Arguments local function checks(j) return args[j..'_'..TIERS[i]] or args[j..'_'..TIERSshort[i]] end --Check if a Parameter contains a "InfoNeeded" Argument local function checkInfoNeeded(j) --"InfoNeeded" Arguments local inVals = { ['in']=true, ['infoneeded']=true, ['ineeded']=true, ['infon']=true, ['moreinfoneeded']=true, ['moreinfo']=true, ['info needed']=true, ['more info needed']=true, ['more info']=true, ['info n']=true, }				if not inVals[string.lower(checks(j))] then return false elseif inVals[string.lower(checks(j))] then return true end end --Process Arguments in Iterator function cost = costProcess(i) mats = matsProcess(i) time = timeProcess(i) --Secondary Input Arguments --Confirm Template Arguments local confirmVals = { ['confirm']=true, ['c']=true, ['check']=true, ['not confirmed']=true, ['unconfirmed']=true, ['notconfirmed']=true, }			--Source needed Template Arguments local srcNeededVals = { ['source needed']=true, ['src needed']=true, ['src n']=true, ['sn']=true, ['source n']=true, ['source?']=true, ['souce']=true, ['s?']=true, }			--Not Base price Arguments local nbpVals = { ['nbp']=true, ['not base price']=true, ['not base']=true, ['check price']=true, ['notbase']=true, ['notbaseprice']=true, ['nb price']=true, }			--Other Arguments local nbp = '[NBP ]' local function notNilWords(j) return string.lower(j) ~= 'n/a' and string.lower(j) ~= 'none' end --Cost if checks('cost') and not checkInfoNeeded('cost') and notNilWords(cost) then --Check for Secondary Inputs if string.match(cost, ';') then --Split Secondary Inputs and Main arguments cost, costEndString = string.unpackedSplit(cost, '%s*;%s*') costEndString = string.lower(costEndString) --Check if Secondary Input contains any notification arguments if confirmVals[costEndString] then costEndNotice = '' elseif nbpVals[costEndString] then costEndNotice = nbp elseif srcNeededVals[costEndString] then costEndNotice = '' else costEndNotice = '' end else costEndNotice = '' end --Format Cost into coins cost = '' cost = cost..costEndNotice --Check if "cost" arguments contain "InfoNeeded" Arguments elseif checks('cost') and checkInfoNeeded('cost') then cost = '' else cost = '' end if checks('mats') and not checkInfoNeeded('mats') and notNilWords(mats) then --Check for Secondary Inputs if string.match(mats, ';') then --Split Secondary Input and main text mats, matsEndString = string.unpackedSplit(mats, '%s*;%s*') matsEndString = string.lower(matsEndString) --Check if Secondary Input contains any notification arguments if confirmVals[matsEndString] then matsEndNotice = '' elseif nbpVals[matsEndString] then matsEndNotice = nbp elseif srcNeededVals[matsEndString] then matsEndNotice = '' else matsEndNotice = '' end else matsEndNotice = '' end local list = string.parseTextList(mats, '*') local items = {} for _, mat in ipairs(list) do					--Split Arguments 1 and 2 local item, num = string.unpackedSplit(mat, '%s*,%s*') if type(mat) ~= "table" and not string.match(mats, ',') then num, item = string.match(mats, '(%d+x?)%s+(%[?%[?.+%]?%]?)') end table.push(items, num .. " " .. item) end mats = ''..matsEndNotice --Check if "mats" arguments contain "InfoNeeded" elseif checks('mats') and checkInfoNeeded('mats') then mats = '' else mats = '' end --Time if checks('time') and not checkInfoNeeded('time') and notNilWords(time) then --Check for Secondary Inputs if string.match(time, ';') then --Split Secondary Input and main text timeSplit = mw.text.split(time, '%s*;%s*') time = timeSplit[1] timeEndString = string.lower(timeSplit[2]) --Check if Secondary Input contains any notification arguments if confirmVals[timeEndString] then T1meEndNotice = '' elseif nbpVals[timeEndString] then T1meEndNotice = nbp elseif srcNeededVals[timeEndString] then T1meEndNotice = '' else T1meEndNotice = '' end else T1meEndNotice = '' end --Split Arguments 1 and 2 time = mw.text.split(time, '%s') --Time Number timeNum = ' ' --Time Unit timeUnit = 'July 28, 2024' time = timeNum..timeUnit..T1meEndNotice --Check if "time" arguments contain "InfoNeeded" elseif checks('time') and checkInfoNeeded('time') then time = '' else time = '' end --Set End notices to blank if not specified if not costEndNotice then costEndNotice = '' end if not endNotice then endNotice = '' end if not T1meEndNotice then T1meEndNotice = '' end --Check for nil words like "n/a" or "none" local checkNil = checks('cost') or checks('mats') or checks('time') local function nilWords(j) return string.lower(j) == 'n/a' or string.lower(j) == 'none' end --Iterate the rarities over Table Rows local row = katTable:tag("tr") --Rarity if checkNil then row:tag("th"):wikitext(upgrades[i]):done end --Cost in Coins if cost ~= '' then row:tag("td"):wikitext(cost) elseif checkNil or nilWords(cost) then row:tag("td"):wikitext('') end --Materials if mats ~= '' then row:tag("td"):wikitext(mats) elseif checkNil or nilWords(mats) then row:tag("td"):wikitext('') end --Time needed if time ~= '' then row:tag("td"):wikitext(time) elseif checkNil or nilWords(time) then row:tag("td"):wikitext('') end --End Row row:done end --End Table katTable:done --Return the table return frame:preprocess(tostring(katTable)) end

- -- Template:Kat cost calc -- -- Calculates the cost for Kat pet caretaking and returns the cost in coins - function p.katCostCalc(frame) --Get arguments from frame local args = getArgs(frame) --Arguments local calcType = assert(args[1], 'Bad argument to #1: Type of operation was undefined (input expected, got none). Valid Operations: total cost, to base price') local inputs = args[2] local doCoins = args["coins"] or args["c"] or '' --Return the function return frame:preprocess(p._katCostCalc(calcType, inputs, doCoins)) end --Calculation Function function p._katCostCalc(calcType, inputs, doCoins) --Operation 1 values local calcType1 = { ['total cost']=true, ['cost']=true, ['total']=true, ['tc']=true, }	--Operation 2 values local calcType2 = { ['to base price']=true, ['base price']=true, ['base cost']=true, ['to base cost']=true, ['tbc']=true, }	--Detect operation 1 from inputs if calcType1[string.lower(calcType)] then --Split the input text into , inputs = mw.text.split(inputs, '%s*\,%s*') a = inputs[1] b = inputs[2] --Calcuate cost total = b-0.003*b*a --Detect operation 2 from inputs elseif calcType2[string.lower(calcType)] then --Split the input text into , inputs = mw.text.split(inputs, '%s*\,%s*') a = inputs[1] b = inputs[2] --Calcuate cost total = ((1000*b)/(3*a-1000))*-1 end --doCoins false value inputs local falseVals = { ['off']=true, ['false']=true, ['f']=true, ['no']=true, ['n']=true, [0]=true, }	--Return Total in coins if falseVals[string.lower(doCoins)] then return shortenNum(total) else return '' end end

return p