Module:SCValue
This module can be used to get information regarding Slayer Coins related shop purchases. For instance, it calculates for much effective profit there can be gained or lost by buying specific items with SC and selling them for GP.
local p = {}
local Shared = require('Module:Shared')
local Shop = require('Module:Shop')
local Items = require('Module:Items')
--local Debug = require('Module:Debug')
local function getPurchase(itemName)
return Shop.getPurchase(itemName)
end
local function getPurchaseValue(purchase)
if purchase == nil or purchase.cost == nil or purchase.contains == nil
then return 0 end
local costs = purchase.cost
local sales = purchase.contains
local function getItemValues(items)
local gpVal = 0
if items ~= nil then
for _, item in pairs(items) do
gpVal = gpVal + Items.getItemValueByID(item['id']) * item['quantity']
end
end
return gpVal
end
-- Get total costs (including gp/item costs)
local gpCost = 0
if costs.gp ~= nil then gpCost = costs.gp['cost'] or 0 end
gpCost = gpCost + getItemValues(costs.items)
-- Get gross profit from sale
local gpProfit = getItemValues(sales.items)
-- Calculate actual profit
return gpProfit - gpCost
end
function p.getSCValue(item)
local purchase = getPurchase(item)
return getPurchaseValue(purchase)
end
function p.test()
local item = 'Necromancer Hat'
local s = getPurchase(item)
mw.log(getPurchaseValue(s))
end
return p