4,951
edits
Falterfire (talk | contribs) (Added level requirements to getItemUpgradeTable's comparisons) |
Falterfire (talk | contribs) (Adding getEquipmentTable category so I can find any pages that actually use that function and fix them.) |
||
Line 16: | Line 16: | ||
local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'} | local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'} | ||
function p._getEquipmentTable(itemList) | local styleOverrides = { | ||
Melee = {'Slayer Helmet (Basic)', 'Slayer Platebody (Basic)'}, | |||
Ranged = {'Slayer Cowl (Basic)', 'Slayer Leather Body (Basic)'}, | |||
Magic = {'Slayer Wizard Hat (Basic)', 'Slayer Wizard Robes (Basic)', 'Enchanted Shield'}, | |||
None = {}, | |||
} | |||
function p._getEquipmentTable(itemList, includeModifiers) | |||
if includeModifiers == nil then includeModifiers = false end | |||
--Getting some lists set up here that will be used later | --Getting some lists set up here that will be used later | ||
--First, the list of columns used by both weapons & armour | --First, the list of columns used by both weapons & armour | ||
Line 85: | Line 94: | ||
result = result..'\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Lvl Req' | result = result..'\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Lvl Req' | ||
end | end | ||
result = result..'\r\n!colspan="1"|' | if includeModifiers then | ||
result = result..'\r\n!colspan="2"|' | |||
else | |||
result = result..'\r\n!colspan="1"|' | |||
end | |||
--One header row down, one to go | --One header row down, one to go | ||
result = result..'\r\n|-class="headerRow-1"' | result = result..'\r\n|-class="headerRow-1"' | ||
Line 147: | Line 160: | ||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}) | result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}) | ||
end | end | ||
--If includeModifiers is set to 'true', add the Modifiers column | |||
if includeModifiers then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Modifiers' | |||
end | |||
--And finally Sources | --And finally Sources | ||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Sources' | result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Sources' | ||
Line 173: | Line 191: | ||
result = result..'"|'..Shared.formatnum(statValue) | result = result..'"|'..Shared.formatnum(statValue) | ||
if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end | if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end | ||
end | |||
--If requested, add the item Modifiers | |||
if includeModifiers then | |||
result = result..'\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|' | |||
result = result..Constants.getModifiersText(item.modifiers, true) | |||
end | end | ||
--Finally, the Sources | --Finally, the Sources | ||
Line 192: | Line 215: | ||
result = result..'"|'..Shared.formatnum(statValue) | result = result..'"|'..Shared.formatnum(statValue) | ||
if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end | if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end | ||
end | |||
--If requested, add the item Modifiers | |||
if includeModifiers then | |||
result = result..'\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|' | |||
result = result..Constants.getModifiersText(item.modifiers, true) | |||
end | end | ||
--Finally, the Sources | --Finally, the Sources | ||
Line 261: | Line 289: | ||
end | end | ||
return p._getEquipmentTable(itemList) | return p._getEquipmentTable(itemList).."[[Category:getEquipmentTable]]" | ||
end | |||
function p._getCategoryTable(style, slot, other, includeModifiers) | |||
if type(slot) == 'string' then | |||
slot = Constants.getEquipmentSlotID(slot) | |||
end | |||
local itemList = Items.getItems(function(item) | |||
local isMatch = true | |||
if style == 'Melee' then | |||
if item.defenceLevelRequired == nil and not Shared.contains(styleOverrides.Melee, item.name) then isMatch = false end | |||
elseif style == 'Ranged' then | |||
if item.rangedLevelRequired == nil and not Shared.contains(styleOverrides.Ranged, item.name) then isMatch = false end | |||
elseif style == 'Magic' then | |||
if item.magicLevelRequired == nil and not Shared.contains(styleOverrides.Magic, item.name) then isMatch = false end | |||
elseif style == 'None' then | |||
if (item.defenceLevelRequired ~= nil or item.rangedLevelRequired ~= nil or 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 slot ~= item.equipmentSlot then isMatch = false end | |||
if isMatch and other ~= nil then | |||
if slot == 4 then --For quiver slot or weapon slot, 'other' is the ammo type | |||
if other == 'Arrows' then | |||
if item.ammoTypeRequired ~= 0 then isMatch = false end | |||
elseif other == 'Bolts' then | |||
if item.ammoTypeRequired ~= 1 then isMatch = false end | |||
end | |||
elseif slot == 9 then | |||
if other == 'Arrows' then | |||
if item.ammoType ~= 0 then isMatch = false end | |||
elseif other == 'Bolts' then | |||
if item.ammoType ~= 1 then isMatch = false end | |||
elseif other == 'Javelins' then | |||
if item.ammoType ~= 2 then isMatch = false end | |||
elseif other == 'Throwing Knives' then | |||
if item.ammoType ~= 3 then isMatch = false end | |||
elseif other == 'Thrown' then | |||
if item.ammoType ~= 2 and item.ammoType ~= 3 then isMatch = false end | |||
end | |||
end | |||
end | |||
return isMatch | |||
end) | |||
return p._getEquipmentTable(itemList, includeModifiers) | |||
end | |||
function p.getCategoryTable(frame) | |||
local style = frame.args ~= nil and frame.args[1] or frame[1] | |||
local slot = frame.args ~= nil and frame.args[2] or frame[2] | |||
local other = frame.args ~= nil and frame.args[3] or frame[3] | |||
local includeModifiers = frame.args ~= nil and frame.args.includeModifiers or frame.includeModifiers | |||
includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false | |||
return p._getCategoryTable(style, slot, other, includeModifiers) | |||
end | end | ||
function p.getTableForList(frame) | function p.getTableForList(frame) | ||
local stuffString = frame.args ~= nil and frame.args[1] or frame | local stuffString = frame.args ~= nil and frame.args[1] or frame[1] | ||
local itemNames = Shared.splitString(stuffString, ',') | local itemNames = Shared.splitString(stuffString, ',') | ||
local includeModifiers = frame.args ~= nil and frame.args[2] or frame[2] | |||
includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false | |||
local itemList = {} | local itemList = {} | ||
Line 284: | Line 377: | ||
return errMsg | return errMsg | ||
else | else | ||
return p._getEquipmentTable(itemList) | return p._getEquipmentTable(itemList, includeModifiers) | ||
end | end | ||
end | end | ||
Line 327: | Line 420: | ||
return table.concat(rowResult, '\r\n') | return table.concat(rowResult, '\r\n') | ||
end | end | ||
Line 346: | Line 431: | ||
if val1 ~= val2 then | if val1 ~= val2 then | ||
local txt = string.gsub(subStr, '{V}', | local txt = string.gsub(subStr, '{V}', Shared.numStrWithSign(val1 - val2)) | ||
table.insert(changeArray, txt) | table.insert(changeArray, txt) | ||
end | end |