Requires: LibStub, CallbackHandler-1.0
With 5.0 a new C_PetJournal API was introduced, and unfortunately the old GetCompanionInfo API no longer works properly (it does not, for example, know anything about non-combat pets obtained before the account-wide merge, and you also can no longer summon non-combat pets using it).
This library provides the list of player owned pet ids and all species ids, which can be used with C_PetJournal.GetPetInfoByPetID() and C_PetJournal.GetPetInfoBySpeciesID().
It primarily deals with two problems with scanning the pet journal:
- Filters: The Pet Journal filters are cleared and then restored, as they affect the return values given from C_PetJournal.GetPetInfoByIndex()
- Updating in response to event: Manipulating the Pet Journal filters causes PET_JOURNAL_LIST_UPDATE to fire, which is also the only event that always fires when you lose or gain a pet. Filter manipulation is detected and we never try to rescan pets in response. When this is not the case, a CallbackHandler event is fired which can be used to safely detect changes to the pet list.
local LibPetJournal = LibStub("LibPetJournal-2.0") local function ScanPets() for _,petid in LibPetJournal:IteratePetIDs() do local speciesID, customName, level, xp, maxXp, displayID, isFavorite, name, icon, petType, creatureID, sourceText, description, isWild, canBattle, tradable, unique = C_PetJournal.GetPetInfoByPetID(petid) if name == "Feline Familiar" then print("Player has a cat in a hat.") end end end ScanPets()
If you wanted to automatically scan for little cats in hats when the pet list changes, you could register a callback, such as:
LibPetJournal.RegisterCallback(addon, "PetListUpdated", ScanPets)
Obviously you would normally use the speciesID or creatureID return values from C_PetJournal.GetPetInfoByPetID() to find a particular pet, but this is just a silly example.
2016-07-17 Robin Schoonover <firstname.lastname@example.org>
|File Name||Release Type||Game Version||Downloads||Date|
|2.0.32||Release||6.2.4||6,210||Jul 17, 2016|
|2.0.31||Release||6.2.4||1,249||May 31, 2016|
|2.0.30||Release||6.2.4||674||May 25, 2016|
|2.0.28||Release||6.2.2||2,154||Oct 24, 2015|
|2.0.27||Release||6.0.2||4,528||Sep 10, 2014|
|2.0.26||Release||5.2.0||3,892||May 4, 2013|
|2.0.25||Release||5.2.0||1,508||Mar 5, 2013|
|188.8.131.52||Release||5.1.0||1,242||Dec 30, 2012|
|2.0.24||Release||5.0.5||1,353||Oct 26, 2012|
|2.0.23||Release||5.0.5||400||Oct 25, 2012|
|2.0.22||Release||5.0.5||761||Oct 10, 2012|
|2.0.21||Release||5.0.5||675||Sep 28, 2012|
|2.0.20||Release||5.0.5||402||Sep 23, 2012|
|2.0.19||Release||5.0.5||63||Sep 23, 2012|
|2.0.18||Release||5.0.5||110||Sep 19, 2012|
|2.0.17||Release||5.0.5||33||Sep 19, 2012|
|2.0.16||Release||5.0.5||117||Sep 16, 2012|
|2.0.15||Release||5.0.5||84||Sep 13, 2012|
|2.0.14||Release||5.0.4||86||Sep 11, 2012|