Module:Pets infobox

-- Hide module's contents from the wikitext parser to avoid unwanted side effects

-- TODO: redo entire module local ChanceMultis = { 1, 1.25, 2, 2.5, 4, 5, 8, 10 } local Rarities = { "Common", "Rare", "Epic", "Legendary" } local Types = { "Walk", "Fly" } local StatMultipliers = require('Module:Utilities/StatMultipliers') local Pets = require('Module:Utilities/PetStats') local p = {} function table.find(t, str) for _,v in pairs(t) do       if tostring(v):lower == tostring(str):lower then return str end end return false end local function commas(str) str = tostring(str) return #str % 3 == 0 and str:reverse:gsub("(%d%d%d)", "%1,"):reverse:sub(2) or str:reverse:gsub("(%d%d%d)", "%1,"):reverse end local function GetStatRating(pet) local Forbidden = { "null1", "null2" }   local Pet = Pets[pet] local BestOfStat = {} for i,v in pairs(Pet.buffs) do       BestOfStat[i] = 0 end for i,v in pairs(Pets) do       for i2,v2 in pairs(v.buffs) do            if BestOfStat[i2] and BestOfStat[i2] < v2 and not table.find(Forbidden, i) then BestOfStat[i2] = v2           end end end local Ratings = {} for i,v in pairs(Pet.buffs) do       Ratings[i] = ((v / BestOfStat[i]) * (Pet.chance and 1 or 0.85)) * 5 end local FinalRating = 0 for i,v in pairs(Ratings) do       FinalRating = FinalRating + v    end return string.format("%2.1f", (FinalRating / 4)) end function p.CreateInfobox(frame) local Namespace = frame:preprocess('') if not Namespace then return '' end frame.args.PetName = frame.args.PetName and mw.text.decode(frame.args.PetName) if Namespace == '' and not Pets[frame.args.PetName] then return '' end local RealPage = Namespace == '' and Pets[frame.args.PetName] and true or false local Info = { title = (RealPage and frame.args.PetName) or frame.args.title1 or frame.args.title or frame:getTitle, image1 = frame.args.image1, image2 = frame.args.image2, image3 = frame.args.image3, image4 = frame.args.image4, caption1 = frame.args.caption1, caption2 = frame.args.caption2, caption3 = frame.args.caption3, caption4 = frame.args.caption4, Chance = (RealPage and Pets[frame.args.PetName].chance) or (not RealPage and frame.args.chance or ''), Rarity = (RealPage and Pets[frame.args.PetName].rarity) or (not RealPage and frame.args.rarity or ''), Type = (RealPage and Pets[frame.args.PetName].type) or (not RealPage and frame.args.type or ''), Coins = (RealPage and Pets[frame.args.PetName].buffs.Coins) or (not RealPage and frame.args.coin or ''), Diamonds = (RealPage and Pets[frame.args.PetName].buffs.Diamonds) or (not RealPage and frame.args.gem or frame.args.diamond or ''), All = (RealPage and Pets[frame.args.PetName].buffs.All) or (not RealPage and frame.args.All or ''), HasMythic = (RealPage and Pets[frame.args.PetName].hasMythic) or (not RealPage and frame.args.HasMythic or '') }   for i,v in pairs(Info) do        pcall(function            Info[i] = tonumber(tostring(string.gsub(v, ',', ''))) or Info[i]        end) if v ==  or v == ' ' or string.match(tostring(v), ']+)') then Info[i] = nil end   end    local Infobox = (' '):format(mw.uri.encode(Info.title, 'WIKI'))    local function Add(str)            Infobox = ('%s%s'):format(Infobox, str)    end    local function done        Infobox = ('%s '):format(Infobox)        Infobox = frame:preprocess(Infobox)    end     Add((                %s             ):format(Info.title or 'Missing Title'))    Add(' ')    local function addSection(name, image, caption, statm, chancem, rarity, invert, invertimg)        name = name or 'Normal'        caption = (image and (caption or )) or 'Image currently unavailable'        statm = statm or 1        chancem = chancem or 1        Add((                  %s             ):format(name, name))        if invert and not image and invertimg then            Add(([===[ ]===]):format(invertimg)) else Add((                           %s                       %s                   ):format(caption, image or 'DefaultShinyImage.png')) end if rarity and table.find(Rarities, rarity) then Add(:format(string.lower(rarity), rarity)) end if Info.Type and table.find(Types, Info.Type) then Add(([===[ ]===]):format(Info.Type, Info.Type, Info.Type)) end if Info.Bubbles then Add((                       %s%sBase Stats ):format(name == 'Normal' and  or name, name == 'Normal' and  or ' ')) for _,v in pairs(StatMultipliers) do               if Info[v[1]] then local stat = tonumber(Info[v[1]]) and commas(math.ceil(Info[v[1]] * statm)) or ('"%s" is not a number'):format(Info[v[1]]) Add(([===[ ]===]):format(v[3], v[1], v[2], v[4] or '', stat)) end end Add if Info.title ~= "Sylently's Pet" and Info.title ~= "Isaac's Creation 2.0" and RealPage then Add(([===[ Stats Rating ]===]):format(GetStatRating(Info.title), GetStatRating(Info.title))) end Add(' ') end if Info.Chance and tonumber(Info.Chance) and Info.Rarity and Info.Rarity == 'Legendary' then local Default = tonumber(Info.Chance) / chancem Add(                      Chances                 ) for _,v in pairs(ChanceMultis) do               Add(:format(v, Default * v, commas(math.ceil(100 / (Default * v))))) end Add(' ') end Add(' ') end addSection('Normal', Info.image1, Info.caption1, 1, 1, Info.Rarity) if Info.HasShiny and tostring(Info.HasShiny):lower == 'true' then addSection('Shiny', Info.image3, Info.caption3, 1.5, 200, 'Shiny') end addSection('Gold', Info.image2, Info.caption2, 2, 100, Info.Rarity, true, Info.image1) if Info.HasShiny and tostring(Info.HasShiny):lower == 'true' then addSection('???', Info.image4, Info.caption4, 3, 20000, 'Shiny', true, Info.image3) end Add(' ') done return RealPage and (' '):format(Info.Rarity, Info.Type) or frame:preprocess(), RealPage and Info.title ~= "Sylently's Pet" and Info.title ~= "Isaac's Creation 2.0" and  (():format(GetStatRating(Info.title))) or '', Infobox end return p

-- Hide module's contents from the wikitext parser to avoid unwanted side effects