comparison Main.lua @ 40:4ae5cde37458

Detect drunkenness via chat messages. When drunk, do not record anything about NPCs, as the character's perception is altered.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 12 Jun 2012 13:50:43 -0500
parents 938abe259516
children 7db268f39c50
comparison
equal deleted inserted replaced
39:938abe259516 40:4ae5cde37458
36 } 36 }
37 } 37 }
38 38
39 39
40 local EVENT_MAPPING = { 40 local EVENT_MAPPING = {
41 CHAT_MSG_SYSTEM = true,
41 COMBAT_LOG_EVENT_UNFILTERED = true, 42 COMBAT_LOG_EVENT_UNFILTERED = true,
42 COMBAT_TEXT_UPDATE = true, 43 COMBAT_TEXT_UPDATE = true,
43 LOOT_OPENED = true, 44 LOOT_OPENED = true,
44 MERCHANT_SHOW = "UpdateMerchantItems", 45 MERCHANT_SHOW = "UpdateMerchantItems",
45 -- MERCHANT_UPDATE = "UpdateMerchantItems", 46 -- MERCHANT_UPDATE = "UpdateMerchantItems",
70 ----------------------------------------------------------------------- 71 -----------------------------------------------------------------------
71 local db 72 local db
72 local durability_timer_handle 73 local durability_timer_handle
73 local target_location_timer_handle 74 local target_location_timer_handle
74 local action_data = {} 75 local action_data = {}
76 local currently_drunk
75 local faction_standings = {} 77 local faction_standings = {}
76 78
77 79
78 ----------------------------------------------------------------------- 80 -----------------------------------------------------------------------
79 -- Helper Functions. 81 -- Helper Functions.
438 end 440 end
439 end 441 end
440 442
441 443
442 function WDP:UpdateTargetLocation() 444 function WDP:UpdateTargetLocation()
443 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then 445 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
444 return 446 return
445 end 447 end
446 448
447 for index = 1, 4 do 449 for index = 1, 4 do
448 if not _G.CheckInteractDistance("target", index) then 450 if not _G.CheckInteractDistance("target", index) then
449 return 451 return
450 end 452 end
451 end 453 end
452 local target_guid = _G.UnitGUID("target") 454 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
453 local unit_type, unit_idnum = ParseGUID(target_guid) 455
454 456 if not unit_idnum or unit_type ~= private.UNIT_TYPES.NPC then
455 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
456 return 457 return
457 end 458 end
458 UpdateNPCLocation(unit_idnum) 459 UpdateNPCLocation(unit_idnum)
459 end 460 end
460 461
461 462
462 ----------------------------------------------------------------------- 463 -----------------------------------------------------------------------
463 -- Event handlers. 464 -- Event handlers.
464 ----------------------------------------------------------------------- 465 -----------------------------------------------------------------------
466 do
467 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
468
469 local DRUNK_COMPARES = {
470 _G.DRUNK_MESSAGE_SELF2,
471 _G.DRUNK_MESSAGE_SELF3,
472 _G.DRUNK_MESSAGE_SELF4,
473 }
474
475 local DRUNK_MATCHES = {
476 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
477 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
478 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
479 }
480
481 function WDP:CHAT_MSG_SYSTEM(event, message)
482 if currently_drunk then
483 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
484 currently_drunk = nil
485 end
486 return
487 end
488
489 for index = 1, #DRUNK_MATCHES do
490 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
491 currently_drunk = true
492 break
493 end
494 end
495 end
496 end
497
498 -- do-block
499
465 do 500 do
466 local EXTRACT_GAS_SPELL_ID = 30427 501 local EXTRACT_GAS_SPELL_ID = 30427
467 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC) 502 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
468 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC) 503 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
469 504
537 reputation_data[("%s:%s"):format(faction_name, faction_standings[faction_name])] = amount 572 reputation_data[("%s:%s"):format(faction_name, faction_standings[faction_name])] = amount
538 end 573 end
539 574
540 575
541 do 576 do
542 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)") 577 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
543 local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)") 578 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
544 local re_copper = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)") 579 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
545 580
546 581
547 local function _moneyMatch(money, re) 582 local function _moneyMatch(money, re)
548 return money:match(re) or 0 583 return money:match(re) or 0
549 end 584 end
551 586
552 local function _toCopper(money) 587 local function _toCopper(money)
553 if not money then 588 if not money then
554 return 0 589 return 0
555 end 590 end
556 591 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER)
557 return _moneyMatch(money, re_gold) * 10000 + _moneyMatch(money, re_silver) * 100 + _moneyMatch(money, re_copper)
558 end 592 end
559 593
560 594
561 local LOOT_VERIFY_FUNCS = { 595 local LOOT_VERIFY_FUNCS = {
562 [AF.ITEM] = function() 596 [AF.ITEM] = function()
837 ["6"] = "RUNIC_POWER", 871 ["6"] = "RUNIC_POWER",
838 } 872 }
839 873
840 874
841 function WDP:PLAYER_TARGET_CHANGED() 875 function WDP:PLAYER_TARGET_CHANGED()
842 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then 876 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
843 return 877 return
844 end 878 end
845 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) 879 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
846 880
847 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 881 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then