comparison Main.lua @ 153:d29109b5aaea

To avoid erroneous reputation gain data; upon CLEU's UNIT_DIED, ignore anything which is not the player's target and set a timer to clear reputation_npc_id 0.2 seconds after being set.
author James D. Callahan III <jcallahan@curse.com>
date Thu, 04 Oct 2012 10:59:54 -0500
parents e2331b00a1cf
children 6c16692eebb0
comparison
equal deleted inserted replaced
152:84c3c91c6164 153:d29109b5aaea
198 return math.floor(copper_cost / modifier) 198 return math.floor(copper_cost / modifier)
199 end 199 end
200 end -- do-block 200 end -- do-block
201 201
202 202
203 -- Called on a timer
204 local function ClearReputationNPC()
205 Debug("Clearing reputation_npc_id")
206 reputation_npc_id = nil
207 end
208
209
203 local function InstanceDifficultyToken() 210 local function InstanceDifficultyToken()
204 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo() 211 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
205 if not difficulty_name or difficulty_name == "" then 212 if not difficulty_name or difficulty_name == "" then
206 difficulty_name = "NONE" 213 difficulty_name = "NONE"
207 end 214 end
644 raw_db.build_num = build_num 651 raw_db.build_num = build_num
645 raw_db.version = DB_VERSION 652 raw_db.version = DB_VERSION
646 end 653 end
647 654
648 655
656 function WDP:EventDispatcher(...)
657 local event_name = ...
658
659 if DEBUGGING then
660 if reputation_npc_id then
661 if event_name == "COMBAT_LOG_EVENT_UNFILTERED" then
662 Debug(event_name)
663 else
664 Debug(...)
665 end
666 Debug(("reputation_npc_id == '%s'"):format(reputation_npc_id))
667 end
668 end
669 local func = EVENT_MAPPING[event_name]
670
671 if _G.type(func) == "boolean" then
672 self[event_name](self, ...)
673 elseif _G.type(func) == "function" then
674 EVENT_MAPPING[event_name](self, ...)
675 end
676 end
677
678
649 function WDP:OnEnable() 679 function WDP:OnEnable()
650 for event_name, mapping in pairs(EVENT_MAPPING) do 680 for event_name, mapping in pairs(EVENT_MAPPING) do
651 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil) 681 if DEBUGGING then
682 self:RegisterEvent(event_name, "EventDispatcher")
683 else
684 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
685 end
652 end 686 end
653 687
654 for index = 1, _G.GetNumLanguages() do 688 for index = 1, _G.GetNumLanguages() do
655 languages_known[_G.GetLanguageByIndex(index)] = true 689 languages_known[_G.GetLanguageByIndex(index)] = true
656 end 690 end
964 end 998 end
965 end 999 end
966 RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) 1000 RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
967 end, 1001 end,
968 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) 1002 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
1003 if dest_guid ~= _G.UnitGUID("target") then
1004 return
1005 end
969 local unit_type, unit_idnum = ParseGUID(dest_guid) 1006 local unit_type, unit_idnum = ParseGUID(dest_guid)
970 1007
971 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 1008 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
972 reputation_npc_id = nil 1009 reputation_npc_id = nil
973 private.harvesting = nil 1010 private.harvesting = nil
974 return 1011 return
975 end 1012 end
976 reputation_npc_id = unit_idnum 1013 reputation_npc_id = unit_idnum
1014 WDP:ScheduleTimer(ClearReputationNPC, 0.1)
977 end, 1015 end,
978 } 1016 }
979 1017
980 1018
981 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event_name, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...) 1019 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event_name, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...)
1091 if not modded_faction or faction_name == modded_faction then 1129 if not modded_faction or faction_name == modded_faction then
1092 modifier = modifier + MODIFIERS[buff_label].modifier 1130 modifier = modifier + MODIFIERS[buff_label].modifier
1093 end 1131 end
1094 end 1132 end
1095 end 1133 end
1134 Debug(("Setting reputation for %s."):format(faction_name))
1096 npc.reputations = npc.reputations or {} 1135 npc.reputations = npc.reputations or {}
1097 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier) 1136 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
1098 end 1137 end
1099 end -- do-block 1138 end -- do-block
1100 1139
1268 -- Prevent opening the same loot window multiple times from recording data multiple times. 1307 -- Prevent opening the same loot window multiple times from recording data multiple times.
1269 local loot_guid_registry = {} 1308 local loot_guid_registry = {}
1270 1309
1271 1310
1272 function WDP:LOOT_CLOSED(event_name) 1311 function WDP:LOOT_CLOSED(event_name)
1273 Debug(event_name)
1274 current_loot = nil 1312 current_loot = nil
1275 table.wipe(current_action) 1313 table.wipe(current_action)
1276 end 1314 end
1277 1315
1278 1316
1279 function WDP:LOOT_OPENED(event_name) 1317 function WDP:LOOT_OPENED(event_name)
1280 if current_loot then 1318 if current_loot then
1281 return 1319 return
1282 end 1320 end
1283 1321
1284 Debug(event_name)
1285 if not current_action.target_type then 1322 if not current_action.target_type then
1286 Debug("No target type.") 1323 Debug("No target type.")
1287 return 1324 return
1288 else 1325 else
1289 Debug(("current_action.target_type: %s"):format(private.ACTION_TYPE_NAMES[current_action.target_type])) 1326 Debug(("current_action.target_type: %s"):format(private.ACTION_TYPE_NAMES[current_action.target_type]))
1551 1588
1552 function WDP:PLAYER_TARGET_CHANGED(event_name) 1589 function WDP:PLAYER_TARGET_CHANGED(event_name)
1553 if not PlayerTarget() then 1590 if not PlayerTarget() then
1554 return 1591 return
1555 end 1592 end
1556 Debug(event_name)
1557 current_action.target_type = AF.NPC 1593 current_action.target_type = AF.NPC
1558 self:UpdateTargetLocation() 1594 self:UpdateTargetLocation()
1559 end 1595 end
1560 1596
1561 1597
1787 if private.tracked_line or unit_id ~= "player" then 1823 if private.tracked_line or unit_id ~= "player" then
1788 return 1824 return
1789 end 1825 end
1790 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name] 1826 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
1791 1827
1792 Debug(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
1793
1794 if not spell_label then 1828 if not spell_label then
1795 return 1829 return
1796 end 1830 end
1797 table.wipe(current_action) 1831 table.wipe(current_action)
1798 1832
1857 if unit_id ~= "player" then 1891 if unit_id ~= "player" then
1858 return 1892 return
1859 end 1893 end
1860 private.tracked_line = nil 1894 private.tracked_line = nil
1861 1895
1862 Debug(event_name)
1863
1864 if spell_name:match("^Harvest.+") then 1896 if spell_name:match("^Harvest.+") then
1865 reputation_npc_id = current_target_id 1897 reputation_npc_id = current_target_id
1866 private.harvesting = true 1898 private.harvesting = true
1867 end 1899 end
1868 1900
1876 1908
1877 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 1909 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
1878 if unit_id ~= "player" then 1910 if unit_id ~= "player" then
1879 return 1911 return
1880 end 1912 end
1881 Debug(event_name)
1882 1913
1883 if private.tracked_line == spell_line then 1914 if private.tracked_line == spell_line then
1884 private.tracked_line = nil 1915 private.tracked_line = nil
1885 end 1916 end
1886 table.wipe(current_action) 1917 table.wipe(current_action)