964
edits
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
local Items = require('Module:Items') | local Items = require('Module:Items') | ||
local Common = require('Module:Common') | local Common = require('Module:Common') | ||
local | local Number = require('Module:Number') | ||
local Icons = require('Module:Icons') | |||
local function getPurchase(itemName) | local function getPurchase(itemName) | ||
Line 64: | Line 65: | ||
local function getMostProfitablePurchases(amount) | local function getMostProfitablePurchases(amount) | ||
amount = tonumber(amount) | amount = tonumber(amount) | ||
amount = math.max(amount, 1) | amount = math.max(amount, 1) | ||
Line 85: | Line 86: | ||
table.sort(data, function(a, b) return a.GPPerSC > b.GPPerSC end) | table.sort(data, function(a, b) return a.GPPerSC > b.GPPerSC end) | ||
-- Keep most profitable entries only | -- Keep top x most profitable entries only | ||
local entries = {} | if amount ~= nil then | ||
local entries = {} | |||
for i = 1, math.min(#data, amount) do table.insert(entries, data[i]) end | |||
return entries | |||
end | end | ||
return | return data | ||
end | end | ||
function p.getSCItemProfits(frame) | function p.getSCItemProfits(frame) | ||
local args = frame:getParent().args | |||
return p._getSCItemProfits(args[1]) | |||
end | end | ||
function p._getSCItemProfits(amount) | function p._getSCItemProfits(amount) | ||
local purchases = getMostProfitablePurchases(amount) | local purchases = getMostProfitablePurchases(amount) | ||
local html = mw.html.create('table') | |||
:addClass('wikitable sortable stickyHeader') | |||
html:tag('tr') | |||
:tag('th'):attr('colspan', 2) | |||
:wikitext('Purchase') | |||
:tag('th'):wikitext('Cost') | |||
:tag('th'):wikitext('Requirements') | |||
:tag('th'):wikitext('GP Value') | |||
:tag('th'):wikitext('GP per SC') | |||
for _, v in pairs(purchases) do | |||
local purchase = v.Purchase | |||
local name = Common.getPurchaseName(purchase) | |||
local expansionIcon = Shop._getPurchaseExpansionIcon(purchase) | |||
local costs = Shop.getCostString(purchase.cost, false) | |||
html:tag('tr') | |||
:tag('td'):addClass('table-img') | |||
:wikitext(Common.getPurchaseIcon({purchase, notext=true, size='50'})) | |||
:tag('td'):attr('data-sort-value', name) | |||
:wikitext(expansionIcon) | |||
:wikitext(Common.getPurchaseIcon({purchase, noicon=true})) | |||
:tag('td'):attr('data-sort-value', v.SCCost) | |||
:css('text-align', 'right') | |||
:wikitext(costs) | |||
:tag('td'):wikitext(Common.getRequirementString(purchase.purchaseRequirements, 'None')) | |||
:tag('td'):attr('data-sort-value', v.GPValue) | |||
:css('text-align', 'right') | |||
:wikitext(Icons.GP(v.GPValue)) | |||
:tag('td'):attr('data-sort-value', v.GPPerSC) | |||
:css('text-align', 'right') | |||
:wikitext(Icons.GP(Number.autoround(v.GPPerSC))) | |||
end | |||
return tostring(html) | |||
end | |||
function p.getSCValue(frame) | |||
local args = frame:getParent().args | |||
return p._getItemSellsFor(args[1], args[2], args.round) | |||
end | end | ||
function p. | function p._getSCValue(itemName, multiplier, rounding) | ||
local purchase = getPurchase( | local purchase = getPurchase(itemName) | ||
if purchase == nil then | if purchase == nil then | ||
return Shared.printError("No Slayer Shop item exists with the name: " .. | return Shared.printError("No Slayer Shop item exists with the name: " .. itemName) | ||
end | end | ||
local itemValue = getPurchaseValue(purchase) | |||
multiplier = tonumber(multiplier) or 1 | |||
rounding = tonumber(rounding) or 0 | |||
return Number.round2(itemValue * multiplier, rounding) | |||
end | end | ||
return p | return p |
edits