Hi, I'm writing a loot-wishlist addon for my guild where players can fill their wishlists via EncouterJournal with small buttons I added. One of the feature in the addon is to remove items from wishlist when you get them (if the item is from or above the difficulty you added them to your wishlist).
I check players' equiped gear and items in inventory for to remove from the wishlist and I have ran into few problems with tier sets that I haven't managed to solve by myself. When going through the wishlist to remove items I have to match not only the tokens and the actual items, but also the Essences found in T17.
First problem: When I started coding this addon I wasn't thinking too far into the future and ended up hard coding the tier-items, tokens and essences into tables. Now with the release of T18 I'm asking if anyone of you have a better idea how to match these things so I don't have to waste time looking up and hardcoding tier items to tables with every new tier added into the game?
Second problem: To remove Essences from the wishlist I counted all the tier-items, tokens and essences and removed essences from wishlist if the total number was equal of above pre-set number, but this also counts duplicates, tokens for slots that has already the tier item and unusable tokens also. This isn't that big of a deal, unless you are the guy in the raid who picks and sells all the unwanted gear and your Essence is removed from your wishlist because of you picking all the unwanted tokens. Is there any way to match usability of tier token or should I try to hardcode a table with matching classes and tokens (I'm trying to reduce the amount of hard coding stuff that I have to add every new tier released)?
Here is some code related to my problems:
local TierItems = { -- List of Tier-items and their matching tokens
-- Helm of the Iron Conqueror
[119308] = 119308, -- Token
[115568] = 119308, -- Paladin
[115563] = 119308, -- Priest
[115586] = 119308, -- Warlock
-- Helm of the Iron Protector
[119321] = 119321, -- Token
[115545] = 119321, -- Hunter
[115556] = 119321, -- Monk
[115579] = 119321, -- Shaman
[115584] = 119321, -- Warrior
-- Helm of the Iron Vanquisher
[119312] = 119312, -- Token
[115539] = 119312, -- Death Knight
[115542] = 119312, -- Druid
[115553] = 119312, -- Mage
[115572] = 119312, -- Rogue
-- 8< SNIP, SNIP - you get the idea... --
}
local Essences = { -- List of Essences (Turn-in questitems for Tier-tokens)
-- Essence of the Iron Conqueror
[119310] = true, -- Horde
[120277] = true, -- Alliance
-- Essence of the Iron Protector
[119323] = true, -- Horde
[120279] = true, -- Alliance
-- Essence of the Iron Vanquisher
[119316] = true, -- Horde
[120278] = true, -- Alliance
}
local function _CheckLink(link) -- Return itemID and difficultyID from itemLink
if not link then -- No link given
return
elseif itemLinks[link] and itemLinks[link].id ~= nil then -- Check if we have scanned this item already
return itemLinks[link].id, itemLinks[link].difficulty
end
local _, itemID, _, _, _, _, _, _, _, _, _, difficultyID = strsplit(":", link)
itemID = tonumber(itemID)
difficultyID = tonumber(difficultyID)
itemLinks[link] = { id = itemID, difficulty = difficultyID } -- Add to table for faster access later
return itemID, difficultyID
end
local function _CheckEssence(essenceID, essenceDiff) -- Check if Player has already enough Tier-items
local tokenCount = 0
-- Check Backbags
local bag, slot = 0, 0
for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do
local itemID, difficultyID = _CheckLink(GetContainerItemLink(bag, slot))
if itemID == essenceID and essenceDiff <= difficultyID then -- Essence found
Debug("Backbags: Essence", itemID)
tokenCount = tokenCount + 1
elseif TierItems[itemID] and essenceDiff <= difficultyID then -- Tier-item found
Debug("Backbags: Tier", itemID)
tokenCount = tokenCount + 1
end
end
end
-- Check Equiped
for i = 1, 10 do -- Head (1), Shoulder (3), Chest (5), Legs (7), Hands (10)
if i == 1 or i == 3 or i == 5 or i == 7 or i == 10 then
local itemID, difficultyID = _CheckLink(GetInventoryItemLink("Player", i))
if TierItems[itemID] and essenceDiff <= difficultyID then -- Tier-item found
Debug("Equiped: Tier", itemID)
tokenCount = tokenCount + 1
end
end
end
return tokenCount
end
for i = 1, 17 do -- Skip the shirt (4) and tabard (18)
if i ~= 4 then
local itemID, difficultyID = _CheckLink(GetInventoryItemLink("Player", i))
if db[itemID] and db[itemID].difficulty <= difficultyID then -- Item found, remove from wishlist
Debug("Remove by Equiped:", itemID, difficultyID)
db[itemID] = nil
elseif db[TierItems[itemID]] and db[TierItems[itemID]].difficulty <= difficultyID then -- Tier-item found, remove from wishlist
Debug("Remove Tier by Equiped:", TierItems[itemID], "->", itemID, difficultyID)
db[TierItems[itemID]] = nil
end
end
end
local bag, slot = 0, 0
for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do
local itemID, difficultyID = _CheckLink(GetContainerItemLink(bag, slot))
if Essences[itemID] then -- Essence found, check if we have enough tier already
local essenceCount = _CheckEssence(itemID, difficultyID)
if essenceCount >= cfg.maxTiersForEssence then
Debug("Remove Essence by Bags:", itemID, difficultyID, essenceCount)
db[itemID] = nil
end
elseif db[itemID] and db[itemID].difficulty <= difficultyID then -- Item found, remove from wishlist
Debug("Remove by Bags:", itemID, difficultyID)
db[itemID] = nil
elseif db[TierItems[itemID]] and db[TierItems[itemID]].difficulty <= difficultyID then -- Tier-item found, remove from wishlist
Debug("Remove Tier by Bags:", TierItems[itemID], "->", itemID, difficultyID)
db[TierItems[itemID]] = nil
end
end
end
Bonus problem for anyone interested in hacking EncounterJournal: Currently the wishlist buttons appear in every loot subpage EJ has (old raids, world bosses and dungeons). Is there any easy way to detect when you are looking at actual WoD (and future expansions) raid instance pages that doesn't bomb server with queries when scrolling the loot subpage scroller so I could hide the buttons for dungeons and world bosses?
I check players' equiped gear and items in inventory for to remove from the wishlist and I have ran into few problems with tier sets that I haven't managed to solve by myself. When going through the wishlist to remove items I have to match not only the tokens and the actual items, but also the Essences found in T17.
First problem: When I started coding this addon I wasn't thinking too far into the future and ended up hard coding the tier-items, tokens and essences into tables. Now with the release of T18 I'm asking if anyone of you have a better idea how to match these things so I don't have to waste time looking up and hardcoding tier items to tables with every new tier added into the game?
Second problem: To remove Essences from the wishlist I counted all the tier-items, tokens and essences and removed essences from wishlist if the total number was equal of above pre-set number, but this also counts duplicates, tokens for slots that has already the tier item and unusable tokens also. This isn't that big of a deal, unless you are the guy in the raid who picks and sells all the unwanted gear and your Essence is removed from your wishlist because of you picking all the unwanted tokens. Is there any way to match usability of tier token or should I try to hardcode a table with matching classes and tokens (I'm trying to reduce the amount of hard coding stuff that I have to add every new tier released)?
Here is some code related to my problems:
Bonus problem for anyone interested in hacking EncounterJournal: Currently the wishlist buttons appear in every loot subpage EJ has (old raids, world bosses and dungeons). Is there any easy way to detect when you are looking at actual WoD (and future expansions) raid instance pages that doesn't bomb server with queries when scrolling the loot subpage scroller so I could hide the buttons for dungeons and world bosses?
If you want/need to see more code, it is all found at http://wow.curseforge.com/addons/loihloot/