comparison Main.lua @ 18:86f02232a9e5

Make looting work under MoP. Added preliminary code for faction-change detection.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 07 May 2012 14:35:14 -0500
parents 632623625cd1
children 6a0c96063003
comparison
equal deleted inserted replaced
17:632623625cd1 18:86f02232a9e5
36 } 36 }
37 } 37 }
38 38
39 39
40 local EVENT_MAPPING = { 40 local EVENT_MAPPING = {
41 COMBAT_TEXT_UPDATE = true,
41 LOOT_CLOSED = true, 42 LOOT_CLOSED = true,
42 LOOT_OPENED = true, 43 LOOT_OPENED = true,
43 MERCHANT_SHOW = "UpdateMerchantItems", 44 MERCHANT_SHOW = "UpdateMerchantItems",
44 MERCHANT_UPDATE = "UpdateMerchantItems", 45 MERCHANT_UPDATE = "UpdateMerchantItems",
45 PLAYER_TARGET_CHANGED = true, 46 PLAYER_TARGET_CHANGED = true,
46 QUEST_COMPLETE = true, 47 QUEST_COMPLETE = true,
47 QUEST_DETAIL = true, 48 QUEST_DETAIL = true,
48 QUEST_LOG_UPDATE = true, 49 QUEST_LOG_UPDATE = true,
49 QUEST_PROGRESS = true,
50 UNIT_QUEST_LOG_CHANGED = true, 50 UNIT_QUEST_LOG_CHANGED = true,
51 UNIT_SPELLCAST_FAILED = "HandleSpellFailure", 51 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
52 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure", 52 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
53 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure", 53 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
54 UNIT_SPELLCAST_SENT = true, 54 UNIT_SPELLCAST_SENT = true,
159 -- Methods. 159 -- Methods.
160 ----------------------------------------------------------------------- 160 -----------------------------------------------------------------------
161 function WDP:OnInitialize() 161 function WDP:OnInitialize()
162 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global 162 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
163 163
164 local wow_version, build_num = _G.GetBuildInfo()
165 local raw_db = _G["WoWDBProfilerData"] 164 local raw_db = _G["WoWDBProfilerData"]
166 165
167 build_num = tonumber(build_num) 166 local build_num = tonumber(private.build_num)
168 167
169 if raw_db.build_num and raw_db.build_num < build_num then 168 if raw_db.build_num and raw_db.build_num < build_num then
170 for entry in pairs(DATABASE_DEFAULTS.global) do 169 for entry in pairs(DATABASE_DEFAULTS.global) do
171 db[entry] = {} 170 db[entry] = {}
172 end 171 end
249 248
250 249
251 ----------------------------------------------------------------------- 250 -----------------------------------------------------------------------
252 -- Event handlers. 251 -- Event handlers.
253 ----------------------------------------------------------------------- 252 -----------------------------------------------------------------------
253 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
254 -- if message_type ~= "FACTION" or _G.UnitIsUnit("target", "questnpc") then
255 -- return
256 -- end
257 -- local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
258 -- local npc = UnitEntry("npcs", unit_idnum)
259 --
260 -- if not npc then
261 -- return
262 -- end
263 -- npc.reputations = npc.reputations or {}
264 -- npc.reputations[faction_name] = amount
265 --
266 -- print(("%s: %s, %s, %s"):format(event, message_type, faction_name, amount))
267 end
268
269
254 function WDP:LOOT_CLOSED() 270 function WDP:LOOT_CLOSED()
255 table.wipe(action_data) 271 -- table.wipe(action_data)
256 end 272 end
257 273
258 274
259 do 275 do
260 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)") 276 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
361 end, 377 end,
362 } 378 }
363 379
364 380
365 function WDP:LOOT_OPENED() 381 function WDP:LOOT_OPENED()
382 if action_data.looting then
383 return
384 end
385
366 if not action_data.type then 386 if not action_data.type then
367 action_data.type = AF.NPC 387 action_data.type = AF.NPC
368 end 388 end
369
370 local verify_func = LOOT_VERIFY_FUNCS[action_data.type] 389 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
371 local update_func = LOOT_UPDATE_FUNCS[action_data.type] 390 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
372 391
373 if not verify_func or not update_func then 392 if not verify_func or not update_func then
374 return 393 return
375 end 394 end
376 395
377 if _G.type(verify_func) == "function" and not verify_func() then 396 if _G.type(verify_func) == "function" and not verify_func() then
378 return 397 return
379 end 398 end
399 -- TODO: Remove this check once the MoP client goes live
400 local wow_version = private.wow_version
380 local loot_registry = {} 401 local loot_registry = {}
381 action_data.loot_list = {} 402 action_data.loot_list = {}
382 403 action_data.looting = true
383 for loot_slot = 1, _G.GetNumLootItems() do 404
384 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 405 if wow_version == "5.0.1" then
385 406 for loot_slot = 1, _G.GetNumLootItems() do
386 if _G.LootSlotIsItem(loot_slot) then 407 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
387 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 408
388 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity 409 local slot_type = _G.GetLootSlotType(loot_slot)
389 elseif _G.LootSlotIsCoin(loot_slot) then 410
390 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text))) 411 if slot_type == _G.LOOT_SLOT_ITEM then
391 elseif _G.LootSlotIsCurrency(loot_slot) then 412 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
392 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) 413 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
414 elseif slot_type == _G.LOOT_SLOT_MONEY then
415 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
416 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
417 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
418 end
419 end
420 else
421 for loot_slot = 1, _G.GetNumLootItems() do
422 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
423 if _G.LootSlotIsItem(loot_slot) then
424 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
425 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
426 elseif _G.LootSlotIsCoin(loot_slot) then
427 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
428 elseif _G.LootSlotIsCurrency(loot_slot) then
429 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
430 end
393 end 431 end
394 end 432 end
395 433
396 for item_id, quantity in pairs(loot_registry) do 434 for item_id, quantity in pairs(loot_registry) do
397 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity)) 435 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
485 merchant.can_repair = true 523 merchant.can_repair = true
486 end 524 end
487 end 525 end
488 526
489 527
490 local GENDER_NAMES = { 528 do
491 "UNKNOWN", 529 local GENDER_NAMES = {
492 "MALE", 530 "UNKNOWN",
493 "FEMALE", 531 "MALE",
494 } 532 "FEMALE",
495 533 }
496 534
497 local REACTION_NAMES = { 535
498 "HATED", 536 local REACTION_NAMES = {
499 "HOSTILE", 537 "HATED",
500 "UNFRIENDLY", 538 "HOSTILE",
501 "NEUTRAL", 539 "UNFRIENDLY",
502 "FRIENDLY", 540 "NEUTRAL",
503 "HONORED", 541 "FRIENDLY",
504 "REVERED", 542 "HONORED",
505 "EXALTED", 543 "REVERED",
506 } 544 "EXALTED",
507 545 }
508 546
509 local POWER_TYPE_NAMES = { 547
510 ["0"] = "MANA", 548 local POWER_TYPE_NAMES = {
511 ["1"] = "RAGE", 549 ["0"] = "MANA",
512 ["2"] = "FOCUS", 550 ["1"] = "RAGE",
513 ["3"] = "ENERGY", 551 ["2"] = "FOCUS",
514 ["6"] = "RUNIC_POWER", 552 ["3"] = "ENERGY",
515 } 553 ["6"] = "RUNIC_POWER",
516 554 }
517 555
518 function WDP:PLAYER_TARGET_CHANGED() 556
519 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then 557 function WDP:PLAYER_TARGET_CHANGED()
520 return 558 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
521 end 559 return
522 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 560 end
523 561 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
524 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 562
525 return 563 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
526 end 564 return
527 local npc = UnitEntry("npcs", unit_idnum) 565 end
528 local _, class_token = _G.UnitClass("target") 566 table.wipe(action_data)
529 npc.class = class_token 567
530 -- TODO: Add faction here 568 local npc = UnitEntry("npcs", unit_idnum)
531 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED" 569 local _, class_token = _G.UnitClass("target")
532 npc.is_pvp = _G.UnitIsPVP("target") and true or nil 570 npc.class = class_token
533 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) 571 -- TODO: Add faction here
534 npc.stats = npc.stats or {} 572 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
535 573 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
536 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) 574 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
537 575 npc.stats = npc.stats or {}
538 if not npc.stats[npc_level] then 576
539 npc.stats[npc_level] = { 577 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
540 max_health = _G.UnitHealthMax("target"), 578
541 } 579 if not npc.stats[npc_level] then
542 580 npc.stats[npc_level] = {
543 local max_power = _G.UnitManaMax("target") 581 max_health = _G.UnitHealthMax("target"),
544 582 }
545 if max_power > 0 then 583
546 local power_type = _G.UnitPowerType("target") 584 local max_power = _G.UnitManaMax("target")
547 npc.stats[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) 585
548 end 586 if max_power > 0 then
549 end 587 local power_type = _G.UnitPowerType("target")
550 end 588 npc.stats[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
551 589 end
590 end
591 end
592 end -- do-block
552 593
553 do 594 do
554 local function UpdateQuestJuncture(point) 595 local function UpdateQuestJuncture(point)
555 local unit_name = _G.UnitName("questnpc") 596 local unit_name = _G.UnitName("questnpc")
556 597
582 function WDP:QUEST_LOG_UPDATE() 623 function WDP:QUEST_LOG_UPDATE()
583 self:UnregisterEvent("QUEST_LOG_UPDATE") 624 self:UnregisterEvent("QUEST_LOG_UPDATE")
584 end 625 end
585 626
586 627
587 function WDP:QUEST_PROGRESS()
588 end
589
590 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id) 628 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
591 if unit_id ~= "player" then 629 if unit_id ~= "player" then
592 return 630 return
593 end 631 end
594 self:RegisterEvent("QUEST_LOG_UPDATE") 632 self:RegisterEvent("QUEST_LOG_UPDATE")
602 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name] 640 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
603 641
604 if not spell_label then 642 if not spell_label then
605 return 643 return
606 end 644 end
607 action_data.type = nil -- This will be set as appropriate below 645 table.wipe(action_data)
608 646
609 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem() 647 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
610 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit() 648 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
611 649
612 if not tt_unit_name and _G.UnitName("target") == target_name then 650 if not tt_unit_name and _G.UnitName("target") == target_name then
656 action_data.type = AF.ZONE 694 action_data.type = AF.ZONE
657 action_data.loot_type = spell_label:lower() 695 action_data.loot_type = spell_label:lower()
658 end 696 end
659 end 697 end
660 698
661 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)) 699 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
662 private.tracked_line = spell_line 700 private.tracked_line = spell_line
663 end 701 end
664 702
665 703
666 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 704 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
667 if unit_id ~= "player" then 705 if unit_id ~= "player" then
668 return 706 return
669 end 707 end
670 708
671 -- if private.SPELL_LABELS_BY_NAME[spell_name] then 709 -- if private.SPELL_LABELS_BY_NAME[spell_name] then
672 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)) 710 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
673 -- end 711 -- end
674 private.tracked_line = nil 712 private.tracked_line = nil
675 end 713 end
676 714
677 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 715 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
678 if unit_id ~= "player" then 716 if unit_id ~= "player" then