Anonymous

Module:Items: Difference between revisions

From Melvor Idle
2,217 bytes added ,  15 March 2021
Fixed string.upper call
(Bolding category names from getOtherItemBoxText)
(Fixed string.upper call)
(5 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 = mw.loadData('Module:Constants/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
function p.getEquipmentSlotName(id)
  for slotName, i in Shared.skpairs(Constants.equipmentSlot) do
    if i == id then
      return slotName
    end
  end
  return 'Invalid'
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.."\r\n|-\r\n|'''Equipment Slot:''' "..p.getEquipmentSlotName(item.equipmentSlot)
     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
Line 234: Line 289:
   if item.prayerPoints ~= nil then
   if item.prayerPoints ~= nil then
     result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Prayer', type='skill'}).." Points:''' "..item.prayerPoints
     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