Module:Items/ComparisonTables: Difference between revisions

Add two-handed indicator column for weapon tables
m (I'm dumb. Properly fixed the DR table)
(Add two-handed indicator column for weapon tables)
 
(42 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Modifiers = require('Module:Modifiers')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Num = require('Module:Number')
local FL = require('Module:FunList')


local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}
local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}


local styleOverrides = {
local styleOverrides = {
Melee = {'Slayer Helmet (Basic)', 'Slayer Platebody (Basic)', 'Paladin Gloves', 'Desert Wrappings', 'Almighty Lute', 'Candy Cane', 'Bob's Rake', "Knight's Defender", "Ward of Flame Platebody"},
Melee = {'Slayer Helmet (Basic)', 'Slayer Platebody (Basic)', 'Paladin Gloves', 'Desert Wrappings', 'Almighty Lute', 'Candy Cane', "Bob's Rake", "Knight's Defender", "Ward of Flame Platebody"},
Ranged = {'Slayer Cowl (Basic)', 'Slayer Leather Body (Basic)', 'Ice Arrows'},
Ranged = {'Slayer Cowl (Basic)', 'Slayer Leather Body (Basic)', 'Ice Arrows'},
Magic = {'Slayer Wizard Hat (Basic)', 'Slayer Wizard Robes (Basic)', 'Enchanted Shield', 'Elementalist Gloves', 'Frostspark Boots', 'Freezing Touch Body', 'Lightning Boots'},
Magic = {'Slayer Wizard Hat (Basic)', 'Slayer Wizard Robes (Basic)', 'Enchanted Shield', 'Elementalist Gloves', 'Frostspark Boots', 'Freezing Touch Body', 'Lightning Boots'},
Line 19: Line 22:
}
}


function p._getEquipmentTable(itemList, includeModifiers, includeDescription, sortByName)
local slotOverrides = {
if includeModifiers == nil then includeModifiers = false end
['Enhancement'] = 'melvorD:Enhancement'
if sortByName == nil then sortByName = false end
}


--Getting some lists set up here that will be used later
local itemStyleOverrides = {
--First, the list of columns used by both weapons & armour
['Melee'] = {
local statColumns = {'stabAttackBonus', 'slashAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'meleeStrengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'meleeDefenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}
'melvorF:Slayer_Helmet_Basic',
'melvorF:Slayer_Platebody_Basic',
'melvorF:Paladin_Gloves',
'melvorF:Desert_Wrappings',
'melvorF:Knights_Defender',
},
['Ranged'] = {
'melvorF:Slayer_Cowl_Basic',
'melvorF:Slayer_Leather_Body_Basic',
'melvorD:Cape_Of_Prat',
'melvorD:Ice_Arrows',
},
['Magic'] = {
'melvorF:Slayer_Wizard_Hat_Basic',
'melvorF:Slayer_Wizard_Robes_Basic',
'melvorF:Skull_Cape',
'melvorD:Enchanted_Shield',
'melvorF:Elementalist_Gloves',
'melvorTotH:Freezing_Touch_Body',
'melvorTotH:Lightning_Boots',
},
['Other'] = {


if Shared.tableIsEmpty(itemList) then
}
return Shared.printError('You must select at least one item to get stats for')
}
end


local isWeaponType = ((itemList[1].validSlots ~= nil and Shared.contains(itemList[1].validSlots, 'Weapon'))
-- Categorise equipment by:
or (itemList[1].occupiesSlots ~= nil and Shared.contains(itemList[1].occupiesSlots, 'Weapon'))) and Shared.contains(weaponTypes, itemList[1].type)
-- - Equipment slot ID
-- - Style (Melee, Ranged, Magic, Other)
p.SlotEquipment = {}


--Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection)
function p.populateSlotEquipment()
local ignoreColumns = Shared.clone(statColumns)
-- Populate from item data
for i, item in pairs(itemList) do
local hiddenItems = {}
local ndx = 1
for _, itemID in ipairs(Items.HiddenItems) do
while Shared.tableCount(ignoreColumns) >= ndx do
hiddenItems[itemID] = true
if Items._getItemStat(item, ignoreColumns[ndx], true) ~= 0 then
table.remove(ignoreColumns, ndx)
else
ndx = ndx + 1
end
end
end
end


--Now to remove the ignored columns (and also we need to track groups like defence bonuses to see how many remain)
-- Transform style overrides into a form where items are indexed by ID
local attBonusCols = 5
local styleOverrides = {}
local strBonusCols = 2
for overType, itemIDs in pairs(itemStyleOverrides) do
local defBonusCols = 3
for _, itemID in ipairs(itemIDs) do
local lvlReqCols = 4
styleOverrides[itemID] = overType
local ndx = 1
while Shared.tableCount(statColumns) >= ndx do
local colName = statColumns[ndx]
if Shared.contains(ignoreColumns, colName) then
if Shared.contains(colName, 'AttackBonus') then attBonusCols = attBonusCols - 1 end
if Shared.contains(colName, 'trengthBonus') then strBonusCols = strBonusCols - 1 end
if Shared.contains(colName, 'efenceBonus') then defBonusCols = defBonusCols - 1 end
if Shared.contains(colName, 'LevelRequired') then lvlReqCols = lvlReqCols - 1 end
table.remove(statColumns, ndx)
else
ndx = ndx + 1
end
end
end
end


--Alright, let's start the table by building the shared header
for _, item in ipairs(GameData.rawData.items) do
local resultPart = {}
if (
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"')
-- Item is not hidden (includes debug items)
if isWeaponType then
hiddenItems[item.id] == nil
--Weapons have extra columns here for Attack Speed and "Two Handed?"
-- Item isn't exclusive to Golbin Raid minigame
table.insert(resultPart, '\r\n!colspan="4"|')
and (item.golbinRaidExclusive == nil or not item.golbinRaidExclusive)
else
-- Item can be equipped to any slot
table.insert(resultPart, '\r\n!colspan="2"|')
and item.validSlots ~= nil
end
) then
if attBonusCols > 0 then
-- Item is equippment to be included within equipment tables
table.insert(resultPart, '\r\n!colspan="'..attBonusCols..'"|Attack Bonus')
local equipEntry = {
end
['item'] = item,
if strBonusCols > 0 then
['slots'] = {},
table.insert(resultPart, '\r\n!colspan="'..strBonusCols..'"|Str. Bonus')
['isWeapon'] = nil,
end
['style'] = nil
if Shared.contains(statColumns, 'magicDamageBonus') then
}
table.insert(resultPart, '\r\n!colspan="1"|% Dmg Bonus')
-- Determine which slots the equipment can be equipped to
end
local occupiesSlots = item.occupiesSlots or {}
if defBonusCols > 0 then
for _, slotLocalID in ipairs(item.validSlots) do
table.insert(resultPart, '\r\n!colspan="'..defBonusCols..'"|Defence Bonus')
local newSlotID = slotLocalID
end
-- Classify javelins and throwing knives as weapons
if Shared.contains(statColumns, 'damageReduction') then
if slotLocalID == 'Quiver' and Shared.contains({'Javelins', 'ThrowingKnives'}, item.ammoType) then
table.insert(resultPart, '\r\n!colspan="1"|DR')
newSlotID = 'Weapon'
end
-- Combine all enhancements
if lvlReqCols > 0 then
elseif Shared.contains({'Enhancement1', 'Enhancement2', 'Enhancement3'}, slotLocalID) then
table.insert(resultPart, '\r\n!colspan="'..lvlReqCols..'"|Lvl Req')
newSlotID = 'Enhancement'
end
if includeModifiers and includeDescription then
table.insert(resultPart, '\r\n!colspan="2"|')
elseif includeModifiers or includeDescription then
table.insert(resultPart, '\r\n!colspan="1"|')
end
--One header row down, one to go
table.insert(resultPart, '\r\n|-class="headerRow-1"')
table.insert(resultPart, '\r\n!Item')
table.insert(resultPart, '\r\n!Name')
--Weapons have Attack Speed here
if isWeaponType then
table.insert(resultPart, '\r\n!Attack Speed')
table.insert(resultPart, '\r\n!Two Handed?')
end
--Attack bonuses
if Shared.contains(statColumns, 'slashAttackBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Attack', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'stabAttackBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Strength', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'blockAttackBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Defence', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'rangedAttackBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Ranged', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'magicAttackBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Magic', type='skill', notext='true'}))
end
--Strength bonuses
if Shared.contains(statColumns, 'meleeStrengthBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Strength', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'rangedStrengthBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Ranged', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'magicDamageBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Magic', type='skill', notext='true'}))
end
--Defence bonuses
if Shared.contains(statColumns, 'meleeDefenceBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Defence', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'rangedDefenceBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Ranged', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'magicDefenceBonus') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Magic', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'damageReduction') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Defence', type='skill', notext='true'}))
end
--Level requirements
if Shared.contains(statColumns, 'attackLevelRequired') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Attack', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'defenceLevelRequired') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Defence', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'rangedLevelRequired') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Ranged', type='skill', notext='true'}))
end
if Shared.contains(statColumns, 'magicLevelRequired') then
table.insert(resultPart, '\r\n!'..Icons.Icon({'Magic', type='skill', notext='true'}))
end
--If includeModifiers is set to 'true', add the Modifiers column
if includeModifiers then
table.insert(resultPart, '\r\n!Modifiers')
end
--If includeDescription is set to 'true', add the Description column
if includeDescription then
table.insert(resultPart, '\r\n!Description')
end
 
if sortByName then
table.sort(itemList, function(a, b) return a.name < b.name end)
end
for i, item in ipairs(itemList) do
if isWeaponType then
--Building rows for weapons
local atkSpeed = Items._getItemStat(item, 'attackSpeed', true)
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|style="text-align: centre;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
table.insert(resultPart, '\r\n|' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
table.insert(resultPart, '\r\n| data-sort-value="' .. atkSpeed .. '" style="text-align:right;" |'..Shared.round(atkSpeed / 1000, 3, 1) .. 's')
--That's the first list out of the way, now for 2-Handed
table.insert(resultPart, '\r\n| style="text-align: right;"|')
table.insert(resultPart, Items._getItemStat(item, 'isTwoHanded') and 'Yes' or 'No')
for j, statName in pairs(statColumns) do
local statValue = Items._getItemStat(item, statName, true)
table.insert(resultPart, '\r\n| style="text-align:right;" class="')
if string.find(statName, '^(.+)LevelRequired$') == nil then
if statValue > 0 then
table.insert(resultPart, 'table-positive')
elseif statValue < 0 then
table.insert(resultPart, 'table-negative')
end
end
end
table.insert(resultPart, '"|'..Shared.formatnum(statValue))
equipEntry.slots[newSlotID] = true
if statName == 'magicDamageBonus' or statName == 'damageReduction' then table.insert(resultPart, '%') end
end
end
--If requested, add the item Modifiers
equipEntry.isWeapon = equipEntry.slots['Weapon'] or Shared.contains(occupiesSlots, 'Weapon')
if includeModifiers then
 
table.insert(resultPart, '\r\n|')
-- Determine the style of the item (Melee, Ranged, Magic, Other)
local txtLines = {}
local function hasSkillReq(reqs, localSkillID)
local modTxt = Constants.getModifiersText(item.modifiers, true)
if reqs ~= nil then
if modTxt ~= '' then
local skillID = Shared.getNamespacedID('melvorD', localSkillID)
table.insert(txtLines, modTxt)
for levelType, typeReqs in pairs(reqs) do
end
if typeReqs[skillID] ~= nil then
--For items with a special attack, show the details
return true
if item.specialAttacks ~= nil and not Shared.tableIsEmpty(item.specialAttacks) then
end
table.insert(txtLines, "'''Special Attack:'''")
for i, spAttID in ipairs(item.specialAttacks) do
local spAtt = GameData.getEntityByID('attacks', spAttID)
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.description)
end
end
end
end
table.insert(resultPart, table.concat(txtLines, '<br/>'))
return false
end
end
--If requested, add description
local levelReqs = Items._getItemLevelReqs(item)
if includeDescription then
-- Apply any overrides first
table.insert(resultPart, '\r\n| ')
if styleOverrides[item.id] ~= nil then
table.insert(resultPart, Constants.getDescription(item.customDescription, item.modifiers) or '')
equipEntry.style = styleOverrides[item.id]
end
-- Weapon styles can be checked using the attackType property
else
elseif equipEntry.isWeapon and Shared.contains({'melee', 'ranged', 'magic'}, item.attackType) then
--Building rows for armour
equipEntry.style = Shared.titleCase(item.attackType)
table.insert(resultPart, '\r\n|-')
-- Magic
table.insert(resultPart, '\r\n|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
elseif hasSkillReq(levelReqs, 'Magic') then
table.insert(resultPart, '\r\n|' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
equipEntry.style = 'Magic'
for j, statName in pairs(statColumns) do
-- Ranged
local statValue = Items._getItemStat(item, statName, true)
elseif (
table.insert(resultPart, '\r\n|style="text-align:right;" class="')
hasSkillReq(levelReqs, 'Ranged')
if statValue > 0 then
or equipEntry.slots.Quiver ~= nil
table.insert(resultPart, 'table-positive')
or item.ammoType ~= nil
elseif statValue < 0 then
) then
table.insert(resultPart, 'table-negative')
equipEntry.style = 'Ranged'
end
-- Melee
table.insert(resultPart, '"|'..Shared.formatnum(statValue))
elseif (
if statName == 'magicDamageBonus' or statName == 'damageReduction' then table.insert(resultPart, '%') end
hasSkillReq(levelReqs, 'Attack')
end
or hasSkillReq(levelReqs, 'Defence')
--If requested, add the item Modifiers
) then
if includeModifiers then
equipEntry.style = 'Melee'
table.insert(resultPart, '\r\n| ')
-- Other, default style if unmatched
local txtLines = {}
else
local modTxt = Constants.getModifiersText(item.modifiers, true)
equipEntry.style = 'Other'
if modTxt ~= '' then
table.insert(txtLines, modTxt)
end
--For items with a special attack, show the details
if item.specialAttacks ~= nil and not Shared.tableIsEmpty(item.specialAttacks) then
table.insert(txtLines, "'''Special Attack:'''")
for i, spAttID in ipairs(item.specialAttacks) do
local spAtt = GameData.getEntityByID('attacks', spAttID)
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.description)
end
end
table.insert(resultPart, table.concat(txtLines, '<br/>'))
end
--If requested, add description
if includeDescription then
table.insert(resultPart, '\r\n| ')
table.insert(resultPart, Constants.getDescription(item.customDescription, item.modifiers) or '')
end
end
-- Finally, add the entry into the slotEquipment table
table.insert(p.SlotEquipment, equipEntry)
end
end
end
end
end


table.insert(resultPart, '\r\n|}')
p.populateSlotEquipment()


return table.concat(resultPart)
local function getEquipItemList(filter)
local equip = GameData.getEntities(p.SlotEquipment, function(x) return filter(x) end)
local items = {}
for _, entry in ipairs(equip) do
table.insert(items, entry.item)
end
return items
end
end


function p._getCategoryTable(style, slot, other, includeModifiers, includeDescription, sortByName)
local function getSlotID(slot)
if type(slot) == 'number' then
local slotID = Shared.getNamespacedID('melvorD', slot)
slot = Constants.getEquipmentSlotName(slot)
local slotData = GameData.getEntityByID('equipmentSlots', slotID)
 
if slotData == nil then
if slotOverrides[slot] ~= nil then
return slotOverrides[slot]
end
 
-- slotID invalid, check if user provided a slot name
slotData = GameData.getEntityByProperty('equipmentSlots', 'emptyName', slot)
if slotData == nil then
return nil
end
slotID = slotData.id
end
end
return slotID
end


local itemList = Items.getItems(function(item)
local function getItemDesc(item)
-- Exclude Golbin raid exclusives for now, such that they don't
if item.customDescription ~= nil then
-- pollute various equipment tables
return item.customDescription
if item.golbinRaidExclusive ~= nil and item.golbinRaidExclusive then
elseif item.modifiers ~= nil then
return false
return Modifiers.getModifiersText(item.modifiers, false, false)
end
else
local isMatch = true
return ''
if style == 'Melee' then
end
if ((Items._getItemStat(item, 'defenceLevelRequired') == nil and Items._getItemStat(item, 'attackLevelRequired') == nil) and not Shared.contains(styleOverrides.Melee, item.name)) or Shared.contains(styleOverrides.NotMelee, item.name) then isMatch = false end
end
elseif style == 'Ranged' then
if (Items._getItemStat(item, 'rangedLevelRequired') == nil and not Shared.contains(styleOverrides.Ranged, item.name)) or Shared.contains(styleOverrides.NotRanged, item.name)  then isMatch = false end
elseif style == 'Magic' then
if (Items._getItemStat(item, 'magicLevelRequired') == nil and not Shared.contains(styleOverrides.Magic, item.name)) or Shared.contains(styleOverrides.NotMagic, item.name) then isMatch = false end
elseif style == 'None' then
if (Items._getItemStat(item, 'defenceLevelRequired') ~= nil or Items._getItemStat(item, 'rangedLevelRequired') ~= nil or Items._getItemStat(item, 'magicLevelRequired') ~= nil or
Shared.contains(styleOverrides.Melee, item.name) or Shared.contains(styleOverrides.Ranged, item.name) or Shared.contains(styleOverrides.Magic, item.name)) and
not Shared.contains(styleOverrides.None, item.name) then
isMatch = false
end
end
if slot == nil or not Shared.contains(item.validSlots, slot) then isMatch = false end


if isMatch and other ~= nil then
local function getItems(slotID, style)
if slot == 'Cape' then
local _, slotLocalID = Shared.getLocalID(slotID)
-- TODO Would be more reliable if based on items appearing within the relevant shop categories instead
local isSkillcape = Shared.contains(item.name, 'Skillcape') or Shared.contains(item.name, 'Cape of Completion')
if other == 'Skillcapes' then
isMatch = isSkillcape
elseif other == 'No Skillcapes' then
isMatch = not isSkillcape
end
end
if slot == 'Weapon' then --For quiver slot or weapon slot, 'other' is the ammo type
isMatch = other == item.ammoTypeRequired
elseif slot == 'Quiver' then
if other == 'Thrown' and Shared.contains({'Javelins', 'ThrowingKnives'}, item.ammoType) then
isMatch = true
else
isMatch = other == item.ammoType
end
end
end


return isMatch
return getEquipItemList(
end)
function(entry)
return (
return p._getEquipmentTable(itemList, includeModifiers, includeDescription, sortByName)
entry.slots[slotLocalID] ~= nil
and (style == nil or style == '' or style == entry.style)
)
end
)
end
end


function p.getCategoryTable(frame)
--== Helper Functions for getCategoryTable ==--
local style = frame.args ~= nil and frame.args[1] or frame[1]
local function createStatCell(row, statVal)
local slot = frame.args ~= nil and frame.args[2] or frame[2]
local cell = row:tag('td')
local other = frame.args ~= nil and frame.args[3] or frame[3]
if statVal > 0 then
local includeModifiers = frame.args ~= nil and frame.args.includeModifiers or frame.includeModifiers
cell:addClass('table-positive')
local includeDescription = frame.args ~= nil and frame.args.includeDescription or frame.includeDescription
elseif statVal < 0 then
local sortByName = frame.args ~= nil and frame.args.sortByName or frame.sortByName
cell:addClass('table-negative')
end
if math.abs(statVal) >= 1000 then
cell:attr('data-sort-value', statVal)
end
cell:css('text-align', 'right')
return cell
end


includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false
local function addStatCell(row, item, stat)
includeDescription = includeDescription ~= nil and string.upper(includeDescription) == 'TRUE' or false
local statVal = 0
sortByName = sortByName ~= nil and string.upper(sortByName) == 'TRUE' or false
if item.equipmentStats ~= nil then
statVal = item.equipmentStats[stat] or 0
end
return createStatCell(row, statVal)
:wikitext(Num.formatnum(statVal))
end


return p._getCategoryTable(style, slot, other, includeModifiers, includeDescription, sortByName)
local function addDRCell(row, item)
local dr = 0
local icon = nil
-- Grab damage reduction figure
if item.equipmentStats ~= nil then
if item.equipmentStats.damageReduction then
dr, icon = item.equipmentStats.damageReduction, 'Damage Reduction'
elseif item.equipmentStats.resistanceAbyssal then
dr, icon = item.equipmentStats.resistanceAbyssal, 'Abyssal Resistance'
elseif item.equipmentStats.resistanceEternal then
dr, icon = item.equipmentStats.resistanceEternal, 'Eternal Resistance'
end
end
local cell = createStatCell(row, dr)
-- Add DR icons, if there's any value
if dr ~= 0 then
cell:wikitext(Icons.Icon({icon, size=15, notext='true'}) .. ' ')
end
-- Add DR value
cell:wikitext(dr .. '%')
return cell
end
end


function p.getTableForList(frame)
local function getRequirements(item)
local stuffString = frame.args ~= nil and frame.args[1] or frame[1]
if item.equipRequirements == nil then
local itemNames = Shared.splitString(stuffString, ',')
return nil
end
local function getSkillName(skillID)
local _, localSkillID = GameData.getLocalID(skillID)
return localSkillID
end
local iconFuncs = {
['AbyssalLevel'] = function(x)
return Icons._SkillRealmIcon(getSkillName(x.skillID), 'melvorItA:Abyssal') .. ' ' .. x.level
end,
['SkillLevel'] = function(x)
return Icons._SkillRealmIcon(getSkillName(x.skillID)) .. ' ' .. x.level
end,
}
local reqs = {}
local abyssalSkills = {}
local highestLvReq = 0
-- Filter out all Abyssal Levels
    for _, req in ipairs(item.equipRequirements) do
        if req.type == 'AbyssalLevel' then abyssalSkills[req.skillID] = true end
    end
-- If the req is a SkillLevel, but the skillID is already an AbyssalLevel, skip the entry
-- These are likely 99 Level requirements in addition to the AbyssalLevel requirement.
    for _, req in ipairs(item.equipRequirements) do
if not (req.type == 'SkillLevel' and abyssalSkills[req.skillID] == true) then
-- Add requirement via factory function.
local func = iconFuncs[req.type]
if func then table.insert(reqs, func(req)) end
-- Track highest level for data sorting.
local lv = req.level or 0
if lv > highestLvReq then highestLvReq = lv end
end
    end
   
    if Shared.tableIsEmpty(abyssalSkills) == false then
    highestLvReq = highestLvReq + 200
    end


local includeModifiers = frame.args ~= nil and frame.args[2] or frame[2]
return {
includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false
['datasortvalue'] = highestLvReq,
['requirements'] = table.concat(reqs, '<br>')
}
end


local itemList = {}
function p.getEquipmentTable(itemList, slot, style)
local errMsg = 'Some items not found in database: '
local iconSize = 20
local hasErr = false
local fl = FL.new(itemList)
for i, name in Shared.skpairs(itemNames) do
local nextItem = Items.getItem(Shared.trim(name))
-- If slot is nil, find out if we have any weapons.
if nextItem == nil then
if slot == nil then
errMsg = errMsg.." '"..name.."'"
if fl:any(function(x) return Shared.contains(x.validSlots, 'Weapon') end) then
hasErr = true
slot = 'Weapon'
else
table.insert(itemList, nextItem)
end
end
end
end
-- Sort itemList by name
itemList = fl:sortBy(function(x) return x.name end)
:sort()
:toTable()
local isWeapon = (slot == 'Weapon')
local itemColspan = (isWeapon and 5) or 3
local html = mw.html.create('table')
:addClass('wikitable sortable stickyHeader')
:addClass('col-1-center col-3-center')


if hasErr then
local header0 = html:tag('tr'):addClass('headerRow-0')
return Shared.printError(errMsg)
header0:tag('th'):attr('colspan', itemColspan)
else
header0:tag('th'):attr('colspan', 5)
return p._getEquipmentTable(itemList, includeModifiers)
:wikitext("Attack Bonus")
header0:tag('th'):attr('colspan', 3)
:wikitext("Strength Bonus")
header0:tag('th'):attr('colspan', 3)
:wikitext("Defence Bonus")
 
header0:tag('th'):wikitext("DR/AR")
header0:tag('th'):wikitext()
local header1 = html:tag('tr'):addClass('headerRow-1')
header1:tag('th'):wikitext('Name')
:attr('colspan', 2)
header1:tag('th'):wikitext('DLC')
if isWeapon == true then
header1:tag('th'):wikitext('Two<br>Handed')
header1:tag('th'):wikitext('Attack<br>Speed')
end
end
end


function p.getDoubleLootTable(frame)
-- Attack bonuses
local modsDL = {
header1:tag('th'):wikitext(Icons.Icon({'Attack', type='skill', size=iconSize, notext='true'}))
'increasedChanceToDoubleLootCombat',
header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
'decreasedChanceToDoubleLootCombat',
header1:tag('th'):wikitext(Icons.Icon({'Defence', type='skill', size=iconSize, notext='true'}))
'increasedChanceToDoubleLootThieving',
header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
'decreasedChanceToDoubleLootThieving',
header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))
'increasedChanceToDoubleItemsGlobal',
 
'decreasedChanceToDoubleItemsGlobal'
--Strength bonuses
}
header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
local modDetail = {}
header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
for i, modName in pairs(modsDL) do
header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))
local mName, mText, mSign, mIsNeg, mValUnsigned = Constants.getModifierDetails(modName)
 
modDetail[modName] = { mult = (mSign == "+" and 1 or -1) }
--Defence bonuses
end
header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))
-- Damage reduction
header1:tag('th'):wikitext(Icons.Icon({'Damage Reduction', size=iconSize, notext='true'}))
--Level requirements
header1:tag('th'):wikitext('Equip Req')
 
-- Fill the table with all items
for _, item in ipairs(itemList) do
local row = html:tag('tr')
row:tag('td'):wikitext(Icons.Icon({item.name, type='item', notext=true}))
:attr('data-sort-value', item.name)
row:tag('td'):wikitext(Icons.Icon({item.name, type='item', noicon=true}))
:attr('data-sort-value', item.name)
row:tag('td'):wikitext(Icons.getDLCColumnIcon(item.id))
:attr('data-sort-value', Icons.getExpansionID(item.id))


local itemList = Items.getItems(function(item)
-- Add two-handed & attack speed.
if item.modifiers ~= nil then
if isWeapon == true then
for modName, val in pairs(item.modifiers) do
local twoHandText = (Items._getItemStat(item, 'isTwoHanded') and 'Yes') or 'No'
if Shared.contains(modsDL, modName) then return true end
row:tag('td'):wikitext(twoHandText)
end
:css('text-align', 'center')
return false
local atkSpeed = Items._getItemStat(item, 'attackSpeed') or 0
if atkSpeed > 0 then
row:tag('td'):wikitext(Num.round(atkSpeed / 1000, 3, 1) .. 's')
:attr('data-sort-value', atkSpeed)
:css('text-align', 'right')
else
row:tag('td'):wikitext('N/A')
:addClass('table-na')
end
end
end)
end
-- Attack bonuses
addStatCell(row, item, 'stabAttackBonus')
addStatCell(row, item, 'slashAttackBonus')
addStatCell(row, item, 'blockAttackBonus')
addStatCell(row, item, 'rangedAttackBonus')
addStatCell(row, item, 'magicAttackBonus')
-- Strength bonuses
addStatCell(row, item, 'meleeStrengthBonus')
addStatCell(row, item, 'rangedStrengthBonus')
addStatCell(row, item, 'magicDamageBonus'):wikitext('%')
 
-- Defence bonuses
addStatCell(row, item, 'meleeDefenceBonus')
addStatCell(row, item, 'rangedDefenceBonus')
addStatCell(row, item, 'magicDefenceBonus')


local resultPart = {}
-- Add Damage Reduction / Abyssal Resistance
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"')
addDRCell(row, item)
table.insert(resultPart, '\r\n!colspan="2"|Name!!Bonus!!Description')
 
for i, item in Shared.skpairs(itemList) do
local reqs = getRequirements(item)
local lootValue = 0
if reqs == nil then
for modName, modDet in pairs(modDetail) do
row:tag('td'):wikitext('None')
lootValue = lootValue + (item.modifiers[modName] or 0) * modDet.mult
:attr('data-sort-value', 0)
else
row:tag('td'):wikitext(reqs.requirements)
:attr('data-sort-value', reqs.datasortvalue)
end
end
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
table.insert(resultPart, '||' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..lootValue..'"|'..lootValue..'%')
table.insert(resultPart, '||'..(Constants.getDescription(item.customDescription, item.modifiers) or ''))
end
end


table.insert(resultPart, '\r\n|}')
return tostring(html)
return table.concat(resultPart)
end
end


function p.getStatChangeString(item1, item2)
function p.getCategoryTable(frame)
--Used by getItemUpgradeTable to get the stat change between two items
local args = frame.args ~= nil and frame.args or frame
local changeArray = {}
local slot, style = args[1], Shared.titleCase(args[2] or '')
local slotID = getSlotID(slot)
if slotID == nil then
return Shared.printError('Invalid slot ID: ' .. (slot or 'nil'))
elseif style ~= nil and style ~= '' and itemStyleOverrides[style] == nil then
return Shared.printError('Invalid style: ' .. (style or 'nil'))
end


local getSpecificStatString = function(val1, val2, subStr)
return p.getEquipmentTable(getItems(slotID, style), slot)
if val1 == nil then val1 = 0 end
end
if val2 == nil then val2 = 0 end


if val1 ~= val2 then
function p.getTableForList(frame)
local txt = string.gsub(subStr, '{V}', Shared.numStrWithSign(val1 - val2))
local pFrame = frame:getParent()
table.insert(changeArray, txt)
local frameArgs = pFrame.args ~= nil and pFrame.args or frame
end
local includeModifiers = frameArgs.includeModifiers ~= nil and string.upper(frameArgs.includeModifiers) == 'TRUE' or false
end


--Unfortunately just gonna have to manually check all the changes I think...
local itemList, errItems = {}, {}
local statList = {
for i, rawItemName in ipairs(frameArgs) do
-- {'statName', 'statDescription'}
local itemName = Shared.trim(rawItemName)
{'stabAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus'},
local item = Items.getItem(itemName)
{'slashAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus'},
if item == nil then
{'blockAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus'},
table.insert(errItems, "'" .. itemName .. "'")
{'meleeStrengthBonus', '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus'},
{'rangedStrengthBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus'},
{'magicStrengthBonus', '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus'},
{'meleeDefenceBonus', '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus'},
{'rangedDefenceBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus'},
{'magicDefenceBonus', '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Defence Bonus'},
{'damageReduction', '{V}% Damage Reduction'},
{'increasedSlayerXP', '{V}% '..Icons.Icon({'Slayer', type='skill', notext=true})..' Bonus XP'},
{'attackLevelRequired', '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required'},
{'defenceLevelRequired', '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required'},
{'rangedLevelRequired', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required'},
{'magicLevelRequired', '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required'},
}
for i, stat in ipairs(statList) do
if stat[1] == 'increasedSlayerXP' then
getSpecificStatString(Items._getItemModifier(item1, stat[1], 'Slayer'), Items._getItemModifier(item2, stat[1], 'Slayer'), stat[2])
else
else
getSpecificStatString(Items._getItemStat(item1, stat[1]), Items._getItemStat(item2, stat[1]), stat[2])
table.insert(itemList, item)
end
end
end
end
 
return table.concat(changeArray, '<br/>')
if not Shared.tableIsEmpty(errItems) then
return Shared.printError('Some items not found in database: ' .. table.concat(errItems, ', '))
else
return p.getEquipmentTable(itemList)
end
end
end


function p.getItemUpgradeTable(frame)
function p.getItemUpgradeTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local args = frame.args ~= nil and frame.args or frame
local category, usedItemName = args[1], args.usedItem
local upgradeArray = {}
local upgradeArray = {}
local isEquipment = false
local isEquipment = false
local usedItemID = nil
if usedItemName ~= nil and usedItemName ~= '' then
local usedItem = Items.getItem(usedItemName)
if usedItem == nil then
return Shared.printError('Used item not found: ' .. usedItemName)
end
usedItemID = usedItem.id
end
local function upgradeConsumesItem(itemUpgrade, itemID)
if itemID == nil then
return true
end
for i, itemCost in ipairs(itemUpgrade.itemCosts) do
if itemCost.id == itemID then
return true
end
end
return false
end


if string.upper(category) == 'POTION' then
if string.upper(category) == 'POTION' then
upgradeArray = GameData.getEntities('itemUpgrades',
upgradeArray = GameData.getEntities('itemUpgrades',
function(upgrade) return Shared.contains(upgrade.upgradedItemID, 'Potion') end
function(upgrade)
return Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID)
end
)
)
elseif string.upper(category) == 'OTHER' then
elseif string.upper(category) == 'OTHER' then
upgradeArray = GameData.getEntities('itemUpgrades',
upgradeArray = GameData.getEntities('itemUpgrades',
function(upgrade)
function(upgrade)
if not Shared.contains(upgrade.upgradedItemID, 'Potion') then
if not Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID) then
local item = Items.getItemByID(upgrade.upgradedItemID)
local item = Items.getItemByID(upgrade.upgradedItemID)
if item ~= nil then
if item ~= nil then
Line 472: Line 516:
)
)
else
else
if Constants.getEquipmentSlotID(category) == nil then
-- If category is a slot name, convert it to the slot ID instead
local slotID = getSlotID(category)
if slotID ~= nil then
local slotNS, slotLocalID = Shared.getLocalID(slotID)
category = slotLocalID
end
 
if category == nil then
return Shared.printError('Invalid option. Choose either an equipment slot, Potion, or Other')
return Shared.printError('Invalid option. Choose either an equipment slot, Potion, or Other')
end
end
Line 478: Line 529:
upgradeArray = GameData.getEntities('itemUpgrades',
upgradeArray = GameData.getEntities('itemUpgrades',
function(upgrade)
function(upgrade)
local item = Items.getItemByID(upgrade.upgradedItemID)
if upgradeConsumesItem(upgrade, usedItemID) then
if item ~= nil then
local item = Items.getItemByID(upgrade.upgradedItemID)
return item.validSlots ~= nil and Shared.contains(item.validSlots, category)
if item ~= nil then
return item.validSlots ~= nil and Shared.contains(item.validSlots, category)
end
end
end
return false
return false
Line 487: Line 540:
end
end


local useStatChange = isEquipment or (string.upper(category) == 'POTION')
local resultPart = {}
local resultPart = {}
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n!colspan="2"|Upgraded Item!!Ingredients')
table.insert(resultPart, '\r\n!colspan="2"|Upgraded Item!!Ingredients')
if isEquipment then table.insert(resultPart, '!!Stat Change') end
if useStatChange then table.insert(resultPart, '!!Stat Change') end


for i, upgrade in ipairs(upgradeArray) do
for i, upgrade in ipairs(upgradeArray) do
Line 499: Line 553:
table.insert(resultPart, '||' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
table.insert(resultPart, '||' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))


local matArray = {}
table.insert(resultPart, '|| ' .. Common.getCostString({ items = upgrade.itemCosts, gp = upgrade.gpCost, sc = upgrade.scCost}, 'None'))
local statChangeString = ''
 
for i, itemCost in ipairs(upgrade.itemCosts) do
if useStatChange then
local mat = Items.getItemByID(itemCost.id)
-- Generate stat change column
if mat ~= nil then
local statChangeString = ''
table.insert(matArray, Icons.Icon({mat.name, type='item', qty=itemCost.quantity}))
if not Shared.tableIsEmpty(upgrade.rootItemIDs) then
if isEquipment and item.validSlots ~= nil and mat.validSlots ~= nil and statChangeString == '' then
-- Some items (e.g. FEZ) may have multiple root items. Simply use the first one
statChangeString = p.getStatChangeString(item, mat)
local rootItem = Items.getItemByID(upgrade.rootItemIDs[1])
if rootItem ~= nil then
statChangeString = Items.getStatChangeString(item, rootItem)
end
end
end
end
end
table.insert(resultPart, '|| '..statChangeString)
if upgrade.gpCost ~= nil and upgrade.gpCost > 0 then
table.insert(matArray, Icons.GP(upgrade.gpCost))
end
if upgrade.scCost ~= nil and upgrade.scCost > 0 then
table.insert(matArray, Icons.SC(upgrade.scCost))
end
table.insert(resultPart, '||'..table.concat(matArray, '<br/>'))
 
if isEquipment then
table.insert(resultPart, '||'..statChangeString)
end
end
end
end
Line 538: Line 584:
local PR = item.providedRunes
local PR = item.providedRunes
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|style="text-align: centre;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
table.insert(resultPart, '\r\n|style="text-align: center;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
table.insert(resultPart, '\r\n|' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
table.insert(resultPart, '\r\n|' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
local runeLines = {}
local runeLines = {}
Line 598: Line 644:
function p.getDRTable(frame)
function p.getDRTable(frame)
local style = frame.args ~= nil and frame.args[1] or frame
local style = frame.args ~= nil and frame.args[1] or frame
local SlotNames = {}
local slotNames = {}
local ItemList = {}
if style == 'Other' then
if style == 'Other' then
SlotNames = {'Helmet', 'Platelegs', 'Gloves', 'Shield', 'Cape', 'Amulet', 'Ring'}
slotNames = {'Helmet', 'Platelegs', 'Gloves', 'Shield', 'Cape', 'Amulet', 'Ring'}
else
else
SlotNames = {'Helmet', 'Platebody', 'Platelegs', 'Boots', 'Gloves', 'Weapon', 'Shield'}
slotNames = {'Helmet', 'Platebody', 'Platelegs', 'Boots', 'Gloves', 'Weapon', 'Shield'}
end
end
ItemList = Items.getItems(function(item)
local itemList = getEquipItemList(
local isMatch = true
function(entry)
if Items._getItemStat(item, 'damageReduction', true) <= 0 then
if Items._getItemStat(entry.item, 'damageReduction', true) <= 0 then
return false
-- Item provides no DR: Exclude
end
return false
-- Exclude Golbin raid exclusives for now, such that they don't
end
-- pollute various equipment tables
 
if item.golbinRaidExclusive ~= nil and item.golbinRaidExclusive then
-- Check equipment slot matches
return false
local slotMatch = false
end
for _, slotName in ipairs(slotNames) do
--Using the same checks for Melee/Ranged/Magic that the Equipment Tables use
if entry.slots[slotName] ~= nil then
if style == 'Melee' then
slotMatch = true
if ((Items._getItemStat(item, 'defenceLevelRequired') == nil and Items._getItemStat(item, 'attackLevelRequired') == nil) and not Shared.contains(styleOverrides.Melee, item.name)) or Shared.contains(styleOverrides.NotMelee, item.name) then isMatch = false end
break
elseif style == 'Ranged' then
end
if (Items._getItemStat(item, 'rangedLevelRequired') == nil and not Shared.contains(styleOverrides.Ranged, item.name)) or Shared.contains(styleOverrides.NotRanged, item.name)  then isMatch = false end
end
elseif style == 'Magic' then
if not slotMatch then
if (Items._getItemStat(item, 'magicLevelRequired') == nil and not Shared.contains(styleOverrides.Magic, item.name)) or Shared.contains(styleOverrides.NotMagic, item.name) then isMatch = false end
return false
else
end
if (Items._getItemStat(item, 'attackLevelRequired') ~= nil or Items._getItemStat(item, 'defenceLevelRequired') ~= nil or Items._getItemStat(item, 'rangedLevelRequired') ~= nil or Items._getItemStat(item, 'magicLevelRequired') ~= nil or
 
Shared.contains(styleOverrides.Melee, item.name) or Shared.contains(styleOverrides.Ranged, item.name) or Shared.contains(styleOverrides.Magic, item.name)) and
-- Finally, ensure the style matches. If no style specified then return evertyhing
not Shared.contains(styleOverrides.None, item.name) then
return (style == nil or style == '' or style == entry.style)
isMatch = false
end
end
)
end
 
if isMatch and not Shared.contains(SlotNames, Items._getItemEquipSlot(item)) then
return p._getDRTable(slotNames, itemList)
isMatch = false
end
return isMatch
end)
return p._getDRTable(SlotNames, ItemList)
end
end


return p
return p