Mercurial > wow > wowdb-profiler
comparison Main.lua @ 118:08bc44830424
Moved the bulk of the PLAYER_TARGET_CHANGED function into PlayerTarget() - now also called from within UpdateTargetLocation() to ensure that valid data is present.
| author | James D. Callahan III <jcallahan@curse.com> |
|---|---|
| date | Sun, 16 Sep 2012 17:34:20 -0500 |
| parents | bdf1ec712304 |
| children | 8df432f8a15a |
comparison
equal
deleted
inserted
replaced
| 117:bdf1ec712304 | 118:08bc44830424 |
|---|---|
| 404 function GenericLootUpdate(data_type, top_field) | 404 function GenericLootUpdate(data_type, top_field) |
| 405 local loot_type = action_data.loot_label or "drops" | 405 local loot_type = action_data.loot_label or "drops" |
| 406 local loot_count = ("%s_count"):format(loot_type) | 406 local loot_count = ("%s_count"):format(loot_type) |
| 407 local source_list = {} | 407 local source_list = {} |
| 408 | 408 |
| 409 for source_guid, loot_data in pairs(action_data.loot_sources) do | 409 for source_guid, loot_data in pairs(action_data.loot_sources) do -- TODO: Find out why this breaks with gas extractions. |
| 410 local entry, source_id | 410 local entry, source_id |
| 411 | 411 |
| 412 if action_data.type == AF.ITEM then | 412 if action_data.type == AF.ITEM then |
| 413 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc) | 413 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc) |
| 414 source_id = action_data.identifier | 414 source_id = action_data.identifier |
| 576 end | 576 end |
| 577 end | 577 end |
| 578 end | 578 end |
| 579 end | 579 end |
| 580 | 580 |
| 581 | |
| 582 local PlayerTarget | |
| 583 do | |
| 584 local GENDER_NAMES = { | |
| 585 "UNKNOWN", | |
| 586 "MALE", | |
| 587 "FEMALE", | |
| 588 } | |
| 589 | |
| 590 | |
| 591 local REACTION_NAMES = { | |
| 592 "HATED", | |
| 593 "HOSTILE", | |
| 594 "UNFRIENDLY", | |
| 595 "NEUTRAL", | |
| 596 "FRIENDLY", | |
| 597 "HONORED", | |
| 598 "REVERED", | |
| 599 "EXALTED", | |
| 600 } | |
| 601 | |
| 602 | |
| 603 local POWER_TYPE_NAMES = { | |
| 604 ["0"] = "MANA", | |
| 605 ["1"] = "RAGE", | |
| 606 ["2"] = "FOCUS", | |
| 607 ["3"] = "ENERGY", | |
| 608 ["6"] = "RUNIC_POWER", | |
| 609 } | |
| 610 | |
| 611 | |
| 612 function PlayerTarget() | |
| 613 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then | |
| 614 current_target_id = nil | |
| 615 return | |
| 616 end | |
| 617 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) | |
| 618 | |
| 619 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then | |
| 620 return | |
| 621 end | |
| 622 current_target_id = unit_idnum | |
| 623 | |
| 624 local npc = NPCEntry(unit_idnum) | |
| 625 local _, class_token = _G.UnitClass("target") | |
| 626 npc.class = class_token | |
| 627 npc.faction = UnitFactionStanding("target") | |
| 628 npc.genders = npc.genders or {} | |
| 629 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true | |
| 630 npc.is_pvp = _G.UnitIsPVP("target") and true or nil | |
| 631 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) | |
| 632 | |
| 633 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats | |
| 634 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) | |
| 635 | |
| 636 if not encounter_data[npc_level] then | |
| 637 encounter_data[npc_level] = { | |
| 638 max_health = _G.UnitHealthMax("target"), | |
| 639 } | |
| 640 | |
| 641 local max_power = _G.UnitManaMax("target") | |
| 642 | |
| 643 if max_power > 0 then | |
| 644 local power_type = _G.UnitPowerType("target") | |
| 645 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) | |
| 646 end | |
| 647 end | |
| 648 name_to_id_map[_G.UnitName("target")] = unit_idnum | |
| 649 | |
| 650 table.wipe(action_data) | |
| 651 action_data.type = AF.NPC | |
| 652 action_data.identifier = unit_idnum | |
| 653 action_data.npc_level = npc_level | |
| 654 return npc, unit_idnum | |
| 655 end | |
| 656 end -- do-block | |
| 657 | |
| 658 | |
| 581 do | 659 do |
| 582 local COORD_MAX = 5 | 660 local COORD_MAX = 5 |
| 583 | 661 |
| 584 function WDP:UpdateTargetLocation() | 662 function WDP:UpdateTargetLocation() |
| 585 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then | 663 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then |
| 589 for index = 1, 4 do | 667 for index = 1, 4 do |
| 590 if not _G.CheckInteractDistance("target", index) then | 668 if not _G.CheckInteractDistance("target", index) then |
| 591 return | 669 return |
| 592 end | 670 end |
| 593 end | 671 end |
| 594 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) | 672 local npc = PlayerTarget() |
| 595 | |
| 596 if not unit_idnum or unit_type ~= private.UNIT_TYPES.NPC then | |
| 597 return | |
| 598 end | |
| 599 local npc = NPCEntry(unit_idnum) | |
| 600 | 673 |
| 601 if not npc then | 674 if not npc then |
| 602 return | 675 return |
| 603 end | 676 end |
| 604 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData() | 677 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData() |
| 605 local npc_data = npc.encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))] | 678 local npc_data = npc.encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))] |
| 606 local zone_token = ("%s:%d"):format(zone_name, area_id) | 679 local zone_token = ("%s:%d"):format(zone_name, area_id) |
| 607 npc_data.locations = npc_data.locations or {} | 680 npc_data.locations = npc_data.locations or {} -- TODO: Fix this. It is broken. Possibly something to do with the timed updates. |
| 608 | 681 |
| 609 local zone_data = npc_data.locations[zone_token] | 682 local zone_data = npc_data.locations[zone_token] |
| 610 | 683 |
| 611 if not zone_data then | 684 if not zone_data then |
| 612 zone_data = {} | 685 zone_data = {} |
| 622 end | 695 end |
| 623 end | 696 end |
| 624 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true | 697 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true |
| 625 end | 698 end |
| 626 end -- do-block | 699 end -- do-block |
| 700 | |
| 627 | 701 |
| 628 ----------------------------------------------------------------------- | 702 ----------------------------------------------------------------------- |
| 629 -- Event handlers. | 703 -- Event handlers. |
| 630 ----------------------------------------------------------------------- | 704 ----------------------------------------------------------------------- |
| 631 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name) | 705 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name) |
| 1261 end | 1335 end |
| 1262 end | 1336 end |
| 1263 end | 1337 end |
| 1264 | 1338 |
| 1265 | 1339 |
| 1266 do | 1340 function WDP:PLAYER_TARGET_CHANGED(event_name) |
| 1267 local GENDER_NAMES = { | 1341 if not PlayerTarget() then |
| 1268 "UNKNOWN", | 1342 return |
| 1269 "MALE", | 1343 end |
| 1270 "FEMALE", | 1344 self:UpdateTargetLocation() |
| 1271 } | 1345 end |
| 1272 | |
| 1273 | |
| 1274 local REACTION_NAMES = { | |
| 1275 "HATED", | |
| 1276 "HOSTILE", | |
| 1277 "UNFRIENDLY", | |
| 1278 "NEUTRAL", | |
| 1279 "FRIENDLY", | |
| 1280 "HONORED", | |
| 1281 "REVERED", | |
| 1282 "EXALTED", | |
| 1283 } | |
| 1284 | |
| 1285 | |
| 1286 local POWER_TYPE_NAMES = { | |
| 1287 ["0"] = "MANA", | |
| 1288 ["1"] = "RAGE", | |
| 1289 ["2"] = "FOCUS", | |
| 1290 ["3"] = "ENERGY", | |
| 1291 ["6"] = "RUNIC_POWER", | |
| 1292 } | |
| 1293 | |
| 1294 | |
| 1295 function WDP:PLAYER_TARGET_CHANGED(event_name) | |
| 1296 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then | |
| 1297 current_target_id = nil | |
| 1298 return | |
| 1299 end | |
| 1300 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) | |
| 1301 | |
| 1302 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then | |
| 1303 return | |
| 1304 end | |
| 1305 current_target_id = unit_idnum | |
| 1306 | |
| 1307 local npc = NPCEntry(unit_idnum) | |
| 1308 local _, class_token = _G.UnitClass("target") | |
| 1309 npc.class = class_token | |
| 1310 npc.faction = UnitFactionStanding("target") | |
| 1311 npc.genders = npc.genders or {} | |
| 1312 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true | |
| 1313 npc.is_pvp = _G.UnitIsPVP("target") and true or nil | |
| 1314 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) | |
| 1315 | |
| 1316 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats | |
| 1317 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) | |
| 1318 | |
| 1319 if not encounter_data[npc_level] then | |
| 1320 encounter_data[npc_level] = { | |
| 1321 max_health = _G.UnitHealthMax("target"), | |
| 1322 } | |
| 1323 | |
| 1324 local max_power = _G.UnitManaMax("target") | |
| 1325 | |
| 1326 if max_power > 0 then | |
| 1327 local power_type = _G.UnitPowerType("target") | |
| 1328 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) | |
| 1329 end | |
| 1330 end | |
| 1331 name_to_id_map[_G.UnitName("target")] = unit_idnum | |
| 1332 | |
| 1333 table.wipe(action_data) | |
| 1334 action_data.type = AF.NPC | |
| 1335 action_data.identifier = unit_idnum | |
| 1336 action_data.npc_level = npc_level | |
| 1337 self:UpdateTargetLocation() | |
| 1338 end | |
| 1339 end -- do-block | |
| 1340 | 1346 |
| 1341 | 1347 |
| 1342 do | 1348 do |
| 1343 local function UpdateQuestJuncture(point) | 1349 local function UpdateQuestJuncture(point) |
| 1344 local unit_name = _G.UnitName("questnpc") | 1350 local unit_name = _G.UnitName("questnpc") |
