Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
m
Changed Ship Table header from 'Survey Time Decrease' to 'Cartography Interval'; This modifier effects more than survey intervals
(mw.log(p.getShopMiscUpgradeTable()))
Tag: Reverted
m (Changed Ship Table header from 'Survey Time Decrease' to 'Cartography Interval'; This modifier effects more than survey intervals)
(4 intermediate revisions by one other user not shown)
Line 238: Line 238:
function p.getPurchaseContents(frame)
function p.getPurchaseContents(frame)
local args = frame.args ~= nil and frame.args or frame
local args = frame.args ~= nil and frame.args or frame
local purchaseName = args[1]
local purchaseName = Shared.fixPagename(args[1])
local asList = (args[2] ~= nil and string.upper(args[2]) == 'TRUE')
local asList = (args[2] ~= nil and string.upper(args[2]) == 'TRUE')
local purchase = p.getPurchase(purchaseName)
local purchase = p.getPurchase(purchaseName)
Line 425: Line 425:
table.insert(resultPart, '|}')
table.insert(resultPart, '|}')


return table.concat(resultPart, '\r\n')
return table.concat(resultPart, '\n')
end
end


Line 515: Line 515:


result = result..'\r\n|-\r\n!style="text-align:right;"|Contains'
result = result..'\r\n|-\r\n!style="text-align:right;"|Contains'
result = result..'\r\n|style="text-align:right;"|'..p._getPurchaseContents(purchase, true)
result = result..'\r\n|'..p._getPurchaseContents(purchase, true)


result = result..'\r\n|}'
result = result..'\r\n|}'
Line 546: Line 546:
local purchList = p.getPurchases(function(purch) return purch.category == 'melvorD:General' and string.find(purch.id, '^melvorD:Auto_Eat') == nil end)
local purchList = p.getPurchases(function(purch) return purch.category == 'melvorD:General' and string.find(purch.id, '^melvorD:Auto_Eat') == nil end)


return p._getShopTable(purchList, { columns = { 'Purchase', 'Description', 'Cost', 'Requirements', 'Buy Limit' }, purchaseHeader = 'Upgrade' })
return p._getShopTable(purchList, { columns = { 'Purchase', 'Description', 'Cost', 'Requirements' }, purchaseHeader = 'Upgrade' })
end
 
function p.getShopSkillUpgradeTable()
-- All purchaes in the SkillUpgrades category except tools and any upgrades displayed as
-- tools (e.g. ship upgrades)
local purchList = p.getPurchases(
function(purch)
return purch.category == 'melvorD:SkillUpgrades'
-- Exclude tools, handled by p.getToolTable()
and string.find(purch.id, '_Axe$') == nil
and string.find(purch.id, '_Pickaxe$') == nil
and string.find(purch.id, '_Rod$') == nil
and string.find(purch.id, '_Pickaxe$') == nil
and string.find(purch.id, 'Fire$') == nil
and string.find(purch.id, 'Furnace$') == nil
and string.find(purch.id, 'Pot$') == nil
and string.find(purch.id, 'Sieve$') == nil
and string.find(purch.id, 'Trowel$') == nil
and string.find(purch.id, 'Brush$') == nil
and string.find(purch.id, 'Shovel$') == nil
and string.find(purch.id, 'ShipUpgrade') == nil
-- Exclude God upgrades, handled by p.getGodUpgradeTable()
and p.getGodUpgradeDungeon(purch) == nil
end
)
 
return p._getShopTable(purchList, { columns = { 'Purchase', 'Description', 'Cost', 'Requirements' }, purchaseHeader = 'Upgrade' })
end
 
function p.isSkillcapePurchase(purch, isSuperior, skillID)
-- Returns true or false depending on whether the purchase is a skillcape or not.
-- If isSuperior is true, then this checks for superior skillcapes, false checks
-- for regular skillcapes, and nil checks for both.
-- If skillID is specified, then the skillcape must also relate to that skill
local checkCategories = (isSuperior == nil and {'melvorTotH:SuperiorSkillcapes', 'melvorD:Skillcapes'}) or (isSuperior and {'melvorTotH:SuperiorSkillcapes'}) or {'melvorD:Skillcapes'}
-- Some skillcapes (such as Archaeology & Cartography) reside outside of the usual categories
local overrideIDs = {
['melvorTotH:SuperiorSkillcapes'] = {
'melvorAoD:Superior_Archaeology_Skillcape',
'melvorAoD:Superior_Cartography_Skillcape',
'melvorAoD:Cape_of_Completion_AoD'
},
['melvorD:Skillcapes'] = {
'melvorAoD:Archaeology_Skillcape',
'melvorAoD:Cartography_Skillcape'
}
}
 
for i, cat in ipairs(checkCategories) do
if purch.category == cat or Shared.contains(overrideIDs[cat], purch.id) then
if skillID == nil then
return true
else
-- Also validate purchase requirements for relevant SkillLevel requirement
local hasReq = false
if type(purch.purchaseRequirements) == 'table' then
for j, req in ipairs(purch.purchaseRequirements) do
if req.type == 'SkillLevel' then
if req.skillID == skillID then
hasReq = true
else
-- The presence of any other skill's requirement indicates
-- this is not a skillcape for skill with ID skillID
return false
end
end
end
end
return hasReq
end
end
end
return false
end
end


function p._getShopSkillcapeTable(showSuperior)
function p._getShopSkillcapeTable(showSuperior)
local categoryID = (showSuperior and 'melvorTotH:SuperiorSkillcapes') or 'melvorD:Skillcapes'
local capeList = p.getPurchases(function(purch) return p.isSkillcapePurchase(purch, showSuperior) end)
local capeList = p.getPurchases(function(purch) return purch.category == categoryID end)
local sortOrderFunc =
local sortOrderFunc =
function(a, b)
function(a, b)
Line 573: Line 645:
local capeCategory = frame.args ~= nil and frame.args[1] or frame
local capeCategory = frame.args ~= nil and frame.args[1] or frame
local showSuperior = string.lower(capeCategory) == 'superior'
local showSuperior = string.lower(capeCategory) == 'superior'
 
return p._getShopSkillcapeTable(showSuperior)
return p._getShopSkillcapeTable(showSuperior)
end
end
Line 579: Line 651:
function p.getSkillcapeTable(frame)
function p.getSkillcapeTable(frame)
local skillName = frame.args ~= nil and frame.args[1] or frame
local skillName = frame.args ~= nil and frame.args[1] or frame
-- Exception for "HP Skillcape" + "Superior Hitpoints Skillcape"
local skillID = Constants.getSkillID(skillName)
local capeList = {}
if skillID == nil then
if skillName == 'HP' or skillName == 'Hitpoints' then
return Shared.printError('No such skill "' .. (skillName or 'nil') .. '"')
capeList = p.getPurchases(function(purch) return Shared.contains({'melvorD:Skillcapes', 'melvorTotH:SuperiorSkillcapes'}, purch.category) and (Common.getPurchaseName(purch) == 'HP Skillcape' or Common.getPurchaseName(purch) == 'Superior Hitpoints Skillcape') end)
else
capeList = p.getPurchases(function(purch) return Shared.contains({'melvorD:Skillcapes', 'melvorTotH:SuperiorSkillcapes'}, purch.category) and string.find(Common.getPurchaseName(purch), skillName) end)
end
end
local capeList = p.getPurchases(function(purch) return p.isSkillcapePurchase(purch, nil, skillID) end)
if Shared.tableIsEmpty(capeList) then
if Shared.tableIsEmpty(capeList) then
return ''
return ''
else
else
capeList = GameData.sortByOrderTable(capeList, GameData.rawData.shopDisplayOrder, true)
local resultPart = {}
local resultPart = {}
table.insert(resultPart, '{| class="wikitable"\r\n')
table.insert(resultPart, '{| class="wikitable"\n')
table.insert(resultPart, '!Skillcape!!Name!!Requirements!!Effect')
table.insert(resultPart, '!Skillcape!!Name!!Requirements!!Effect')
for i, cape in ipairs(capeList) do
for i, cape in ipairs(capeList) do
local capeItem = Items.getItemByID(cape.contains.items[1].id)
local capeItem = Items.getItemByID(cape.contains.items[1].id)
if capeItem ~= nil then
if capeItem ~= nil then
table.insert(resultPart, '\r\n|-\r\n| ' .. Icons.Icon({capeItem.name, type='item', size='60', notext=true}))
table.insert(resultPart, '\n|-\n| ' .. Icons.Icon({capeItem.name, type='item', size='60', notext=true}))
table.insert(resultPart, '\r\n| data-sort-value="'..capeItem.name..'"|'..Icons.getExpansionIcon(capeItem.id) .. Icons.Icon({capeItem.name, type='item', noicon=true}))
table.insert(resultPart, '\n| data-sort-value="'..capeItem.name..'"|'..Icons.getExpansionIcon(capeItem.id) .. Icons.Icon({capeItem.name, type='item', noicon=true}))
table.insert(resultPart, '\r\n| ' .. Common.getRequirementString(cape.purchaseRequirements, 'None'))
table.insert(resultPart, '\n| ' .. Common.getRequirementString(cape.purchaseRequirements, 'None'))
table.insert(resultPart, '\r\n| ' .. p._getPurchaseDescription(cape))
table.insert(resultPart, '\n| ' .. p._getPurchaseDescription(cape))
end
end
end
end
table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\n|}')
return table.concat(resultPart)
return table.concat(resultPart)
end
end
Line 638: Line 710:
end
end


function p.getGodUpgradeTable()
function p.getGodUpgradeDungeon(purch)
local resultPart = {}
-- Identifies skill upgrades which have a dungeon completion requirement for an area
-- Obtain list of God upgrades: look for skill upgrades which have a dungeon completion
-- whose name ends with 'God Dungeon'. Returns the ID of the dungeon which must be
--   requirement for an area whose name ends with 'God Dungeon'
-- completed before the purchase may be bought if the purchase is a god upgrade
local getGodDungeon =
if purch.category == 'melvorD:SkillUpgrades' and type(purch.purchaseRequirements) == 'table' then
function(reqs)
for i, req in ipairs(purch.purchaseRequirements) do
for i, req in ipairs(reqs) do
if req.type == 'DungeonCompletion' and string.find(req.dungeonID, 'God_Dungeon$') ~= nil then
if req.type == 'DungeonCompletion' and string.find(req.dungeonID, 'God_Dungeon$') ~= nil then
return req.dungeonID
return GameData.getEntityByID('dungeons', req.dungeonID)
end
end
end
end
end
end
end


function p.getGodUpgradeTable()
local resultPart = {}
local upgradeList = p.getPurchases(
local upgradeList = p.getPurchases(
function(purch)
function(purch)
if purch.category == 'melvorD:SkillUpgrades' and purch.purchaseRequirements ~= nil then
return p.getGodUpgradeDungeon(purch) ~= nil
return getGodDungeon(purch.purchaseRequirements) ~= nil
end
return false
end)
end)
if Shared.tableIsEmpty(upgradeList) then
if Shared.tableIsEmpty(upgradeList) then
Line 670: Line 741:
for i, upgrade in ipairs(upgradeList) do
for i, upgrade in ipairs(upgradeList) do
local upgradeName = Common.getPurchaseName(upgrade)
local upgradeName = Common.getPurchaseName(upgrade)
local dung = getGodDungeon(upgrade.purchaseRequirements)
local dung = GameData.getEntityByID('dungeons', p.getGodUpgradeDungeon(upgrade))
local costSortValue = p._getPurchaseSortValue(upgrade)
local costSortValue = p._getPurchaseSortValue(upgrade)
table.insert(resultPart, '|-\r\n|class="table-img" data-sort-value="' .. upgradeName .. '"| ' ..p._getPurchaseExpansionIcon(upgrade).. Icons.Icon({upgradeName, type='upgrade', size=50, notext=true}))
table.insert(resultPart, '|-\r\n|class="table-img" data-sort-value="' .. upgradeName .. '"| ' ..p._getPurchaseExpansionIcon(upgrade).. Icons.Icon({upgradeName, type='upgrade', size=50, notext=true}))
Line 681: Line 752:


return table.concat(resultPart, '\r\n')
return table.concat(resultPart, '\r\n')
end
function p.getAoDTable(frame)
-- All purchases in the Atlas of Discovery category except for skillcapes, which are handled
-- by p.getShopSKilcapeTable()
local purchList = p.getPurchases(
function(purch)
return purch.category == 'melvorAoD:AtlasOfDiscovery' and not p.isSkillcapePurchase(purch)
end
)
return p._getShopTable(purchList, { columns = { 'Purchase', 'Description', 'Cost', 'Requirements' } })
end
end


Line 870: Line 953:
function p.getShipTable(frame)
function p.getShipTable(frame)
local modifiers = {
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Survey Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', header = 'Cartography Interval', sign = '-', suffix = '%' },
{ name = 'increasedSightRange', header = 'Increased Sight Range', sign = '+', suffix = '' },
{ name = 'increasedSightRange', header = 'Increased Sight Range', sign = '+', suffix = '' },
{ name = 'increasedSurveyRange', header = 'Increased Survey Range', sign = '+', suffix = ''},
{ name = 'increasedSurveyRange', header = 'Increased Survey Range', sign = '+', suffix = ''},
457

edits