Module:Items: Difference between revisions

1,933 bytes added ,  14 March 2021
Added p.getItemModifier and a related p.getItemStat modifier so that pulling slayerBonusXP properly pulls the new modifier
(Added modifier list to getOtherItemBoxText)
(Added p.getItemModifier and a related p.getItemStat modifier so that pulling slayerBonusXP properly pulls the new modifier)
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 strupper(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 248: 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 269: 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