Module:Sandbox/User:Daan/Glassblow
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sandbox/User:Daan/Glassblow/doc
--Based on: https://docs.google.com/spreadsheets/d/1YW5Wz4r6LPOF7N1yniUcJbvxBwp99isbWR4pFCTc144/edit?usp=sharing
--First try: https://oldschool.runescape.wiki/w/Module:Sandbox/User:Daan/Glassblowing_Crafting_Calculator
--Function to lookup amount of exp based on lvl.
local XPAtLevel = mw.loadData('Module:Experience/data')
--Giant seaweed average yield including compost type.
local gsay = {
{23,8.26,11.01,13.76,16.52},
{30,8.63,11.51,14.38,17.26},
{40,9.25,12.34,15.42,18.51},
{50,10.11,13.47,16.84,20.21},
{60,10.97,14.63,18.29,21.94},
{70,12.00,16.00,20.00,24.00},
{80,13.24,17.66,22.07,26.48},
{90,14.77,19.69,24.62,29.54},
{99,16.70,22.26,27.83,33.39}}
--compost type
local ct = {
['None'] = {1},
['Normal'] = {2},
['Super'] = {3},
['Ultra'] = {4}}
--yield + compost combined
local sws = {
['None'] = {8.26,8.63,9.25,10.11,10.97,12,13.24,14.77,16.7},
['Normal'] = {11.01,11.51,12.34,13.47,14.63,16,17.66,19.69,22.26},
['Super'] = {13.76,14.38,15.42,16.84,18.29,20,22.07,24.62,27.83},
['Ultra'] = {16.52,17.26,18.51,20.21,21.94,24,26.48,29.54,33.39}}
--crafting methods
local methods = {
['1.0(1:1)'] = {1,14,0},
['1.3(1:1)'] = {1.3,14,1},
['1.45(2:12)'] = {1.45,12,1},
['1.488(3:18)'] = {1.488,18,1},
['1.6(3:18)'] = {1.6,18,1}}
--methods stacked.
local method = {0,0,0}
--banked items stacked.
local banked = {0,0,0}
--Default.
local p = {}
--compost selector.
local compost
--Craft items.
local xprate = {
['Unpowerd orb'] = {52.5},
['Lantern lens'] = {55},
['Light orb'] = {70}}
--Lvl glassblow item.
local threshold = {46,49,87}
--Table1.
local table1 = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}
--Table2.
local table2 = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}
--Table3.
local table3 = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}
--main function
function p.main(frame)
local args = frame:getParent().args
local gsy
local ph_bos = tonumber(args.f_sand_ph)
local ph_gb = tonumber(args.f_glassb_ph)
local ph_sc = tonumber(args.f_spellc_ph)
local farm_lvl = tonumber(args.farming)
--local craft_lvl = tonumber(args.craftlvl)
local composttype = args.f_composttype
local target_lvl = tonumber(args.goal)
local craft_xp = tonumber(args.crafting)
local target_xp = XPAtLevel[target_lvl]
local SGM = args.f_SGM
local xpmode = {52.5, 52.5, 52.5}
local after = {'Unpowered orb','Unpowered orb','Light orb'}
local craft_lvl = LevelAtXP(craft_xp)
banked[1] = tonumber(args.f_bucketofsand)
banked[2] = tonumber(args.f_giantseaweed)
banked[3] = tonumber(args.f_moltenglass)
after[2] = args.f_after49
after[3] = args.f_after87
if target_lvl < 46 then --lvl goal.
table1[1][1] = 1 --lvl 1 means 0 exp, can't calculate.
else
if target_lvl < 49 then
table1[1][1] = target_lvl
else
table1[1][1] = 49
end
end
if target_lvl < 49+1 then --reverse this like part at 87
table1[1][2] = 1
else
if target_lvl < 87 then
table1[1][2] = target_lvl
else
table1[1][2] = 87
end
end
if target_lvl > 87 then
table1[1][3] = target_lvl
else
table1[1][3] = 1
end
for i=1,3 do --exp goal.
table1[2][i] = XPAtLevel[table1[1][i]]
end
for i=1,3 do --xp at lvl
if (table1[2][i] - craft_xp) < 0 then
table1[3][i] = 0
else
if craft_xp < XPAtLevel[threshold[i]] then
table1[3][i] = table1[2][i] - XPAtLevel[threshold[i]]
else
table1[3][i] = table1[2][i] - craft_xp
end
end
end
for key,value in pairs(ct) do --Compost select.
if key == composttype then
compost = value[1]
end
end
for i=1,9 do --average yield. (Can be combined with above.)
if farm_lvl >= gsay[i][1] then
gsy = gsay[i][1+compost]
end
end
for key,value in pairs(xprate) do --user picked craft.
for i=2,3 do
if key == after[i] then
xpmode[i] = value[1]
end
end
end
for key,value in pairs(methods) do --user picked method.
if key == SGM then
for i=1,3 do
method[i] = value[i]
end
end
end
for i=1,3 do --Amount of items.
table1[4][i] = table1[3][i]/xpmode[i]
end
--banked glass (Can be more efficient)
if table1[4][3] < banked[3] then
table1[5][3] = table1[4][3]
else
table1[5][3] = banked[3]
end
if (banked[3]-table1[4][3]-table1[4][2]) > 0 then
table1[5][2] = table1[4][2]
else
table1[5][2] = banked[3] - table1[5][3]
end
if (banked[3]-table1[5][3]-table1[5][2]) > 0 then
if table1[4][1] == 0 then
table1[5][1] = 0
else
table1[5][1] = banked[3] - table1[4][3] - table1[4][2]
end
else
table1[5][1] = 0
end
for i=1,3 do --Gather glass.
if table1[4][i] == 0 then
table1[6][i] = 0
else
table1[6][i] = table1[4][i] - table1[5][i]
end
end
for i=1,3 do
table2[1][i] = table1[6][i]*xpmode[i] --xp left.
table2[2][i] = table2[1][i]/((xpmode[i]*method[1])+(10*method[3])) --bucket of sand req.
table2[3][i] = table2[2][i]*method[1] --molten glass req.
table2[4][i] = table2[2][i]/6 --giant seaweed req.
end
--(looking into this to make it more efficient)
if (table2[2][1]+table2[2][2]+table2[2][3]-banked[1]) < 0 then --total bucket of sand
table3[2][1] = 0
else
table3[2][1] = table2[2][1]+table2[2][2]+table2[2][3]-banked[1]
end
table3[2][2] = table2[3][1]+table2[3][2]+table2[3][3]--total create molten glass
table3[2][3] = table3[2][2]+table1[5][1]+table1[5][2]+table1[5][3] --total glassblow
if (table2[4][1]+table2[4][2]+table2[4][3]-banked[2]) < 0 then --total giant seaweed
table3[2][4] = 0
else
table3[2][4] = table2[4][1]+table2[4][2]+table2[4][3]-banked[2]
end
table3[2][5] = table3[2][4]/gsy --total seaweedspores
table3[3][1] = table3[2][1]/ph_bos --time sand
table3[3][2] = table3[2][2]/(ph_sc*method[1]*method[2]) --time lunar
table3[3][3] = table3[2][3]/ph_gb --time glassblow
table3[3][4] = table3[2][4]/(2*gsy*(60/40)) --time farm giant seaweed
table3[3][6] = table3[3][1]+table3[3][2]+table3[3][3]+table3[3][4] -- total time
ret = mw.html.create('table'):addClass('wikitable sticky-header align-left-1 align-right-2 align-right-3')
ret:tag('tr')
:tag('th'):wikitext('Todo'):done()
:tag('th'):wikitext('Amount'):done()
:tag('th'):wikitext('Hours'):done()
ret:tag('tr')
:tag('td'):wikitext('Gather bucket of sand'):done()
:tag('td'):wikitext(round(table3[2][1])):done()
:tag('td'):wikitext(round(table3[3][1],2)):done()
ret:tag('tr')
:tag('td'):wikitext('Creating molten glass'):done()
:tag('td'):wikitext(round(table3[2][2])):done()
:tag('td'):wikitext(round(table3[3][2],2)):done()
ret:tag('tr')
:tag('td'):wikitext('Glass blowing'):done()
:tag('td'):wikitext(round(table3[2][3])):done()
:tag('td'):wikitext(round(table3[3][3],2)):done()
ret:tag('tr')
:tag('td'):wikitext('Farming giant seaweed'):done()
:tag('td'):wikitext(round(table3[2][4])):done()
:tag('td'):wikitext(round(table3[3][4],2)):done()
ret:tag('tr')
:tag('td'):wikitext('Gather seaweed spores'):done()
:tag('td'):wikitext(round(table3[2][5])):done()
:tag('td'):wikitext(''):done()
ret:tag('tr')
:tag('td'):wikitext(''):done()
:tag('td'):wikitext(''):done()
:tag('td'):wikitext(round(table3[3][6],2)):done()
:done()
return ret
end
--http://lua-users.org/wiki/SimpleRound
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
--reverse XPAtLevel
--import from https://oldschool.runescape.wiki/w/Module:Experience
--has several checks
function LevelAtXP(xp)
for i=99,1,-1 do
if (XPAtLevel[i]<= xp) then
return i
end
end
end
return p