Module:Magic damage calculator

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 00:12, 17 October 2024 (Created page with "local p = {} -- For rendering the tables local yesno = require('Module:Yesno') local skillpic = require('Module:SCP')._main local SPELL_TABLE = require('Module:Magic damage calculator/data') local PRAYER_MODIFIER = { 0, 0.01, 0.02, 0.04, } function p.main(frame) -- Parse the args local args = frame.args local selectedSpell = string.gsub(args.spell, "'", "'") local selectedSpellData = SPELL_TABLE[selectedSpell] local selectedWeapon = string.gsub(args.wea..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Magic damage calculator/doc

local p = {}

-- For rendering the tables
local yesno = require('Module:Yesno')
local skillpic = require('Module:SCP')._main
local SPELL_TABLE = require('Module:Magic damage calculator/data')

local PRAYER_MODIFIER = {
	0,
	0.01,
	0.02,
	0.04,
}

function p.main(frame)
	-- Parse the args
	local args = frame.args

	local selectedSpell = string.gsub(args.spell, "'", "'")
	local selectedSpellData = SPELL_TABLE[selectedSpell]
	local selectedWeapon = string.gsub(args.weapon or '', "'", "'")
	
	local magicStrength = (tonumber(args.magicStrength) or 0) / 100
	local specialModifier = tostring(args.specialModifier)
	
	local inTombsOfAmascut = yesno(args.inTombsOfAmascut)
	local haveForinthrySurge = yesno(args.haveForinthrySurge)
	
	local equipTome = yesno(args.equipTome)
	local equipChaosGauntlets = yesno(args.equipChaosGauntlets)
	
	local castMarkOfDarkness = yesno(args.castMarkOfDarkness)
	local castCharge = yesno(args.castCharge)
	
	local elementalWeakness = (tonumber(args.elementalWeakness) or 0) / 100
	
	local calculatedDamage = p.calc(selectedSpell, selectedSpellData, selectedWeapon, magicStrength, specialModifier,
		inTombsOfAmascut, haveForinthrySurge, equipTome, equipChaosGauntlets, castMarkOfDarkness, castCharge, elementalWeakness)
	
	return renderTable(calculatedDamage)
end

function p.calc(selectedSpell, selectedSpellData, selectedWeapon, magicStrength, specialModifier,
	inTombsOfAmascut, haveForinthrySurge, equipTome, equipChaosGauntlets, castMarkOfDarkness, castCharge, elementalWeakness)
	
	-- Tumeken's multiplier to (visible) % magic strength
	if selectedSpell == "Tumeken's shadow" then
		if inTombsOfAmascut then
			magicStrength = magicStrength * 4
		else
			magicStrength = magicStrength * 3
		end
	
		magicStrength = math.min(magicStrength, 1)
	end
	
	-- Boosts that are additive w/ % magic strength (Salve, Avarice, Forinthry Surge)
	if specialModifier == 'Salve amulet (i)' then
		magicStrength = magicStrength + 0.15
	end
	if specialModifier == 'Salve amulet (ei)' then
		magicStrength = magicStrength + 0.2
	end
	if specialModifier == 'Amulet of avarice (Revenants)' then
		if haveForinthrySurge then
			magicStrength = magicStrength + 0.35
		else
			magicStrength = magicStrength + 0.2
		end
	end
	if selectedWeapon == 'Smoke battlestaff' then
		magicStrength = magicStrength + 0.1
	end
	
	-- Iterate through weapon damage table
	for i, v in ipairs(selectedSpellData) do
		
		-- get base max hit, add pre-mult bonuses
		local baseMaxHit = tonumber(selectedSpellData[i][2])
		if equipChaosGauntlets then
			baseMaxHit = baseMaxHit + 3
		elseif castCharge then
			baseMaxHit = baseMaxHit + 10
		end
		
		-- iterate over prayers
		for p = 1, 4, 1 do
			-- apply % magic strength
			local maxHit = math.modf(baseMaxHit * (1 + magicStrength + PRAYER_MODIFIER[p]))
			
			-- slayer helmet
			if specialModifier == 'Slayer helmet (i)' then
				maxHit = math.modf(maxHit * 1.15)
			end
			
			-- rev sceptre
			if selectedWeapon == "Thammaron's sceptre (Wilderness)" or selectedWeapon == 'Accursed sceptre (Wilderness)' then
				maxHit = math.modf(maxHit * 1.5)
			end
			
			-- elemental weakness
			maxHit = maxHit + math.modf(elementalWeakness * baseMaxHit)
			
			-- elemental tome
			if equipTome then
				maxHit = math.modf(maxHit * 1.1)
			end
			
			if castMarkOfDarkness then
				if selectedWeapon == 'Purging staff' then
					maxHit = math.modf(maxHit * 1.5)
				else
					maxHit = math.modf(maxHit * 1.25)
				end
			end
			
			selectedSpellData[i][p+2] = maxHit
		end
	end
	
	return selectedSpellData
end

function renderTable(calculatedDamage)
	frame = mw.getCurrentFrame()
	
	-- Create the table
	local hTable = mw.html.create('table')
		:addClass('wikitable align-center-1')
		:css('text-align', 'right')
		:attr('style', 'text-align:right')
	-- Add the headers
	hTable
		:tag('caption'):wikitext('Maximum hit')
		:tag('tr')
			:tag('th'):attr('rowspan', 2):wikitext(skillpic('Magic',nil,false) .. 'Level')
			:tag('th'):attr('rowspan', 2):wikitext('Before<br/>boosts')
			:tag('th'):attr('colspan', 4):wikitext(skillpic('Prayer',nil,true) .. ' used')
		:tag('tr')
			:tag('th'):wikitext('None')
			:tag('th'):wikitext('[[File:Mystic_Lore.png|link=Mystic Lore|x21px]]')
			:tag('th'):wikitext('[[File:Mystic_Might.png|link=Mystic Might|x21px]]')
			:tag('th'):wikitext('[[File:Augury.png|link=Augury|x21px]]')
		:done()
		
	-- Add the rows
	for _, i in ipairs(calculatedDamage) do
		hTable:tag('tr')
			:tag('td'):wikitext(i[1])
			:tag('td'):wikitext(i[2])
			:tag('td'):wikitext(i[3])
			:tag('td'):wikitext(i[4])
			:tag('td'):wikitext(i[5])
			:tag('td'):wikitext(i[6])
		:done()
	end
	
	local div = mw.html.create('div')
	
	div	
		:node(hTable)
		:done()
		
	return tostring(div)
end

return p