Anonymous

Module:Items: Difference between revisions

From Melvor Idle
3,725 bytes added ,  15 March 2021
Fixed string.upper call
(Added category for Tier + Type)
(Fixed string.upper call)
(15 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 Magic = require('Module:Magic')
local Areas = require('Module:CombatAreas')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')


Line 132: Line 130:
     result = item.description
     result = item.description
     if result == nil or result == '' then result = 'No Description' end
     if result == nil or result == '' then result = 'No Description' end
  elseif StatName == 'completionReq' then
    if item.ignoreCompletion == nil or not item.ignoreCompletion then
      return 'Yes'
    else
      return 'No'
    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 145: 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 169: 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 195: 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 210: 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
   if item.hasSpecialAttack then
   if item.hasSpecialAttack then
     local spAtt = p.getSpecialAttackByID(item.specialAttackID)
     local spAtt = p.getSpecialAttackByID(item.specialAttackID)
     result = result..'\r\n|-\r\n|Special Attack:'
     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 221: 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..'\r\n|-\r\n|Charges: '..item.potionCharges
     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..'\r\n|-\r\n|Heals for: '..Icons.Icon({"Hitpoints", type="skill", notext="true"})..' '..(item.healsFor * 10)
     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..'\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 242: 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 253: Line 320:
   if item.type ~= nil then result = result..'[[Category:'..item.type..']]' end
   if item.type ~= nil then result = result..'[[Category:'..item.type..']]' end
   if item.tier ~= nil then result = result..'[[Category:'..Shared.titleCase(item.tier)..' '..item.type..']]' end
   if item.tier ~= nil then result = result..'[[Category:'..Shared.titleCase(item.tier)..' '..item.type..']]' end
  if item.hasSpecialAttack then result = result..'[[Category:Items With Special Attacks]]' end
  if item.isPassiveItem then result = result..'[[Category:Passive Items]]' end
  if item.chanceToDoubleLoot ~= nil and item.chanceToDoubleLoot > 0 then result = result..'[[Category:Double Loot Chance Items]]' end
   return result
   return result
end
end
Line 260: 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


Line 322: Line 392:
   end
   end
   result = result..'\r\n|}'
   result = result..'\r\n|}'
  return result
end
function p.getSpecialAttackTable(frame)
  local spAttTable = {}
 
  for i, item in Shared.skpairs(ItemData.Items) do
    if item.hasSpecialAttack then
      if spAttTable[item.specialAttackID] == nil then spAttTable[item.specialAttackID] = {sortName=item.name, Icons = {}} end
      table.insert(spAttTable[item.specialAttackID].Icons, Icons.Icon({item.name, type='item'}))
    end
  end 
  local result = '{|class="wikitable sortable stickyHeader"'
  result = result..'\r\n|-class="headerRow-0"'
  result = result..'\r\n!style="min-width:180px"|Weapon(s)!!Name!!Chance!!Effect'
  for i, spAttData in Shared.skpairs(spAttTable) do
    local spAtt = p.getSpecialAttackByID(i)
    table.sort(spAttData.Icons, function(a, b) return a < b end)
    result = result..'\r\n|-'
    result = result..'\r\n|data-sort-value="'..spAttData.sortName..'"|'..table.concat(spAttData.Icons, '<br/>')
    result = result..'||'..spAtt.name..'||data-sort-value="'..spAtt.chance..'"|'..spAtt.chance..'%'
    result = result..'||'..spAtt.description
  end
  result = result..'\r\n|}'
   return result
   return result
end
end


return p
return p