comparison Main.lua @ 383:d3e8a11a21ea

Removed AceTimer dependency, replacing all timers with native WoW API functions.
author MMOSimca <MMOSimca@gmail.com>
date Thu, 11 Dec 2014 02:42:07 -0500
parents 8d63f8348496
children ae63dafab1e6
comparison
equal deleted inserted replaced
382:8d63f8348496 383:d3e8a11a21ea
12 12
13 local next = _G.next 13 local next = _G.next
14 local select = _G.select 14 local select = _G.select
15 local unpack = _G.unpack 15 local unpack = _G.unpack
16 16
17 local C_Timer = _G.C_Timer
18
17 19
18 -- ADDON NAMESPACE ---------------------------------------------------- 20 -- ADDON NAMESPACE ----------------------------------------------------
19 21
20 local ADDON_NAME, private = ... 22 local ADDON_NAME, private = ...
21 23
22 local LibStub = _G.LibStub 24 local LibStub = _G.LibStub
23 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") 25 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0")
24 26
25 local deformat = LibStub("LibDeformat-3.0") 27 local deformat = LibStub("LibDeformat-3.0")
26 local LPJ = LibStub("LibPetJournal-2.0") 28 local LPJ = LibStub("LibPetJournal-2.0")
27 local MapData = LibStub("LibMapData-1.0") 29 local MapData = LibStub("LibMapData-1.0")
28 30
847 end 849 end
848 850
849 851
850 local function ClearKilledBossID() 852 local function ClearKilledBossID()
851 if killed_boss_id_timer_handle then 853 if killed_boss_id_timer_handle then
852 WDP:CancelTimer(killed_boss_id_timer_handle) 854 killed_boss_id_timer_handle:Cancel()
853 killed_boss_id_timer_handle = nil 855 killed_boss_id_timer_handle = nil
854 end 856 end
855 857
856 table.wipe(boss_loot_toasting) 858 table.wipe(boss_loot_toasting)
857 private.raid_boss_id = nil 859 private.raid_boss_id = nil
858 end 860 end
859 861
860 862
861 local function ClearLootToastContainerID() 863 local function ClearLootToastContainerID()
862 if loot_toast_container_timer_handle then 864 if loot_toast_container_timer_handle then
863 WDP:CancelTimer(loot_toast_container_timer_handle) 865 loot_toast_container_timer_handle:Cancel()
864 loot_toast_container_timer_handle = nil 866 loot_toast_container_timer_handle = nil
865 end 867 end
866 868
867 private.container_loot_toasting = false 869 private.container_loot_toasting = false
868 private.loot_toast_container_id = nil 870 private.loot_toast_container_id = nil
869 end 871 end
870 872
871 873
872 local function ClearLootToastData() 874 local function ClearLootToastData()
873 -- cancel existing timer if found
874 if loot_toast_data_timer_handle then 875 if loot_toast_data_timer_handle then
875 WDP:CancelTimer(loot_toast_data_timer_handle) 876 loot_toast_data_timer_handle:Cancel()
876 loot_toast_data_timer_handle = nil 877 loot_toast_data_timer_handle = nil
877 end 878 end
878 879
879 if loot_toast_data then 880 if loot_toast_data then
880 table.wipe(loot_toast_data) 881 table.wipe(loot_toast_data)
883 884
884 885
885 local function ClearTimeBasedLootData() 886 local function ClearTimeBasedLootData()
886 Debug("ClearTimeBasedLootData: Ending salvage loot timer.") 887 Debug("ClearTimeBasedLootData: Ending salvage loot timer.")
887 if chat_loot_timer_handle then 888 if chat_loot_timer_handle then
888 WDP:CancelTimer(chat_loot_timer_handle) 889 chat_loot_timer_handle:Cancel()
889 chat_loot_timer_handle = nil 890 chat_loot_timer_handle = nil
890 end 891 end
891 892
892 if current_loot and current_loot.identifier and (current_loot.identifier == BAG_OF_SALVAGE_ITEM_ID or current_loot.identifier == CRATE_OF_SALVAGE_ITEM_ID or current_loot.identifier == BIG_CRATE_OF_SALVAGE_ITEM_ID) then 893 if current_loot and current_loot.identifier and (current_loot.identifier == BAG_OF_SALVAGE_ITEM_ID or current_loot.identifier == CRATE_OF_SALVAGE_ITEM_ID or current_loot.identifier == BIG_CRATE_OF_SALVAGE_ITEM_ID) then
893 GenericLootUpdate("items") 894 GenericLootUpdate("items")
953 end 954 end
954 955
955 for index = 1, _G.GetNumLanguages() do 956 for index = 1, _G.GetNumLanguages() do
956 languages_known[_G.GetLanguageByIndex(index)] = true 957 languages_known[_G.GetLanguageByIndex(index)] = true
957 end 958 end
958 item_process_timer_handle = self:ScheduleRepeatingTimer("ProcessItems", 30) 959
959 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5) 960 -- These two timers loop indefinitely by constantly resetting their remaining iterations to 100k.
961 item_process_timer_handle = C_Timer.NewTicker(30, function()
962 item_process_timer_handle._remainingIterations = 100000
963 WDP:ProcessItems()
964 end, 100000)
965 target_location_timer_handle = C_Timer.NewTicker(0.5, function()
966 target_location_timer_handle._remainingIterations = 100000
967 WDP:UpdateTargetLocation()
968 end, 100000)
960 969
961 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit) 970 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
962 if target_unit then 971 if target_unit then
963 return 972 return
964 end 973 end
1418 local item_id = ItemLinkToID(item_link) 1427 local item_id = ItemLinkToID(item_link)
1419 if item_id then 1428 if item_id then
1420 RecordItemData(item_id, item_link, true) 1429 RecordItemData(item_id, item_link, true)
1421 end 1430 end
1422 1431
1423 loot_toast_data_timer_handle = WDP:ScheduleTimer(ClearLootToastData, 5) 1432 loot_toast_data_timer_handle = C_Timer.NewTimer(5, ClearLootToastData)
1424 end 1433 end
1425 end 1434 end
1426 1435
1427 1436
1428 do 1437 do
1579 return 1588 return
1580 end 1589 end
1581 private.discovered_recipe_name = recipe_name 1590 private.discovered_recipe_name = recipe_name
1582 private.profession_level = prof_level 1591 private.profession_level = prof_level
1583 1592
1584 self:ScheduleTimer(IterativeRecordDiscovery, 0.2) 1593 C_Timer.After(0.2, IterativeRecordDiscovery)
1585 end 1594 end
1586 end 1595 end
1587 1596
1588 if currently_drunk then 1597 if currently_drunk then
1589 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then 1598 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
1662 ClearKilledNPC() 1671 ClearKilledNPC()
1663 else 1672 else
1664 --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4 1673 --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4
1665 end 1674 end
1666 killed_npc_id = unit_idnum 1675 killed_npc_id = unit_idnum
1667 WDP:ScheduleTimer(ClearKilledNPC, 0.1) 1676 C_Timer.After(0.1, ClearKilledNPC)
1668 end, 1677 end,
1669 } 1678 }
1670 1679
1671 1680
1672 local NON_DAMAGE_EVENTS = { 1681 local NON_DAMAGE_EVENTS = {
2682 end 2691 end
2683 end 2692 end
2684 2693
2685 ClearLootToastData() 2694 ClearLootToastData()
2686 2695
2687 killed_boss_id_timer_handle = WDP:ScheduleTimer(ClearKilledBossID, 5) -- we need to assign a handle here to cancel it later 2696 killed_boss_id_timer_handle = C_Timer.NewTimer(5, ClearKilledBossID) -- we need to assign a handle here to cancel it later
2688 end 2697 end
2689 2698
2690 2699
2691 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 2700 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
2692 if unit_id ~= "player" then 2701 if unit_id ~= "player" then
2707 ClearKilledBossID() 2716 ClearKilledBossID()
2708 ClearLootToastContainerID() 2717 ClearLootToastContainerID()
2709 ClearLootToastData() 2718 ClearLootToastData()
2710 2719
2711 private.loot_toast_container_id = private.LOOT_TOAST_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] 2720 private.loot_toast_container_id = private.LOOT_TOAST_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id]
2712 loot_toast_container_timer_handle = WDP:ScheduleTimer(ClearLootToastContainerID, 1) -- we need to assign a handle here to cancel it later 2721 loot_toast_container_timer_handle = C_Timer.NewTimer(1, ClearLootToastContainerID) -- we need to assign a handle here to cancel it later
2713 return 2722 return
2714 end 2723 end
2715 2724
2716 -- For Crates of Salvage (and potentially other items based on spell casts in the future which need manual handling) 2725 -- For Crates of Salvage (and potentially other items based on spell casts in the future which need manual handling)
2717 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then 2726 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then
2718 -- Set up timer 2727 -- Set up timer
2719 Debug("%s: Beginning Salvage loot timer for spellID %d", event_name, spell_id) 2728 Debug("%s: Beginning Salvage loot timer for spellID %d", event_name, spell_id)
2720 chat_loot_timer_handle = WDP:ScheduleTimer(ClearTimeBasedLootData, 1) 2729 chat_loot_timer_handle = C_Timer.NewTimer(1, ClearTimeBasedLootData)
2721 2730
2722 -- Standard item handling setup 2731 -- Standard item handling setup
2723 table.wipe(current_action) 2732 table.wipe(current_action)
2724 current_loot = nil 2733 current_loot = nil
2725 current_action.target_type = AF.ITEM 2734 current_action.target_type = AF.ITEM