Anonymous

Module:Items: Difference between revisions

From Melvor Idle
Tweaks to the getEquipmentTable code
(Improvements to the getItemSources code to account for more things. Probably not everything quite yet, but getting there)
(Tweaks to the getEquipmentTable code)
Line 384: Line 384:
   local ammoTypeStr = args.ammoType
   local ammoTypeStr = args.ammoType
   local category = args.category ~= nil and args.category or 'Combat'
   local category = args.category ~= nil and args.category or 'Combat'
  local i = 0
  local j = 0


   --Find out what Ammo Type we're working with
   --Find out what Ammo Type we're working with
Line 410: Line 408:


   --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 & armor
   --First, the list of columns used by both weapons & armour
   local statColumns = {'slashAttackBonus', 'stabAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus'}
   local statColumns = {'slashAttackBonus', 'stabAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus'}
   --Then the lists for just weapons/just armor
   --Then the lists for just weapons/just armour
   local weaponStatColumns = {'attackLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}  
   local weaponStatColumns = {'attackLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}  
   local armorStatColumns = {'damageReduction', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}
   local armourStatColumns = {'damageReduction', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}
   --Then the list of weapon types
   --Then the list of weapon types
   local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}
   local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}
Line 436: Line 434:
     result = result..'\r\n!colspan="1"|'
     result = result..'\r\n!colspan="1"|'
   else
   else
     --Only armor pieces have DR right now, so ignore that column for weapons
     --Only armour pieces have DR right now, so ignore that column for weapons
     result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|Damage Reduction'
     result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|Damage Reduction'
   end
   end
Line 463: Line 461:
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
   --Damage Reduction/Defence Req for armor, 2-handed/Attack Req for weapons
   --Damage Reduction/Defence Req for armour, 2-handed/Attack Req for weapons
   if isWeaponType then
   if isWeaponType then
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?'
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?'
Line 478: Line 476:


   --And with all the header out of the way, finally time to actually build the table itself.
   --And with all the header out of the way, finally time to actually build the table itself.
  local itemList = {}
   for i, itemBase in pairs(ItemData) do
   for i, itemBase in pairs(ItemData) do
     local item = Shared.clone(itemBase)
     local item = Shared.clone(itemBase)
Line 483: Line 482:
     local listItem = false
     local listItem = false
     if isWeaponType then
     if isWeaponType then
      listItem = item.type == type and item.category == category
    listItem = item.type == type and item.category == category
       if ammoType ~= nil then listItem = listItem and item.ammoTypeRequired == ammoType end
       if ammoType ~= nil then listItem = listItem and item.ammoTypeRequired == ammoType end
       if listItem then
    else
         result = result..'\r\n|-'
      --Now for handling armour
        result = result..'\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
       if type == "Armour" or type == "Melee" then
        result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
         listItem = item.defenceLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Armour')
        result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(item.attackSpeed)
      elseif type == "Ranged Armour" or type == "Ranged" then
         for j, statName in pairs(statColumns) do
         listItem = item.rangedLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Ranged Armour')
          local statValue = p._getItemStat(item, statName, true)
      elseif type == "Magic Armour" or type == "Magic" then
          result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
         listItem = item.magicLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Magic Armour')
          if statValue > 0 then
      else
            result = result..'background-color:lightgreen;'
        listItem = item.type == type and item.category ~= 'Combat'
          elseif statValue < 0 then
            result = result..'background-color:lightpink;'
          end
          result = result..'"|'..Shared.formatnum(statValue)
          if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
         end
        --That's the first list out of the way, now for 2-Handed
        result = result..'\r\n| style ="text-align: right;"|'
        if item.isTwoHanded then result = result..'Yes' else result = result..'No' end
        --Now the weapon exclusive columns
        for j, statName in pairs(weaponStatColumns) do
          local statValue = p._getItemStat(item, statName, true)
          result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
          result = result..'"|'..Shared.formatnum(statValue)
          if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
        end
        --Finally, the Sources
        result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
        result = result..p._getItemSources(item)
       end
       end
    else
      --Now for handling armor
      listItem = item.type == type and item.category == category
       if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end
       if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end
       if slot ~= nil then listItem = listItem and item.equipmentSlot == slot end
       if slot ~= nil then listItem = listItem and item.equipmentSlot == slot end
    end
    if listItem then
      table.insert(itemList, item)
    end
  end


       if listItem then
  table.sort(itemList, function(a, b) return a.id < b.id end)
         result = result..'\r\n|-'
  for i, item in pairs(itemList) do
         result = result..'\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
    if isWeaponType then
        result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
      --Building rows for weapons
        for j, statName in pairs(statColumns) do
      result = result..'\r\n|-'
           local statValue = p._getItemStat(item, statName, true)
      result = result..'\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
          result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
      result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
      result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(item.attackSpeed)
      for j, statName in pairs(statColumns) do
        local statValue = p._getItemStat(item, statName, true)
        result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
        if statValue > 0 then
          result = result..'background-color:lightgreen;'
        elseif statValue < 0 then
          result = result..'background-color:lightpink;'
        end
        result = result..'"|'..Shared.formatnum(statValue)
        if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
      end
      --That's the first list out of the way, now for 2-Handed
      result = result..'\r\n| style ="text-align: right;"|'
       if item.isTwoHanded then result = result..'Yes' else result = result..'No' end
      --Now the weapon exclusive columns
      for j, statName in pairs(weaponStatColumns) do
        local statValue = p._getItemStat(item, statName, true)
         result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
         result = result..'"|'..Shared.formatnum(statValue)
        if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
      end
      --Finally, the Sources
      result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
      result = result..p._getItemSources(item)
    else
      --Building rows for armour
      result = result..'\r\n|-'
      result = result..'\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
      result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
      for j, statName in pairs(statColumns) do
        local statValue = p._getItemStat(item, statName, true)
        result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
        if statValue > 0 then
           result = result..'background-color:lightgreen;'
        elseif statValue < 0 then
          result = result..'background-color:lightpink;'
        end
        result = result..'"|'..Shared.formatnum(statValue)
        if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
      end
      --That's the first list out of the way, now for armour specific things
      for j, statName in pairs(armourStatColumns) do
        local statValue = p._getItemStat(item, statName, true)
        result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
        if j == 1 then
           if statValue > 0 then
           if statValue > 0 then
             result = result..'background-color:lightgreen;'
             result = result..'background-color:lightgreen;'
Line 533: Line 561:
             result = result..'background-color:lightpink;'
             result = result..'background-color:lightpink;'
           end
           end
          result = result..'"|'..Shared.formatnum(statValue)
          if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
        end
        --That's the first list out of the way, now for armor specific things
        for j, statName in pairs(armorStatColumns) do
          local statValue = p._getItemStat(item, statName, true)
          result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
          if j == 1 then
            if statValue > 0 then
              result = result..'background-color:lightgreen;'
            elseif statValue < 0 then
              result = result..'background-color:lightpink;'
            end
          end
          result = result..'"|'..Shared.formatnum(statValue)
          if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
         end
         end
        --Finally, the Sources
         result = result..'"|'..Shared.formatnum(statValue)
         result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
         if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
         result = result..p._getItemSources(item)
       end
       end
      --Finally, the Sources
      result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
      result = result..p._getItemSources(item)
     end
     end
   end
   end