Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
1,925 bytes added ,  25 July 2021
getGodUpgradeTable: Initial implementation
m (_getShopTable: Top tier solution to <math> not working as expected)
(getGodUpgradeTable: Initial implementation)
Line 403: Line 403:
     table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. mods.increasedAutoEatHPLimit .. '" | ' .. Shared.formatnum(Shared.round(mods.increasedAutoEatHPLimit, 0, 0)) .. '%')
     table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. mods.increasedAutoEatHPLimit .. '" | ' .. Shared.formatnum(Shared.round(mods.increasedAutoEatHPLimit, 0, 0)) .. '%')
     table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. costAmt .. '" | ' .. Icons.GP(costAmt))
     table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. costAmt .. '" | ' .. Icons.GP(costAmt))
  end
  table.insert(resultPart, '|}')
  return table.concat(resultPart, '\r\n')
end
function p.getGodUpgradeTable()
  local resultPart = {}
  -- Obtain list of God upgrades: look for skill upgrades which have a dungeon completion
  --  requirement for an area whose name ends with 'God Dungeon'
  local getGodDungeon =
    function(reqs)
      if reqs.dungeonCompletion ~= nil then
        for i, areaReq in ipairs(reqs.dungeonCompletion) do
          local dung = Areas.getAreaByID('dungeon', areaReq[1])
          if string.find(dung.name, 'God Dungeon$') ~= nil then return dung end
        end
      end
    end
                         
  local upgradeList = p.getPurchases(
    function(cat, purch)
      if cat == 'SkillUpgrades' and purch.unlockRequirements ~= nil then
        return getGodDungeon(purch.unlockRequirements) ~= nil
      end
      return false
    end)
  if Shared.tableCount(upgradeList) == 0 then return '' end
  -- Table header
  table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
  table.insert(resultPart, '|- class="headerRow-0"')
  table.insert(resultPart, '!colspan="2"|God Upgrade!!Effect!!Dungeon!!Cost')
  -- Rows for each God upgrade
  for i, upgrade in ipairs(upgradeList) do
    local dung = getGodDungeon(upgrade.unlockRequirements)
    local costSortValue = p._getPurchaseSortValue(upgrade)
    table.insert(resultPart, '|-\r\n|style="min-width:25px; text-align:center;" data-sort-value="' .. upgrade.name .. '"| ' .. Icons.Icon({upgrade.name, type='upgrade', size=50, notext=true}))
    table.insert(resultPart, '| [[' .. upgrade.name .. ']]')
    table.insert(resultPart, '| ' .. upgrade.description)
    table.insert(resultPart, '| data-sort-value="' .. dung.name .. '"| ' .. Icons.Icon({dung.name, type='dungeon'}))
    table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. costSortValue .. '"| ' .. p.getCostString(upgrade.cost))
   end
   end
   table.insert(resultPart, '|}')
   table.insert(resultPart, '|}')