Module:Disassembler profit

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Disassembler profit/doc. [edit] [history] [purge]
Module:Disassembler profit's function main is invoked by Template:Disassembler profit.
Function list
L 15 — ilink
L 19 — p.main

Module for table showing profit options for auto disassembler. Currently shows only making empty divine charges from simple parts.


-- <nowiki>
-- Module for auto disassembler profit table.

local p = {}
local data = require('Module:Disassembler_profit/data')
local gemw = require('Module:Exchange')
local coins = require('Module:Coins')._amount
local numbers = require('Module:Number')._round
local addCommas = require('Module:Addcommas')._add
local yesno = require('Module:Yesno')
local junkReductionModifier = { 1, 0.99, 0.97, 0.95, 0.93, 0.91, 0.88, 0.86, 0.83, 0.80 }
require("Module:Mw.html extension")

-- Image-only
local function ilink(a)
	return '[[File:' .. a .. '.png|link=' .. a .. ']]'
end

function p.main(frame)
	local args = frame:getParent().args

	-- Get args
	local junkReductionLevel = 0
	if args.junkreductionlevel ~= nil then
		junkReductionLevel = tonumber(string.sub(args.junkreductionlevel, 1, 1))
		if junkReductionLevel == nil then
			junkReductionLevel = 0
		end
	end

	local isUpgrade = yesno(args.isupgrade, false)

	-- Numbers that are used in every iteration
	local junkReduction = junkReductionModifier[junkReductionLevel + 1]
	local disassemblesPerHour, chargesPerHour
	if isUpgrade then -- mk II
		disassemblesPerHour = 60
		chargesPerHour = 230
	else -- normal disassembler
		disassemblesPerHour = 35
		chargesPerHour = 180
	end
	local chargesPerDivineCharge = 3000
	local simplePartsPerCharge = 20

	-- GE prices
	local divineChargeGEPrice = gemw._price("Divine charge")
	local emptyChargeGEPrice = gemw._price("Divine charge (empty)")
	local incandescentGEPrice = gemw._price("Incandescent energy")
	local divineChargeCost = chargesPerHour / chargesPerDivineCharge * divineChargeGEPrice

	-- Most profitable item to make
	local divineChargeProfit, itemLink
	local fullChargeProfit = divineChargeGEPrice - 225*incandescentGEPrice
	if fullChargeProfit > emptyChargeGEPrice then
		divineChargeProfit = fullChargeProfit
		itemLink = ilink("Divine charge")
	else
		divineChargeProfit = emptyChargeGEPrice
		itemLink = ilink("Divine charge (empty)")
	end

	-- Get list of items
	local simplePartSrcs = data()

	-- Table headers
	local t = mw.html.create('table')
	t
		:addClass('wikitable sortable autosort=8,d text-align-right align-left-2')
		:tr()
		:th{'Item', attr = {colspan = '2'}}
		:th{'GE<br/>price'}
		:th{'GE<br/>volume'}
		:th{'Hourly<br/>charges'}
		:th{'Hourly profit'}
		:th{'Daily profit'}
		:th{'Weekly profit'}
		:th{'Weekly profit<br/>at GE buy limit'}

	for _, item in ipairs(simplePartSrcs) do
		local finalSimpleChance = (1 - item.baseJunkChance * junkReduction) * item.simpleChance
		local itemGEPrice = gemw._price(item.name)

		local itemsPerHour = disassemblesPerHour * item.quantity
		local inputCost = itemsPerHour * itemGEPrice
		local totalCost = inputCost + divineChargeCost

		local simplePartsPerHour = item.matCount * (itemsPerHour / item.quantity) * finalSimpleChance
		local chargesPerHour = simplePartsPerHour / simplePartsPerCharge
		local revenue = chargesPerHour * divineChargeProfit
		local profit = revenue - totalCost

		local volume = gemw._volume(item.name)
		local limit = gemw._limit(item.name) / 4
		local itemsPerHourLimit = math.min(disassemblesPerHour * item.quantity, limit)
		local inputCostLimit = itemsPerHourLimit * itemGEPrice
		local totalCostLimit = inputCostLimit + divineChargeCost * itemsPerHourLimit / itemsPerHour

		local simplePartsPerHourLimit = item.matCount * (itemsPerHourLimit / item.quantity) * finalSimpleChance
		local chargesPerHourLimit = simplePartsPerHourLimit / simplePartsPerCharge
		local revenueLimit = chargesPerHourLimit * divineChargeProfit
		local profitLimit = revenueLimit - totalCostLimit
		
		local itemStr = "[[" .. item.name .. "]]"
		if item.quantity > 1 then
			itemStr = item.quantity .. " × " .. itemStr
		end

		-- Add row to table
		t:tr()
		 :td{ilink(item.name)}                         -- item img
		 :td(itemStr)                                  -- item name
		 :td{coins(itemGEPrice)}                       -- price
		 :td{addCommas(volume)}                        -- volume
		 :td{itemLink .. " " .. numbers(chargesPerHour, 2)} -- hourly charges
		 :td{coins(numbers(profit, 0))}                -- hourly profit
		 :td{coins(numbers(profit * 24, 0))}           -- daily profit
		 :td{coins(numbers(profit * 24 * 7, 0))}       -- weekly profit
		 :td{coins(numbers(profitLimit * 24 * 7, 0))}  -- maximum weekly profit if buying from GE due to buy limits
	end
	return t
end

return p
-- </nowiki>