Module:Bolt costs

local p = {} local gep = require('Module:ExchangeLite').price local bolts = { ['Bronze'] = {'Opal'}, ['Blurite'] = {'Jade'}, ['Iron'] = {'Pearl'}, ['Steel'] = {'Topaz'}, ['Mithril'] = {'Sapphire', 'Emerald'}, ['Adamant'] = {'Ruby', 'Diamond'}, ['Runite'] = {'Dragon', 'Onyx'}, ['Ascension'] = {'Hydrix'}, }

function p.main(frame) local t = mw.html.create('table'):done t:tag('tr') :tag('th') :attr('colspan',2) :done :tag('th') :wikitext('Uncut') :done :tag('th') :wikitext('Cut') :done :tag('th') :wikitext('Tip') :done :done t:node(tostring(p.core(frame))):done return t end

function p.core(frame) local costs = getCosts(frame) local gem = frame.args[2] local bolt = gem..' bolts' if frame.args[1] == 'Bakriminel' then bolt = gem..' bakriminel bolts' end local outputPrice = gep(bolt) local tr1 = mw.html.create('tr'):done tr1	:tag('th') :attr('rowspan', 2) :wikitext(gem) :done :tag('th') :wikitext('Unenchanted') :done :tag('td') :wikitext(outputPrice - costs[uncut][1]) :done :tag('td') :wikitext(outputPrice - costs[cut][1]) :done :tag('td') :wikitext(outputPrice - costs[tip][1]) :done :done outputPrice = gep(bolt..' (e)') local tr2 = mw.html.create('tr') tr2 :tag('th') :wikitext('Enchanted') :done :tag('td') :wikitext(outputPrice - costs[uncut][2]) :done :tag('td') :wikitext(outputPrice - costs[cut][2]) :done :tag('td') :wikitext(outputPrice - costs[tip][2]) :done :done return tr1..tr2 --if any issue, here is probably where it is end

function getCosts(data) local data = data:getParent.args local bolt = data.args[1] local gem = data.args[2] local boltType = bolt local boltCost = 0 --start validation local gemTip = ValidateGemTip(gem) if bolt:lower == 'ascendri' then bolt = 'Ascension' end if not (bolts[boltMetal] ~= nil) and ValidateTipToBolt(bolt, gemTip) then boltType = 'Metal' boltCost = gep(bolt..' bolts') elseif bolt == 'Bakriminel' then boltCost = 200 end --end validation local spellCost = SpellCost(boltType,gem) local data = { uncut = { uncutCosts(gemTip) + boltCost, uncutCosts(gemTip) + boltCost + spellCost },		cut = { cutCosts(gemTip) + boltCost, cutCosts(gemTip) + boltCost + spellCost },		tip = { tipCosts(gemTip) + boltCost, tipCosts(gemTip) + boltCost + spellCost }   }    return data end

local function SpellCost(boltType,gem) local air = gep('Air rune') local water = gep('Water rune') local earth = gep('Earth rune') local fire = gep('Fire rune') local blood = gep('Blood rune') local cosmic = gep('Cosmic rune') local mind = gep('Mind rune') local nature = gep('Nature rune') local law = gep('Law rune') local soul = gep('Soul rune') local death = gep('Death rune') local spells = { ['Opal'] = air * 2 + cosmic, ['Sapphire'] = water + mind + cosmic, ['Jade'] = earth * 2 + cosmic, ['Pearl'] = water * 2 + cosmic, ['Emerald'] = air * 3 + nature + cosmic, ['Topaz'] = fire * 2 + cosmic, ['Ruby'] = fire * 5 + blood + cosmic, ['Diamond'] = earth * 10 + law * 2 + cosmic, ['Dragon'] = earth * 15 + soul + cosmic, ['Onyx'] = fire * 20 + death + cosmic, ['Hydrix'] = fire * 20 + death + cosmic }   if spells[gem] ~= nil then return false end if boltType == 'Bakriminel' then return spells[gem] + blood end return spells[gem] end

local function uncutCosts(gem) if gem == 'Oyster pearl' then return gep('Oyster pearl') / 6 elseif gem == 'Oyster pearls' then return gep('Oyster pearls') / 24 else return gep('Uncut '..gem:lower) / 12 end end

local function cutCosts(gem) if gem == 'Oyster pearl' or gem == 'Oyster pearls' then return nil else return gep(gem) / 12 end end

local function tipCosts(gem) if gem == 'Oyster pearl' or gem == 'Oyster pearls' then return gep('Pearl bolt tips') elseif gem == 'Dragonstone' then return gep('Dragon bolt tips') elseif gem == 'Red topaz' then return gep('Topaz bolt tips') else return gep(gem..' bolt tips') end end

local function ValidateTipToBolt(boltMetal, gem) for key,val in bolts[boltMetal] do       if gem == val then return true end end return false end

local function ValidateGemTip(gem) gem = gem:lower if gem == 'oyster pearl' or gem == 'oyster pearls' then return 'Pearl' elseif gem == 'red topaz' then return 'Topaz' elseif gem == 'dragonstone' then return 'Dragon' else return strsub(gem,1,1):upper..strsub(gem,2) end end return p