17,370
edits
m (_getShopTable: Remove duplicate declaration of 'purchOverrides') |
(getCookingUtilityTable: Initial implementation) |
||
Line 594: | Line 594: | ||
return table.concat(resultPart, '\r\n') | return table.concat(resultPart, '\r\n') | ||
end | |||
function p.getCookingUtilityTable(frame) | |||
local category = nil | |||
if frame ~= nil then category = frame.args ~= nil and frame.args[1] or frame end | |||
local validCategories = {'Cooking Fire', 'Furnace', 'Pot'} | |||
if category == nil or not Shared.contains({'Cooking Fire', 'Furnace', 'Pot'}, category) then | |||
return 'ERROR: Invalid category specified. Must be one of the following: ' .. mw.text.listToText(validCategories, ', ', ' or ') | |||
end | |||
local categoryShort = string.match(category, '[^%s]+$') | |||
local bonusSkillID = Constants.getSkillID('Cooking') | |||
local bonusColMod, bonusColName = nil, nil | |||
if category == 'Cooking Fire' then | |||
bonusColMod = 'increasedSkillXP' | |||
bonusColName = 'Bonus ' .. Icons.Icon({'Cooking', type='skill', notext=true}) .. ' XP' | |||
else | |||
bonusColMod = 'increasedChanceToDoubleItemsSkill' | |||
bonusColName = 'Double Items Chance' | |||
end | |||
local modsPerfectChance = {'increasedChancePerfectCookFire', 'increasedChancePerfectCookFurnace', | |||
'increasedChancePerfectCookPot', 'increasedChancePerfectCookGlobal'} | |||
local totalBonusVal, totalPerfectChance = 0, 0 | |||
local utilityList = p.getPurchases(function(cat, purch) return cat == 'SkillUpgrades' and string.find(purch.name, category .. '$') ~= nil end) | |||
local resultPart = {} | |||
-- Table header | |||
table.insert(resultPart, '{| class="wikitable stickyHeader"') | |||
table.insert(resultPart, '|- class="headerRow-0"') | |||
table.insert(resultPart, '!colspan="4"| !!colspan="2"|' .. bonusColName .. '!!colspan="2"|Bonus Perfect Chance') | |||
table.insert(resultPart, '|- class="headerRow-1"') | |||
table.insert(resultPart, '!colspan="2"|Name!!Level!!Cost' .. string.rep('!!This ' .. categoryShort .. '!!Total', 2)) | |||
-- Row for each upgrade | |||
for i, utility in ipairs(utilityList) do | |||
-- First determine bonus XP/doubling chance and perfect chance | |||
local bonusVal, perfectChance = 0, 0 | |||
if type(utility.contains) == 'table' then | |||
if type(utility.contains.modifiers) == 'table' then | |||
for modName, modVal in pairs(utility.contains.modifiers) do | |||
if modName == bonusColMod and type(modVal) == 'table' then | |||
-- Bonus XP/doubling | |||
for skID, skVal in pairs(modVal) do | |||
if skVal[1] == bonusSkillID then bonusVal = bonusVal + skVal[2] end | |||
end | |||
elseif Shared.contains(modsPerfectChance, modName) then | |||
-- Perfect chance | |||
perfectChance = perfectChance + modVal | |||
end | |||
end | |||
end | |||
end | |||
totalBonusVal = totalBonusVal + bonusVal | |||
totalPerfectChance = totalPerfectChance + perfectChance | |||
-- Mangle unlockRequirements so that it only includes skillLevels | |||
local unlockReqs = {} | |||
if type(utility.unlockRequirements) == 'table' then | |||
unlockReqs['skillLevel'] = utility.unlockRequirements.skillLevel | |||
end | |||
table.insert(resultPart, '|-') | |||
table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({utility.name, type='upgrade', size='50', notext=true})) | |||
table.insert(resultPart, '|' .. utility.name) | |||
table.insert(resultPart, '|style="text-align:right"|' .. p.getRequirementString(unlockReqs)) | |||
table.insert(resultPart, '|style="text-align:right"|' .. p.getCostString(utility.cost, false)) | |||
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. bonusVal .. '%') | |||
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalBonusVal .. '%') | |||
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. perfectChance .. '%') | |||
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalPerfectChance .. '%') | |||
end | |||
table.insert(resultPart, '|}') | |||
return table.concat(resultPart, '\r\n') | |||
end | end | ||
return p | return p |