Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
Update for v1.3
No edit summary
(Update for v1.3)
Line 5: Line 5:
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Common = require('Module:Common')
local Modifiers = require('Module:Modifiers')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
Line 119: Line 120:
local item = nil
local item = nil
if purch.contains.modifiers ~= nil then
if purch.contains.modifiers ~= nil then
return Constants.getModifiersText(purch.contains.modifiers, false)
return Modifiers.getModifiersText(purch.contains.modifiers, false)
elseif purch.contains.petID ~= nil then
elseif purch.contains.petID ~= nil then
local pet = Pets.getPetByID(purch.contains.petID)
local pet = Pets.getPetByID(purch.contains.petID)
Line 132: Line 133:
return item.customDescription
return item.customDescription
elseif item.modifiers ~= nil then
elseif item.modifiers ~= nil then
return Constants.getModifiersText(item.modifiers, false)
return Modifiers.getModifiersText(item.modifiers, false)
end
end
end
end
Line 142: Line 143:
local displayInline = (inline ~= nil and inline or false)
local displayInline = (inline ~= nil and inline or false)
local costArray = {}
local costArray = {}
local currencies = {'gp', 'slayerCoins', 'raidCoins'}
if cost.currencies ~= nil then
for i, currency in ipairs(currencies) do
for i, costAmt in ipairs(cost.currencies) do
if cost[currency] ~= nil then
local costStr = p.getCurrencyCostString(costAmt)
local costStr = p.getCurrencyCostString(cost[currency], currency)
if costStr ~= nil then
if costStr ~= nil then
table.insert(costArray, costStr)
table.insert(costArray, costStr)
Line 172: Line 172:
return mw.text.listToText(costArray, sep, lastSep)
return mw.text.listToText(costArray, sep, lastSep)
end
end
return ''
end
end


Line 186: Line 187:
end
end


function p.getCurrencyCostString(cost, currency)
function p.getCurrencyCostString(cost)
local decoratorList = {
["gp"] = Icons.GP,
["slayerCoins"] = Icons.SC,
["raidCoins"] = Icons.RC
}
local decorator = nil
if currency ~= nil then
decorator = decoratorList[currency]
end
if decorator == nil then
decorator = function(cost) return cost end
end
 
if cost.type == 'BankSlot' then
if cost.type == 'BankSlot' then
-- Unusual bit of code that basically evaluates wikitext '<math>C_b</math>*'
-- Unusual bit of code that basically evaluates wikitext '<math>C_b</math>*'
return mw.getCurrentFrame():callParserFunction('#tag:math', {'C_b'}) .. '*'
return mw.getCurrentFrame():callParserFunction('#tag:math', {'C_b'}) .. '*'
elseif cost.type == 'Linear' and (cost.initial > 0 or cost.scaling > 0) then
elseif cost.type == 'Linear' and (cost.initial > 0 or cost.scaling > 0) then
return decorator(cost.initial) .. '<br/>+' .. decorator(cost.scaling) .. ' for each purchase'
return Icons._Currency(cost.currency, cost.initial) .. '<br/>+' .. Icons._Currency(cost.currency, cost.scaling) .. ' for each purchase'
elseif cost.type == 'Glove' or cost.type == 'Fixed' and cost.cost > 0 then
elseif cost.type == 'Glove' or cost.type == 'Fixed' and cost.cost > 0 then
-- Type Glove exists in game so the Merchant's Permit cost reduction can be applied,
-- Type Glove exists in game so the Merchant's Permit cost reduction can be applied,
-- it makes no difference here
-- it makes no difference here
return decorator(cost.cost)
return Icons._Currency(cost.currency, cost.cost)
end
end
end
end
Line 339: Line 327:


function p._getPurchaseSortValue(purchase)
function p._getPurchaseSortValue(purchase)
local costCurrencies = {'gp', 'slayerCoins', 'raidCoins'}
if purchase.cost ~= nil and purchase.cost.currencies ~= nil then
for j, curr in ipairs(costCurrencies) do
for _, costAmt in ipairs(purchase.cost.currencies) do
local costAmt = purchase.cost[curr]
-- Find cost for the current currency, if it exists
if costAmt.type == 'BankSlot' then
if costAmt.type == 'BankSlot' then
return -1
return -1
elseif costAmt.type == 'Linear' then
elseif costAmt.type == 'Linear' then
return costAmt.initial
return costAmt.initial
elseif costAmt.type == 'Glove' or costAmt.type == 'Fixed' and costAmt.cost > 0 then
elseif costAmt.type == 'Glove' or costAmt.type == 'Fixed' and costAmt.cost > 0 then
return costAmt.cost
return costAmt.cost
end
end
end
end
end
Line 828: Line 817:
-- Keep track of modifiers which are present on tools but not exposed within the table, so
-- Keep track of modifiers which are present on tools but not exposed within the table, so
-- that an error may be printed if any are omitted
-- that an error may be printed if any are omitted
local modsUnused = {}
for i, tool in ipairs(toolArray) do
for i, tool in ipairs(toolArray) do
local toolName = Common.getPurchaseName(tool)
local toolName = Common.getPurchaseName(tool)
Line 867: Line 855:
local cellStart = '\n|style="text-align:right"'
local cellStart = '\n|style="text-align:right"'
if tool.contains ~= nil and tool.contains.modifiers ~= nil then
if tool.contains ~= nil and tool.contains.modifiers ~= nil then
for modName, modVal in pairs(tool.contains.modifiers) do
local toolMods = tool.contains.modifiers
if modTotal[modName] == nil and not Shared.contains(modsUnused, modName) then
-- Mod with name modName is provided by the purchase, but not exposed within
-- the output table
table.insert(modsUnused, modName)
end
end
 
for j, modDef in ipairs(modifiers) do
for j, modDef in ipairs(modifiers) do
local modName = modDef.name
local modName = modDef.name
local modVal = tool.contains.modifiers[modName]
local matchRules = { { ["alias"] = modName } }
if modVal ~= nil then
local matchedMods = Modifiers.getMatchingModifiers(tool.contains.modifiers, matchRules)
if type(modVal) == 'table' and type(modVal[1]) == 'table' and modVal[1].skillID ~= nil and (modDef.skillID == nil or modDef.skillID == modVal[1].skillID) then
local modVal = Modifiers.getModifierValue(matchedMods.matched) or 0
modVal = modVal[1].value
modTotal[modName] = modTotal[modName] + modVal
end
modTotal[modName] = modTotal[modName] + modVal
else
modVal = 0
end
local cellStartVal = cellStart .. ((modVal == 0 and ' class="table-na"') or '')
local cellStartVal = cellStart .. ((modVal == 0 and ' class="table-na"') or '')
local cellStartTot = cellStart .. ((modTotal[modName] == 0 and ' class="table-na"') or '')
local cellStartTot = cellStart .. ((modTotal[modName] == 0 and ' class="table-na"') or '')
Line 894: Line 870:
end
end


local resultPrefix = ''
if not Shared.tableIsEmpty(modsUnused) then
resultPrefix = Shared.printError('The following modifiers are not included within the table: ' .. table.concat(modsUnused, ', ')) .. '\n'
end
table.insert(resultPart, '\n|}')
table.insert(resultPart, '\n|}')
return resultPrefix .. table.concat(resultPart)
return table.concat(resultPart)
end
end


function p.getAxeTable(frame)
function p.getAxeTable(frame)
local modifiers = {
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Cut Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', header = 'Cut Time Decrease', sign = '', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', header = 'Double Items Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', header = 'Double Items Chance', sign = '+', suffix = '%' },
{ name = 'increasedBirdNestDropRate', header = Icons.Icon({'Bird Nest', 'Drop Chance', type='item', nolink=true}), sign = '+', suffix = '%' },
{ name = 'increasedBirdNestDropRate', header = Icons.Icon({'Bird Nest', 'Drop Chance', type='item', nolink=true}), sign = '+', suffix = '%' },
Line 915: Line 887:
function p.getPickaxeTable(frame)
function p.getPickaxeTable(frame)
local modifiers = {
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Mining Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', header = 'Mining Time Decrease', sign = '', suffix = '%' },
{ name = 'increasedChanceToDoubleOres', header = '2x Ore Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleOres', header = '2x Ore Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceForOneExtraOre', header = '+1 Ore Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceForOneExtraOre', header = '+1 Ore Chance', sign = '+', suffix = '%' },
Line 927: Line 899:
function p.getRodTable(frame)
function p.getRodTable(frame)
local modifiers = {
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Catch Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', header = 'Catch Time Decrease', sign = '', suffix = '%' },
{ name = 'increasedChanceForOneExtraFish', header = '+1 Fish Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceForOneExtraFish', header = '+1 Fish Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToFindLostChest', header = Icons.Icon({'Lost Chest', type='item', notext=true}) .. ' Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToFindLostChest', header = Icons.Icon({'Lost Chest', type='item', notext=true}) .. ' Chance', sign = '+', suffix = '%' },
Line 949: Line 921:
{ name = 'increasedSkillXP', skillID = 'melvorD:Cooking', header = 'Bonus ' .. Icons.Icon({'Cooking', type='skill', notext=true}) .. ' XP', sign = '+', suffix = '%' },
{ name = 'increasedSkillXP', skillID = 'melvorD:Cooking', header = 'Bonus ' .. Icons.Icon({'Cooking', type='skill', notext=true}) .. ' XP', sign = '+', suffix = '%' },
{ name = 'increasedChancePerfectCookFire', header = Icons.Icon({'Normal Cooking Fire', type='upgrade', notext=true, nolink=true}) .. ' Perfect Cook Chance', sign ='+', suffix = '%' },
{ name = 'increasedChancePerfectCookFire', header = Icons.Icon({'Normal Cooking Fire', type='upgrade', notext=true, nolink=true}) .. ' Perfect Cook Chance', sign ='+', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' }
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '', suffix = '%' }
},
},
['Furnace'] = {
['Furnace'] = {
{ name = 'increasedChancePerfectCookFurnace', header = Icons.Icon({'Basic Furnace', type='upgrade', notext=true, nolink=true}) .. ' Perfect Cook Chance', sign = '+', suffix = '%' },
{ name = 'increasedChancePerfectCookFurnace', header = Icons.Icon({'Basic Furnace', type='upgrade', notext=true, nolink=true}) .. ' Perfect Cook Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '', suffix = '%' },
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' }
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' }
},
},
Line 963: Line 935:
{ name = 'increasedChancePerfectCookPot', header = Icons.Icon({'Basic Pot', type='upgrade', notext=true, nolink=true}) .. ' Perfect Cook Chance', sign = '+', suffix = '%' },
{ name = 'increasedChancePerfectCookPot', header = Icons.Icon({'Basic Pot', type='upgrade', notext=true, nolink=true}) .. ' Perfect Cook Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '', suffix = '%' },
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' },
{ name = 'increasedMasteryXP', skillID = 'melvorD:Cooking', header = 'Increased Cooking ' .. Icons.Icon({'Mastery', nolink=true}) .. ' XP', sign = '+', suffix = '%'}
{ name = 'increasedMasteryXP', skillID = 'melvorD:Cooking', header = 'Increased Cooking ' .. Icons.Icon({'Mastery', nolink=true}) .. ' XP', sign = '+', suffix = '%'}
Line 976: Line 948:
function p.getShipTable(frame)
function p.getShipTable(frame)
local modifiers = {
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Cartography Interval', 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 = ''},