4,951
edits
Falterfire (talk | contribs) (Added option to getItemStat for getting whether an item is needed for 100% Item Completion) |
Falterfire (talk | contribs) (Fixed string.upper call) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
local ItemData = mw.loadData('Module:Items/data') | local ItemData = mw.loadData('Module:Items/data') | ||
local SkillData = mw.loadData('Module:Skills/data') | local SkillData = mw.loadData('Module:Skills/data') | ||
local Constants = require('Module:Constants') | |||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
Line 136: | Line 136: | ||
return 'No' | return 'No' | ||
end | end | ||
elseif StatName == 'slayerBonusXP' then | |||
return p._getItemModifier(item, 'increasedSkillXP', 'Slayer', false) | |||
end | end | ||
if result == nil and ZeroIfNil then result = 0 end | if result == nil and ZeroIfNil then result = 0 end | ||
Line 149: | Line 151: | ||
local item = p.getItem(ItemName) | local item = p.getItem(ItemName) | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..ItemName.." exists in the data module" | return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
local result = p._getItemStat(item, StatName, ZeroIfNil) | local result = p._getItemStat(item, StatName, ZeroIfNil) | ||
if formatNum then result = Shared.formatnum(result) end | if formatNum then result = Shared.formatnum(result) end | ||
return result | return result | ||
end | |||
--Gets the value of a given modifier for a given item | |||
--asString is false by default, when true it writes the full bonus text | |||
function p._getItemModifier(item, modifier, skill, asString) | |||
if asString == nil then asString = false end | |||
if skill == '' then | |||
skill = nil | |||
elseif type(skill) == 'string' then | |||
skill = Constants.getSkillID(skill) | |||
end | |||
mw.log(item.name..', '..modifier) | |||
local result = 0 | |||
if item.modifiers ~= nil and item.modifiers[modifier] ~= nil then | |||
if type(item.modifiers[modifier]) == 'table' then | |||
for i, subVal in Shared.skpairs(item.modifiers[modifier]) do | |||
if subVal[1] == skill then | |||
result = subVal[2] | |||
break | |||
end | |||
end | |||
else | |||
result = item.modifiers[modifier] | |||
end | |||
end | |||
if asString then | |||
if skill ~= nil then | |||
return Constants._getModifierText(modifier, {skill, result}) | |||
else | |||
return Constants._getModifierText(modifier, result) | |||
end | |||
else | |||
return result | |||
end | |||
end | |||
function p.getItemModifier(frame) | |||
local itemName = frame.args ~= nil and frame.args[1] or frame[1] | |||
local modName = frame.args ~= nil and frame.args[2] or frame[2] | |||
local skillName = frame.args ~= nil and frame.args[3] or frame[3] | |||
local asString = frame.args ~= nil and frame.args[4] or frame[4] | |||
if asString ~= nil then | |||
if string.upper(asString) == 'FALSE' then | |||
asString = false | |||
else | |||
asString = true | |||
end | |||
end | |||
local item = p.getItem(itemName) | |||
if item == nil then | |||
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]" | |||
end | |||
return p._getItemModifier(item, modName, skillName, asString) | |||
end | end | ||
Line 173: | Line 234: | ||
local item = p.getItem(itemName) | local item = p.getItem(itemName) | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..ItemName.." exists in the data module" | return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
return p._getWeaponAttackType(item) | return p._getWeaponAttackType(item) | ||
Line 199: | Line 260: | ||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
return result | return result | ||
end | end | ||
Line 214: | Line 266: | ||
--For equipment, show the slot they go in | --For equipment, show the slot they go in | ||
if item.equipmentSlot ~= nil then | if item.equipmentSlot ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''Equipment Slot:''' "..Constants.getEquipmentSlotName(item.equipmentSlot) | ||
if item.isPassiveItem then | |||
result = result..', Passive' | |||
end | |||
end | end | ||
--For weapons with a special attack, show the details | --For weapons with a special attack, show the details | ||
if item.hasSpecialAttack then | if item.hasSpecialAttack then | ||
local spAtt = p.getSpecialAttackByID(item.specialAttackID) | local spAtt = p.getSpecialAttackByID(item.specialAttackID) | ||
result = result.. | result = result.."\r\n|-\r\n|'''Special Attack:'''" | ||
result = result..'\r\n* '..spAtt.chance..'% chance for '..spAtt.name..':' | result = result..'\r\n* '..spAtt.chance..'% chance for '..spAtt.name..':' | ||
result = result..'\r\n** '..spAtt.description | result = result..'\r\n** '..spAtt.description | ||
Line 225: | Line 280: | ||
--For potions, show the number of charges | --For potions, show the number of charges | ||
if item.potionCharges ~= nil then | if item.potionCharges ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''Charges:''' "..item.potionCharges | ||
end | end | ||
--For food, show how much it heals for | --For food, show how much it heals for | ||
if item.healsFor ~= nil then | if item.healsFor ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''Heals for:''' "..Icons.Icon({"Hitpoints", type="skill", notext="true"})..' '..(item.healsFor * 10) | ||
end | end | ||
--For Prayer Points, show how many you get | --For Prayer Points, show how many you get | ||
if item.prayerPoints ~= nil then | if item.prayerPoints ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Prayer', type='skill'}).." Points:''' "..item.prayerPoints | ||
end | |||
--For items with modifiers, show what those are | |||
if item.modifiers ~= nil and Shared.tableCount(item.modifiers) > 0 then | |||
local modArray = {} | |||
for bonus, value in Shared.skpairs(item.modifiers) do | |||
table.insert(modArray, Constants._getModifierText(bonus, value, false)) | |||
end | |||
result = result.."\r\n|-\r\n|'''Bonuses:'''\r\n"..table.concat(modArray, "<br/>") | |||
end | end | ||
return result | return result | ||
Line 246: | Line 309: | ||
end | end | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..itemName.." exists in the data module" | return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
Line 267: | Line 330: | ||
local item = p.getItem(itemName) | local item = p.getItem(itemName) | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..itemName.." exists in the data module" | return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||