comparison Main.lua @ 34:2a094108d89b

Attempt at recording gas cloud locations (no Engineer to test with).
author James D. Callahan III <jcallahan@curse.com>
date Tue, 05 Jun 2012 11:36:50 -0500
parents 6422f3b61962
children b0264b73986e
comparison
equal deleted inserted replaced
33:6422f3b61962 34:2a094108d89b
60 60
61 local AF = private.ACTION_TYPE_FLAGS 61 local AF = private.ACTION_TYPE_FLAGS
62 62
63 63
64 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player")) 64 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
65 local PLAYER_GUID = _G.UnitGUID("player")
65 66
66 67
67 ----------------------------------------------------------------------- 68 -----------------------------------------------------------------------
68 -- Local variables. 69 -- Local variables.
69 ----------------------------------------------------------------------- 70 -----------------------------------------------------------------------
157 end 158 end
158 return tonumber(item_link:match("item:(%d+)")) 159 return tonumber(item_link:match("item:(%d+)"))
159 end 160 end
160 161
161 162
163 local ParseGUID
162 do 164 do
163 local UNIT_TYPE_BITMASK = 0x007 165 local UNIT_TYPE_BITMASK = 0x007
164 166
165 function WDP:ParseGUID(guid) 167 function ParseGUID(guid)
166 if not guid then 168 if not guid then
167 return 169 return
168 end 170 end
169 local types = private.UNIT_TYPES 171 local types = private.UNIT_TYPES
170 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK) 172 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
172 if unit_type ~= types.PLAYER and unit_type ~= types.PET then 174 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
173 return unit_type, tonumber(guid:sub(-12, -9), 16) 175 return unit_type, tonumber(guid:sub(-12, -9), 16)
174 end 176 end
175 177
176 return unit_type 178 return unit_type
179 end
180 end -- do-block
181
182
183 local UpdateNPCLocation
184 do
185 local COORD_MAX = 5
186
187 function UpdateNPCLocation(unit_idnum)
188 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
189 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
190 local zone_token = ("%s:%d"):format(zone_name, area_id)
191 npc_data.locations = npc_data.locations or {}
192
193 local zone_data = npc_data.locations[zone_token]
194
195 if not zone_data then
196 zone_data = {}
197 npc_data.locations[zone_token] = zone_data
198 end
199
200 for location_token in pairs(zone_data) do
201 local loc_level, loc_x, loc_y = (":"):split(location_token)
202 loc_level = tonumber(loc_level)
203
204 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
205 return
206 end
207 end
208 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true
177 end 209 end
178 end -- do-block 210 end -- do-block
179 211
180 212
181 local function UpdateObjectLocation(identifier) 213 local function UpdateObjectLocation(identifier)
351 end 383 end
352 end 384 end
353 end 385 end
354 386
355 387
356 local COORD_MAX = 5
357
358 function WDP:UpdateTargetLocation() 388 function WDP:UpdateTargetLocation()
359 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then 389 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
360 return 390 return
361 end 391 end
362 392
364 if not _G.CheckInteractDistance("target", index) then 394 if not _G.CheckInteractDistance("target", index) then
365 return 395 return
366 end 396 end
367 end 397 end
368 local target_guid = _G.UnitGUID("target") 398 local target_guid = _G.UnitGUID("target")
369 local unit_type, unit_idnum = self:ParseGUID(target_guid) 399 local unit_type, unit_idnum = ParseGUID(target_guid)
370 400
371 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 401 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
372 return 402 return
373 end 403 end
374 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData() 404 UpdateNPCLocation(unit_idnum)
375 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
376 local zone_token = ("%s:%d"):format(zone_name, area_id)
377 npc_data.locations = npc_data.locations or {}
378
379 local zone_data = npc_data.locations[zone_token]
380
381 if not zone_data then
382 zone_data = {}
383 npc_data.locations[zone_token] = zone_data
384 end
385
386 for location_token in pairs(zone_data) do
387 local loc_level, loc_x, loc_y = (":"):split(location_token)
388 loc_level = tonumber(loc_level)
389
390 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
391 return
392 end
393 end
394 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true
395 end 405 end
396 406
397 407
398 ----------------------------------------------------------------------- 408 -----------------------------------------------------------------------
399 -- Event handlers. 409 -- Event handlers.
406 416
407 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) 417 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
408 if not spell_id then 418 if not spell_id then
409 return 419 return
410 end 420 end
411 local source_type, source_id = WDP:ParseGUID(source_guid) 421 local source_type, source_id = ParseGUID(source_guid)
412 422
413 if not source_id or source_type ~= private.UNIT_TYPES.NPC then 423 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
414 return 424 return
415 end 425 end
416 426
419 encounter_data.spells = encounter_data.spells or {} 429 encounter_data.spells = encounter_data.spells or {}
420 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1 430 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
421 end 431 end
422 end 432 end
423 433
424
425 local COMBAT_LOG_FUNCS = { 434 local COMBAT_LOG_FUNCS = {
426 SPELL_AURA_APPLIED = RecordNPCSpell, 435 SPELL_AURA_APPLIED = RecordNPCSpell,
427 SPELL_CAST_START = RecordNPCSpell, 436 SPELL_CAST_START = RecordNPCSpell,
428 SPELL_CAST_SUCCESS = RecordNPCSpell, 437 SPELL_CAST_SUCCESS = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, ...)
438 if spell_id == EXTRACT_GAS_SPELL_ID and source_guid == PLAYER_GUID then
439 table.wipe(action_data)
440 action_data.extracting_gas = true
441 action_data.timestamp = _G.GetTime()
442 else
443 RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, ...)
444 end
445 end,
429 UNIT_DISSIPATES = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags) 446 UNIT_DISSIPATES = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags)
430 -- TODO: Write this. 447 if action_data.extracting_gas and _G.GetTime() - action_data.timestamp <= 3 then
448 local unit_type, unit_idnum = ParseGUID(dest_guid)
449 UpdateNPCLocation(unit_idnum)
450 end
431 end, 451 end,
432 } 452 }
433 453
434 454
435 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...) 455 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...)
506 end, 526 end,
507 [AF.NPC] = function() 527 [AF.NPC] = function()
508 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then 528 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
509 return false 529 return false
510 end 530 end
511 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target")) 531 local unit_type, id_num = ParseGUID(_G.UnitGUID("target"))
512 action_data.identifier = id_num 532 action_data.identifier = id_num
513 return true 533 return true
514 end, 534 end,
515 [AF.OBJECT] = true, 535 [AF.OBJECT] = true,
516 [AF.ZONE] = function() 536 [AF.ZONE] = function()
656 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")), 676 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
657 } 677 }
658 678
659 679
660 function WDP:UpdateMerchantItems() 680 function WDP:UpdateMerchantItems()
661 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 681 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
662 682
663 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 683 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
664 return 684 return
665 end 685 end
666 local merchant = NPCEntry(unit_idnum) 686 local merchant = NPCEntry(unit_idnum)
736 756
737 function WDP:PET_BAR_UPDATE() 757 function WDP:PET_BAR_UPDATE()
738 if not action_data.label or not action_data.label == "mind_control" then 758 if not action_data.label or not action_data.label == "mind_control" then
739 return 759 return
740 end 760 end
741 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("pet")) 761 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
742 762
743 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 763 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
744 return 764 return
745 end 765 end
746 NPCEntry(unit_idnum).mind_control = true 766 NPCEntry(unit_idnum).mind_control = true
779 799
780 function WDP:PLAYER_TARGET_CHANGED() 800 function WDP:PLAYER_TARGET_CHANGED()
781 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then 801 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
782 return 802 return
783 end 803 end
784 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 804 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
785 805
786 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 806 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
787 return 807 return
788 end 808 end
789 local npc = NPCEntry(unit_idnum) 809 local npc = NPCEntry(unit_idnum)
841 local unit_name = _G.UnitName("questnpc") 861 local unit_name = _G.UnitName("questnpc")
842 862
843 if not unit_name then 863 if not unit_name then
844 return 864 return
845 end 865 end
846 local unit_type, unit_id = WDP:ParseGUID(_G.UnitGUID("questnpc")) 866 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
847 867
848 if unit_type == private.UNIT_TYPES.OBJECT then 868 if unit_type == private.UNIT_TYPES.OBJECT then
849 UpdateObjectLocation(unit_id) 869 UpdateObjectLocation(unit_id)
850 end 870 end
851 local quest = DBEntry("quests", _G.GetQuestID()) 871 local quest = DBEntry("quests", _G.GetQuestID())
889 909
890 function WDP:TRAINER_SHOW() 910 function WDP:TRAINER_SHOW()
891 if not _G.IsTradeskillTrainer() then 911 if not _G.IsTradeskillTrainer() then
892 return 912 return
893 end 913 end
894 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 914 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
895 local npc = NPCEntry(unit_idnum) 915 local npc = NPCEntry(unit_idnum)
896 npc.teaches = npc.teaches or {} 916 npc.teaches = npc.teaches or {}
897 917
898 -- Get the initial trainer filters 918 -- Get the initial trainer filters
899 local available = _G.GetTrainerServiceTypeFilter("available") 919 local available = _G.GetTrainerServiceTypeFilter("available")