Module:Shop: Difference between revisions

161 bytes removed ,  8 January 2022
Use tabs instead of spaces for indentation
(getCostString: Fix regression for cost display within tables)
(Use tabs instead of spaces for indentation)
Line 669: Line 669:
end
end
local modsPerfectChance = {'increasedChancePerfectCookFire', 'increasedChancePerfectCookFurnace',
local modsPerfectChance = {'increasedChancePerfectCookFire', 'increasedChancePerfectCookFurnace',
                      'increasedChancePerfectCookPot', 'increasedChancePerfectCookGlobal'}
'increasedChancePerfectCookPot', 'increasedChancePerfectCookGlobal'}
local totalBonusVal, totalPerfectChance = 0, 0
local totalBonusVal, totalPerfectChance = 0, 0
local utilityList = p.getPurchases(function(cat, purch) return cat == 'SkillUpgrades' and string.find(purch.name, category .. '$') ~= nil end)
local utilityList = p.getPurchases(function(cat, purch) return cat == 'SkillUpgrades' and string.find(purch.name, category .. '$') ~= nil end)
local resultPart = {}
local resultPart = {}
    -- Table header
-- Table header
    table.insert(resultPart, '{| class="wikitable stickyHeader"')
table.insert(resultPart, '{| class="wikitable stickyHeader"')
    table.insert(resultPart, '|- class="headerRow-0"')
table.insert(resultPart, '|- class="headerRow-0"')
    table.insert(resultPart, '!colspan="4"| !!colspan="2"|' .. bonusColName .. '!!colspan="2"|Bonus Perfect Chance')
table.insert(resultPart, '!colspan="4"| !!colspan="2"|' .. bonusColName .. '!!colspan="2"|Bonus Perfect Chance')
    table.insert(resultPart, '|- class="headerRow-1"')
table.insert(resultPart, '|- class="headerRow-1"')
    table.insert(resultPart, '!colspan="2"|Name!!Level!!Cost' .. string.rep('!!This ' .. categoryShort .. '!!Total', 2))
table.insert(resultPart, '!colspan="2"|Name!!Level!!Cost' .. string.rep('!!This ' .. categoryShort .. '!!Total', 2))
   
 
    -- Row for each upgrade
-- Row for each upgrade
    for i, utility in ipairs(utilityList) do
for i, utility in ipairs(utilityList) do
    -- First determine bonus XP/doubling chance and perfect chance
-- First determine bonus XP/doubling chance and perfect chance
    local bonusVal, perfectChance = 0, 0
local bonusVal, perfectChance = 0, 0
    if type(utility.contains) == 'table' then
if type(utility.contains) == 'table' then
    if type(utility.contains.modifiers) == 'table' then
if type(utility.contains.modifiers) == 'table' then
    for modName, modVal in pairs(utility.contains.modifiers) do
for modName, modVal in pairs(utility.contains.modifiers) do
    if modName == bonusColMod and type(modVal) == 'table' then
if modName == bonusColMod and type(modVal) == 'table' then
    -- Bonus XP/doubling
-- Bonus XP/doubling
    for skID, skVal in pairs(modVal) do
for skID, skVal in pairs(modVal) do
    if skVal[1] == bonusSkillID then bonusVal = bonusVal + skVal[2] end
if skVal[1] == bonusSkillID then bonusVal = bonusVal + skVal[2] end
    end
end
    elseif Shared.contains(modsPerfectChance, modName) then
elseif Shared.contains(modsPerfectChance, modName) then
    -- Perfect chance
-- Perfect chance
    perfectChance = perfectChance + modVal
perfectChance = perfectChance + modVal
    end
end
    end
end
    end
end
    end
end
    totalBonusVal = totalBonusVal + bonusVal
totalBonusVal = totalBonusVal + bonusVal
    totalPerfectChance = totalPerfectChance + perfectChance
totalPerfectChance = totalPerfectChance + perfectChance
   
 
    -- Mangle unlockRequirements so that it only includes skillLevels
-- Mangle unlockRequirements so that it only includes skillLevels
    local unlockReqs = {}
local unlockReqs = {}
    if type(utility.unlockRequirements) == 'table' then
if type(utility.unlockRequirements) == 'table' then
    unlockReqs['skillLevel'] = utility.unlockRequirements.skillLevel
unlockReqs['skillLevel'] = utility.unlockRequirements.skillLevel
    end
end
   
 
    table.insert(resultPart, '|-')
table.insert(resultPart, '|-')
    table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({utility.name, type='upgrade', size='50', notext=true}))
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, '|' .. utility.name)
    table.insert(resultPart, '|style="text-align:right"|' .. p.getRequirementString(unlockReqs))
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"|' .. p.getCostString(utility.cost, false))
    table.insert(resultPart, '|style="text-align:right"|' .. '+' .. bonusVal .. '%')
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. bonusVal .. '%')
    table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalBonusVal .. '%')
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalBonusVal .. '%')
    table.insert(resultPart, '|style="text-align:right"|' .. '+' .. perfectChance .. '%')
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. perfectChance .. '%')
    table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalPerfectChance .. '%')
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalPerfectChance .. '%')
    end
end
    table.insert(resultPart, '|}')
table.insert(resultPart, '|}')
 
return table.concat(resultPart, '\r\n')
return table.concat(resultPart, '\r\n')
end
end


return p
return p