Anonymous

Module:SCValue: Difference between revisions

From Melvor Idle
no edit summary
mNo edit summary
No edit summary
Line 4: Line 4:
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local Items = require('Module:Items')
local Items = require('Module:Items')
--local Debug = require('Module:Debug')
local Common = require('Module:Common')
local Debug = require('Module:Debug')


local function getPurchase(itemName)
local function getPurchase(itemName)
return Shop.getPurchase(itemName)
local func =
function(purchase, name)
return name == itemName
end
 
local purchList = Shop.getCategoryPurchases(func, 'Slayer')
if purchList ~= nil and not Shared.tableIsEmpty(purchList) then
return purchList[1]
end
end
end


Line 37: Line 46:
-- Calculate actual profit
-- Calculate actual profit
return gpProfit - gpCost
return gpProfit - gpCost
end
-- Returns all SC items that can be sold for GP, and can be bought in bulk.
local function getSellablePurchases()
-- We need something to sell!
-- We also want to buy/sell massive quantities for profit!
local func =
function(purchase, name)
local items = purchase.contains.items
return purchase.allowQuantityPurchase and
items ~= nil and
not Shared.tableIsEmpty(items)
end
return Shop.getCategoryPurchases(func, 'Slayer')
end
local function getMostProfitablePurchases(amount)
amount = tonumber(amount) or 1
amount = math.max(amount, 1)
local data = {}
-- Gather value data about SC Shop Items
for _, v in pairs(getSellablePurchases()) do
local gpValue = getPurchaseValue(v)
local scCost = (v.cost.slayerCoins or {}).cost or 0
local gpPersc = (scCost ~= 0) and (gpValue / scCost) or (gpValue == 0 and 0 or 0)
table.insert(data, {
Purchase = v,
SCCost = scCost,
GPValue = gpValue,
GPPerSC = gpPersc,
})
end
-- Sort by most profitable to least profitable
table.sort(data, function(a, b) return a.GPPerSC > b.GPPerSC end)
-- Keep most profitable entries only
local entries = {}
for i = 1, math.min(#data, amount) do
table.insert(entries, data[i])
end
return entries
end
function p.getSCItemProfits(frame)
end
function p._getSCItemProfits(amount)
local purchases = getMostProfitablePurchases(amount)
Debug.log(purchases)
end
end


function p.getSCValue(item)
function p.getSCValue(item)
local purchase = getPurchase(item)
local purchase = getPurchase(item)
if purchase == nil then
return Shared.printError("No Slayer Shop item exists with the name: " .. item)
end
return getPurchaseValue(purchase)
return getPurchaseValue(purchase)
end
end


function p.test()
function p.test()
local item = 'Necromancer Hat'
p._getSCItemProfits(1)
local s = getPurchase(item)
Debug.log(getPurchase('Mystic Lantern'))
mw.log(getPurchaseValue(s))
--mw.log(p.getSCValue(item))
end
end


return p
return p
2,875

edits