Anonymous

Module:Pets: Difference between revisions

From Melvor Idle
1,190 bytes added ,  22 April 2021
Added new getPets function for use in the new ModifierTables module that's in progress
(getPetSidebar: Add completion indicator & formatting for consistency with {{ItemBox}})
(Added new getPets function for use in the new ModifierTables module that's in progress)
(6 intermediate revisions by the same user not shown)
Line 9: Line 9:
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Skills = require('Module:Skills')
local Skills = require('Module:Skills')
local Zones = require('Module:CombatAreas')
local CombatAreas = require('Module:CombatAreas')




Line 41: Line 41:
   local skillID = Skills.getSkillID(skillName)
   local skillID = Skills.getSkillID(skillName)
   for i, pet in pairs(PetData.Pets) do
   for i, pet in pairs(PetData.Pets) do
     if(skillID == pet.skill) then
    --Deliberately excluding Ty. He knows what he did.
     if(skillID == pet.skill and pet.name ~= 'Ty') then
       result = Shared.clone(pet)
       result = Shared.clone(pet)
       --Make sure every pet has an id, and account for Lua being 1-index
       --Make sure every pet has an id, and account for Lua being 1-index
       result.id = i - 1
       result.id = i - 1
       break
       break
    end
  end
  return result
end
function p.getPets(checkFunc)
  local result = {}
  for i, pet in Shared.skpairs(PetData.Pets) do
    if checkFunc(pet) then
      local newPet = Shared.clone(pet)
      newPet.id = i - 1
      table.insert(result, newPet)
     end
     end
   end
   end
Line 75: Line 88:
     iconType = 'skill'
     iconType = 'skill'
   else
   else
     local combatArea = Zones.getArea(petSource)
     local combatArea = CombatAreas.getArea(petSource)
     if combatArea ~= nil then
     if combatArea ~= nil then
       iconType = combatArea.type
       iconType = combatArea.type
Line 96: Line 109:
     local effects = {}
     local effects = {}
     for effectName, effectValue in pairs(pet.modifiers) do
     for effectName, effectValue in pairs(pet.modifiers) do
       table.insert(effects, Constants.getModifierText(effectName, effectValue, false))
       table.insert(effects, Constants._getModifierText(effectName, effectValue, false))
     end
     end
     return table.concat(effects, '<br/>')
     return table.concat(effects, '<br/>')
Line 168: Line 181:
   end
   end
   result = result..'\r\n|}'
   result = result..'\r\n|}'
  return result
end
function p.getDungeonBoxPetText(frame)
  local dungeonName = frame.args ~= nil and frame.args[1] or frame
  local dung = CombatAreas.getArea(dungeonName)
  if dung == nil then
    return 'ERROR: Invalid dungeon name '..dungeonName..'[[Category:Pages with script errors]]'
  end
  local result = ''
  local pet = p.getPetByID(dung.petID)
  if pet ~= nil then
    result = "\r\n|-\r\n|'''[[Pets#Boss Pets|Pet]]:'''<br/>"
    result = result..Icons.Icon({pet.name, type='pet'})
    local dropChance = ''
    if dung.name == 'Into the Mist' then
      dropChance = 'Guaranteed after 5 clears'
    else
      local odds = pet.obtained.dungeonCompletion[1][2]
      dropChance = '1 in '..odds..' ('..Shared.round(100 / odds, 2, 2)..'%)'
    end
    result = result.."\r\n|-\r\n|'''Pet Drop Chance:'''<br/>"..dropChance
  end


   return result
   return result