vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | -- |
||
3 | -- Sea.wow.item |
||
4 | -- |
||
5 | -- Item related wow functions |
||
6 | -- |
||
7 | -- $LastChangedBy: Sinaloit $ |
||
8 | -- $Rev: 2025 $ |
||
9 | -- $Date: 2005-07-02 18:51:34 -0500 (Sat, 02 Jul 2005) $ |
||
10 | --]] |
||
11 | |||
12 | Sea.wow.item = { |
||
13 | |||
14 | -- |
||
15 | -- getInventoryItemName( bag, slot ) |
||
16 | -- |
||
17 | -- Gets the name of the item in the specified bag/slot |
||
18 | -- |
||
19 | -- Args: |
||
20 | -- (int bag, int slot) |
||
21 | -- bag - 0 through 8, the bag number |
||
22 | -- slot - index within the bag |
||
23 | -- |
||
24 | -- Returns: |
||
25 | -- (string name) |
||
26 | -- name - the item's name |
||
27 | -- |
||
28 | getInventoryItemName = function (bag, slot) |
||
29 | local name = ""; |
||
30 | local strings = nil; |
||
31 | strings = Sea.wow.item.getInventoryItemInfoStrings(bag, slot, "GameTooltip"); |
||
32 | -- Determine if the item is an ore, gem or herb |
||
33 | if ( strings[1] ) then |
||
34 | name = strings[1].left; |
||
35 | end |
||
36 | return name; |
||
37 | end; |
||
38 | |||
39 | -- |
||
40 | -- classifyInventoryItem(bag, slot, TooltipNameBase) |
||
41 | -- |
||
42 | -- Returns a great deal of useful information about an item. |
||
43 | -- |
||
44 | -- Return: |
||
45 | -- Table[ |
||
46 | -- .classification |
||
47 | -- .name |
||
48 | -- .quality |
||
49 | -- .count |
||
50 | -- .minLevel |
||
51 | -- .unique |
||
52 | -- .soulbound |
||
53 | -- .bindOnPickup |
||
54 | -- .bindOnEquip |
||
55 | -- .quest |
||
56 | -- ] itemInfo; |
||
57 | -- |
||
58 | -- |
||
59 | |||
60 | classifyInventoryItem = function (bag, slot, TooltipNameBase) |
||
61 | if ( TooltipNameBase == nil ) then |
||
62 | TooltipNameBase = "GameTooltip"; |
||
63 | end |
||
64 | |||
65 | local strings = Sea.wow.item.getInventoryItemInfoStrings(bag, slot, TooltipNameBase); |
||
66 | |||
67 | local texture, itemCount, locked, quality = GetContainerItemInfo(bag,slot); |
||
68 | |||
69 | return Sea.wow.item.classifyItemStrings(strings, itemCount, quality); |
||
70 | end; |
||
71 | |||
72 | |||
73 | -- |
||
74 | -- classifyItemStrings(strings, itemCount, quality) |
||
75 | -- |
||
76 | -- Args: |
||
77 | -- |
||
78 | -- strings - array of strings that mimic the tooltip of the item to classify |
||
79 | -- itemCount - optional number that indicates the number of items |
||
80 | -- quality - optional number that indicates the quality of the item |
||
81 | -- |
||
82 | -- Returns a great deal of useful information about an item. |
||
83 | -- The tooltip strings must be gathered from the item, using the |
||
84 | -- getInventoryItemInfoStrings syntax. |
||
85 | -- |
||
86 | -- |
||
87 | -- Return: |
||
88 | -- Table[ |
||
89 | -- .classification |
||
90 | -- .name |
||
91 | -- .quality |
||
92 | -- .count |
||
93 | -- .minLevel |
||
94 | -- .unique |
||
95 | -- .soulbound |
||
96 | -- .bindOnPickup |
||
97 | -- .bindOnEquip |
||
98 | -- .quest |
||
99 | -- ] itemInfo; |
||
100 | -- |
||
101 | -- |
||
102 | classifyItemStrings = function (strings, itemCount, quality) |
||
103 | if ( not itemCount ) then |
||
104 | itemCount = 1; |
||
105 | end |
||
106 | local classification = "Misc"; |
||
107 | local leftString, rightString, minLevel; |
||
108 | local unique = false; |
||
109 | local soulbound = false; |
||
110 | local bindsOnPickup = false; |
||
111 | local bindsOnEquip = false; |
||
112 | local questItem = false; |
||
113 | local isHerb = false; |
||
114 | local isGem = false; |
||
115 | local isOre = false; |
||
116 | local isLeather = false; |
||
117 | local isTailor = false; |
||
118 | local isFishing = false; |
||
119 | local isFood = false; |
||
120 | local isDrink = false; |
||
121 | local isShaman = false; |
||
122 | local isPoison = false; |
||
123 | local isWarlock = false; |
||
124 | local isJunk = false; |
||
125 | local engineering = false; |
||
126 | local firstaid = false; |
||
127 | local classitem = false; |
||
128 | local class = ""; |
||
129 | local name = ""; |
||
130 | -- Look for the target line that identifies an item; it'll either be line 2, 3, or 4. |
||
131 | |||
132 | -- Determine if the item is an ore, gem or herb |
||
133 | if ( strings[1] ) then |
||
134 | name = strings[1].left; |
||
135 | end |
||
136 | |||
137 | isHerb = Sea.list.isWordInList(Sea.data.item.herb, name); |
||
138 | isGem = Sea.list.isWordInList(Sea.data.item.gem, name); |
||
139 | isOre = Sea.list.isWordInList(Sea.data.item.ore, name); |
||
140 | isLeather = Sea.list.isWordInList(Sea.data.item.leather, name); |
||
141 | isFishing = Sea.list.isWordInList(Sea.data.item.fishing, name); |
||
142 | isTailor = Sea.list.isWordInList(Sea.data.item.cloth, name); |
||
143 | isPotion = Sea.list.isWordInList(Sea.data.item.potion, name); |
||
144 | isMage = Sea.list.isWordInList(Sea.data.item.mage, name); |
||
145 | isFood = Sea.list.isWordInList(Sea.data.item.food, name); |
||
146 | isDrink = Sea.list.isWordInList(Sea.data.item.drink, name); |
||
147 | isShaman = Sea.list.isWordInList(Sea.data.item.shaman, name); |
||
148 | isPoison = Sea.list.isWordInList(Sea.data.item.poison, name); |
||
149 | isWarlock = Sea.list.isWordInList(Sea.data.item.warlock, name); |
||
150 | |||
151 | if ( ( quality ) and ( quality < 0 ) ) then |
||
152 | isJunk = true; |
||
153 | end |
||
154 | |||
155 | for i = 2, 5, 1 do |
||
156 | if (not strings[i]) |
||
157 | then |
||
158 | break; |
||
159 | end |
||
160 | if (strings[i].left == ITEM_UNIQUE or strings[i].left == ITEM_UNIQUE_MULTIPLE ) then unique = true; end |
||
161 | if (strings[i].left == ITEM_SOULBOUND ) then soulbound = true; end |
||
162 | if (strings[i].left == ITEM_BIND_ON_PICKUP ) then bindsOnPickup = true; end |
||
163 | if (strings[i].left == ITEM_BIND_ON_EQUIP ) then bindsOnEquip = true; end |
||
164 | if (strings[i].left == ITEM_BIND_QUEST ) then questItem = true; end |
||
165 | |||
166 | if (string.find(strings[i].left,"First Aid", 0, true ) ) then firstaid = true; end |
||
167 | if (string.find(strings[i].left,"Engineering", 0, true ) ) then engineering = true; end |
||
168 | if (string.find(strings[i].left,"Classes:", 0, true ) ) then classitem = true; class = string.sub(strings[i].left, string.find(strings[i].left,":", 0, true )+2); end |
||
169 | |||
170 | if (strings[i].left and |
||
171 | strings[i].left ~= ITEM_UNIQUE and |
||
172 | strings[i].left ~= ITEM_SOULBOUND and |
||
173 | strings[i].left ~= ITEM_BIND_ON_EQUIP and |
||
174 | strings[i].left ~= ITEM_BIND_ON_PICKUP and |
||
175 | strings[i].left ~= ITEM_BIND_QUEST) |
||
176 | then |
||
177 | leftString = strings[i].left; |
||
178 | rightString = strings[i].right; |
||
179 | break; |
||
180 | end |
||
181 | end |
||
182 | |||
183 | -- Find last line |
||
184 | local lastLine; |
||
185 | for i = 1, 10, 1 do |
||
186 | if (strings[i] and strings[i].left) |
||
187 | then |
||
188 | lastLine = strings[i].left; |
||
189 | else |
||
190 | break; |
||
191 | end |
||
192 | end |
||
193 | |||
194 | -- look at last line to see if it's a level requirement |
||
195 | local minLevel = 0; |
||
196 | if (lastLine) |
||
197 | then |
||
198 | local index, length, levelString = string.find(lastLine, "^Requires Level (%d+)$"); |
||
199 | if (index) then |
||
200 | minLevel = Sea.string.toInt(levelString); |
||
201 | end |
||
202 | end |
||
203 | |||
204 | -- classify item based on found strings |
||
205 | if (leftString) |
||
206 | then |
||
207 | if (leftString == "Main Hand" or |
||
208 | leftString == "Two-Hand" or |
||
209 | leftString == "One-Hand") |
||
210 | then |
||
211 | classification = "Weapon"; |
||
212 | elseif (leftString == "Head" or |
||
213 | leftString == "Hand" or |
||
214 | leftString == "Waist" or |
||
215 | leftString == "Shoulders" or |
||
216 | leftString == "Legs" or |
||
217 | leftString == "Back" or |
||
218 | leftString == "Feet" or |
||
219 | leftString == "Chest" or |
||
220 | leftString == "Wrist") |
||
221 | then |
||
222 | classification = "Armor"; |
||
223 | elseif (leftString == "Off Hand") |
||
224 | then |
||
225 | classification = "Shield"; |
||
226 | elseif (leftString == "Wand" or |
||
227 | leftString == "Ranged" or |
||
228 | leftString == "Gun" ) |
||
229 | then |
||
230 | classification = "Ranged"; |
||
231 | elseif (leftString == "Projectile") |
||
232 | then |
||
233 | classification = "Ammo"; |
||
234 | elseif (leftString == "Shirt" or |
||
235 | leftString == "Tabard" or |
||
236 | leftString == "Finger" or |
||
237 | leftString == "Neck" or |
||
238 | leftString == "Trinket" or |
||
239 | leftString == "Held In Hand") |
||
240 | then |
||
241 | classification = "Clothing"; |
||
242 | end |
||
243 | end |
||
244 | if ( classification == "Misc" ) then |
||
245 | if ( isJunk ) then classification = "Junk"; end |
||
246 | if ( isGem ) then classification = "Gem"; end |
||
247 | if ( isOre ) then classification = "Ore"; end |
||
248 | if ( isHerb ) then classification = "Herb"; end |
||
249 | if ( engineering ) then classification = "Engineering"; end |
||
250 | if ( firstaid ) then classification = "First Aid"; end |
||
251 | if ( isLeather ) then classification = "Leather"; end |
||
252 | if ( isTailor ) then classification = "Thread"; end |
||
253 | if ( isPotion ) then classification = "Potion"; end |
||
254 | if ( isFishing ) then classification = "Fishing"; end |
||
255 | if ( isFood ) then classification = "Food"; end |
||
256 | if ( isDrink ) then classification = "Drink"; end |
||
257 | if ( isMage ) then classification = "Mage"; end |
||
258 | if ( isShaman ) then classification = "Shaman"; end |
||
259 | if ( isWarlock ) then classification = "Warlock"; end |
||
260 | if ( isPoison ) then classification = "Poison"; end |
||
261 | if ( classitem ) then classification = class; end |
||
262 | if ( questItem ) then classification = "QuestItem"; end |
||
263 | end |
||
264 | |||
265 | -- Create the item table |
||
266 | -- Will soon have item information |
||
267 | itemInfo = {}; |
||
268 | itemInfo.classification = classification; |
||
269 | itemInfo.name = name; |
||
270 | itemInfo.quality = quality; |
||
271 | itemInfo.count = itemCount; |
||
272 | itemInfo.minLevel = minLevel; |
||
273 | itemInfo.unique = unique; |
||
274 | itemInfo.soulbound = soulbound; |
||
275 | itemInfo.bindOnPickup = bindsOnPickup; |
||
276 | itemInfo.bindOnEquip = bindsOnEquip; |
||
277 | itemInfo.quest = questItem; |
||
278 | |||
279 | return itemInfo; |
||
280 | end; |
||
281 | |||
282 | -- |
||
283 | -- getInventoryItemInfoStrings ( bag, slot [, tooltip] ) |
||
284 | -- |
||
285 | -- Obtains all information about a bag/slot and returns it as an array |
||
286 | -- |
||
287 | -- Args: |
||
288 | -- (int bag, int slot, string tooltipbase ) |
||
289 | -- |
||
290 | -- Returns: |
||
291 | -- (table[row][.left .right] strings) |
||
292 | -- string - the string data of the tooltip |
||
293 | -- |
||
294 | getInventoryItemInfoStrings = function (bag,slot, TooltipNameBase) |
||
295 | if ( TooltipNameBase == nil ) then |
||
296 | TooltipNameBase = "GameTooltip"; |
||
297 | end |
||
298 | |||
299 | Sea.wow.tooltip.clear(TooltipNameBase); |
||
300 | |||
301 | local tooltip = getglobal(TooltipNameBase); |
||
302 | |||
303 | -- Open tooltip & read contents |
||
304 | Sea.wow.tooltip.protectTooltipMoney(); |
||
305 | if ( bag > -1 ) then |
||
306 | tooltip:SetBagItem( bag, slot ); |
||
307 | else |
||
308 | tooltip:SetInventoryItem( "player", slot); |
||
309 | end |
||
310 | Sea.wow.tooltip.unprotectTooltipMoney(); |
||
311 | local strings = Sea.wow.tooltip.scan(TooltipNameBase); |
||
312 | |||
313 | -- Done our duty, send report |
||
314 | return strings; |
||
315 | end; |
||
316 | |||
317 | }; |