Module:Prayer: Difference between revisions

From Melvor Idle
(Added 'lvl' to the level column for the prayer table)
(Removed functions in favour of manual tables)
 
(32 intermediate revisions by 5 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local SkillData = mw.loadData('Module:Skills/data')


local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Modifiers = require('Module:Modifiers')
local Skills = require('Module:Skills')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Constants = require('Module:Constants')
local Items = require('Module:Items')
local ItemSources = require('Module:Items/SourceTables')
local Num = require('Module:Number')


function p.getPrayerByID(id)
function p.getPrayerByID(id)
  local result = Shared.clone(SkillData.Prayer[id + 1])
return GameData.getEntityByID('prayers', id)
  if result ~= nil and result.id == nil then result.id = id end
  return result
end
end


function p.getPrayer(name)
function p.getPrayer(name)
  local result = nil
return GameData.getEntityByName('prayers', name)
  for i, prayer in pairs(SkillData.Prayer) do
    local prayName = prayer.name
    if prayName == name then
      result = Shared.clone(prayer)
      result.id = i - 1
      break
    end
  end
  return result
end
end


function p.getPrayerCost(prayer)
function p.getPrayers(checkFunc)
  local costLines = {}
return GameData.getEntities('prayers', checkFunc)
  if prayer.pointsPerPlayer > 0 then
    local pluralString = prayer.pointsPerPlayer > 1 and 's' or ''
    table.insert(costLines, prayer.pointsPerPlayer..' Prayer Point'..pluralString..' per player attack')
  end
  if prayer.pointsPerEnemy > 0 then
    local pluralString = prayer.pointsPerEnemy > 1 and 's' or ''
    table.insert(costLines, prayer.pointsPerEnemy..' Prayer Point'..pluralString..' per enemy attack')
  end
  if prayer.pointsPerRegen > 0 then
    local pluralString = prayer.pointsPerRegen > 1 and 's' or ''
    table.insert(costLines, prayer.pointsPerRegen..' Prayer Point'..pluralString..' when health regenerates')
  end
  return table.concat(costLines, '<br/>')
end
end


function p.formatEffectLine(var, val)
--Returns the expansion icon for the prayer if it has one
  if var == 'prayerBonusDefence' then
function p.getExpansionIcon(frame)
    return '+'..val..'% [[Combat#Melee Evasion Rating|Melee Evasion Rating]]'
local prayerName = frame.args ~= nil and frame.args[1] or frame
  elseif var == 'prayerBonusStrength' then
local prayer = p.getPrayer(prayerName)
    return '+'..val..'% [[Combat#Melee Max Hit|Melee Strength]]'
if prayer == nil then
  elseif var == 'prayerBonusAttack' then
return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
    return '+'..val..'% [[Combat#Melee Accuracy Rating|Melee Accuracy Rating]]'
end
  elseif var == 'prayerBonusDefenceRanged' then
    return '+'..val..'% [[Combat#Ranged Evasion Rating|Ranged Evasion Rating]]'
return Icons.getExpansionIcon(prayer.id)
  elseif var == 'prayerBonusAttackRanged' then
end
    return '+'..val..'% [[Combat#Ranged Accuracy Rating|Ranged Accuracy Rating]]'
 
  elseif var == 'prayerBonusStrengthRanged' then
function p.getPrayerCost(prayer)
    return '+'..val..'% [[Combat#Ranged Max Hit|Ranged Strength]]'
local costLines = {}
  elseif var == 'prayerBonusDefenceMagic' then
if prayer.pointsPerPlayer > 0 then
    return '+'..val..'% [[Combat#Magic Evasion Rating|Ranged Evasion Rating]]'
local pluralString = prayer.pointsPerPlayer > 1 and 's' or ''
  elseif var == 'prayerBonusAttackMagic' then
table.insert(costLines, prayer.pointsPerPlayer..' Prayer Point'..pluralString..' per player attack')
    return '+'..val..'% [[Combat#Magic Accuracy Rating|Magic Accuracy Rating]]'
end
  elseif var == 'prayerBonusDamageMagic' then
if prayer.pointsPerEnemy > 0 then
    return '+'..val..'% [[Combat#Magic Max Hit|Magic Damage]]'
local pluralString = prayer.pointsPerEnemy > 1 and 's' or ''
  elseif var == 'prayerBonusHitpoints' then
table.insert(costLines, prayer.pointsPerEnemy..' Prayer Point'..pluralString..' per enemy attack')
    return val..'x Restore Rate for [[Hitpoints]]'
end
  elseif var == 'prayerBonusProtectItem' then
if prayer.pointsPerRegen > 0 then
    return 'Prevents losing an item upon [[Death]]'
local pluralString = prayer.pointsPerRegen > 1 and 's' or ''
  elseif var == 'prayerBonusProtectFromMelee' then
table.insert(costLines, prayer.pointsPerRegen..' Prayer Point'..pluralString..' when health regenerates')
    return '85% chance to dodge Melee attacks'
end
  elseif var == 'prayerBonusProtectFromRanged' then
return table.concat(costLines, '<br/>')
    return '85% chance to dodge Ranged attacks'
  elseif var == 'prayerBonusProtectFromMagic' then
    return '85% chance to dodge Magic attacks'
  elseif var == 'prayerBonusHitpointHeal' then
    return 'Heal +'..val..'% HP when HP falls below 10%'
  elseif var == 'prayerBonusDamageReduction' then
    return '+'..val..'% [[Damage Reduction]]'
  else
    return '+'..val..' of unknown bonus '..var..'[[Category:Unknown Prayer Bonus]]'
  end
end
end


function p._getPrayerEffect(prayer, asList)
function p._getPrayerEffect(prayer, asList)
  if asList == nil then asList = false end
if asList == nil then asList = false end
  local chr = asList and '* ' or ''
  local bonusLines = {}


  for bonusKey, bonusVal in Shared.skpairs(prayer.modifiers) do
local lineSep = (asList and '\n' or '<br>')
    table.insert(bonusLines, chr..Constants.getModifierText(bonusKey, bonusVal, false))
local chr = (asList and '* ' or '')
  end
local bonusLines = {}
if prayer.isUnholy then
table.insert(bonusLines, "For each Unholy Mark stack on the enemy:")
end
if type(prayer.modifiers) == 'table' then
local formatLine = function(text) return chr .. text end


  --If there are no actual effects, just use the prayer's description 
table.insert(bonusLines, Modifiers.getModifiersText(prayer.modifiers, false, false, 10, formatLine, lineSep))
  if Shared.tableCount(prayer.modifiers) == 0 then
end
    table.insert(bonusLines, chr..prayer.description)
  end


  if prayer.pointsPerPlayer > 0 then
if type(prayer.enemyModifiers) == 'table' then
    local val = 0.2 * prayer.pointsPerPlayer
local formatLine = function(text) return chr .. 'Gives the enemy: ' .. text end
    table.insert(bonusLines, chr.."+"..Shared.round(val, 1, 1).." Prayer XP per damage done")
  end
table.insert(bonusLines, Modifiers.getModifiersText(prayer.enemyModifiers, false, false, 10, formatLine, lineSep))
end


  return table.concat(bonusLines, '<br/>')
if prayer.pointsPerPlayer > 0 then
-- Prayer XP ratio is 1/3 in game but is divided by 10 here as HP/damage values
-- displayed to the player are multiplied by 10 in the standard game mode
local xpRatio = 1 / 30
local val = xpRatio * prayer.pointsPerPlayer
table.insert(bonusLines, chr .. "+" .. Num.round(val, 3, 3) .. " Prayer XP per damage done")
end
return table.concat(bonusLines, lineSep)
end
end


function p.getPrayerEffect(frame)
function p.getPrayerEffect(frame)
  local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
  local asListTxt = frame.args ~= nil and frame.args[2] or frame[2]
local asListTxt = frame.args ~= nil and frame.args[2] or frame[2]
  local asList = asListTxt ~= nil and asListTxt ~= 'false' and asListTxt ~= 'no'
local asList = asListTxt ~= nil and asListTxt ~= 'false' and asListTxt ~= 'no'
  local prayer = p.getPrayer(prayerName)
local prayer = p.getPrayer(prayerName)
  if prayer == nil then
if prayer == nil then
    return "ERROR: Could not find a prayer named "..prayerName
return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
  end
end


  return p._getPrayerEffect(prayer, asList)
return p._getPrayerEffect(prayer, asList)
end
end


function p._getPrayerStat(prayer, statName)
function p._getPrayerStat(prayer, statName)
  if statName == "prayerCost" then
if statName == "prayerCost" then
    return p.getPrayerCost(prayer)
return p.getPrayerCost(prayer)
  elseif statName == "prayerEffect" then
elseif statName == "prayerEffect" then
    return p._getPrayerEffect(prayer)
return p._getPrayerEffect(prayer)
  elseif statName == "prayerEffectList" then
elseif statName == "prayerEffectList" then
    return p.getPrayerEffect(prayer, true)
return p.getPrayerEffect(prayer)
  elseif statName == 'prayerLevel' then
elseif statName == 'prayerLevel' then
    return Icons._SkillReq('Prayer', prayer['prayerLevel'])
return Skills.getRecipeRequirementText('Prayer', prayer)
  else
else
    return prayer[statName]
return prayer[statName]
  end
end
end
end


function p.getPrayerStat(frame)
function p.getPrayerStat(frame)
  local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
  local statName = frame.args ~= nil and frame.args[2] or frame[2]
local statName = frame.args ~= nil and frame.args[2] or frame[2]
  local prayer = p.getPrayer(prayerName)
local prayer = p.getPrayer(prayerName)
  if prayer == nil then
if prayer == nil then
    return "ERROR: Could not find a prayer named "..prayerName
return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
  end
end


  return p._getPrayerStat(prayer, statName)
return p._getPrayerStat(prayer, statName)
end
end


function p._getPrayerCategories(prayer)
function p._getPrayerCategories(prayer)
  return '[[Category:Prayers]]'
return '[[Category:Prayers]]'
end
end


function p.getPrayerCategories(frame)
function p.getPrayerCategories(frame)
  local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
  local prayer = p.getPrayer(prayerName)
local prayer = p.getPrayer(prayerName)
  if prayer == nil then
if prayer == nil then
    return "ERROR: Could not find a prayer named "..prayerName
return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
  end
end


  return p._getPrayerCategories(prayer)
return p._getPrayerCategories(prayer)
end
end


-- Returns only the regular prayers.
function p.getPrayerTable(frame)
function p.getPrayerTable(frame)
  local result = '{| class="wikitable sortable stickyHeader"'
local func = function(prayer)
  result = result..'\r\n|-class=headerRow-0'
return not prayer.isUnholy and not prayer.isAbyssal
  result = result..'\r\n!colspan="2"|Prayer!!'..Icons.Icon({"Prayer", type="skill", notext=true})..' Lvl'
end
  result = result..'!!Effects!!Point Cost'
return p.getPrayerTableFiltered(frame, func)
end
 
function p.getUnholyPrayerTable(frame)
return p.getPrayerTableFiltered(frame, function(prayer) return prayer.isUnholy end)
end
 
function p.getAbyssalPrayerTable(frame)
return p.getPrayerTableFiltered(frame, function(prayer) return prayer.isAbyssal end, 'Abyssal Realm')
end
 
-- Realm is defined "manually" here to define custom styling
function p.getPrayerTableFiltered(frame, prayerPredicate, realm)
local skillID = 'Prayer'
local realm = realm or 'Melvor Realm'
local html = mw.html.create('table')
:addClass('wikitable sortable stickyHeader')
 
html:tag('tr'):addClass('headerRow-0')
:tag('th'):attr('colspan', 2)
  :wikitext('Prayer')
:tag('th'):wikitext('DLC')
:tag('th'):wikitext(Icons.Icon({'Prayer', type='skill', notext=true}) .. '<br>Level')
:tag('th'):wikitext('Effects')
:tag('th'):wikitext('Point Cost')
 
local prayerList = p.getPrayers(prayerPredicate)
table.sort(prayerList, function(a, b) return Skills.standardRecipeSort(skillID, a, b) end)


  for i, prayer in Shared.skpairs(SkillData.Prayer) do
for i, prayer in ipairs(prayerList) do
    result = result..'\r\n|-'
local level = Skills.getRecipeLevel(skillID, prayer)
    result = result..'\r\n|'..Icons.Icon({prayer.name, type='prayer', notext=true, size='50'})
local reqText = Skills.getRecipeRequirementText(skillID, prayer)
    result = result..'||[['..prayer.name..']]||'..prayer.prayerLevel
    result = result..'||'..p._getPrayerEffect(prayer)
html:tag('tr')
    result = result..'||'..p.getPrayerCost(prayer)
:tag('td'):wikitext(Icons.Icon({prayer.name, type='prayer', notext=true}))
  end
:tag('td'):wikitext('[[' .. prayer.name .. ']]')
:tag('td'):wikitext(Icons.getDLCColumnIcon(prayer.id))
  :css('text-align', 'center')
  :attr('data-sort-value', Icons.getExpansionID(prayer.id))
:tag('td'):wikitext(level)
  :css('text-align', 'center')
:tag('td'):wikitext(p._getPrayerEffect(prayer))
:tag('td'):wikitext(p.getPrayerCost(prayer))
end


  result = result..'\r\n|}'
return tostring(html)
  return result
end
end


return p
return p

Latest revision as of 13:02, 8 July 2024

Documentation for this module may be created at Module:Prayer/doc

local p = {}

local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Modifiers = require('Module:Modifiers')
local Skills = require('Module:Skills')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local ItemSources = require('Module:Items/SourceTables')
local Num = require('Module:Number')

function p.getPrayerByID(id)
	return GameData.getEntityByID('prayers', id)
end

function p.getPrayer(name)
	return GameData.getEntityByName('prayers', name)
end

function p.getPrayers(checkFunc)
	return GameData.getEntities('prayers', checkFunc)
end

--Returns the expansion icon for the prayer if it has one
function p.getExpansionIcon(frame)
	local prayerName = frame.args ~= nil and frame.args[1] or frame
	local prayer = p.getPrayer(prayerName)
	if prayer == nil then
		return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
	end
	
	return Icons.getExpansionIcon(prayer.id)
end

function p.getPrayerCost(prayer)
	local costLines = {}
	if prayer.pointsPerPlayer > 0 then
		local pluralString = prayer.pointsPerPlayer > 1 and 's' or ''
		table.insert(costLines, prayer.pointsPerPlayer..' Prayer Point'..pluralString..' per player attack')
	end
	if prayer.pointsPerEnemy > 0 then
		local pluralString = prayer.pointsPerEnemy > 1 and 's' or ''
		table.insert(costLines, prayer.pointsPerEnemy..' Prayer Point'..pluralString..' per enemy attack')
	end
	if prayer.pointsPerRegen > 0 then
		local pluralString = prayer.pointsPerRegen > 1 and 's' or ''
		table.insert(costLines, prayer.pointsPerRegen..' Prayer Point'..pluralString..' when health regenerates')
	end
	return table.concat(costLines, '<br/>')
end

function p._getPrayerEffect(prayer, asList)
	if asList == nil then asList = false end

	local lineSep = (asList and '\n' or '<br>')
	local chr = (asList and '* ' or '')
	local bonusLines = {}
	
	if prayer.isUnholy then
		table.insert(bonusLines, "For each Unholy Mark stack on the enemy:")
	end
	
	if type(prayer.modifiers) == 'table' then
		local formatLine = function(text) return chr .. text	end

		table.insert(bonusLines, Modifiers.getModifiersText(prayer.modifiers, false, false, 10, formatLine, lineSep))
	end

	if type(prayer.enemyModifiers) == 'table' then
		local formatLine = function(text) return chr .. 'Gives the enemy: ' .. text	end
		
		table.insert(bonusLines, Modifiers.getModifiersText(prayer.enemyModifiers, false, false, 10, formatLine, lineSep))
	end

	if prayer.pointsPerPlayer > 0 then
		-- Prayer XP ratio is 1/3 in game but is divided by 10 here as HP/damage values
		-- displayed to the player are multiplied by 10 in the standard game mode
		local xpRatio = 1 / 30
		local val = xpRatio * prayer.pointsPerPlayer
		table.insert(bonusLines, chr .. "+" .. Num.round(val, 3, 3) .. " Prayer XP per damage done")
	end
	return table.concat(bonusLines, lineSep)
end

function p.getPrayerEffect(frame)
	local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
	local asListTxt = frame.args ~= nil and frame.args[2] or frame[2]
	local asList = asListTxt ~= nil and asListTxt ~= 'false' and asListTxt ~= 'no'
	local prayer = p.getPrayer(prayerName)
	if prayer == nil then
		return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
	end

	return p._getPrayerEffect(prayer, asList)
end

function p._getPrayerStat(prayer, statName)
	if statName == "prayerCost" then
		return p.getPrayerCost(prayer)
	elseif statName == "prayerEffect" then
		return p._getPrayerEffect(prayer)
	elseif statName == "prayerEffectList" then
		return p.getPrayerEffect(prayer)
	elseif statName == 'prayerLevel' then
		return Skills.getRecipeRequirementText('Prayer', prayer)
	else
		return prayer[statName]
	end
end

function p.getPrayerStat(frame)
	local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
	local statName = frame.args ~= nil and frame.args[2] or frame[2]
	local prayer = p.getPrayer(prayerName)
	if prayer == nil then
		return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
	end

	return p._getPrayerStat(prayer, statName)
end

function p._getPrayerCategories(prayer)
	return '[[Category:Prayers]]'
end

function p.getPrayerCategories(frame)
	local prayerName = frame.args ~= nil and frame.args[1] or frame[1]
	local prayer = p.getPrayer(prayerName)
	if prayer == nil then
		return Shared.printError('No prayer named "' .. prayerName .. '" exists in the data module')
	end

	return p._getPrayerCategories(prayer)
end

-- Returns only the regular prayers.
function p.getPrayerTable(frame)
	local func = function(prayer)
		return not prayer.isUnholy and not prayer.isAbyssal
	end
	
	return p.getPrayerTableFiltered(frame, func)
end

function p.getUnholyPrayerTable(frame)
	return p.getPrayerTableFiltered(frame, function(prayer) return prayer.isUnholy end)
end

function p.getAbyssalPrayerTable(frame)
	return p.getPrayerTableFiltered(frame, function(prayer) return prayer.isAbyssal end, 'Abyssal Realm')
end

-- Realm is defined "manually" here to define custom styling
function p.getPrayerTableFiltered(frame, prayerPredicate, realm)
	local skillID = 'Prayer'
	local realm = realm or 'Melvor Realm'
	
	local html = mw.html.create('table')
		:addClass('wikitable sortable stickyHeader')

	html:tag('tr'):addClass('headerRow-0')
			:tag('th'):attr('colspan', 2)
					  :wikitext('Prayer')
			:tag('th'):wikitext('DLC')
			:tag('th'):wikitext(Icons.Icon({'Prayer', type='skill', notext=true}) .. '<br>Level')
			:tag('th'):wikitext('Effects')
			:tag('th'):wikitext('Point Cost')

	local prayerList = p.getPrayers(prayerPredicate)
	table.sort(prayerList, function(a, b) return Skills.standardRecipeSort(skillID, a, b) end)

	for i, prayer in ipairs(prayerList) do
		local level = Skills.getRecipeLevel(skillID, prayer)
		local reqText = Skills.getRecipeRequirementText(skillID, prayer)
		
		html:tag('tr')
				:tag('td'):wikitext(Icons.Icon({prayer.name, type='prayer', notext=true}))
				:tag('td'):wikitext('[[' .. prayer.name .. ']]')
				:tag('td'):wikitext(Icons.getDLCColumnIcon(prayer.id))
						  :css('text-align', 'center')
						  :attr('data-sort-value', Icons.getExpansionID(prayer.id))
				:tag('td'):wikitext(level)
						  :css('text-align', 'center')
				:tag('td'):wikitext(p._getPrayerEffect(prayer))
				:tag('td'):wikitext(p.getPrayerCost(prayer))
	end

	return tostring(html)
end

return p