Module:Magic: Difference between revisions

11,663 bytes added ,  15 November 2023
m
Fix typo
m (Undo revision 51303: This change made many pages unhappy (error 1))
Tag: Undo
m (Fix typo)
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local MagicData = mw.loadData('Module:Magic/data')
local Constants = require('Module:Constants')
 
local Areas = require('Module:CombatAreas')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Common = require('Module:Common')
local Attacks = require('Module:Attacks')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Constants = require('Module:Constants')


function processSpell(section, index)
p.spellBooks = {
local result = Shared.clone(MagicData[section][index])
{ id = 'standard', dataID = 'standardSpells', name = 'Standard Magic', imgType = 'spell' },
result.id = index - 1
{ id = 'ancient', dataID = 'ancientSpells', name = 'Ancient Magick', imgType = 'spell' },
result.type = section
{ id = 'archaic', dataID = 'archaicSpells', name = 'Archaic Magick', imgType = 'spell' },
return result
{ id = 'curse', dataID = 'curseSpells', name = 'Curse', imgType = 'curse' },
{ id = 'aurora', dataID = 'auroraSpells', name = 'Aurora', imgType = 'aurora' },
{ id = 'altMagic', dataID = 'altSpells', name = 'Alt. Magic', imgType = 'spell', dataBySkill = true }
}
 
p.spellBookIndex = {}
for i, spellBook in ipairs(p.spellBooks) do
p.spellBookIndex[spellBook.id] = i
end
 
function p.getSpellBookID(sectionName)
if sectionName == 'Spell' or sectionName == 'Standard' then
return 'standard'
elseif sectionName == 'Ancient' then
return 'ancient'
elseif sectionName == 'Archaic' then
return 'archaic'
elseif sectionName == 'Curse' then
return 'curse'
elseif sectionName == 'Aurora' then
return 'aurora'
elseif Shared.contains({'Alt Magic', 'Alt. Magic', 'Alternative Magic'}, sectionName) then
return 'altMagic'
else
return sectionName
end
end
end


function p.getSpell(name, type)
-- Retrieves all spells within the given spellbook
local section = type
function p.getSpellsBySpellBook(spellBookID)
if type == 'Spell' or type == 'Standard' then
if type(spellBookID) == 'string' then
section = 'Spells'
local spellBook = GameData.getEntityByID(p.spellBooks, spellBookID)
elseif type == 'Curse' then
if spellBook ~= nil then
section = 'Curses'
if spellBook.dataBySkill then
elseif type == 'Aurora' then
-- Data is part of the Magic skill object
section = 'Auroras'
local magicData = GameData.getSkillData('melvorD:Magic')
elseif type == 'Alt Magic' or type == 'Alternative Magic' then
if magicData ~= nil then
section = 'AltMagic'
return magicData[spellBook.dataID]
end
else
-- Data is at the root of GameData
return GameData.rawData[spellBook.dataID]
end
end
end
end
end


function p.getSpell(name, spellType)
local spellBookID = p.getSpellBookID(spellType)
name = Shared.fixPagename(name)
name = Shared.fixPagename(name)
if section == nil then
 
for i, section in Shared.skpairs(MagicData) do
for i, spellBook in ipairs(p.spellBooks) do
for j, spell in Shared.skpairs(section) do
if spellBookID == nil or spellBookID == spellBook.id then
if spell.name == name then
local spells = p.getSpellsBySpellBook(spellBook.id)
return processSpell(i, j)
local spell = GameData.getEntityByName(spells, name)
end
if spell ~= nil then
return spell
end
end
end
end
elseif section ~= nil and MagicData[section] ~= nil then
end
for i, spell in Shared.skpairs(MagicData[section]) do
end
if spell.name == name then
 
return processSpell(section, i)
function p.getSpellByID(id, spellType)
local spellBookID = p.getSpellBookID(spellType)
 
if spellType == nil or spellBookID ~= nil then
for i, spellBook in ipairs(p.spellBooks) do
if spellType == nil or spellBookID == spellBook.id then
if spellBook.dataBySkill then
return GameData.getEntityByID(p.getSpellsBySpellBook(spellBook.id), id)
else
return GameData.getEntityByID(spellBook.dataID, id)
end
end
end
end
end
else
return nil
end
end
end
end


function p.getSpellByID(type, id)
--Returns the expansion icon for the spell if it has one
local section = type
function p.getExpansionIcon(frame)
if type == nil or type == 'Spell' or type == 'Standard' then
local spellName = frame.args ~= nil and frame.args[1] or frame
section = 'Spells'
local spell = p.getSpell(spellName)
elseif type == 'Curse' then
if spell == nil then
section = 'Curses'
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
elseif type == 'Aurora' then
end
section = 'Auroras'
elseif type == 'Alt Magic' or type == 'Alternative Magic' then
return Icons.getExpansionIcon(spell.id)
section = 'AltMagic'
end
 
function p.getTypeString(spellType)
local spellBookID = p.getSpellBookID(spellType)
if spellBookID ~= nil then
local spellBook = GameData.getEntityByID(p.spellBooks, spellBookID)
if spellBook ~= nil then
return spellBook.name
end
end
end
end


if MagicData[section] ~= nil then
function p._getSpellIconType(spell)
return processSpell(section, id + 1)
local spellBook = GameData.getEntityByID(p.spellBooks, spell.spellBook)
if spellBook == nil then
-- Pick a suitable default
return 'spell'
else
else
return nil
return spellBook.imgType
end
end
end
end


function p.getTypeString(type)
function p.getSpellIconType(frame)
if type == 'Auroras' then
local spellName = frame.args ~= nil and frame.args[1] or frame
return 'Aurora'
local spell = p.getSpell(spellName)
elseif type == 'Curses' then
if spell == nil then
return 'Curse'
return 'spell'
elseif type == 'AltMagic' then
else
return 'Alt. Magic'
return p._getSpellIconType(spell)
elseif type == 'Spells' then
return "Combat Spell"
elseif type == 'Ancient' then
return 'Ancient Magick'
end
end
end
end
Line 83: Line 135:
function p._getSpellIcon(spell, size)
function p._getSpellIcon(spell, size)
if size == nil then size = 50 end
if size == nil then size = 50 end
if spell.type == 'Auroras' then
local imgType = p._getSpellIconType(spell)
return Icons.Icon({spell.name, type='aurora', notext=true, size=size})
return Icons.Icon({spell.name, type=imgType, notext=true, size=size})
elseif spell.type == 'Curses' then
end
return Icons.Icon({spell.name, type='curse', notext=true, size=size})
 
function p._getSpellRequirements(spell)
-- All spells have a Magic level requirement
local extraReqs = {
{ ['type'] = 'SkillLevel', ['skillID'] = 'melvorD:Magic', ['level'] = spell.level }
}
if spell.requiredItemID ~= nil then
table.insert(extraReqs, { ['type'] = 'SlayerItem', ['itemID'] = spell.requiredItemID })
end
 
local resultPart = {}
for i, reqs in ipairs({ extraReqs, spell.requirements }) do
local reqStr = Common.getRequirementString(reqs)
if reqStr ~= nil then
table.insert(resultPart, reqStr)
end
end
 
if Shared.tableIsEmpty(resultPart) then
return 'None'
else
else
return Icons.Icon({spell.name, type='spell', notext=true, size=size})
return table.concat(resultPart, '<br/>')
end
end
end
end


function p._getSpellRequirements(spell)
local function formatRuneList(runes)
local result = ''
local runeList = {}
result = result..Icons._SkillReq('Magic', spell.level)
for i, req in ipairs(runes) do
if spell.requiredItem ~= nil and spell.requiredItem >= 0 then
local rune = Items.getItemByID(req.id)
local reqItem = Items.getItemByID(spell.requiredItem)
if rune ~= nil then
result = result..'<br/>'..Icons.Icon({reqItem.name, type='item', notext=true})..' equipped'
table.insert(runeList, Icons.Icon({rune.name, type='item', notext=true, qty=req.quantity}))
end
end
return table.concat(runeList, ', ')
end
 
 
function p._getSpellItems(spell)
if type(spell.fixedItemCosts) == 'table' then
local resultPart = {}
for i, req in ipairs(spell.fixedItemCosts) do
local item = Items.getItemByID(req.id)
if item ~= nil then
table.insert(resultPart, Icons.Icon({item.name, type='item', qty = req.quantity}))
end
end
return table.concat(resultPart, '<br/>')
else
return ''
end
end
if spell.requiredDungeonCompletion ~= nil then
end
local dung = Areas.getAreaByID('dungeon', spell.requiredDungeonCompletion[1])
 
result = result..'<br/>'..Icons.Icon({dung.name, type='dungeon', notext=true, qty=spell.requiredDungeonCompletion[2]})..' Clears'
function p.getSpellItems(frame)
local spellName = frame.args ~= nil and frame.args[1] or frame
local spell = p.getSpell(spellName)
if spell == nil then
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
end
end
return result
return p._getSpellItems(spell)
end
end


function p._getSpellRunes(spell)
function p._getSpellRunes(spell)
local formatRuneList = function(runes)
local runeList = {}
for i, req in ipairs(runes) do
local rune = Items.getItemByID(req.id)
if rune ~= nil then
table.insert(runeList, Icons.Icon({rune.name, type='item', notext=true, qty=req.qty}))
end
end
return table.concat(runeList, ', ')
end
if type(spell.runesRequired) == 'table' then
if type(spell.runesRequired) == 'table' then
local resultPart  = {}
local resultPart  = {}
Line 133: Line 216:
local spell = p.getSpell(spellName)
local spell = p.getSpell(spellName)
if spell == nil then
if spell == nil then
return "ERROR: No spell named "..spellName.." exists in the data module"
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
end
end
return p._getSpellRunes(spell)
return p._getSpellRunes(spell)
end
end


function p._getSpellDescription(spell)
-- Generates description template data. See: altMagic.js, description()
local result = ''
function p._getSpellTemplateData(spell)
local templateData = nil
if spell.spellBook == 'altMagic' then
if spell.produces ~= nil then
-- Item produced varies depending on items consumed
if spell.produces == 'Bar' then
templateData = {
["barAmount"] = spell.productionRatio,
["oreAmount"] = spell.specialCost.quantity
}
elseif spell.produces == 'GP' then
templateData = {
["percent"] = spell.productionRatio * 100
}
else
local itemProduced = Items.getItemByID(spell.produces)
local spellNS, spellLocalID = GameData.getLocalID(spell.id)
if itemProduced ~= nil and itemProduced.prayerPoints ~= nil and type(spell.fixedItemCosts) == 'table' and Shared.tableCount(spell.fixedItemCosts) == 1 and spellNS ~= 'melvorAoD' then
-- Item produced is a bone and spell is not from AoD (logic from altMagic.js)
local costItem = Items.getItemByID(spell.fixedItemCosts[1].id)
if costItem ~= nil then
templateData = {
["itemName"] = costItem.name,
["qty1"] = spell.fixedItemCosts[1].quantity,
["qty2"] = itemProduced.prayerPoints
}
end
end
end
end
if templateData == nil then
templateData = {
["amount"] = spell.productionRatio,
["percent"] = spell.productionRatio * 100,
["specialCostQty"] = spell.specialCost.quantity
}
if type(spell.fixedItemCosts) == 'table' then
for i, fixedCost in ipairs(spell.fixedItemCosts) do
local item = Items.getItemByID(fixedCost.id)
if item ~= nil then
templateData['fixedItemName' .. (i - 1)] = item.name
templateData['fixedItemQty' .. (i - 1)] = fixedCost.quantity
end
end
end
end
end
return (templateData or {})
end
 
function p._getSpellDescription(spell, inline)
if inline == nil then inline = false end
local connector = inline and '<br/>' or ' and '
if spell.description ~= nil then
if spell.description ~= nil then
if p.getSpellTypeIndex(spell.type) == 4 and string.find(spell.description, "<br>") ~= nil then
return Shared.applyTemplateData(spell.description, p._getSpellTemplateData(spell))
result = string.sub(spell.description, 0, string.find(spell.description, "<br>")-1)
elseif spell.modifiers ~= nil or spell.targetModifiers ~= nil then
else
local resultPart = {}
result = spell.description
if spell.modifiers ~= nil then
table.insert(resultPart, Constants.getModifiersText(spell.modifiers, false))
end
end
elseif (spell.modifiers ~= nil or spell.enemyModifiers ~= nil) then
if spell.targetModifiers ~= nil then
if spell.modifiers ~= nil then
local targetModText = Constants.getModifiersText(spell.targetModifiers, false, inline)
local playerModText = Constants.getModifiersText(spell.modifiers, false)
if inline then
result = playerModText
table.insert(resultPart, targetModText)
else
table.insert(resultPart, 'Enemies are inflicted with:<br/>' .. targetModText)
end
end
end
if spell.enemyModifiers ~= nil then
return table.concat(resultPart, connector)
local enemyModText = Constants.getModifiersText(spell.enemyModifiers, false)
elseif spell.specialAttackID ~= nil or spell.specialAttack ~= nil then
result = result .. (string.len(result) > 0 and '<br/>' or '') .. 'Enemies are inflicted with:<br/>' .. enemyModText
local spAtt = Attacks.getAttackByID(spell.specialAttackID or spell.specialAttack)
if spAtt ~= nil then
return spAtt.description
end
end
elseif spell.type == 'Spells' then
elseif spell.spellBook == 'standard' then
result = 'Combat spell with a max hit of '..(spell.maxHit * 10)
return 'Combat spell with a max hit of ' .. Shared.formatnum(spell.maxHit * 10)
else
return ''
end
end
return result
end
end


Line 174: Line 315:
return p._getSpellRunes(spell)
return p._getSpellRunes(spell)
elseif stat == 'type' then
elseif stat == 'type' then
return p.getTypeString(spell.type)
return p.getTypeString(spell.spellBook)
elseif stat == 'spellDamage' then
if spell.maxHit ~= nil then
return spell.maxHit * 10
else
return 0
end
end
end
return spell[stat]
return spell[stat]
Line 184: Line 331:
local spell = p.getSpell(spellName)
local spell = p.getSpell(spellName)
if spell == nil then
if spell == nil then
return "ERROR: No spell named "..spellName.." found"
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
end
end
return p._getSpellStat(spell, statName)
return p._getSpellStat(spell, statName)
Line 193: Line 340:
local spell = p.getSpell(spellName)
local spell = p.getSpell(spellName)
if spell == nil then
if spell == nil then
return "ERROR: No spell named "..spellName.." found"
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
end
end


local result = ''
local result = ''


--11/01/22: Added Spell Damage for standard & archaic spells
if spell.spellBook == 'standard' or spell.spellBook == 'archaic' then
result = result.."\r\n|-\r\n|'''Spell Damage:''' "..p._getSpellStat(spell, 'spellDamage')
end
--8/20/21: Changed to using the new getSpellDescription function
--8/20/21: Changed to using the new getSpellDescription function
result = result.."\r\n|-\r\n|'''Description:'''<br/>"..p._getSpellStat(spell, 'description')
result = result.."\r\n|-\r\n|'''Description:'''<br/>"..p._getSpellStat(spell, 'description')
Line 206: Line 357:
function p._getSpellCategories(spell)
function p._getSpellCategories(spell)
local result = '[[Category:Spells]]'
local result = '[[Category:Spells]]'
result = result..'[[Category:'..p.getTypeString(spell.type)..']]'
result = result..'[[Category:'..p.getTypeString(spell.spellBook)..']]'
return result
return result
end
end
Line 214: Line 365:
local spell = p.getSpell(spellName)
local spell = p.getSpell(spellName)
if spell == nil then
if spell == nil then
return "ERROR: No spell named "..spellName.." found"
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
end
end
return p._getSpellCategories(spell)
return p._getSpellCategories(spell)
end
end


function p.getSpellsForRune(runeID)
function p._getAltSpellCostText(spell)
if spell.specialCost ~= nil then
local costType = spell.specialCost.type
if costType == nil or costType == 'None' then
if type(spell.fixedItemCosts) == 'table' then
local costText = {}
for i, itemCost in ipairs(spell.fixedItemCosts) do
local item = Items.getItemByID(itemCost.id)
if item ~= nil then
table.insert(costText, Icons.Icon({item.name, type='item', qty=itemCost.quantity}))
end
end
if not Shared.tableIsEmpty(costText) then
return table.concat(costText, ', ')
end
else
return nil
end
else
local qty = Shared.formatnum(spell.specialCost.quantity)
local typeString = {
['AnyItem'] = qty .. ' of any item',
['BarIngredientsWithCoal'] = qty .. ' x required ores for the chosen bar',
['BarIngredientsWithoutCoal'] = qty .. ' x required ores (except ' .. Icons.Icon({'Coal Ore', type='item'}) .. ') for the chosen bar',
['JunkItem'] = qty .. ' of any [[Fishing#Junk|Junk]] item',
['SuperiorGem'] = qty .. ' of any superior gem',
['AnyNormalFood'] = qty .. ' x non-perfect food'
}
return typeString[costType]
end
end
end
 
function p.getSpellsProducingItem(itemID)
-- Only need to check Alt. Magic spells
local spellList = {}
 
-- Classify whether the item fits into various categories
local isBar, isShard, isGem, isSuperiorGem, isPerfectFood = false, false, false, false, false
local item = Items.getItemByID(itemID)
if item ~= nil then
isBar = not Shared.tableIsEmpty(GameData.getEntities(SkillData.Smithing.recipes,
function(recipe)
return recipe.categoryID == 'melvorD:Bars' and recipe.productID == item.id
end))
isShard = GameData.getEntityByProperty(SkillData.Magic.randomShards, 'itemID', item.id) ~= nil
isGem = GameData.getEntityByProperty('randomGems', 'itemID', itemID) ~= nil
--Runestone can't be created by Alt Magic spells that make random superior gems.
isSuperiorGem = item.type == 'Superior Gem' and item.id ~= SkillData.Mining.runestoneItemID
if item.healsFor ~= nil then
-- Item is food, but is it a product of perfect cooking?
local cookData = GameData.getSkillData('melvorD:Cooking')
if cookData ~= nil and cookData.recipes ~= nil then
isPerfectFood = GameData.getEntityByProperty(cookData.recipes, 'perfectCookID', itemID) ~= nil
end
end
end
 
for i, spell in ipairs(p.getSpellsBySpellBook('altMagic')) do
local includeSpell = false
if spell.produces ~= nil then
if spell.produces == itemID then
includeSpell = true
else
includeSpell = ((isBar and spell.produces == 'Bar') or
(isShard and spell.produces == 'RandomShards') or
(isGem and spell.produces == 'RandomGem') or
(isSuperiorGem and spell.produces == 'RandomSuperiorGem') or
(isPerfectFood and spell.produces == 'PerfectFood'))
end
if includeSpell then
table.insert(spellList, spell)
end
end
end
 
table.sort(spellList, function(a, b) return a.level < b.level end)
return spellList
end
 
-- If includeConsumes = true, then checks for Alt. Magic spell resource consumptions as well as
-- the rune cost of spells
function p.getSpellsUsingItem(itemID, includeConsumes)
if type(includeConsumes) ~= 'boolean' then
includeConsumes = false
end
local runeKeys = { 'runesRequired', 'runesRequiredAlt' }
local spellList = {}
local spellList = {}
for secName, secArray in Shared.skpairs(MagicData) do
for i, spell in pairs(secArray) do
-- Initialize some vars & only populate if we're including resource consumptions
local isJunkItem, isSuperiorGem, isNormalFood, isCoal, isBarIngredient = false, false, false, false, false
if includeConsumes then
local thisItem = Items.getItemByID(itemID)
local junkItemIDs = GameData.getSkillData('melvorD:Fishing').junkItemIDs
isJunkItem = Shared.contains(junkItemIDs, itemID)
isSuperiorGem = thisItem.type == 'Superior Gem'
if thisItem.healsFor ~= nil then
-- Item is food, but is it from cooking & is it normal or perfect?
local cookData = GameData.getSkillData('melvorD:Cooking')
if cookData ~= nil and cookData.recipes ~= nil then
isNormalFood = GameData.getEntityByProperty(cookData.recipes, 'productID', itemID) ~= nil
end
end
isCoal = itemID == 'melvorD:Coal_Ore'
if not isCoal then
-- Don't need to check if the item is another bar ingredient if we already know it is coal
local smithingRecipes = GameData.getSkillData('melvorD:Smithing').recipes
for i, recipe in ipairs(smithingRecipes) do
if recipe.categoryID == 'melvorD:Bars' then
for k, itemCost in ipairs(recipe.itemCosts) do
if itemCost.id == itemID then
isBarIngredient = true
break
end
end
if isBarIngredient then
break
end
end
end
end
end
 
-- Find applicable spells
for i, spellBook in ipairs(p.spellBooks) do
local spells = p.getSpellsBySpellBook(spellBook.id)
for j, spell in ipairs(spells) do
local foundSpell = false
local foundSpell = false
for j, req in pairs(spell.runesRequired) do
-- Check runes first
if req.id == runeID then
for k, runeKey in ipairs(runeKeys) do
table.insert(spellList, processSpell(secName, i))
if spell[runeKey] ~= nil then
foundSpell = true
for m, req in ipairs(spell[runeKey]) do
if req.id == itemID then
foundSpell = true
break
end
end
end
if foundSpell then
break
break
end
end
end
end
if spell.runesRequiredAlt ~= nil and not foundSpell then
if includeConsumes and not foundSpell then
for j, req in pairs(spell.runesRequiredAlt) do
-- Check items consumed by the spell
if req.id == runeID then
-- Fixed costs first, as that is a well-defined list of item IDs
table.insert(spellList, processSpell(secName, i))
if spell.fixedItemCosts ~= nil then
break
for k, itemCost in ipairs(spell.fixedItemCosts) do
if itemCost.id == itemID then
foundSpell = true
break
end
end
end
end
if not foundSpell and spell.specialCost ~= nil then
local costType = spell.specialCost.type
foundSpell = (isJunkItem and costType == 'JunkItem') or
(isSuperiorGem and costType == 'AnySuperiorGem') or
(isNormalFood and costType == 'AnyNormalFood') or
((isCoal or isBarIngredient) and costType == 'BarIngredientsWithCoal') or
(isBarIngredient and costType == 'BarIngredientsWithoutCoal')
end
end
end
if foundSpell then
table.insert(spellList, spell)
end
end
end
end
end
end
table.sort(spellList, function(a, b)
table.sort(spellList, function(a, b)
if a.type ~= b.type then
if a.spellBook ~= b.spellBook then
return p.getSpellTypeIndex(a.type) < p.getSpellTypeIndex(b.type)
return p.spellBookIndex[a.spellBook] < p.spellBookIndex[b.spellBook]
else
else
return a.level < b.level
return a.level < b.level
Line 251: Line 549:
end
end


function p.getSpellTypeIndex(type)
-- The below function is included for backwards compatibility
if type == 'Spells' then
function p.getSpellsForRune(runeID)
return 0
return p.getSpellsUsingItem(runeID, false)
elseif type == 'Curses' then
return 1
elseif type == 'Auroras' then
return 2
elseif type == 'Ancient' then
return 3
elseif type == 'AltMagic' then
return 4
end
return -1
end
end


function p.getSpellTypeLink(type)
function p.getSpellTypeLink(spellBookID)
if type == 'Spells' then
if spellBookID == 'standard' then
return Icons.Icon({'Magic', 'Standard', img='Standard', type='spellType'})
return Icons.Icon({'Standard Magic', 'Standard', img='Standard', type='spellType'})
elseif type == 'Curses' then
elseif spellBookID == 'ancient' then
return Icons.Icon({'Ancient Magicks', 'Ancient', img='Ancient', type='spellType'})
elseif spellBookID == 'archaic' then
return Icons.Icon({'Archaic Magicks', 'Archaic', img='Archaic', type='spellType'})
elseif spellBookID == 'curse' then
return Icons.Icon({'Curses', 'Curse', img='Curse', type='spellType'})
return Icons.Icon({'Curses', 'Curse', img='Curse', type='spellType'})
elseif type == 'Auroras' then
elseif spellBookID == 'aurora' then
return Icons.Icon({'Auroras', 'Aurora', img='Aurora', type='spellType'})
return Icons.Icon({'Auroras', 'Aurora', img='Aurora', type='spellType'})
elseif type == 'Ancient' then
elseif spellBookID == 'altMagic' then
return Icons.Icon({'Ancient Magicks', 'Ancient', img='Ancient', type='spellType'})
elseif type == 'AltMagic' then
return Icons.Icon({'Alt. Magic', type='skill'})
return Icons.Icon({'Alt. Magic', type='skill'})
end
end
Line 281: Line 571:
end
end


function p._getSpellRow(spell, includeTypeColumn)
function p._getSpellHeader(includeTypeColumn, includeItems, includeDamage, includeExperience)
local rowTxt = '\r\n|-\r\n|data-sort-value="'..spell.name..'"|'
local resultPart = {}
if spell.type == 'Auroras' then
table.insert(resultPart, '{|class="wikitable sortable"\n!colspan="2"| Spell')
rowTxt = rowTxt..Icons.Icon({spell.name, type='aurora', notext=true, size=50})
if includeTypeColumn then
elseif spell.type == 'Curses' then
table.insert(resultPart, 'Spellbook')
rowTxt = rowTxt..Icons.Icon({spell.name, type='curse', notext=true, size=50})
end
else
table.insert(resultPart, 'Requirements')
rowTxt = rowTxt..Icons.Icon({spell.name, type='spell', notext=true, size=50})
if includeDamage then
table.insert(resultPart, 'Spell Dmg')
end
end
rowTxt = rowTxt..'||'..Icons.Icon({spell.name, type='spell', noicon=true})
table.insert(resultPart, 'style="width:275px"| Description')
rowTxt = rowTxt..'||data-sort-value="'..spell.level..'"|'..Icons._SkillReq('Magic', spell.level)
if includeExperience then
--Handle required items/dungeon clears
table.insert(resultPart, 'XP')
if spell.requiredItem ~= nil and spell.requiredItem >= 0 then
local reqItem = Items.getItemByID(spell.requiredItem)
rowTxt = rowTxt..'<br/>'..Icons.Icon({reqItem.name, type='item', notext=true})..' equipped'
end
end
if spell.requiredDungeonCompletion ~= nil then
table.insert(resultPart, 'style="min-width:90px"| Runes')
local dung = Areas.getAreaByID('dungeon', spell.requiredDungeonCompletion[1])
if includeItems then
rowTxt = rowTxt..'<br/>'..Icons.Icon({dung.name, type='dungeon', notext=true, qty=spell.requiredDungeonCompletion[2]})..' Clears'
table.insert(resultPart, 'Item Cost')
end
end
return table.concat(resultPart, '\n! ')
end


function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage, includeExperience)
local spellBookIdx = p.spellBookIndex[spell.spellBook]
local spellBook = p.spellBooks[spellBookIdx]
local rowPart = {'\n|-\n|data-sort-value="' .. spell.name .. '"| '}
table.insert(rowPart, Icons.Icon({spell.name, type=spellBook.imgType, notext=true, size=50}))
table.insert(rowPart, '|| ' .. Icons.getExpansionIcon(spell.id) .. Icons.Icon({spell.name, type=spellBook.imgType, noicon=true}))
if includeTypeColumn then
if includeTypeColumn then
rowTxt = rowTxt..'||data-sort-value="'..p.getSpellTypeIndex(spell.type)..'"|'
table.insert(rowPart, '||data-sort-value="' .. spellBookIdx .. '"| ' .. p.getSpellTypeLink(spell.spellBook))
rowTxt = rowTxt..p.getSpellTypeLink(spell.type)
end
end
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell))
--11/01/22: Added base damage if requested
if includeDamage then
local dmg = p._getSpellStat(spell, 'spellDamage')
table.insert(rowPart, (dmg > 0 and '||style="text-align:right"| ' .. dmg or '||class="table-na"| N/A'))
end
--8/20/21: Changed to just getting the spell's description outright
--8/20/21: Changed to just getting the spell's description outright
rowTxt = rowTxt..'||'..p._getSpellStat(spell, 'description')
table.insert(rowPart, '|| ' .. p._getSpellStat(spell, 'description'))
--1/4/22: haha just kidding. Now we're also getting delay between attacks for spells with special attacks
--1/4/22: haha just kidding. Now we're also getting delay between attacks for spells with special attacks
if spell.specialAttack ~= nil then
local spAttID = spell.specialAttackID or spell.specialAttack
local spAtt = spell.specialAttack
if spAttID ~= nil then
local interval = spAtt.attackInterval ~= nil and spAtt.attackInterval or -1
local spAtt = Attacks.getAttackByID(spAttID)
if interval ~= -1 then
local interval = spAtt.attackInterval
local hits = spAtt.attackCount ~= nil and spAtt.attackCount or 1
local hits = spAtt.attackCount ~= nil and spAtt.attackCount or 1
rowTxt = rowTxt..'<br/>('
if interval ~= nil and hits > 1 then
rowTxt = rowTxt..Shared.round(interval / 1000, 2, 2)..'s delay between attacks.'
table.insert(rowPart, '<br/>(' .. Shared.round(interval / 1000, 2, 2) .. 's delay between attacks.')
if hits > 2 then
if hits > 2 then
rowTxt = rowTxt..' '..Shared.round(interval * (hits - 1) / 1000, 2, 2)..'s total duration.'
table.insert(rowPart, ' ' .. Shared.round(interval * (hits - 1) / 1000, 2, 2) .. 's total duration.')
end
end
rowTxt = rowTxt..')'
table.insert(rowPart, ')')
end
end
end
end
if p.getSpellTypeIndex(spell.type) == 4 then
if includeExperience then
rowTxt = rowTxt..'||'..spell.baseExperience
local xp = spell.baseExperience
table.insert(rowPart, ((xp == nil or xp == 0) and '||class="table-na"| N/A' or '||style="text-align:right"| ' .. xp))
end
end
rowTxt = rowTxt..'||style="text-align:center"|'
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
rowTxt = rowTxt..p._getSpellRunes(spell)
if includeItems then
return rowTxt
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellItems(spell))
end
return table.concat(rowPart)
end
end


function p.getStandardSpellsTable(frame)
function p._getSpellTable(spellList, includeTypeColumn)
local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
if type(spellList) == 'table' and not Shared.tableIsEmpty(spellList) then
result = result..'!!Requirements'
local includeSpellbook, includeItems, includeDamage, includeExperience = false, false, false, false
result = result..'!!style="width:275px"|Description'
if type(includeTypeColumn) == 'boolean' then
result = result..'!!Runes'
includeSpellbook = includeTypeColumn
local spellList = {}
end
for i, spell in Shared.skpairs(MagicData.Spells) do
-- Check to see what columns are required
local rowTxt = p._getSpellRow(processSpell('Spells', i), false)
for i, spell in ipairs(spellList) do
result = result..rowTxt
if not includeItems and p._getSpellItems(spell) ~= '' then
includeItems = true
end
if not includeExperience and spell.spellBook == 'altMagic' then
includeExperience = true
end
if not includeDamage and (spell.spellBook == 'archaic' or spell.spellBook == 'standard') then
includeDamage = true
end
end
 
local spellListSorted = Shared.shallowClone(spellList)
table.sort(spellListSorted, function(a, b) return a.level < b.level end)
local resultPart = {p._getSpellHeader(includeSpellbook, includeItems, includeDamage, includeExperience)}
for i, spell in ipairs(spellListSorted) do
table.insert(resultPart, p._getSpellRow(spell, includeSpellbook, includeItems, includeDamage, includeExperience))
end
 
table.insert(resultPart, '\n|}')
return table.concat(resultPart)
end
end
result = result..'\r\n|}'
return result
end
end


function p.getCurseTable(frame)
function p.getSpellTableFromList(frame)
local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
local args = frame.args ~= nil and frame.args or frame
result = result..'!!Requirements'
local spellListText = args[1]
result = result..'!!style="width:275px"|Description'
local includeSpellbook = args.includeSpellbook ~= nil and string.lower(args.includeSpellbook) == 'true'
result = result..'!!Runes'
local spellNames = Shared.splitString(spellListText, ',')
local spellList = {}
local spellList = {}
for i, spell in Shared.skpairs(MagicData.Curses) do
for i, spellName in ipairs(spellNames) do
local rowTxt = p._getSpellRow(processSpell('Curses', i), false)
local spell = p.getSpell(spellName)
result = result..rowTxt
if spell == nil then
return Shared.printError('No spell named "' .. spellName .. '" exists in the data module')
else
table.insert(spellList, spell)
end
end
end
result = result..'\r\n|}'
return p._getSpellTable(spellList, includeSpellbook)
return result
end
 
function p.getSpellBookTable(frame)
local spellBook = frame.args ~= nil and frame.args[1] or frame[1]
spellBook = p.getSpellBookID(spellBook)
return p._getSpellTable(p.getSpellsBySpellBook(spellBook), false)
end
end


function p.getAuroraTable(frame)
-- Included below for backwards compatibility
local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
function p.getStandardSpellsTable(frame)
result = result..'!!Requirements'
return p._getSpellTable(p.getSpellsBySpellBook('standard'), false)
result = result..'!!style="width:275px"|Description'
result = result..'!!Runes'
for i, spell in Shared.skpairs(MagicData.Auroras) do
local rowTxt = p._getSpellRow(processSpell('Auroras', i), false)
result = result..rowTxt
end
result = result..'\r\n|}'
return result
end
end


function p.getAncientTable(frame)
function p.getAncientTable(frame)
local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
return p._getSpellTable(p.getSpellsBySpellBook('ancient'), false)
result = result..'!!Requirements'
end
result = result..'!!style="width:275px"|Description'
 
result = result..'!!Runes'
function p.getCurseTable(frame)
for i, spell in Shared.skpairs(MagicData.Ancient) do
return p._getSpellTable(p.getSpellsBySpellBook('curse'), false)
local rowTxt = p._getSpellRow(processSpell('Ancient', i), false)
end
result = result..rowTxt
 
end
function p.getAuroraTable(frame)
result = result..'\r\n|}'
return p._getSpellTable(p.getSpellsBySpellBook('aurora'), false)
return result
end
end


function p.getAltSpellsTable(frame)
function p.getAltSpellsTable(frame)
local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
return p._getSpellTable(p.getSpellsBySpellBook('altMagic'), false)
result = result..'!!Requirements'
result = result..'!!style="width:275px"|Description'
result = result..'!!Experience'
result = result..'!!Runes'
local spellList = {}
for i, spell in Shared.skpairs(MagicData.AltMagic) do
local rowTxt = p._getSpellRow(processSpell('AltMagic', i), false)
result = result..rowTxt
end
result = result..'\r\n|}'
return result
end
end


return p
return p