Anonymous

Module:Pets: Difference between revisions

From Melvor Idle
m
getPetPageTable: Add acquiredOverrides for Golbin Raid pets
m (Fix acquired by links for boss pets in pet table)
m (getPetPageTable: Add acquiredOverrides for Golbin Raid pets)
(3 intermediate revisions by one other user not shown)
Line 39: Line 39:
function p.getPetBySkill(skillName)
function p.getPetBySkill(skillName)
   local result = nil
   local result = nil
   skillName = string.gsub(skillName, "%%27", "'")
   local skillID = Skills.getSkillID(skillName)
  skillName = string.gsub(skillName, "'", "'")
  skillName = string.gsub(skillName, "'", "'")
   for i, pet in pairs(PetData.Pets) do
   for i, pet in pairs(PetData.Pets) do
     if(Skills.getSkillID(skillName) == pet.skill) then
     if(skillID == pet.skill) 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
Line 67: Line 65:
   local result = nil
   local result = nil
   local skillName = frame.args ~= nil and frame.args[1] or frame
   local skillName = frame.args ~= nil and frame.args[1] or frame
  skillName = string.gsub(skillName, "%%27", "'")
 
   skillName = string.gsub(skillName, "'", "'")
   return p.getPetTable(p.getPetBySkill(skillName).name)
  skillName = string.gsub(skillName, "'", "'")
  local pet = p.getPetBySkill(skillName)
  result = p.getPetTable(pet.name)
  return result
end
end


Line 80: Line 74:
   local name = (args.name ~= nil and args.name ~= '') and args.name or args[1]
   local name = (args.name ~= nil and args.name ~= '') and args.name or args[1]
   local pet = p.getPet(name)
   local pet = p.getPet(name)
  local skill = (args.skill ~= nil and args.skill ~= '') and args.skill or Icons.Icon({Skills.getSkillName(pet.skill), type='skill'})
   local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or pet.description
   local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or pet.description
  local source = nil
  if (args.skill ~= nil and args.skill ~= '') then
    source = args.skill
  elseif pet.skill ~= nil and pet.skill >= 0 then
    source = Icons.Icon({Skills.getSkillName(pet.skill), type='skill'})
  else
    local combatArea = Zones.getArea(pet.acquiredBy)
    if combatArea ~= nil then
      source = Icons.Icon({combatArea.name, type=combatArea.type})
    end
  end
  local dropChance = nil
  if pet.obtained ~= nil and pet.obtained.dungeonCompletion ~= nil then
    local odds = pet.obtained.dungeonCompletion[1][2]
    dropChance = '1 in '..odds..' ('..Shared.round(100 / odds, 2, 2)..'%)'
  end
    
    
   result = '{| class="wikitable" style="float:right; clear:right;"\r\n|-\r\n'
   result = '{| class="wikitable" style="float:right; clear:right;"\r\n|-\r\n'
Line 87: Line 99:
   result = result..Icons.Icon({name, type='pet', size='250', notext=true})
   result = result..Icons.Icon({name, type='pet', size='250', notext=true})
   result = result..'\r\n|-\r\n| Pet ID: '..pet.id
   result = result..'\r\n|-\r\n| Pet ID: '..pet.id
   result = result..'\r\n|-\r\n| Skill: '..skill
 
   result = result..'\r\n|-\r\n| Source: '..source
  if dropChance ~= nil then
    result = result..'\r\n|-\r\n| Drop Chance: '..dropChance
  end
 
   result = result..'\r\n|-\r\n| style ="width: 250px;"|Effect: '..effect..'\r\n|}'
   result = result..'\r\n|-\r\n| style ="width: 250px;"|Effect: '..effect..'\r\n|}'


Line 99: Line 116:
   local acquiredOverrides = {
   local acquiredOverrides = {
     ['Ripper the Reindeer'] = '[[Events#Christmas_Event_2020|Christmas Event 2020]]',
     ['Ripper the Reindeer'] = '[[Events#Christmas_Event_2020|Christmas Event 2020]]',
    ['Jerry the Giraffe'] = '[[Golbin Raid|Golbin Raid Shop]]',
    ['Preston the Platypus'] = '[[Golbin Raid|Golbin Raid Shop]]',
   }
   }
   local effectOverrides = {
   local effectOverrides = {
Line 155: Line 174:


   local skillPetList = {}
   local skillPetList = {}
  local bossPetList = {}
   local otherPetList = {}
   local otherPetList = {}
   for i, petData in Shared.skpairs(PetData.Pets) do
   for i, petData in Shared.skpairs(PetData.Pets) do
     if petData.skill ~= nil and petData.skill >= 0 and petData.name ~= "Ty" then
     if petData.skill ~= nil and petData.skill >= 0 and petData.name ~= "Ty" then
       table.insert(skillPetList, Icons.Icon({petData.name, type='pet'}))
       table.insert(skillPetList, Icons.Icon({petData.name, type='pet'}))
    elseif petData.obtained ~= nil and petData.obtained.dungeonCompletion ~= nil then
      table.insert(bossPetList, Icons.Icon({petData.name, type='pet'}))
     else
     else
       table.insert(otherPetList, Icons.Icon({petData.name, type='pet'}))
       table.insert(otherPetList, Icons.Icon({petData.name, type='pet'}))
Line 164: Line 186:
   end
   end
   table.sort(skillPetList, function(a, b) return a < b end)
   table.sort(skillPetList, function(a, b) return a < b end)
  table.sort(bossPetList, function(a, b) return a < b end)
   table.sort(otherPetList, function(a, b) return a < b end)
   table.sort(otherPetList, function(a, b) return a < b end)
   result = result..'\r\n|-\r\n!Skill Pets\r\n|'..table.concat(skillPetList, ' • ')
   result = result..'\r\n|-\r\n!Skill Pets\r\n|'..table.concat(skillPetList, ' • ')
  result = result..'\r\n|-\r\n!Boss Pets\r\n|'..table.concat(bossPetList, ' • ')
   result = result..'\r\n|-\r\n!Other Pets\r\n|'..table.concat(otherPetList, ' • ')
   result = result..'\r\n|-\r\n!Other Pets\r\n|'..table.concat(otherPetList, ' • ')
   result = result..'\r\n|}'
   result = result..'\r\n|}'