comparison Main.lua @ 17:632623625cd1

Minor clarification. Added support for recording fishing drops.
author James D. Callahan III <jcallahan@curse.com>
date Thu, 03 May 2012 16:48:50 -0500
parents 9f314ea42267
children 86f02232a9e5
comparison
equal deleted inserted replaced
16:9f314ea42267 17:632623625cd1
30 global = { 30 global = {
31 items = {}, 31 items = {},
32 npcs = {}, 32 npcs = {},
33 objects = {}, 33 objects = {},
34 quests = {}, 34 quests = {},
35 zones = {},
35 } 36 }
36 } 37 }
37 38
38 39
39 local EVENT_MAPPING = { 40 local EVENT_MAPPING = {
294 end 295 end
295 action_data.item_id = locked_item_id 296 action_data.item_id = locked_item_id
296 return true 297 return true
297 end, 298 end,
298 [AF.NPC] = function() 299 [AF.NPC] = function()
299 if _G.IsFishingLoot() or not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then 300 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
300 return false 301 return false
301 end 302 end
302 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target")) 303 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
303 action_data.id_num = id_num 304 action_data.id_num = id_num
304 return true 305 return true
305 end, 306 end,
306 [AF.OBJECT] = true, 307 [AF.OBJECT] = true,
308 [AF.ZONE] = function()
309 return action_data.loot_type and _G.IsFishingLoot()
310 end,
307 } 311 }
308 312
309 313
310 local LOOT_UPDATE_FUNCS = { 314 local LOOT_UPDATE_FUNCS = {
311 [AF.ITEM] = function() 315 [AF.ITEM] = function()
312 local item = UnitEntry("items", action_data.item_id) 316 local item = UnitEntry("items", action_data.item_id)
313 local loot_type = action_data.loot_type or "drops" 317 local loot_type = action_data.loot_type
314 item[loot_type] = item[loot_type] or {} 318 item[loot_type] = item[loot_type] or {}
315 319
316 for index = 1, #action_data.drops do 320 for index = 1, #action_data.loot_list do
317 table.insert(item[loot_type], action_data.drops[index]) 321 table.insert(item[loot_type], action_data.loot_list[index])
318 end 322 end
319 end, 323 end,
320 [AF.NPC] = function() 324 [AF.NPC] = function()
321 local npc = UnitEntry("npcs", action_data.id_num) 325 local npc = UnitEntry("npcs", action_data.id_num)
322 326
324 return 328 return
325 end 329 end
326 local loot_type = action_data.loot_type or "drops" 330 local loot_type = action_data.loot_type or "drops"
327 npc[loot_type] = npc[loot_type] or {} 331 npc[loot_type] = npc[loot_type] or {}
328 332
329 for index = 1, #action_data.drops do 333 for index = 1, #action_data.loot_list do
330 table.insert(npc[loot_type], action_data.drops[index]) 334 table.insert(npc[loot_type], action_data.loot_list[index])
331 end 335 end
332 end, 336 end,
333 [AF.OBJECT] = function() 337 [AF.OBJECT] = function()
334 local object = UnitEntry("objects", action_data.identifier) 338 local object = UnitEntry("objects", action_data.identifier)
335 object.drops = object.drops or {} 339 object.drops = object.drops or {}
336 340
337 for index = 1, #action_data.drops do 341 for index = 1, #action_data.loot_list do
338 table.insert(object.drops, action_data.drops[index]) 342 table.insert(object.drops, action_data.loot_list[index])
343 end
344 end,
345 [AF.ZONE] = function()
346 local loot_type = action_data.loot_type or "drops"
347 local zone = UnitEntry("zones", action_data.zone)
348 zone[loot_type] = zone[loot_type] or {}
349
350 local location_data = ("%s:%s:%s:%s"):format(action_data.instance_type, action_data.map_level, action_data.x, action_data.y)
351 local loot_data = zone[loot_type][location_data]
352
353 if not loot_data then
354 zone[loot_type][location_data] = {}
355 loot_data = zone[loot_type][location_data]
356 end
357
358 for index = 1, #action_data.loot_list do
359 table.insert(loot_data, action_data.loot_list[index])
339 end 360 end
340 end, 361 end,
341 } 362 }
342 363
343 364
344 function WDP:LOOT_OPENED() 365 function WDP:LOOT_OPENED()
345 if not action_data.type then 366 if not action_data.type then
346 action_data.type = AF.NPC 367 action_data.type = AF.NPC
347 end 368 end
369
348 local verify_func = LOOT_VERIFY_FUNCS[action_data.type] 370 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
349 local update_func = LOOT_UPDATE_FUNCS[action_data.type] 371 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
350 372
351 if not verify_func or not update_func then 373 if not verify_func or not update_func then
352 return 374 return
354 376
355 if _G.type(verify_func) == "function" and not verify_func() then 377 if _G.type(verify_func) == "function" and not verify_func() then
356 return 378 return
357 end 379 end
358 local loot_registry = {} 380 local loot_registry = {}
359 action_data.drops = {} 381 action_data.loot_list = {}
360 382
361 for loot_slot = 1, _G.GetNumLootItems() do 383 for loot_slot = 1, _G.GetNumLootItems() do
362 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 384 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
363 385
364 if _G.LootSlotIsItem(loot_slot) then 386 if _G.LootSlotIsItem(loot_slot) then
365 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 387 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
366 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity 388 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
367 elseif _G.LootSlotIsCoin(loot_slot) then 389 elseif _G.LootSlotIsCoin(loot_slot) then
368 table.insert(action_data.drops, ("money:%d"):format(_toCopper(item_text))) 390 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
369 elseif _G.LootSlotIsCurrency(loot_slot) then 391 elseif _G.LootSlotIsCurrency(loot_slot) then
370 table.insert(action_data.drops, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) 392 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
371 end 393 end
372 end 394 end
373 395
374 for item_id, quantity in pairs(loot_registry) do 396 for item_id, quantity in pairs(loot_registry) do
375 table.insert(action_data.drops, ("%d:%d"):format(item_id, quantity)) 397 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
376 end 398 end
377 update_func() 399 update_func()
378 end 400 end
379 end -- do-block 401 end -- do-block
380 402
610 elseif target_name and target_name ~= "" then 632 elseif target_name and target_name ~= "" then
611 local _, target_item_link = _G.GetItemInfo(target_name) 633 local _, target_item_link = _G.GetItemInfo(target_name)
612 action_data.item_id = ItemLinkToID(target_item_link) 634 action_data.item_id = ItemLinkToID(target_item_link)
613 end 635 end
614 elseif not tt_item_name and not tt_unit_name then 636 elseif not tt_item_name and not tt_unit_name then
615 if target_name == "" then
616 return
617 end
618
619 local zone_name, x, y, map_level, instance_type = CurrentLocationData() 637 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
620 638
639 action_data.instance_type = instance_type
640 action_data.map_level = map_level
641 action_data.name = target_name
642 action_data.x = x
643 action_data.y = y
644 action_data.zone = zone_name
645
621 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then 646 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
647 if target_name == "" then
648 return
649 end
622 local identifier = ("%s:%s"):format(spell_label, target_name) 650 local identifier = ("%s:%s"):format(spell_label, target_name)
623 UpdateObjectLocation(identifier) 651 UpdateObjectLocation(identifier)
624 652
625 action_data.instance_type = instance_type
626 action_data.map_level = map_level
627 action_data.name = target_name
628 action_data.type = AF.OBJECT 653 action_data.type = AF.OBJECT
629 action_data.x = x
630 action_data.y = y
631 action_data.zone = zone_name
632 action_data.identifier = identifier 654 action_data.identifier = identifier
633 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then 655 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
634 print("Found spell flagged for ZONE") 656 action_data.type = AF.ZONE
635 end 657 action_data.loot_type = spell_label:lower()
636 else 658 end
637 print(("%s: We have an issue with types and flags."), event_name) 659 end
638 end 660
639 661 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
640 print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
641 private.tracked_line = spell_line 662 private.tracked_line = spell_line
642 end 663 end
643 664
644 665
645 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 666 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
646 if unit_id ~= "player" then 667 if unit_id ~= "player" then
647 return 668 return
648 end 669 end
649 670
650 if private.SPELL_LABELS_BY_NAME[spell_name] then 671 -- if private.SPELL_LABELS_BY_NAME[spell_name] then
651 print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)) 672 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
652 end 673 -- end
653 private.tracked_line = nil 674 private.tracked_line = nil
654 end 675 end
655 676
656 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 677 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
657 if unit_id ~= "player" then 678 if unit_id ~= "player" then