Module:Sandbox/User:Daan/Glassblowing

From Illerai
Jump to navigation Jump to search

Documentation for this module may be created at Module:Sandbox/User:Daan/Glassblowing/doc

--Experience table:
Experience = {
{0	,0},
{1	,0},
{2	,83},
{3	,174},
{4	,276},
{5	,388},
{6	,512},
{7	,650},
{8	,801},
{9	,969},
{10	,1154},
{11	,1358},
{12	,1584},
{13	,1833},
{14	,2107},
{15	,2411},
{16	,2746},
{17	,3115},
{18	,3523},
{19	,3973},
{20	,4470},
{21	,5018},
{22	,5624},
{23	,6291},
{24	,7028},
{25	,7842},
{26	,8740},
{27	,9730},
{28	,10824},
{29	,12031},
{30	,13363},
{31	,14833},
{32	,16456},
{33	,18247},
{34	,20224},
{35	,22406},
{36	,24815},
{37	,27473},
{38	,30408},
{39	,33648},
{40	,37224},
{41	,41171},
{42	,45529},
{43	,50339},
{44	,55649},
{45	,61512},
{46	,67983},
{47	,75127},
{48	,83014},
{49	,91721},
{50	,101333},
{51	,111945},
{52	,123660},
{53	,136594},
{54	,150872},
{55	,166636},
{56	,184040},
{57	,203254},
{58	,224466},
{59	,247886},
{60	,273742},
{61	,302288},
{62	,333804},
{63	,368599},
{64	,407015},
{65	,449428},
{66	,496254},
{67	,547953},
{68	,605032},
{69	,668051},
{70	,737627},
{71	,814445},
{72	,899257},
{73	,992895},
{74	,1096278},
{75	,1210421},
{76	,1336443},
{77	,1475581},
{78	,1629200},
{79	,1798808},
{80	,1986068},
{81	,2192818},
{82	,2421087},
{83	,2673114},
{84	,2951373},
{85	,3258594},
{86	,3597792},
{87	,3972294},
{88	,4385776},
{89	,4842295},
{90	,5346332},
{91	,5902831},
{92	,6517253},
{93	,7195629},
{94	,7944614},
{95	,8771558},
{96	,9684577},
{97	,10692629},
{98	,11805606},
{99	,13034431}}

--Exp rate table:
xprate = {
{1,17.5,0.0},     --'Beer glass'
{4,19,276},       --'Empty candle lantern'
{12,25,1584},     --'Empty oil lamp'
{33,35,22406},    --'Vial'
{42,42.5,45529},  --'Fishbowl'
{46,52.5,67983},  --'Unpowerd orb' 
{49,55,91721},    --'Lantern lens' 
{61,55,302288},   --'Lunar' 
{87,70,3972294},  --'Light orb'
{99,70,13034431}} --'Crafting Cape'

--Method table:
craft = {
{1.000,14,0}, --"1.0(1:1)"
{1.300,14,1}, --"1.3(1:1)"
{1.450,12,1}, --"1.45(2:12)"
{1.488,18,1}, --"1.48(3:18)"
{1.600,18,1}} --"1.60(3:18)"

--Data table:
cluster = {
{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},
{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},
{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},
{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}}

--Compare list, user picked method:
local oldmethod = {
	['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}}



local AstralAmount
local p = {}

--main function:
function p.main(frame)
	local args			= frame:getParent().args
	
	local target_lvl	= tonumber(args.target)
	if (target_lvl == nil) then
		target_lvl = 0
	end
	
	local target_exp	= Experience[target_lvl+1][2]
	local SGM			= args.method
	
	local giantseaweed	= tonumber(args.giantseaweed)
	if (giantseaweed == nil) then
		giantseaweed = 0
	end
	
	local moltenglass	= tonumber(args.moltenglass)
	if (moltenglass == nil) then
		moltenglass = 0
	end
	
	local bucketofsand	= tonumber(args.bucketofsand)
	if (bucketofsand == nil) then
		bucketofsand = 0
	end
	
	local crafting_exp	= tonumber(args.crafting)
	if (crafting_exp == nil) then
		crafting_exp = 0
	end
	
	local farming_exp	= 0--tonumber(args.farming)
	local crafting_lvl	= Experience2Level(crafting_exp) 
	local farming_lvl	= Experience2Level(farming_exp)
	
	--Overrule craft table:
	for key,value in pairs(oldmethod) do --user picked method.
		if key == SGM then
			for i=1,3 do
				oldmethod[i] = value[i]	
			end
		end
	end
	
	--Item level thresholds:
	for i=1,10,1 do
		if (target_exp > xprate[i][3]) then
			cluster[i][1] = xprate[i][1]
		else
			cluster[i][1] = target_lvl
			for p=(i+1),10,1 do
				cluster[p][1] = 0
			end
			break
		end
	end
	
	--Experience threshold:
	for i=1,10,1 do
		if (Experience[(cluster[i][1]+1)][2] - crafting_exp >= 0) then
			cluster[i][2] = Experience[(cluster[i][1]+1)][2] - crafting_exp
		else
			cluster[i][2] = 0
		end
	end
	
	--Experience left:
	for i=2,10,1 do
		if (cluster[i][2] > 0 ) then
			cluster[i][3] = cluster[i][2] - cluster[i-1][2]
		end
	end
	
	--Items to craft:
	for i=2,10,1 do
		cluster[i][4] = cluster[i][3] / xprate[i-1][2]
	end
	
	--After lvl 61, calculate back from goal:
	if (moltenglass - cluster[10][4] > 0) then
		cluster[10][5] = cluster[10][4]
	else
		cluster[10][5] = moltenglass
	end
	if (moltenglass - cluster[10][4] - cluster[9][4] > 0) then
		cluster[9][5] = cluster[9][4]
	else
		cluster[9][5] = moltenglass - cluster[10][5]
	end
	
	for i=9,10,1 do
		cluster[i][6] = cluster[i][4] - (cluster[i][5]);
		cluster[i][7] = cluster[i][6] * (xprate[i-1][2]);
		cluster[i][8] = cluster[i][7] / ((xprate[i-1][2]*oldmethod[1])+(10*oldmethod[3]));
		cluster[i][9] = cluster[i][8] * oldmethod[1];
		cluster[i][10] = cluster[i][8] / 6;
	end
	for i=2,8,1 do
		cluster[i][8] = cluster[i][4];
		cluster[i][9] = cluster[i][8];
		cluster[i][10] = cluster[i][8] / 6;
	end
	
	local var1
	local var2
	
	var1 = cluster[2][8] + cluster[3][8] + cluster[4][8] +cluster[5][8] + cluster[6][8] + cluster[7][8] + cluster[8][8] + cluster[9][8] + cluster[10][8]
	var2 = cluster[2][10] + cluster[3][10] + cluster[4][10] +cluster[5][10] + cluster[6][10] + cluster[7][10] + cluster[8][10] + cluster[9][10] + cluster[10][10]
	cluster[11][9] = cluster[2][9] + cluster[3][9] + cluster[4][9] +cluster[5][9] + cluster[6][9] + cluster[7][9] + cluster[8][9] + cluster[9][9] + cluster[10][9]
	
	AstralAmount = (var1/oldmethod[2]) * 2 *  oldmethod[3]
	
	if (var1 - bucketofsand < 0) then
		cluster[11][8] = 0
	else
		cluster[11][8] = var1 - bucketofsand
	end
	if (var2 - giantseaweed < 0) then
		cluster[11][10] = 0
	else
		cluster[11][10] = var2 - giantseaweed
	end
	
	cluster[9][11]	= ((cluster[9][7]-(cluster[9][8] * oldmethod[3] * 10)) / xprate[9-1][2])+cluster[9][5]
	cluster[10][11]	= ((cluster[10][7]-(cluster[10][8] * oldmethod[3] * 10)) / xprate[10-1][2])+cluster[10][5]
	
	cluster[11][11] = cluster[10][11] + cluster[9][11] + cluster[8][4] + cluster[7][4] + cluster[6][4] + cluster[5][4] + cluster[4][4] + cluster[3][4] + cluster[2][4]
	
	ret = mw.html.create('table'):addClass('wikitable sticky-header align-left-1 align-left-2 align-left-3 align-left-4 align-left-5 align-left-6')
	ret:tag('tr')
	:tag('th'):wikitext('Until crafting level:'):done()
	:tag('th'):wikitext('Crafting item:'):done()
	:tag('th'):wikitext('Quantity:'):done()
	:tag('th'):wikitext('Bucket of sand:'):done()
	:tag('th'):wikitext('Molten glass:'):done()
	:tag('th'):wikitext('Giant seaweed:'):done()
	if (cluster[2][4] > 0) then
	ret:tag('tr')
	:tag('td'):wikitext(round(cluster[2][1])):done()
	:tag('td'):wikitext('[[File:Beer glass.png]] Beer glass (Lv. 1)'):done()
	:tag('td'):wikitext(round(cluster[2][4])):done()
	:tag('td'):wikitext(round(cluster[2][8])):done()
	:tag('td'):wikitext(round(cluster[2][9])):done()
	:tag('td'):wikitext(round(cluster[2][10])):done()
	end
	if (cluster[3][4] > 0) then
	ret:tag('tr')
	:tag('td'):wikitext(round(cluster[3][1])):done()
	:tag('td'):wikitext('[[File:Empty candle lantern.png]] Empty candle lantern (Lv. 4)'):done()
	:tag('td'):wikitext(round(cluster[3][4])):done()
	:tag('td'):wikitext(round(cluster[3][8])):done()
	:tag('td'):wikitext(round(cluster[3][9])):done()
	:tag('td'):wikitext(round(cluster[3][10])):done()
	end
	if (cluster[4][4] > 0) then
	ret:tag('tr')
	:tag('td'):wikitext(round(cluster[4][1])):done()
	:tag('td'):wikitext('[[File:Empty oil lamp.png]] Empty oil lamp (Lv. 12)'):done()
	:tag('td'):wikitext(round(cluster[4][4])):done()
	:tag('td'):wikitext(round(cluster[4][8])):done()
	:tag('td'):wikitext(round(cluster[4][9])):done()
	:tag('td'):wikitext(round(cluster[4][10])):done()
	end
	if (cluster[5][4] > 0) then
	ret:tag('tr')
	:tag('td'):wikitext(round(cluster[5][1])):done()
	:tag('td'):wikitext('[[File:Vial.png]] Vial (Lv. 33)'):done()
	:tag('td'):wikitext(round(cluster[5][4])):done()
	:tag('td'):wikitext(round(cluster[5][8])):done()
	:tag('td'):wikitext(round(cluster[5][9])):done()
	:tag('td'):wikitext(round(cluster[5][10])):done()
	end
	if (cluster[6][4] > 0) then
	ret:tag('tr')		
	:tag('td'):wikitext(round(cluster[6][1])):done()
	:tag('td'):wikitext('[[File:Empty fishbowl.png]] Empty fishbowl (Lv. 42)'):done()
	:tag('td'):wikitext(round(cluster[6][4])):done()
	:tag('td'):wikitext(round(cluster[6][8])):done()
	:tag('td'):wikitext(round(cluster[6][9])):done()
	:tag('td'):wikitext(round(cluster[6][10])):done()
	end
	if (cluster[7][4] > 0) then
	ret:tag('tr')		
	:tag('td'):wikitext(round(cluster[7][1])):done()
	:tag('td'):wikitext('[[File:Unpowered orb.png]] Unpowered orb (Lv. 46)'):done()
	:tag('td'):wikitext(round(cluster[7][4])):done()
	:tag('td'):wikitext(round(cluster[7][8])):done()
	:tag('td'):wikitext(round(cluster[7][9])):done()
	:tag('td'):wikitext(round(cluster[7][10])):done()
	end
	if (cluster[8][4] > 0) then
	ret:tag('tr')		
	:tag('td'):wikitext(round(cluster[8][1])):done()
	:tag('td'):wikitext('[[File:Lantern_lens.png]] Lantern lens (Lv. 49[2])'):done()
	:tag('td'):wikitext(round(cluster[8][4])):done()
	:tag('td'):wikitext(round(cluster[8][8])):done()
	:tag('td'):wikitext(round(cluster[8][9])):done()
	:tag('td'):wikitext(round(cluster[8][10])):done()
	end
	if (cluster[9][4] > 0) then
	ret:tag('tr')		
	:tag('td'):wikitext(round(cluster[9][1])):done()
	:tag('td'):wikitext('[[File:Lantern_lens.png]] Lantern lens (Lv. 49)'):done()
	:tag('td'):wikitext(round(cluster[9][11])):done()
	:tag('td'):wikitext(round(cluster[9][8])):done()
	:tag('td'):wikitext(round(cluster[9][9])):done()
	:tag('td'):wikitext(round(cluster[9][10])):done()
	end
	--local picture = 'Empty light orb'
	--local action.name = 'Empty light orb'
	if (cluster[10][4] > 0) then
	ret:tag('tr')		
	:tag('td'):wikitext(round(cluster[10][1])):done()
	:tag('td'):wikitext('[[File:Empty_light_orb.png]] Empty light orb (Lv. 87)'):done()
	:tag('td'):wikitext(round(cluster[10][11])):done() 
	:tag('td'):wikitext(round(cluster[10][8])):done()
	:tag('td'):wikitext(round(cluster[10][9])):done()
	:tag('td'):wikitext(round(cluster[10][10])):done()
	end
	ret:tag('tr')	
	:tag('td'):wikitext(''):done()
	:tag('th'):wikitext(''):done()
	:tag('th'):wikitext(''):done()
	:tag('th'):wikitext(''):done()
	:tag('th'):wikitext(''):done()
	:tag('th'):wikitext(''):done()
	ret:tag('tr')
	:tag('td'):wikitext(''):done()
	:tag('th'):wikitext('Collect:'):done()
	:tag('td'):wikitext(round(cluster[11][11]) .. ' x [[File:Glassblowing pipe.png]]'):done()
	:tag('td'):wikitext(round(cluster[11][8]) .. ' x [[File:Bucket_of_sand.png]]'):done()
	:tag('td'):wikitext(round(cluster[11][9]) .. ' x [[File:Molten_glass.png]]'):done()
	:tag('td'):wikitext((round(cluster[11][10]) .. ' x [[File:Giant_seaweed.png]]')):done()
	:done()
	return ret
end

--Convert experience to level:
function Experience2Level(exp)
	for i=100,1,-1 do
		if (Experience[i][2] <= exp) then
			return Experience[i][1]
		end
	end
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

return p