17,105
edits
m (getTableForList: Fix includeModifiers param handling) |
(Update for v1.3) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
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 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') | ||
Line 19: | Line 19: | ||
NotMagic = {'Torrential Blast Crossbow', 'Spectral Ice Sword', 'Lightning Strike 1H Sword', 'FrostSpark 1H Sword'} | NotMagic = {'Torrential Blast Crossbow', 'Spectral Ice Sword', 'Lightning Strike 1H Sword', 'FrostSpark 1H Sword'} | ||
} | } | ||
local function getSlotID(slot) | |||
-- If slot is a slot name, convert it to the slot ID instead | |||
local slotID = Shared.getNamespacedID('melvorD', slot) | |||
local slotData = GameData.getEntityByID('equipmentSlots', slotID) | |||
-- Validate slotID | |||
if slotData == nil then | |||
-- 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 | |||
return slotID | |||
end | |||
local function getItemDesc(item) | |||
if item.customDescription ~= nil then | |||
return item.customDescription | |||
elseif item.modifiers ~= nil then | |||
return Modifiers.getModifiersText(item.modifiers, false, false) | |||
else | |||
return '' | |||
end | |||
end | |||
function p._getEquipmentTable(itemList, includeModifiers, includeDescription, sortByName) | function p._getEquipmentTable(itemList, includeModifiers, includeDescription, sortByName) | ||
Line 208: | Line 234: | ||
--If requested, add the item Modifiers | --If requested, add the item Modifiers | ||
if includeModifiers then | if includeModifiers then | ||
table.insert(resultPart, '\r\n|') | table.insert(resultPart, '\r\n| ') | ||
local txtLines = {} | local txtLines = {} | ||
if item.modifiers ~= nil then | |||
table.insert(txtLines, Modifiers.getModifiersText(item.modifiers, true, false, 10)) | |||
table.insert(txtLines, | |||
end | end | ||
--For items with a special attack, show the details | --For items with a special attack, show the details | ||
Line 231: | Line 256: | ||
--If requested, add description | --If requested, add description | ||
if includeDescription then | if includeDescription then | ||
table.insert(resultPart, '\r\n| ' | table.insert(resultPart, '\r\n| ' .. getItemDesc(item)) | ||
end | end | ||
else | else | ||
--Building rows for armour | --Building rows for armour | ||
table.insert(resultPart, '\r\n|-') | table.insert(resultPart, '\r\n|-') | ||
table.insert(resultPart, '\r\n|'..Icons.Icon({item.name, type='item', size=50, notext=true})) | table.insert(resultPart, '\r\n|'..Icons.Icon({(item.name or 'Unknown'), 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})) | ||
for j, statName in pairs(statColumns) do | for j, statName in pairs(statColumns) do | ||
Line 254: | Line 278: | ||
table.insert(resultPart, '\r\n| ') | table.insert(resultPart, '\r\n| ') | ||
local txtLines = {} | local txtLines = {} | ||
if item.modifiers ~= nil then | |||
table.insert(txtLines, Modifiers.getModifiersText(item.modifiers, true, false, 10)) | |||
table.insert(txtLines, | |||
end | end | ||
--For items with a special attack, show the details | --For items with a special attack, show the details | ||
Line 275: | Line 298: | ||
--If requested, add description | --If requested, add description | ||
if includeDescription then | if includeDescription then | ||
table.insert(resultPart, '\r\n| ' | table.insert(resultPart, '\r\n| ' .. getItemDesc(item)) | ||
end | end | ||
end | end | ||
Line 288: | Line 310: | ||
function p._getCategoryTable(style, slot, other, includeModifiers, includeDescription, sortByName) | function p._getCategoryTable(style, slot, other, includeModifiers, includeDescription, sortByName) | ||
-- If slot is a slot name, convert it to the slot ID instead | -- If slot is a slot name, convert it to the slot ID instead | ||
slot = | local slotID = getSlotID(slot) | ||
if slotID == nil then | |||
return Shared.printError('Invalid slot ID: ' .. (slot or 'nil')) | |||
end | |||
local slotNS, slotLocalID = Shared.getLocalID(slotID) | |||
local itemList = Items.getItems(function(item) | local itemList = Items.getItems(function(item) | ||
-- Exclude the debug item | |||
if item.id == 'melvorD:DEBUG_ITEM' then | |||
return false | |||
end | |||
-- Exclude Golbin raid exclusives for now, such that they don't | -- Exclude Golbin raid exclusives for now, such that they don't | ||
-- pollute various equipment tables | -- pollute various equipment tables | ||
Line 310: | Line 340: | ||
end | end | ||
end | end | ||
if | local sID = slotLocalID | ||
if sID == nil or not Shared.contains(item.validSlots, sID) then isMatch = false end | |||
if isMatch and other ~= nil then | if isMatch and other ~= nil then | ||
Line 322: | Line 353: | ||
end | end | ||
end | end | ||
if | if slotLocalID == 'Weapon' then --For quiver slot or weapon slot, 'other' is the ammo type | ||
isMatch = other == item.ammoTypeRequired | isMatch = other == item.ammoTypeRequired | ||
elseif | elseif slotLocalID == 'Quiver' then | ||
if other == 'Thrown' and Shared.contains({'Javelins', 'ThrowingKnives'}, item.ammoType) then | if other == 'Thrown' and Shared.contains({'Javelins', 'ThrowingKnives'}, item.ammoType) then | ||
isMatch = true | isMatch = true | ||
Line 381: | Line 412: | ||
function p.getDoubleLootTable(frame) | function p.getDoubleLootTable(frame) | ||
local modsDL = { | local modsDL = { | ||
' | ["id"] = { | ||
'melvorD:doubleItemsSkill', | |||
' | 'melvorD:doubleItemsChanceAgainstDamageType' | ||
}, | |||
["alias"] = { | |||
'increasedChanceToDoubleLootCombat', | |||
'decreasedChanceToDoubleLootCombat', | |||
'increasedChanceToDoubleItemsGlobal', | |||
'decreasedChanceToDoubleItemsGlobal' | |||
} | |||
} | } | ||
local | local matchCriteria = Modifiers.getMatchCriteriaFromIDs(modsDL.id, modsDL.alias) | ||
local itemMatchedMods = {} | |||
local itemList = Items.getItems( | |||
function(item) | |||
local itemList = Items.getItems(function(item) | |||
if item.modifiers ~= nil then | if item.modifiers ~= nil then | ||
local matchedMods = Modifiers.getMatchingModifiers(item.modifiers, matchCriteria) | |||
if Shared.tableIsEmpty(matchedMods.matched) then | |||
return false | |||
else | |||
itemMatchedMods[item.id] = matchedMods.matched | |||
return true | |||
end | end | ||
end | end | ||
end) | end | ||
) | |||
local resultPart = {} | local resultPart = {} | ||
Line 407: | Line 443: | ||
table.insert(resultPart, '\r\n!colspan="2"|Name!!Bonus!!Description') | table.insert(resultPart, '\r\n!colspan="2"|Name!!Bonus!!Description') | ||
for i, item in Shared.skpairs(itemList) do | for i, item in Shared.skpairs(itemList) do | ||
local lootValue = | local lootValue = Modifiers.getModifierValue(itemMatchedMods[item.id]) | ||
table.insert(resultPart, '\r\n|-') | 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, '\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, '||' .. 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, '||style ="text-align: right;" data-sort-value="'..lootValue..'"|'..lootValue..'%') | ||
table.insert(resultPart, '||'..( | table.insert(resultPart, '||' .. getItemDesc(item)) | ||
end | end | ||
Line 469: | Line 503: | ||
else | else | ||
-- If category is a slot name, convert it to the slot ID instead | -- 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 | 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') |