4,951
edits
Falterfire (talk | contribs) (Moving code over) |
Falterfire (talk | contribs) (Added new function for getting a comparison for a list of items.) |
||
Line 13: | Line 13: | ||
local ItemSourceTables = require('Module:Items/SourceTables') | local ItemSourceTables = require('Module:Items/SourceTables') | ||
local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'} | |||
function p._getEquipmentTable(itemList) | |||
--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 | ||
local statColumns = {'stabAttackBonus', 'slashAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'} | local statColumns = {'stabAttackBonus', 'slashAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'} | ||
if(Shared.tableCount(itemList) == 0) then | |||
return 'ERROR: you must select at least one item to get stats for' | |||
end | |||
local isWeaponType = Shared.contains(weaponTypes, itemList[1].type) | |||
local | |||
--Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection) | --Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection) | ||
Line 110: | Line 57: | ||
end | end | ||
end | end | ||
--Alright, let's start the table by building the shared header | --Alright, let's start the table by building the shared header | ||
Line 248: | Line 194: | ||
--Finally, the Sources | --Finally, the Sources | ||
result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |' | result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |' | ||
result = result.. | result = result..ItemSourceTables._getItemSources(item) | ||
end | end | ||
end | end | ||
Line 254: | Line 200: | ||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
return result | return result | ||
end | |||
function p.getEquipmentTable(frame) | |||
local args = frame.args ~= nil and frame.args or frame | |||
local type = args.type | |||
local tier = args.tier | |||
local slotStr = args.slot | |||
local ammoTypeStr = args.ammoType | |||
local category = args.category ~= nil and args.category or 'Combat' | |||
--Find out what Ammo Type we're working with | |||
local ammoType = nil | |||
if ammoTypeStr ~= nil then | |||
if ammoTypeStr == "Arrows" then | |||
ammoType = 0 | |||
elseif ammoTypeStr == 'Bolts' then | |||
ammoType = 1 | |||
elseif ammoTypeStr == 'Javelins' then | |||
ammoType = 2 | |||
elseif ammoTypeStr == 'Throwing Knives' then | |||
ammoType = 3 | |||
end | |||
end | |||
--Find out what slot we're working with | |||
local slot = nil | |||
if slotStr ~= nil then | |||
slot = Constants.equipmentSlot[slotStr] | |||
end | |||
local isWeaponType = Shared.contains(weaponTypes, type) | |||
--Now we need to figure out which items are in this list | |||
local itemList = {} | |||
for i, itemBase in pairs(ItemData.Items) do | |||
local item = Shared.clone(itemBase) | |||
item.id = i - 1 | |||
local listItem = false | |||
if isWeaponType then | |||
listItem = item.type == type and item.category == category | |||
if ammoType ~= nil then listItem = listItem and item.ammoTypeRequired == ammoType end | |||
else | |||
--Now for handling armour | |||
if type == "Armour" or type == "Melee" then | |||
listItem = item.defenceLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Armour') | |||
elseif type == "Ranged Armour" or type == "Ranged" then | |||
listItem = item.rangedLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Ranged Armour') | |||
elseif type == "Magic Armour" or type == "Magic" then | |||
listItem = item.magicLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Magic Armour') | |||
else | |||
listItem = item.type == type and item.category ~= 'Combat' | |||
end | |||
if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end | |||
if slot ~= nil then listItem = listItem and item.equipmentSlot == slot end | |||
end | |||
if listItem then | |||
table.insert(itemList, item) | |||
end | |||
end | |||
return p._getEquipmentTable(itemList) | |||
end | |||
function p.getTableForList(frame) | |||
local stuffString = frame.args ~= nil and frame.args[1] or frame | |||
local itemNames = Shared.splitString(stuffString, ',') | |||
local itemList = {} | |||
local errMsg = 'ERROR: Some items not found in database: ' | |||
local hasErr = false | |||
for i, name in Shared.skpairs(itemNames) do | |||
local nextItem = Items.getItem(name) | |||
if nextItem == nil then | |||
errMsg = errMsg.." '"..name.."'" | |||
hasErr = true | |||
else | |||
table.insert(itemList, nextItem) | |||
end | |||
end | |||
if hasErr then | |||
return errMsg | |||
else | |||
return p._getEquipmentTable(itemList) | |||
end | |||
end | end | ||
return p | return p |