Mercurial > wow > wowdb-profiler
comparison Main.lua @ 322:fdf96c61d1b7
Attempt to extrapolate valid current_action data in cases where it is invalid/incomplete when LOOT_OPENED fires.
| author | James D. Callahan III <jcallahan@curse.com> |
|---|---|
| date | Mon, 14 Oct 2013 17:02:28 -0500 |
| parents | 10d45fef6ae1 |
| children | 901b9cd2a6c2 |
comparison
equal
deleted
inserted
replaced
| 321:10d45fef6ae1 | 322:fdf96c61d1b7 |
|---|---|
| 34 local AF = private.ACTION_TYPE_FLAGS | 34 local AF = private.ACTION_TYPE_FLAGS |
| 35 local CLIENT_LOCALE = _G.GetLocale() | 35 local CLIENT_LOCALE = _G.GetLocale() |
| 36 local DB_VERSION = 18 | 36 local DB_VERSION = 18 |
| 37 local DEBUGGING = false | 37 local DEBUGGING = false |
| 38 local EVENT_DEBUG = false | 38 local EVENT_DEBUG = false |
| 39 | |
| 39 local OBJECT_ID_ANVIL = 192628 | 40 local OBJECT_ID_ANVIL = 192628 |
| 41 local OBJECT_ID_FISHING_BOBBER = 35591 | |
| 40 local OBJECT_ID_FORGE = 1685 | 42 local OBJECT_ID_FORGE = 1685 |
| 43 | |
| 41 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player")) | 44 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player")) |
| 42 local PLAYER_FACTION = _G.UnitFactionGroup("player") | 45 local PLAYER_FACTION = _G.UnitFactionGroup("player") |
| 43 local PLAYER_GUID | 46 local PLAYER_GUID |
| 44 local PLAYER_NAME = _G.UnitName("player") | 47 local PLAYER_NAME = _G.UnitName("player") |
| 45 local PLAYER_RACE = _G.select(2, _G.UnitRace("player")) | 48 local PLAYER_RACE = _G.select(2, _G.UnitRace("player")) |
| 1686 return false | 1689 return false |
| 1687 end | 1690 end |
| 1688 current_action.identifier = locked_item_id | 1691 current_action.identifier = locked_item_id |
| 1689 return true | 1692 return true |
| 1690 end, | 1693 end, |
| 1691 [AF.NPC] = function() | 1694 [AF.NPC] = true, |
| 1692 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then | |
| 1693 return false | |
| 1694 end | |
| 1695 | |
| 1696 if not current_action.identifier then | |
| 1697 local unit_type, id_num = ParseGUID(_G.UnitGUID("target")) | |
| 1698 current_action.identifier = id_num | |
| 1699 end | |
| 1700 return true | |
| 1701 end, | |
| 1702 [AF.OBJECT] = true, | 1695 [AF.OBJECT] = true, |
| 1703 [AF.ZONE] = function() | 1696 [AF.ZONE] = function() |
| 1704 current_action.zone_data = UpdateDBEntryLocation("zones", current_action.identifier) | 1697 current_action.zone_data = UpdateDBEntryLocation("zones", current_action.identifier) |
| 1705 return _G.IsFishingLoot() | 1698 return _G.IsFishingLoot() |
| 1706 end, | 1699 end, |
| 1785 current_loot = nil | 1778 current_loot = nil |
| 1786 table.wipe(current_action) | 1779 table.wipe(current_action) |
| 1787 end | 1780 end |
| 1788 | 1781 |
| 1789 | 1782 |
| 1783 local function ExtrapolatedCurrentActionFromLootData(event_name) | |
| 1784 local extrapolated_guid_registry = {} | |
| 1785 local num_guids = 0 | |
| 1786 | |
| 1787 table.wipe(current_action) | |
| 1788 | |
| 1789 for loot_slot = 1, _G.GetNumLootItems() do | |
| 1790 local loot_info = { | |
| 1791 _G.GetLootSourceInfo(loot_slot) | |
| 1792 } | |
| 1793 | |
| 1794 for loot_index = 1, #loot_info, 2 do | |
| 1795 local source_guid = loot_info[loot_index] | |
| 1796 | |
| 1797 if not extrapolated_guid_registry[source_guid] then | |
| 1798 local unit_type, unit_idnum = ParseGUID(source_guid) | |
| 1799 | |
| 1800 if unit_type and unit_idnum then | |
| 1801 extrapolated_guid_registry[source_guid] = { | |
| 1802 unit_type, | |
| 1803 unit_idnum | |
| 1804 } | |
| 1805 | |
| 1806 num_guids = num_guids + 1 | |
| 1807 end | |
| 1808 end | |
| 1809 end | |
| 1810 end | |
| 1811 local log_source = event_name .. "- ExtrapolatedCurrentActionFromLootData" | |
| 1812 | |
| 1813 if num_guids == 0 then | |
| 1814 Debug("%s: No GUIDs found in loot. Blank loot window?", log_source) | |
| 1815 return false | |
| 1816 end | |
| 1817 local num_npcs = 0 | |
| 1818 local num_objects = 0 | |
| 1819 | |
| 1820 for source_guid, guid_data in pairs(extrapolated_guid_registry) do | |
| 1821 local unit_type = guid_data[1] | |
| 1822 local loot_label = (unit_type == private.UNIT_TYPES.OBJECT) and "opening" or (UnitTypeIsNPC(unit_type) and "drops" or nil) | |
| 1823 | |
| 1824 if loot_label then | |
| 1825 local unit_idnum = guid_data[2] | |
| 1826 | |
| 1827 if loot_guid_registry[loot_label] and loot_guid_registry[loot_label][source_guid] then | |
| 1828 Debug("%s: Previously scanned loot for unit with GUID %s and identifier %s.", log_source, source_guid, unit_idnum) | |
| 1829 elseif unit_type == private.UNIT_TYPES.OBJECT and unit_idnum ~= OBJECT_ID_FISHING_BOBBER then | |
| 1830 current_action.loot_label = loot_label | |
| 1831 current_action.spell_label = "OPENING" | |
| 1832 current_action.target_type = AF.OBJECT | |
| 1833 current_action.identifier = unit_idnum | |
| 1834 num_objects = num_objects + 1 | |
| 1835 elseif UnitTypeIsNPC(unit_type) then | |
| 1836 current_action.loot_label = loot_label | |
| 1837 current_action.target_type = AF.NPC | |
| 1838 current_action.identifier = unit_idnum | |
| 1839 num_npcs = num_npcs + 1 | |
| 1840 end | |
| 1841 else | |
| 1842 -- Bail here; not only do we not know what this unit is, but we don't want to attribute loot to something that doesn't actually drop it. | |
| 1843 Debug("%s: Unit with GUID %s has unsupported type for looting.", log_source, source_guid) | |
| 1844 return false | |
| 1845 end | |
| 1846 end | |
| 1847 | |
| 1848 if not current_action.target_type then | |
| 1849 Debug("%s: Failure to obtain target_type.", log_source) | |
| 1850 return false | |
| 1851 end | |
| 1852 | |
| 1853 -- We can't figure out what dropped the loot. This shouldn't ever happen, but hey - Blizzard does some awesome stuff on occasion. | |
| 1854 if num_npcs ~= 0 and num_objects ~= 0 then | |
| 1855 Debug("%s: Mixed target types are not supported.", log_source) | |
| 1856 return false | |
| 1857 end | |
| 1858 | |
| 1859 Debug("%s: Successfully extrapolated information for current_action.", log_source) | |
| 1860 return true | |
| 1861 end | |
| 1862 | |
| 1863 | |
| 1790 function WDP:LOOT_OPENED(event_name) | 1864 function WDP:LOOT_OPENED(event_name) |
| 1791 if current_loot then | 1865 if current_loot then |
| 1792 Debug("%s: Previous loot did not process.", event_name) | 1866 current_loot = nil |
| 1793 return | 1867 Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name) |
| 1868 | |
| 1869 if not ExtrapolatedCurrentActionFromLootData(event_name) then | |
| 1870 Debug("%s: Unable to extrapolate current_action. Aborting attempts to handle loot for now.", event_name) | |
| 1871 return | |
| 1872 end | |
| 1794 end | 1873 end |
| 1795 | 1874 |
| 1796 if not current_action.target_type then | 1875 if not current_action.target_type then |
| 1797 Debug("%s: No target type found.", event_name) | 1876 Debug("%s: No target type found. Attempting to extrapolate current_action from loot data.", event_name) |
| 1798 return | 1877 |
| 1878 if not ExtrapolatedCurrentActionFromLootData(event_name) then | |
| 1879 Debug("%s: Unable to extrapolate current_action. Aborting attempts to handle loot for now.", event_name) | |
| 1880 return | |
| 1881 end | |
| 1799 end | 1882 end |
| 1800 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type] | 1883 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type] |
| 1801 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type] | 1884 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type] |
| 1802 | 1885 |
| 1803 if not verify_func or not update_func then | 1886 if not verify_func or not update_func then |
| 1887 Debug("%s: The current action's target type is unsupported or nil.", event_name) | |
| 1804 return | 1888 return |
| 1805 end | 1889 end |
| 1806 | 1890 |
| 1807 if _G.type(verify_func) == "function" and not verify_func() then | 1891 if _G.type(verify_func) == "function" and not verify_func() then |
| 1892 Debug("%s: The current action type, %s, is supported but has failed loot verification.", event_name, current_action.target_type) | |
| 1808 return | 1893 return |
| 1809 end | 1894 end |
| 1810 local guids_used = {} | 1895 local guids_used = {} |
| 1811 | 1896 |
| 1812 InitializeCurrentLoot() | 1897 InitializeCurrentLoot() |
