vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --============================================================================================--
2 --============================================================================================--
3 -- --
4 -- ITEM, BAG, TOOLTIP FUNCTIONS --
5 -- --
6 --============================================================================================--
7 --============================================================================================--
8  
9 --GetContainerItemLink item name strfind syntax
10 local WARDROBE_ITEM_NAME_FROM_LINK = "|h%[(.-)%]|h";
11 local WARDROBE_ITEM_UNIQUE_IDS_FROM_LINK = "|Hitem:(.-):(.-):(.-):(.-)|h%[(.-)%]|h"
12 --/script local itemNum=GetMouseFocus():GetID(); Sea.io.printComma(string.gfind(GetInventoryItemLink("player", itemNum), WARDROBE_ITEM_UNIQUE_IDS_FROM_LINK)())
13  
14 local CraftableItemIDs = {
15 -- These item id's will ignore suffix
16 [1254] = true; --Lesser Firestone
17 [13699] = true; --Firestone
18 [13700] = true; --Greater Firestone
19 [13701] = true; --Major Firestone
20  
21 [5522] = true; --Spellstone
22 [13602] = true; --Greater Spellstone
23 [13603] = true; --Major Spellstone
24 };
25  
26 ---------------------------------------------------------------------------------
27 -- Return the name of the item in the specified player's inventory slot number
28 -- (1 = "headslot" etc - see Wardrobe.InventorySlots above for a full list of the slots)
29 ---------------------------------------------------------------------------------
30 function Wardrobe.GetItemNameAtInventorySlotNumber(slotNum)
31  
32 local itemName, _ = "";
33 -- get the id number for the item slot
34 local id = GetInventorySlotInfo(Wardrobe.InventorySlots[slotNum]);
35 local linktext = GetInventoryItemLink("player", id);
36 if (linktext) then
37 _,_,itemName = strfind(linktext, WARDROBE_ITEM_NAME_FROM_LINK);
38 end
39 return itemName;
40 end
41  
42 function Wardrobe.GetItemInfoAtInventorySlotNumber(slotNum)
43  
44 local itemID, permEnchant, tempEnchant, suffix, itemName;
45 -- get the id number for the item slot
46 local linktext = GetInventoryItemLink("player", GetInventorySlotInfo(Wardrobe.InventorySlots[slotNum]));
47 if (linktext) then
48 itemID, permEnchant, tempEnchant, suffix, itemName = string.gfind(linktext, WARDROBE_ITEM_UNIQUE_IDS_FROM_LINK)();
49 end
50 return itemID, permEnchant, tempEnchant, suffix, itemName;
51 end
52  
53  
54 ---------------------------------------------------------------------------------
55 -- Find the named item on the character's inventory (head slot, hand slot, etc -- not bags)
56 ---------------------------------------------------------------------------------
57 function Wardrobe.FindInventoryItem(targetItemID, targetSuffix, targetPermEnchant, targetItemName)
58  
59 local itemSlot, itemID, permEnchant, tempEnchant, suffix, invItemName;
60 for i = 1, table.getn(Wardrobe.InventorySlots) do
61 itemID, permEnchant, tempEnchant, suffix, invItemName = Wardrobe.GetItemInfoAtInventorySlotNumber(i);
62  
63 if (itemID) then
64 if (targetItemID) and (targetSuffix) and (targetPermEnchant) then
65 -- If target item ID and suffix are passed try to match them.
66 if (targetItemID == itemID) and (targetSuffix == suffix) then
67 if (targetPermEnchant == permEnchant) then
68 itemSlot = i;
69 break;
70 else
71 -- Perm enchant doesn't match, ignore
72 end
73 end
74 elseif (targetItemName == invItemName) then
75 -- If only name is passed match loosely.
76 itemSlot = i;
77 break;
78 end
79 end
80 end
81  
82 return itemSlot;
83 end
84  
85  
86 ---------------------------------------------------------------------------------
87 -- Return the name of the item in the specified bag and slot
88 ---------------------------------------------------------------------------------
89 function Wardrobe.GetItemNameInBagSlot(bagNum, slotNum)
90  
91 local itemName, _ = "";
92 local linktext = GetContainerItemLink(bagNum, slotNum)
93 if (linktext) then
94 _,_,itemName = strfind(linktext, WARDROBE_ITEM_NAME_FROM_LINK);
95 end
96  
97 return itemName;
98 end
99  
100 function Wardrobe.GetItemInfoInBagSlot(bagNum, slotNum)
101  
102 local itemID, permEnchant, tempEnchant, suffix, itemName;
103 local linktext = GetContainerItemLink(bagNum, slotNum);
104 if (linktext) then
105 itemID, permEnchant, tempEnchant, suffix, itemName = string.gfind(linktext, WARDROBE_ITEM_UNIQUE_IDS_FROM_LINK)();
106 end
107 return itemID, permEnchant, tempEnchant, suffix, itemName;
108 end
109  
110 ---------------------------------------------------------------------------------
111 -- Given the name of an item, find the bag and slot the item is in
112 ---------------------------------------------------------------------------------
113 function Wardrobe.FindContainerItem(targetItemID, targetSuffix, targetPermEnchant, targetItemName)
114 local foundBag, foundSlot, wrongEnchant;
115 --Wardrobe.Debug(" Looking in inventory for ["..targetItemName.."]");
116  
117 -- for each bag and slot
118 if ( Wardrobe.InventorySearchForward == 1 ) then
119 bagcounterA = 0
120 bagcounterB = NUM_CONTAINER_FRAMES
121 else
122 bagcounterB = 0
123 bagcounterA = NUM_CONTAINER_FRAMES
124 end
125  
126 local backupItems = {};
127 local itemID, permEnchant, tempEnchant, suffix, bagItemName;
128  
129 for bag = bagcounterA, bagcounterB, Wardrobe.InventorySearchForward do
130 local frame = getglobal("ContainerFrame"..bag);
131 local counterA = 1
132 local counterB = 1
133  
134 if ( Wardrobe.InventorySearchForward == 1 ) then
135 counterA = 1
136 counterB = GetContainerNumSlots(bag)
137 else
138 counterB = 1
139 counterA = GetContainerNumSlots(bag)
140 end
141  
142 for slot = counterA, counterB, Wardrobe.InventorySearchForward do
143 itemID, permEnchant, tempEnchant, suffix, bagItemName = Wardrobe.GetItemInfoInBagSlot(bag, slot);
144 Wardrobe.Debug(" Comparing with "..tostring(bagItemName).." Bag:"..bag.." Slot:"..slot);
145 if (itemID) then
146 if (targetItemID) and (targetItemID == itemID) and CraftableItemIDs[targetItemID] then
147 Wardrobe.Debug(" FOUND [by craftable ID] in bag = "..bag.." slot = "..slot);
148 foundBag = bag;
149 foundSlot = slot;
150 break;
151 elseif (targetItemID) and (targetSuffix) and (targetPermEnchant) then
152 -- If target item ID and suffix are passed try to match them.
153 if (targetItemID == itemID) and (targetSuffix == suffix) then
154 if (targetPermEnchant == permEnchant) then
155 Wardrobe.Debug(" FOUND [by full ID] in bag = "..bag.." slot = "..slot);
156 foundBag = bag;
157 foundSlot = slot;
158 break;
159 else
160 -- Perm enchant doesn't match, add to backup list for 2nd pass
161 -- Currently Ignored for absolute match...
162 --table.insert(backupItems, {bag=bag,slot=slot});
163 end
164 end
165 elseif (targetItemName == bagItemName) then
166 -- If only name is passed match loosely.
167 Wardrobe.Debug(" FOUND [by name] in bag = "..bag.." slot = "..slot);
168 foundBag = bag;
169 foundSlot = slot;
170 break;
171 end
172 end
173 end
174 if (foundBag and foundSlot) then
175 break;
176 end
177 end
178  
179 if (not foundBag and not foundSlot) then
180 for index, info in backupItems do
181 -- Print out all found backups. Use the last one found.
182 foundBag = info.bag;
183 foundSlot = info.slot;
184 wrongEnchant = true;
185 Wardrobe.Debug(" FOUND [by partial ID] in bag = "..foundBag.." slot = "..foundSlot);
186 end
187 end
188  
189 if ( Wardrobe.InventorySearchForward == 1 ) then
190 Wardrobe.InventorySearchForward = -1
191 else
192 Wardrobe.InventorySearchForward = 1
193 end
194  
195 return foundBag, foundSlot, wrongEnchant;
196 end
197  
198  
199 ---------------------------------------------------------------------------------
200 -- Build a list of items in our bags and on our person
201 ---------------------------------------------------------------------------------
202 function Wardrobe.BuildItemList()
203  
204 tempList = {};
205  
206 -- for each bag and slot
207 local itemID, permEnchant, tempEnchant, suffix, itemName
208 for bag = 0, NUM_CONTAINER_FRAMES, 1 do
209 local frame = getglobal("ContainerFrame"..bag);
210 for slot = 1, GetContainerNumSlots(bag) do
211  
212 -- get the name of the item in this bag/slot
213 --itemName = Wardrobe.GetItemNameInBagSlot(bag, slot);
214 itemID, permEnchant, tempEnchant, suffix, itemName = Wardrobe.GetItemInfoInBagSlot(bag, slot);
215 if (itemName) and (itemName ~= "") then
216 table.insert(tempList, {Name = itemName, ItemID = itemID, PermEnchant = permEnchant, TempEnchant = tempEnchant, Suffix = suffix});
217 end
218 end
219 end
220  
221 -- for each inventory item
222 for i = 1, table.getn(Wardrobe.InventorySlots) do
223 --itemName = Wardrobe.GetItemNameAtInventorySlotNumber(i);
224 itemID, permEnchant, tempEnchant, suffix, itemName = Wardrobe.GetItemInfoAtInventorySlotNumber(i);
225 if (itemName) and (itemName ~= "") then
226 table.insert(tempList, {Name = itemName, ItemID = itemID, PermEnchant = permEnchant, TempEnchant = tempEnchant, Suffix = suffix});
227 end
228 end
229  
230  
231 return tempList;
232 end
233  
234  
235  
236 ---------------------------------------------------------------------------------
237 -- Equip the specified item into the specified slot on our character (hands, chest, etc)
238 ---------------------------------------------------------------------------------
239 function Wardrobe.Equip(itemName, equipSlot, itemID, suffix, permEnchant)
240  
241 -- if we're already holding something, bail
242 if (CursorHasItem()) then
243 return false;
244 end
245  
246 -- find the bag and slot of this item
247 local bag, slot, wrongEnchant = Wardrobe.FindContainerItem(itemID, suffix, permEnchant, itemName);
248 if (bag and slot) then
249 PickupContainerItem(bag, slot);
250 if (equipSlot) and (equipSlot >= 11) and (equipSlot <= 17) and (equipSlot ~= 15) then
251 --Fingers, Trinkets, Weapons
252 --PickupInventoryItem(equipSlot);
253 EquipCursorItem(equipSlot);
254 else
255 AutoEquipCursorItem();
256 end
257 return true;
258 elseif (equipSlot) and (equipSlot >= 11) and (equipSlot <= 17) and (equipSlot ~= 15) then
259 -- Fingers, Trinkets, Weapons
260 -- Find the inventory slot of this item
261 local invSlot = Wardrobe.FindInventoryItem(itemID, suffix, permEnchant, itemName);
262 if (invSlot) then
263 --convert to inventory id
264 invSlot = GetInventorySlotInfo(Wardrobe.InventorySlots[invSlot]);
265  
266 if (invSlot ~= equipSlot) then
267 PickupInventoryItem(invSlot);
268 EquipCursorItem(equipSlot);
269 return true;
270 end
271 end
272 end
273 return false;
274 end
275  
276  
277 ---------------------------------------------------------------------------------
278 -- Check to see if the specified outfit name is already being used
279 ---------------------------------------------------------------------------------
280 function Wardrobe.FoundOutfitName(outfitName)
281  
282 for i, outfit in Wardrobe_Config[WD_realmID][WD_charID].Outfit do
283 if (outfit.OutfitName == outfitName) then
284 return true;
285 end
286 end
287  
288 return false;
289 end
290  
291  
292 ---------------------------------------------------------------------------------
293 -- Return the index of the specified outfitName
294 ---------------------------------------------------------------------------------
295 function Wardrobe.GetOutfitNum(outfitName)
296  
297 for i, outfit in Wardrobe_Config[WD_realmID][WD_charID].Outfit do
298 if (outfit.OutfitName == outfitName) then
299 return i;
300 end
301 end
302 end
303  
304  
305  
306 ---------------------------------------------------------------------------------
307 -- See if this bag / slot is being used or is free
308 ---------------------------------------------------------------------------------
309 function Wardrobe.UsedThisSlot(freeBagSpacesUsed, theBag, theSlot)
310 for i = 1, table.getn(freeBagSpacesUsed) do
311 if (freeBagSpacesUsed[i][1] == theBag and freeBagSpacesUsed[i][2] == theSlot) then
312 return true;
313 end
314 end
315 return false;
316 end
317  
318  
319 ---------------------------------------------------------------------------------
320 -- Put an item into a free bag slot
321 ---------------------------------------------------------------------------------
322 function BagItem(freeBagSpacesUsed, backwards)
323 if (not freeBagSpacesUsed) then
324 freeBagSpacesUsed = {};
325 end
326 local firstBag, lastBag, inc;
327 if (backwards) then
328 firstBag = 4
329 lastBag = 1;
330 inc = -1;
331 else
332 firstBag = 0
333 lastBag = 4;
334 inc = 1;
335 end
336 -- for each bag and slot
337 for theBag = firstBag, lastBag, inc do
338 local numSlot = GetContainerNumSlots(theBag);
339 for theSlot = 1, numSlot do
340  
341 -- get info about the item here
342 local texture, itemCount, locked = GetContainerItemInfo(theBag, theSlot);
343  
344 -- if we found nothing, add us to the list of free bag slots
345 if (not texture and not Wardrobe.UsedThisSlot(freeBagSpacesUsed, theBag, theSlot)) then
346 PickupContainerItem(theBag,theSlot);
347 table.insert(freeBagSpacesUsed, {theBag, theSlot});
348 return true, freeBagSpacesUsed;
349 end
350 end
351 end
352  
353 AutoEquipCursorItem();
354  
355 return false, freeBagSpacesUsed;
356 end
357  
358 ---------------------------------------------------------------------------------
359 -- Move an item in your bags to the back most free bag slot
360 ---------------------------------------------------------------------------------
361 function ReBagContainerItem(invItemName)
362 local foundBag, foundSlot, wrongEnchant = Wardrobe.FindContainerItem(nil, nil, nil, invItemName);
363 PickupContainerItem(foundBag, foundSlot);
364 BagItem(nil,true);
365 end