Module:Items: Difference between revisions

no edit summary
(Add function to grab item value (sellsfor) based on item name or item object)
No edit summary
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Num = require('Module:Number')


p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon', 'Easter Egg',
p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon', 'Easter Egg',
Line 114: Line 115:
end
end


function p.getItemValue(item)
function p.getItemValueByID(itemID)
function isGP(itemName)
local item = p.getItemByID(itemID)
return itemName == 'GP' or itemName == 'Gold Pieces'
if item == nil then
return 0
end
end
return p.getItemValue(item['name'])
end
function p.getItemValue(item)
if type(item) == 'string' then
if type(item) == 'string' then
if isGP(item:upper()) then  
-- Specific check if the item is GP (value of 1)
return 1  
if Shared.compareString('GP', item, true)
or Shared.compareString('Gold Pieces', item, true) then
return 1
end
end
 
item = p.getItem(item)
item = p.getItem(item)
end
end
Line 132: Line 140:
return nil
return nil
end
-- Function already exists, but without fame.
-- Giving it a slightly different name since function overloading doesn't exist
function p.getItemSellsFor(frame)
local args = frame:getParent().args
return p._getItemSellsFor(args[1], args[2], args.round)
end
function p._getItemSellsFor(itemName, multiplier, rounding)
local itemValue = p.getItemValue(itemName)
multiplier = tonumber(multiplier) or 1
rounding = tonumber(rounding) or 0
if itemValue == nil then
error('No item named "' .. itemName .. '" exists in the data module')
end
return Num.round2(itemValue * multiplier, rounding)
end
end


Line 373: Line 401:
["Passive"] = 'Combat Passive Slot',
["Passive"] = 'Combat Passive Slot',
["Summon1"] = 'Summoning',
["Summon1"] = 'Summoning',
["Summon2"] = 'Summoning'
["Summon2"] = 'Summoning',
["Gem"] = "Gems_(Equipment)"
}
}
local slotText = {}
local slotText = {}
937

edits