Mercurial > wow > wowdb-profiler
comparison Main.lua @ 28:11afd2cc0b83
Huge revamp to data layout format - many things now reside under the Instance difficulty.
| author | James D. Callahan III <jcallahan@curse.com> |
|---|---|
| date | Mon, 21 May 2012 16:36:35 -0500 |
| parents | 120740b8a54f |
| children | 5802628b2bf0 |
comparison
equal
deleted
inserted
replaced
| 27:120740b8a54f | 28:11afd2cc0b83 |
|---|---|
| 121 end | 121 end |
| 122 | 122 |
| 123 if _G.DungeonUsesTerrainMap() then | 123 if _G.DungeonUsesTerrainMap() then |
| 124 map_level = map_level - 1 | 124 map_level = map_level - 1 |
| 125 end | 125 end |
| 126 local x_floor = floor(x * 1000) | |
| 127 local y_floor = floor(y * 1000) | |
| 128 | |
| 129 if x_floor % 2 ~= 0 then | |
| 130 x_floor = x_floor + 1 | |
| 131 end | |
| 132 | |
| 133 if y_floor % 2 ~= 0 then | |
| 134 y_floor = y_floor + 1 | |
| 135 end | |
| 136 -- print(("x: %d - y: %d"):format(x_floor, y_floor)) | |
| 137 | |
| 126 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level, InstanceDifficultyToken() | 138 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level, InstanceDifficultyToken() |
| 127 end | 139 end |
| 128 | 140 |
| 129 | 141 |
| 130 local function ItemLinkToID(item_link) | 142 local function ItemLinkToID(item_link) |
| 158 if not identifier then | 170 if not identifier then |
| 159 return | 171 return |
| 160 end | 172 end |
| 161 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() | 173 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() |
| 162 local object = DBEntry("objects", identifier) | 174 local object = DBEntry("objects", identifier) |
| 163 object.locations = object.locations or {} | 175 object[instance_token] = object[instance_token] or {} |
| 176 object[instance_token].locations = object[instance_token].locations or {} | |
| 164 | 177 |
| 165 local location_token = ("%s:%d"):format(zone_name, area_id) | 178 local location_token = ("%s:%d"):format(zone_name, area_id) |
| 166 | 179 |
| 167 if not object.locations[location_token] then | 180 if not object[instance_token].locations[location_token] then |
| 168 object.locations[location_token] = {} | 181 object[instance_token].locations[location_token] = {} |
| 169 end | 182 end |
| 170 object.locations[location_token][("%s:%s:%s:%s"):format(instance_token, map_level, x, y)] = true | 183 object[instance_token].locations[location_token][("%s:%s:%s"):format(map_level, x, y)] = true |
| 171 end | 184 end |
| 172 | 185 |
| 173 | 186 |
| 174 local function HandleItemUse(item_link, bag_index, slot_index) | 187 local function HandleItemUse(item_link, bag_index, slot_index) |
| 175 if not item_link then | 188 if not item_link then |
| 208 end | 221 end |
| 209 | 222 |
| 210 if current_line:GetText() == _G.ITEM_OPENABLE then | 223 if current_line:GetText() == _G.ITEM_OPENABLE then |
| 211 table.wipe(action_data) | 224 table.wipe(action_data) |
| 212 action_data.type = AF.ITEM | 225 action_data.type = AF.ITEM |
| 213 action_data.item_id = item_id | 226 action_data.identifier = item_id |
| 214 action_data.label = "contains" | 227 action_data.label = "contains" |
| 215 break | 228 break |
| 216 end | 229 end |
| 217 end | 230 end |
| 218 end | 231 end |
| 328 | 341 |
| 329 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then | 342 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then |
| 330 return | 343 return |
| 331 end | 344 end |
| 332 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() | 345 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() |
| 333 local npc_data = DBEntry("npcs", unit_idnum).encounter_data[("level_%d"):format(_G.UnitLevel("target"))] | 346 local npc_data = DBEntry("npcs", unit_idnum).encounter_data[instance_token][("level_%d"):format(_G.UnitLevel("target"))] |
| 334 npc_data.locations = npc_data.locations or {} | 347 npc_data.locations = npc_data.locations or {} |
| 335 | 348 |
| 336 local location_token = ("%s:%d"):format(zone_name, area_id) | 349 local location_token = ("%s:%d"):format(zone_name, area_id) |
| 337 | 350 |
| 338 if not npc_data.locations[location_token] then | 351 if not npc_data.locations[location_token] then |
| 341 | 354 |
| 342 -- Only record corpse location if there is no entry for this GUID. | 355 -- Only record corpse location if there is no entry for this GUID. |
| 343 if is_dead and npc_data.locations[location_token][target_guid] then | 356 if is_dead and npc_data.locations[location_token][target_guid] then |
| 344 return | 357 return |
| 345 end | 358 end |
| 346 npc_data.locations[location_token][target_guid] = ("%s:%s:%s:%s"):format(instance_token, map_level, x, y) | 359 npc_data.locations[location_token][target_guid] = ("%s:%s:%s"):format(map_level, x, y) |
| 347 end | 360 end |
| 348 | 361 |
| 349 | 362 |
| 350 ----------------------------------------------------------------------- | 363 ----------------------------------------------------------------------- |
| 351 -- Event handlers. | 364 -- Event handlers. |
| 367 end | 380 end |
| 368 | 381 |
| 369 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then | 382 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then |
| 370 local npc = DBEntry("npcs", source_id) | 383 local npc = DBEntry("npcs", source_id) |
| 371 local instance_token = InstanceDifficultyToken() | 384 local instance_token = InstanceDifficultyToken() |
| 372 npc.spells = npc.spells or {} | 385 npc.encounter_data = npc.encounter_data or {} |
| 373 npc.spells[instance_token] = npc.spells[instance_token] or {} | 386 |
| 374 npc.spells[instance_token][spell_id] = true | 387 if not npc.encounter_data[instance_token] then |
| 388 npc.encounter_data[instance_token] = {} | |
| 389 end | |
| 390 local encounter_data = npc.encounter_data[instance_token] | |
| 391 | |
| 392 encounter_data.spells = encounter_data.spells or {} | |
| 393 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1 | |
| 375 end | 394 end |
| 376 end | 395 end |
| 377 | 396 |
| 378 | 397 |
| 379 local COMBAT_LOG_FUNCS = { | 398 local COMBAT_LOG_FUNCS = { |
| 401 local npc = DBEntry("npcs", action_data.identifier) | 420 local npc = DBEntry("npcs", action_data.identifier) |
| 402 | 421 |
| 403 if not npc then | 422 if not npc then |
| 404 return | 423 return |
| 405 end | 424 end |
| 406 npc.encounter_data[action_data.npc_level].reputations = npc.encounter_data[action_data.npc_level].reputations or {} | 425 local instance_token = InstanceDifficultyToken() |
| 407 npc.encounter_data[action_data.npc_level].reputations[faction_name] = amount | 426 |
| 427 if not npc.encounter_data[instance_token][action_data.npc_level].reputations then | |
| 428 npc.encounter_data[instance_token][action_data.npc_level].reputations = {} | |
| 429 end | |
| 430 npc.encounter_data[instance_token][action_data.npc_level].reputations[faction_name] = amount | |
| 408 end | 431 end |
| 409 | 432 |
| 410 | 433 |
| 411 do | 434 do |
| 412 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)") | 435 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)") |
| 440 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index)) | 463 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index)) |
| 441 end | 464 end |
| 442 end | 465 end |
| 443 end | 466 end |
| 444 | 467 |
| 445 if not locked_item_id or (action_data.item_id and action_data.item_id ~= locked_item_id) then | 468 if not locked_item_id or (action_data.identifier and action_data.identifier ~= locked_item_id) then |
| 446 return false | 469 return false |
| 447 end | 470 end |
| 448 action_data.item_id = locked_item_id | 471 action_data.identifier = locked_item_id |
| 449 return true | 472 return true |
| 450 end, | 473 end, |
| 451 [AF.NPC] = function() | 474 [AF.NPC] = function() |
| 452 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then | 475 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then |
| 453 return false | 476 return false |
| 461 return action_data.label and _G.IsFishingLoot() | 484 return action_data.label and _G.IsFishingLoot() |
| 462 end, | 485 end, |
| 463 } | 486 } |
| 464 | 487 |
| 465 | 488 |
| 466 local function GenericLootUpdate(data_type) | 489 local function GenericLootUpdate(data_type, top_field) |
| 467 local entry = DBEntry(data_type, action_data.identifier) | 490 local entry = DBEntry(data_type, action_data.identifier) |
| 468 | 491 |
| 469 print("GenericLootUpdate") | |
| 470 if not entry then | 492 if not entry then |
| 471 print(("Missing DB entry for %s (%s)"):format(data_type, tostring(action_data.identifier))) | |
| 472 return | 493 return |
| 473 end | 494 end |
| 474 local loot_type = action_data.label or "drops" | 495 local loot_type = action_data.label or "drops" |
| 475 entry[loot_type] = entry[loot_type] or {} | 496 local loot_data |
| 497 | |
| 498 if top_field then | |
| 499 entry[top_field] = entry[top_field] or {} | |
| 500 entry[top_field][loot_type] = entry[top_field][loot_type] or {} | |
| 501 | |
| 502 loot_data = entry[top_field][loot_type] | |
| 503 else | |
| 504 entry[loot_type] = entry[loot_type] or {} | |
| 505 | |
| 506 loot_data = entry[loot_type] | |
| 507 end | |
| 476 | 508 |
| 477 for index = 1, #action_data.loot_list do | 509 for index = 1, #action_data.loot_list do |
| 478 table.insert(entry[loot_type], action_data.loot_list[index]) | 510 table.insert(loot_data, action_data.loot_list[index]) |
| 479 end | 511 end |
| 480 end | 512 end |
| 481 | 513 |
| 482 | 514 |
| 483 local LOOT_UPDATE_FUNCS = { | 515 local LOOT_UPDATE_FUNCS = { |
| 484 [AF.ITEM] = function() | 516 [AF.ITEM] = function() |
| 485 local item = DBEntry("items", action_data.item_id) | 517 GenericLootUpdate("items") |
| 486 local loot_type = action_data.label or "drops" | |
| 487 item[loot_type] = item[loot_type] or {} | |
| 488 | |
| 489 for index = 1, #action_data.loot_list do | |
| 490 table.insert(item[loot_type], action_data.loot_list[index]) | |
| 491 end | |
| 492 end, | 518 end, |
| 493 [AF.NPC] = function() | 519 [AF.NPC] = function() |
| 494 GenericLootUpdate("npcs") | 520 local npc = DBEntry("npcs", action_data.identifier) |
| 521 | |
| 522 if not npc then | |
| 523 return | |
| 524 end | |
| 525 local instance_token = InstanceDifficultyToken() | |
| 526 | |
| 527 if not npc.encounter_data[instance_token] then | |
| 528 npc.encounter_data[instance_token] = {} | |
| 529 end | |
| 530 local loot_type = action_data.label or "drops" | |
| 531 npc.encounter_data[instance_token][loot_type] = npc.encounter_data[instance_token][loot_type] or {} | |
| 532 | |
| 533 local loot_data = npc.encounter_data[instance_token][loot_type] | |
| 534 | |
| 535 for index = 1, #action_data.loot_list do | |
| 536 table.insert(loot_data, action_data.loot_list[index]) | |
| 537 end | |
| 495 end, | 538 end, |
| 496 [AF.OBJECT] = function() | 539 [AF.OBJECT] = function() |
| 497 GenericLootUpdate("objects") | 540 GenericLootUpdate("objects", InstanceDifficultyToken()) |
| 498 end, | 541 end, |
| 499 [AF.ZONE] = function() | 542 [AF.ZONE] = function() |
| 500 local loot_type = action_data.label or "drops" | 543 local loot_type = action_data.label or "drops" |
| 501 local zone = DBEntry("zones", action_data.zone) | 544 local zone = DBEntry("zones", action_data.zone) |
| 502 zone[loot_type] = zone[loot_type] or {} | 545 zone[action_data.instance_token] = zone[action_data.instance_token] or {} |
| 503 | 546 zone[action_data.instance_token][loot_type] = zone[loot_type][action_data.instance_token] or {} |
| 504 local location_data = ("%s:%s:%s:%s"):format(action_data.instance_token, action_data.map_level, action_data.x, action_data.y) | 547 |
| 505 local loot_data = zone[loot_type][location_data] | 548 local location_data = ("%s:%s:%s"):format(action_data.map_level, action_data.x, action_data.y) |
| 549 local loot_data = zone[action_data.instance_token][loot_type][location_data] | |
| 506 | 550 |
| 507 if not loot_data then | 551 if not loot_data then |
| 508 zone[loot_type][location_data] = {} | 552 zone[action_data.instance_token][loot_type][location_data] = {} |
| 509 loot_data = zone[loot_type][location_data] | 553 loot_data = zone[action_data.instance_token][loot_type][location_data] |
| 510 end | 554 end |
| 511 | 555 |
| 512 for index = 1, #action_data.loot_list do | 556 for index = 1, #action_data.loot_list do |
| 513 table.insert(loot_data, action_data.loot_list[index]) | 557 table.insert(loot_data, action_data.loot_list[index]) |
| 514 end | 558 end |
| 671 | 715 |
| 672 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then | 716 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then |
| 673 return | 717 return |
| 674 end | 718 end |
| 675 DBEntry("npcs", unit_idnum).mind_control = true | 719 DBEntry("npcs", unit_idnum).mind_control = true |
| 676 print("Wiping action_data") | |
| 677 table.wipe(action_data) | 720 table.wipe(action_data) |
| 678 end | 721 end |
| 679 | 722 |
| 680 | 723 |
| 681 do | 724 do |
| 741 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true | 784 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true |
| 742 npc.is_pvp = _G.UnitIsPVP("target") and true or nil | 785 npc.is_pvp = _G.UnitIsPVP("target") and true or nil |
| 743 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) | 786 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) |
| 744 npc.encounter_data = npc.encounter_data or {} | 787 npc.encounter_data = npc.encounter_data or {} |
| 745 | 788 |
| 789 local instance_token = InstanceDifficultyToken() | |
| 790 | |
| 791 if not npc.encounter_data[instance_token] then | |
| 792 npc.encounter_data[instance_token] = {} | |
| 793 end | |
| 794 local encounter_data = npc.encounter_data[instance_token] | |
| 746 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) | 795 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) |
| 747 | 796 |
| 748 if not npc.encounter_data[npc_level] then | 797 if not encounter_data[npc_level] then |
| 749 npc.encounter_data[npc_level] = { | 798 encounter_data[npc_level] = { |
| 750 max_health = _G.UnitHealthMax("target"), | 799 max_health = _G.UnitHealthMax("target"), |
| 751 } | 800 } |
| 752 | 801 |
| 753 local max_power = _G.UnitManaMax("target") | 802 local max_power = _G.UnitManaMax("target") |
| 754 | 803 |
| 755 if max_power > 0 then | 804 if max_power > 0 then |
| 756 local power_type = _G.UnitPowerType("target") | 805 local power_type = _G.UnitPowerType("target") |
| 757 npc.encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) | 806 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) |
| 758 end | 807 end |
| 759 end | 808 end |
| 760 table.wipe(action_data) | 809 table.wipe(action_data) |
| 761 action_data.type = AF.NPC | 810 action_data.type = AF.NPC |
| 762 action_data.identifier = unit_idnum | 811 action_data.identifier = unit_idnum |
| 883 if not tt_unit_name and _G.UnitName("target") == target_name then | 932 if not tt_unit_name and _G.UnitName("target") == target_name then |
| 884 tt_unit_name = target_name | 933 tt_unit_name = target_name |
| 885 tt_unit_id = "target" | 934 tt_unit_id = "target" |
| 886 end | 935 end |
| 887 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label] | 936 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label] |
| 937 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() | |
| 938 | |
| 939 action_data.instance_token = instance_token | |
| 940 action_data.map_level = map_level | |
| 941 action_data.x = x | |
| 942 action_data.y = y | |
| 943 action_data.zone = ("%s:%d"):format(zone_name, area_id) | |
| 888 | 944 |
| 889 if tt_unit_name and not tt_item_name then | 945 if tt_unit_name and not tt_item_name then |
| 890 if bit.band(spell_flags, AF.NPC) == AF.NPC then | 946 if bit.band(spell_flags, AF.NPC) == AF.NPC then |
| 891 if not tt_unit_id or tt_unit_name ~= target_name then | 947 if not tt_unit_id or tt_unit_name ~= target_name then |
| 892 return | 948 return |
| 898 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then | 954 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then |
| 899 action_data.type = AF.ITEM | 955 action_data.type = AF.ITEM |
| 900 action_data.label = spell_label:lower() | 956 action_data.label = spell_label:lower() |
| 901 | 957 |
| 902 if tt_item_name and tt_item_name == target_name then | 958 if tt_item_name and tt_item_name == target_name then |
| 903 action_data.item_id = ItemLinkToID(tt_item_link) | 959 action_data.identifier = ItemLinkToID(tt_item_link) |
| 904 elseif target_name and target_name ~= "" then | 960 elseif target_name and target_name ~= "" then |
| 905 local _, target_item_link = _G.GetItemInfo(target_name) | 961 local _, target_item_link = _G.GetItemInfo(target_name) |
| 906 action_data.item_id = ItemLinkToID(target_item_link) | 962 action_data.identifier = ItemLinkToID(target_item_link) |
| 907 end | 963 end |
| 908 elseif not tt_item_name and not tt_unit_name then | 964 elseif not tt_item_name and not tt_unit_name then |
| 909 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() | |
| 910 | |
| 911 action_data.instance_token = instance_token | |
| 912 action_data.map_level = map_level | |
| 913 action_data.name = target_name | 965 action_data.name = target_name |
| 914 action_data.x = x | |
| 915 action_data.y = y | |
| 916 action_data.zone = ("%s:%d"):format(zone_name, area_id) | |
| 917 | 966 |
| 918 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then | 967 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then |
| 919 if target_name == "" then | 968 if target_name == "" then |
| 920 return | 969 return |
| 921 end | 970 end |
| 927 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then | 976 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then |
| 928 action_data.type = AF.ZONE | 977 action_data.type = AF.ZONE |
| 929 action_data.label = spell_label:lower() | 978 action_data.label = spell_label:lower() |
| 930 end | 979 end |
| 931 end | 980 end |
| 932 | |
| 933 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)) | |
| 934 private.tracked_line = spell_line | 981 private.tracked_line = spell_line |
| 935 end | 982 end |
| 936 | 983 |
| 937 | 984 |
| 938 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) | 985 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) |
