Module:MiningGeode

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:MiningGeode/doc. [edit]
Module:MiningGeode's function geode is invoked by Template:MiningGeode.
Module:MiningGeode requires Module:Coins.
Module:MiningGeode requires Module:ExchangeLite.
Module:MiningGeode requires Module:Paramtest.

local p = {}

local gemw = require('Module:ExchangeLite')
local coins = require('Module:Coins')
local uclc = require('Module:Paramtest').ucflc

local lang = mw.language.getContentLanguage()
local commas = function (n) return lang:formatNum(n) end

local novaluemsg = "This item cannot be traded on the Grand Exchange nor alchemised and has no applicable value to display."
local alchvaluemsg = "This is the high alchemy value; this item cannot be traded on the Grand Exchange."
local merchvaluemsg = "This is the price of purchasing the reward from the Travelling Merchant's Shop; this item cannot be traded on the Grand Exchange."

local geodes = {
	sedimentary = {
		{name = 'Uncut opal',			prob = 0.2},
		{name = 'Uncut jade',			prob = 0.125},
		{name = 'Uncut red topaz',		prob = 0.075},
		{name = 'Uncut sapphire',		prob = 0.05},
		{name = 'Uncut emerald',		prob = 0.025},
		{name = 'Uncut ruby',			prob = 0.015},
		{name = 'Uncut diamond',		prob = 0.01},
		{name = 'Spirit shards',		prob = 0.5},
	},
	igneous = {
		{name = 'Uncut opal',			prob = 0.05},
		{name = 'Uncut jade',			prob = 0.06},
		{name = 'Uncut red topaz',		prob = 0.07},
		{name = 'Uncut sapphire',		prob = 0.08},
		{name = 'Uncut emerald',		prob = 0.09},
		{name = 'Uncut ruby',			prob = 0.08},
		{name = 'Uncut diamond',		prob = 0.05},
		{name = 'Uncut dragonstone',	prob = 0.02},
		{name = 'Spirit shards',		prob = 0.5},
	},
	metamorphic = {
		{name = 'Uncut onyx',					number = 1},
		{name = 'Onyx dust',					low = 5, high = 15},
		{name = 'Crystal triskelion fragment',	image = "Crystal triskelion fragment 1", number = 1, ge="no"},
		{name = 'Dragon equipment', 			image = "Dragon full helm", number = 1},
		{name = 'Concentrated alloy bar',		low = 1, high = 10},
		{name = 'Enriched alloy bar',			number = 1},
		{name = 'Sealed clue scroll (elite)',	number = 1, ge="no"},
		{name = 'Ancient effigy',				number = 1, ge="no", merch="yes", merchvalue=1000000},
		{name = 'Anima crystal',				number = 1, ge="no", merch="yes", merchvalue=150000},
		{name = 'Corrupted ore',				low = 100, high = 300, ge="no"},
		{name = 'First Age coin',				number = 1, ge="no", alch="yes", alchvalue=1000000},
		{name = 'Hydrix bolt tips',				low = 25, high = 50},
		{name = 'Banite stone spirit',			low = 25, high = 75},
		{name = 'Dark animica stone spirit',	low = 10, high = 30},
		{name = 'Light animica stone spirit',	low = 10, high = 30},
	}
}
function p.geode(frame)
	local args = frame:getParent().args
	local geodetype = string.lower(args[1] or '')
	if geodetype == "sedimentary" then
		geodedata = geodes.sedimentary
	elseif geodetype == "igneous" then
		geodedata = geodes.igneous
	elseif geodetype == "metamorphic" then
		geodedata = geodes.metamorphic
	else
		error('Unrecognized geode type. Use: "sedimentary", "igneous" or "metamorphic".')
	end
	
	return p._main(geodedata, geodetype)
end

function p._main(geodedata, geodetype)
	local t = mw.html.create('table')
	local average = 0  
	local totaldrops = 0 --Number of lines on possible drops table for metamorphic
	local price 
	local effective_value
	local alch
	local merch
	local alchvalue
	local merchvalue
	--Create table headers
	if geodetype == "metamorphic" then
		t:addClass('wikitable')
		:tag('tr')
		:tag('th')  :wikitext('Item')       :done()
		:tag('th')  :wikitext('Quantity')   :done()
		:tag('th')  :wikitext('Value')  	:done()
		:done()
	else
		--Sed/Ign
		t:addClass('wikitable')
		:tag('tr')
		:tag('th')  :wikitext('Item')       :done()
		:tag('th')  :wikitext('Chance')     :done()
		:tag('th')  :wikitext('GE Price')   :done()
		:done()
	end
	
	--Fill table rewards
	for index,i in ipairs(geodedata) do
		local image_file = i.image or i.name
		local image = '[[File:'..image_file..'.png|link='..i.name..']]'
		if geodetype == "metamorphic" then
			if i.name == "Dragon equipment" then
				--This drops line can be multiple things; select one from array below
				local dragonequip = {
					--Includes dragon equipment specced by Mod Breezy on Discord 22-Jan-19
					gemw.price('Dragon battleaxe'),
					gemw.price('Off-hand dragon battleaxe'),
					gemw.price('Dragon claw'),
					gemw.price('Off-hand dragon claw'),
					gemw.price('Dragon longsword'),
					gemw.price('Off-hand dragon longsword'),
					gemw.price('Dragon mace'),
					gemw.price('Off-hand dragon mace'),
					gemw.price('Dragon scimitar'),
					gemw.price('Off-hand dragon scimitar'),
					gemw.price('Dragon warhammer'),
					gemw.price('Off-hand dragon warhammer'),
					gemw.price('Dragon hasta'),
					gemw.price('Dragon 2h sword'),
					gemw.price('Dragon halberd'),
					gemw.price('Dragon spear'),
					gemw.price('Dragon full helm'),
					gemw.price('Dragon helm'),
					gemw.price('Dragon chainbody'),
					gemw.price('Dragon kiteshield'),
					gemw.price('Dragon sq shield'),
					gemw.price('Dragon platelegs'),
					gemw.price('Dragon plateskirt'),
					gemw.price('Dragon boots'),
				}
				--NOTE: unpack has quantity limits, used here as list is short
				local minprice = math.min(unpack(dragonequip))		
				local maxprice = math.max(unpack(dragonequip))
				price = coins._amount(minprice) .. " - " .. coins._amount(maxprice)
				effective_value = (minprice+maxprice)/2
				average = average + effective_value
				totaldrops = totaldrops + 1
			elseif i.ge == "no" then
				--No GE, check for Alch or merch
				if i.alch == "yes" then
					--Display a High Alch value rather than GE Price
					price = "[[File:High_Level_Alchemy_icon.png|link=|frameless|30px]] "..commas(i.alchvalue)
					effective_value = i.alchvalue
					average = average  + effective_value
					totaldrops = totaldrops + 1
				elseif i.merch == "yes" then
					--Displays travelling merchant price
					price = "[[File:Travelling_merchant.png|link=|frameless|30px]] "..commas(i.merchvalue)
					effective_value = i.merchvalue
					average = average  + effective_value
					totaldrops = totaldrops + 1
				else
					--No alch or merch, display Not Sold
					price = "Not Sold"
					effective_value = 0
					average = average  + effective_value
					totaldrops = totaldrops + 1
				end
			else
				--Shows the GE value of the item
				if i.number == 1 then
					--Shows single quantity GE
					price = coins._amount(gemw.price(i.name))
					effective_value = gemw.price(i.name)
					average = average  + effective_value
					totaldrops = totaldrops + 1
				else
					--Shows range of prices from min to max qty
					pricelow = (gemw.price(i.name)*(i.low))
					pricehigh =(gemw.price(i.name)*(i.high))
					price = coins._amount(pricelow).." - "..coins._amount(pricehigh)
					effective_value = (pricelow+pricehigh)/2
					average = average  + effective_value
					totaldrops = totaldrops + 1
				end
			end
		else 
			--Sed/Ign all drops single quantity GE
			price = coins._amount(gemw.price(i.name))
			effective_value = gemw.price(i.name) * i.prob
			average = average + effective_value
		end
		
		
		if geodetype == "metamorphic" then
			if i.alch == "yes" then
				--Shows the alch price
				t:tag('tr')
				:tag('td')  :wikitext(image..' '..'[['..i.name..']]')		:done()
				:tag('td')  :wikitext(i.number)								:done()
				:tag('td')  
				:attr('title',alchvaluemsg)
				:css('cursor','help')
				:css('text-align', 'center')
				:wikitext(price)
				:done()
			elseif i.merch == "yes" then
				--Shows the merchprice
				t:tag('tr')
				:tag('td')  :wikitext(image..' '..'[['..i.name..']]')		:done()
				:tag('td')  :wikitext(i.number)								:done()
				:tag('td')  
				:attr('title',merchvaluemsg)
				:css('cursor','help')
				:css('text-align', 'center')
				:wikitext(price)
				:done()	
			elseif i.ge == "no" and i.number == 1 then
				--Meta Single quantity non-ge
				t:tag('tr')
				:tag('td')  :wikitext(image..' '..'[['..i.name..']]')		:done()
				:tag('td')  :wikitext(i.number)								:done()
				:tag('td')  :attr('title',novaluemsg)
				:css('cursor', 'help')
				:css('color', '#666')
				:css('text-align', 'center')
				:wikitext(price)
				:done()
			elseif i.ge == "no" then
				--Meta Range of quantities non-ge
				t:tag('tr')
				:tag('td')  :wikitext(image..' '..'[['..i.name..']]')       :done()
				:tag('td')  :wikitext(i.low.."-"..i.high)					:done()
				:tag('td')  :attr('title',novaluemsg)
				:css('cursor', 'help')
				:css('color', '#666')
				:css('text-align', 'center')
				:wikitext(price)
				:done()
			elseif i.number == 1 then
				--Meta Single quantity with GE price
				t:tag('tr')
				:tag('td')  :wikitext(image..' '..'[['..i.name..']]')       :done()
				:tag('td')  :wikitext(i.number)								:done()
				:tag('td')  :css('text-align', 'center') :wikitext(price)   :done()
			else
				--Meta Range of quantities with GE price
				t:tag('tr')
				:tag('td')  :wikitext(image..' '..'[['..i.name..']]')       :done()
				:tag('td')  :wikitext(i.low.."-"..i.high)					:done()
				:tag('td')	:css('text-align', 'center') :wikitext(price)   :done()
			end
		else
			--Sed/Ign all sinlge qty ge 
			t:tag('tr')
			:tag('td')  :wikitext(image..' '..'[['..i.name..']]')                       :done()
			:tag('td')  :wikitext((i.prob*100)..'%')    :css('text-align', 'center')    :done()
			:tag('td')  :wikitext(price)    											:done()
		end
	end
	
	--Average Value Display
	if geodetype == "metamorphic" then
		--Metamorphic Average value
		t:tag('tr')
		:tag('th')  :wikitext('Average Value')
		:attr('colspan', 2)
		:attr('title', "Average value is calculated based on an equal 6.25% chance for each reward; rewards that have a range of quantities use the average of the lowest and highest possible value for that reward.")
		:css('cursor','help')
		:done()
		:tag('th')  :wikitext(coins._amount(math.floor(average/totaldrops)))	:done()
		:done()	
	else 
		--Sed/Ign Average value
		t:tag('tr')
		:tag('th')  :wikitext('Average Value')  :attr('colspan', 2)     :done()
		:tag('th')  :wikitext(coins._amount(math.floor(average)))       :done()
		:done()
	end
	
	return t
end

return p