Module:Pets: Difference between revisions

44 bytes removed ,  17 November 2021
Ensure consistent pet drop chance logic by creating _getPetChance()
m (Amend odd indentation)
(Ensure consistent pet drop chance logic by creating _getPetChance())
Line 81: Line 81:
     end
     end
   end
   end
 
 
   if useIcon then
   if useIcon then
     petSource = Icons.Icon({petSource, type=iconType})
     petSource = Icons.Icon({petSource, type=iconType})
Line 115: Line 115:
   end
   end
   end
   end
end
function p._getPetChance(pet)
    if pet.obtained ~= nil and pet.obtained.dungeonCompletion ~= nil then
        local odds = pet.obtained.dungeonCompletion[1][2]
        if pet.name == 'Pablo' then
            -- Special handling for Into the Mist/Pablo
            return 'Guaranteed after ' .. odds .. ' clears'
        else
            -- Dungeon pet
            return '1 in ' .. odds .. ' (' .. Shared.round(100 / odds, 2, 2) .. '%)'
        end
    elseif pet.name == 'Bone' then
        -- Special handling for Impending Darkness/Bone
        return 'Guaranteed after 1 clear'
    else
        -- Skill pet or other
        return 'See: [[Pets#Acquiring Pets|Acquiring Pets]]'
    end
end
end


Line 174: Line 193:
   local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or p._getPetEffect(pet)
   local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or p._getPetEffect(pet)
   local completionReq = (pet.ignoreCompletion ~= nil and pet.ignoreCompletion) and 'No' or 'Yes'
   local completionReq = (pet.ignoreCompletion ~= nil and pet.ignoreCompletion) and 'No' or 'Yes'
  local dropChance = p._getPetChance(pet)


  local dropChance = nil
  if pet.obtained ~= nil and pet.obtained.dungeonCompletion ~= nil then
    local odds = pet.obtained.dungeonCompletion[1][2]
    -- Special handling for Into the Mist/Pablo
    if pet.obtained.dungeonCompletion[1][1] == 15 then
      dropChance = 'Guaranteed after ' .. odds .. ' completions'
    else
      dropChance = '1 in '..odds..' ('..Shared.round(100 / odds, 2, 2)..'%)'
    end
  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'
   result = result..'! '..name..'\r\n|-\r\n| '
   result = result..'! '..name..'\r\n|-\r\n| '
Line 234: Line 243:
     result = "\r\n|-\r\n|'''[[Pets#Boss Pets|Pet]]:'''<br/>"
     result = "\r\n|-\r\n|'''[[Pets#Boss Pets|Pet]]:'''<br/>"
     result = result..Icons.Icon({pet.name, type='pet'})
     result = result..Icons.Icon({pet.name, type='pet'})
 
     result = result.."\r\n|-\r\n|'''Pet Drop Chance:'''<br/>"..p._getPetChance(pet)
    local dropChance = ''
    if dung.name == 'Into the Mist' then
      dropChance = 'Guaranteed after 5 clears'
    elseif dung.name == 'Impending Darkness Event' then
      dropChance = 'Guaranteed after one clear'
    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
   end