ahakola / AlreadyKnown

WoW-addon // Puts green tint on already known scrolls/pets/other learnable items on vendors.
MIT License
4 stars 2 forks source link

Guildbank BattlePet cages #5

Closed Dairyman closed 3 years ago

Dairyman commented 3 years ago

Snippet which checks if the item is a cage and when yes checks if any pet of this species is learned.

local learned = false
local speciesID = scantip:SetGuildBankItem(tab, button:GetID())
if speciesID and speciesID > 0 then
    learned = C_PetJournal.GetNumCollectedInfo(speciesID) > 0
end

Edit: Use GetNumCollectedInfo instead of GetOwnedBattlePetString

ahakola commented 3 years ago

How is this different from the current C_PetJournal.GetNumCollectedInfo method other than using the tooltip:SetGuildBankItem() instead of pulling the itemlink from the button first and using that? As far as I understand, both of these methods should yield the exact same results.

if itemLink:match("|H(.-):") == "battlepet" then -- Check if item is Caged Battlepet (dummy item 82800)
    local _, battlepetId = strsplit(":", itemLink)
    if C_PetJournal.GetNumCollectedInfo(battlepetId) > 0 then
        if db.debug and not knownTable[itemLink] then Print("%d - BattlePet: %s %d", itemId, battlepetId, C_PetJournal.GetNumCollectedInfo(battlepetId)) end
        knownTable[itemLink] = true -- Mark as known for later use
        return true -- Battlepet is collected
    end
    return false -- Battlepet is uncollected... or something went wrong
end
Dairyman commented 3 years ago

The itemLinkfrom the GuildBank is the dummy one ("item:82800::::::::60:102:::::::::") which has no information. That's why the need to call GameTooltip:SetGuildBankItem(), to get the speciesID.

ahakola commented 3 years ago

Oh yes, now I remember working on this back in the days and how stupid the system is. I'll see what I can come up with.

ahakola commented 3 years ago

Sorry for taking so long (had ton of stuff IRL going on), but I have combined your suggestion with the way how I handle caged battlepets in the New AH -hook. I hope this works out of the box, but I don't want to close this issue yet just in case. If this doesn't work, I'll just update the addon to be more close to your original suggestion.

Don't hesitate to let me know if you have any other suggestions/bug fixes for this or other aspects of the addon.

Dairyman commented 3 years ago

Need to use itemID the texture in the GuildBank is from the Pet itself, e.g:

if itemLink and strmatch(itemLink, "item:82800" then -- Inv_box_petcarrier_01 (BattlePet, itemId 82800)

Then it works.

ahakola commented 3 years ago

Changed the addon to use itemId instead of texture in GBank, hope it works for real this time!

Dairyman commented 3 years ago

Works now 🎉.