comparison Main.lua @ 151:e2331b00a1cf 1.0.15

Added some debugging prints (turned off). Removed defaulting to NPC if no target_type - simply ignore the loot. Removed setting target_type to NPC every time a target's location is updated. Ensure the unit name on the tooltip matches the spell's target name. Bumped DB version to 10.
author James D. Callahan III <jcallahan@curse.com>
date Wed, 03 Oct 2012 17:27:10 -0500
parents 11f242b0b170
children d29109b5aaea
comparison
equal deleted inserted replaced
150:11f242b0b170 151:e2331b00a1cf
30 30
31 31
32 ----------------------------------------------------------------------- 32 -----------------------------------------------------------------------
33 -- Local constants. 33 -- Local constants.
34 ----------------------------------------------------------------------- 34 -----------------------------------------------------------------------
35 local DB_VERSION = 9 35 local DB_VERSION = 10
36 36 local DEBUGGING = false
37 37
38 local DATABASE_DEFAULTS = { 38 local DATABASE_DEFAULTS = {
39 char = {}, 39 char = {},
40 global = { 40 global = {
41 items = {}, 41 items = {},
152 } 152 }
153 153
154 ----------------------------------------------------------------------- 154 -----------------------------------------------------------------------
155 -- Helper Functions. 155 -- Helper Functions.
156 ----------------------------------------------------------------------- 156 -----------------------------------------------------------------------
157 local function Debug(...)
158 if not DEBUGGING then
159 return
160 end
161 _G.print(...)
162 end
163
164
157 local ActualCopperCost 165 local ActualCopperCost
158 do 166 do
159 local BARTERING_SPELL_ID = 83964 167 local BARTERING_SPELL_ID = 83964
160 168
161 local STANDING_DISCOUNTS = { 169 local STANDING_DISCOUNTS = {
772 local power_type = _G.UnitPowerType("target") 780 local power_type = _G.UnitPowerType("target")
773 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) 781 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
774 end 782 end
775 end 783 end
776 name_to_id_map[_G.UnitName("target")] = unit_idnum 784 name_to_id_map[_G.UnitName("target")] = unit_idnum
777
778 current_action.target_type = AF.NPC
779 current_action.identifier = unit_idnum 785 current_action.identifier = unit_idnum
780 return npc, unit_idnum 786 return npc, unit_idnum
781 end 787 end
782 end -- do-block 788 end -- do-block
783 789
1262 -- Prevent opening the same loot window multiple times from recording data multiple times. 1268 -- Prevent opening the same loot window multiple times from recording data multiple times.
1263 local loot_guid_registry = {} 1269 local loot_guid_registry = {}
1264 1270
1265 1271
1266 function WDP:LOOT_CLOSED(event_name) 1272 function WDP:LOOT_CLOSED(event_name)
1273 Debug(event_name)
1267 current_loot = nil 1274 current_loot = nil
1268 table.wipe(current_action) 1275 table.wipe(current_action)
1269 end 1276 end
1270 1277
1271 1278
1272 function WDP:LOOT_OPENED(event_name) 1279 function WDP:LOOT_OPENED(event_name)
1273 if current_loot then 1280 if current_loot then
1274 return 1281 return
1275 end 1282 end
1276 current_action.target_type = current_action.target_type or AF.NPC 1283
1284 Debug(event_name)
1285 if not current_action.target_type then
1286 Debug("No target type.")
1287 return
1288 else
1289 Debug(("current_action.target_type: %s"):format(private.ACTION_TYPE_NAMES[current_action.target_type]))
1290 end
1277 1291
1278 local verify_func = LOOT_VERIFY_FUNCS[current_action.target_type] 1292 local verify_func = LOOT_VERIFY_FUNCS[current_action.target_type]
1279 local update_func = LOOT_UPDATE_FUNCS[current_action.target_type] 1293 local update_func = LOOT_UPDATE_FUNCS[current_action.target_type]
1280 1294
1281 if not verify_func or not update_func then 1295 if not verify_func or not update_func then
1318 1332
1319 if not loot_guid_registry[source_guid] then 1333 if not loot_guid_registry[source_guid] then
1320 local loot_quantity = loot_info[loot_index + 1] 1334 local loot_quantity = loot_info[loot_index + 1]
1321 local source_type, source_id = ParseGUID(source_guid) 1335 local source_type, source_id = ParseGUID(source_guid)
1322 -- TODO: Remove debugging 1336 -- TODO: Remove debugging
1323 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) 1337 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
1324 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity)) 1338 Debug(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
1325 1339
1326 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 1340 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
1327 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} 1341 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
1328 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity 1342 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity
1329 guids_used[source_guid] = true 1343 guids_used[source_guid] = true
1537 1551
1538 function WDP:PLAYER_TARGET_CHANGED(event_name) 1552 function WDP:PLAYER_TARGET_CHANGED(event_name)
1539 if not PlayerTarget() then 1553 if not PlayerTarget() then
1540 return 1554 return
1541 end 1555 end
1556 Debug(event_name)
1557 current_action.target_type = AF.NPC
1542 self:UpdateTargetLocation() 1558 self:UpdateTargetLocation()
1543 end 1559 end
1544 1560
1545 1561
1546 do 1562 do
1771 if private.tracked_line or unit_id ~= "player" then 1787 if private.tracked_line or unit_id ~= "player" then
1772 return 1788 return
1773 end 1789 end
1774 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name] 1790 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
1775 1791
1792 Debug(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
1793
1776 if not spell_label then 1794 if not spell_label then
1777 return 1795 return
1778 end 1796 end
1779 table.wipe(current_action) 1797 table.wipe(current_action)
1780 1798
1781 local item_name, item_link = _G.GameTooltip:GetItem() 1799 local item_name, item_link = _G.GameTooltip:GetItem()
1782 local unit_name, unit_id = _G.GameTooltip:GetUnit() 1800 local unit_name, unit_id = _G.GameTooltip:GetUnit()
1801
1802 Debug(("Item name: '%s', Unit name: '%s'"):format(tostring(item_name), tostring(unit_name)))
1783 1803
1784 if not unit_name and _G.UnitName("target") == target_name then 1804 if not unit_name and _G.UnitName("target") == target_name then
1785 unit_name = target_name 1805 unit_name = target_name
1786 unit_id = "target" 1806 unit_id = "target"
1787 end 1807 end
1797 1817
1798 if not private.NON_LOOT_SPELL_LABELS[spell_label] then 1818 if not private.NON_LOOT_SPELL_LABELS[spell_label] then
1799 current_action.loot_label = spell_label:lower() 1819 current_action.loot_label = spell_label:lower()
1800 end 1820 end
1801 1821
1802 if unit_name and not item_name then 1822 if unit_name and unit_name == target_name and not item_name then
1823 Debug("Unit name is same as target_name")
1803 if bit.band(spell_flags, AF.NPC) == AF.NPC then 1824 if bit.band(spell_flags, AF.NPC) == AF.NPC then
1804 if not unit_id or unit_name ~= target_name then 1825 if not unit_id or unit_name ~= target_name then
1805 return 1826 return
1806 end 1827 end
1807 current_action.target_type = AF.NPC 1828 current_action.target_type = AF.NPC
1815 current_action.identifier = ItemLinkToID(select(2, _G.GetItemInfo(target_name))) 1836 current_action.identifier = ItemLinkToID(select(2, _G.GetItemInfo(target_name)))
1816 end 1837 end
1817 elseif not item_name and not unit_name then 1838 elseif not item_name and not unit_name then
1818 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then 1839 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
1819 if target_name == "" then 1840 if target_name == "" then
1841 Debug("Didn't set current_action.target_type")
1820 return 1842 return
1821 end 1843 end
1822 current_action.object_name = target_name 1844 current_action.object_name = target_name
1823 current_action.target_type = AF.OBJECT 1845 current_action.target_type = AF.OBJECT
1846
1847 Debug(("Set current_action.target_type to %s"):format(private.ACTION_TYPE_NAMES[current_action.target_type]))
1824 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then 1848 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
1825 current_action.target_type = AF.ZONE 1849 current_action.target_type = AF.ZONE
1826 end 1850 end
1827 end 1851 end
1828 private.tracked_line = spell_line 1852 private.tracked_line = spell_line
1832 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 1856 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
1833 if unit_id ~= "player" then 1857 if unit_id ~= "player" then
1834 return 1858 return
1835 end 1859 end
1836 private.tracked_line = nil 1860 private.tracked_line = nil
1861
1862 Debug(event_name)
1837 1863
1838 if spell_name:match("^Harvest.+") then 1864 if spell_name:match("^Harvest.+") then
1839 reputation_npc_id = current_target_id 1865 reputation_npc_id = current_target_id
1840 private.harvesting = true 1866 private.harvesting = true
1841 end 1867 end
1850 1876
1851 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 1877 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
1852 if unit_id ~= "player" then 1878 if unit_id ~= "player" then
1853 return 1879 return
1854 end 1880 end
1881 Debug(event_name)
1855 1882
1856 if private.tracked_line == spell_line then 1883 if private.tracked_line == spell_line then
1857 private.tracked_line = nil 1884 private.tracked_line = nil
1858 end 1885 end
1859 table.wipe(current_action) 1886 table.wipe(current_action)