Anonymous

Module:SCValue: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 49: Line 49:
end
end


-- Returns all SC items that can be sold for GP, and can be bought in bulk.
local function getSellablePurchases(checkFunc)
local function getSellablePurchases()
-- We need something to sell!
-- We also want to buy/sell massive quantities for profit!
local func =  
local func =  
function(purchase, name)
function(purchase, name)
-- Exclude SC Purchases that provide no items.
local items = purchase.contains.items
local items = purchase.contains.items
return purchase.allowQuantityPurchase and
if items == nil or Shared.tableIsEmpty(items) then
items ~= nil and
return false
not Shared.tableIsEmpty(items)
end
 
if checkFunc == nil then
return true
end
return checkFunc(purchase)
end
end
Line 64: Line 68:
end
end


local function getMostProfitablePurchases(amount)
local function getMostProfitablePurchases(amount, includeOnlyBulk)
amount = tonumber(amount)
amount = tonumber(amount)
amount = math.max(amount, 1)
if includeOnlyBulk == nil then includeOnlyBulk = true end
local func = function(x)
if includeOnlyBulk == true then
return x.allowQuantityPurchase == true
else
return true
end
end
local data = {}
local data = {}
-- Gather value data about SC Shop Items
-- Gather value data about SC Shop Items
for _, v in pairs(getSellablePurchases()) do
for _, v in pairs(getSellablePurchases(func)) do
local gpValue = getPurchaseValue(v)
local gpValue = getPurchaseValue(v)
local scCost = (v.cost.slayerCoins or {}).cost or 0
local scCost = (v.cost.slayerCoins or {}).cost or 0
Line 98: Line 109:
function p.getSCItemProfits(frame)
function p.getSCItemProfits(frame)
local args = frame:getParent().args
local args = frame:getParent().args
return p._getSCItemProfits(args[1])
return p._getSCItemProfits(args[1], args[2] or true)
end
end


function p._getSCItemProfits(amount)
function p._getSCItemProfits(amount, includeOnlyBulk)
local purchases = getMostProfitablePurchases(amount)
local purchases = getMostProfitablePurchases(amount, includeOnlyBulk)


local html = mw.html.create('table')
local html = mw.html.create('table')
Line 160: Line 171:
end
end


function p.test()
mw.logObject(getPurchase("Magical Ring"))
end
return p
return p
2,875

edits