-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchTimer.lua
72 lines (56 loc) · 1.67 KB
/
SwitchTimer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local _, addon = ...
local module = addon:NewModule("SwitchTimer", "AceEvent-3.0", "AceTimer-3.0")
addon.SwitchTimer = module
local GetZoneText, IsResting = GetZoneText, IsResting
--
--
--
function module:OnInitialize()
self.db = addon.db
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
end
function module:Start(no_restart)
if self.switch_timer then
if no_restart then return end
self:CancelTimer(self.switch_timer)
self.switch_timer = nil
end
local enabled = self.db.profile.autoSwitch.timer
local value = self.db.profile.autoSwitch.timerValue
if enabled then
self.switch_timer = self:ScheduleTimer("AutoSwitchTimer", value)
end
end
function module:Stop()
if self.switch_timer then
self:CancelTimer(self.switch_timer)
self.switch_timer = nil
end
end
function module:AutoSwitchTimer()
self.switch_timer = nil
if self.db.profile.autoSwitch.citiesOnly and not IsResting() then
return self:Start()
end
addon:ResummonPet()
end
function module:PLAYER_ENTERING_WORLD()
if addon:CurrentPet() then
self:Start()
end
end
function module:ZONE_CHANGED_NEW_AREA()
if addon.db.profile.autoSwitch.onZone then
-- check to make sure we really changed areas
-- unfortunately the event fires before the area changes
self:ScheduleTimer("CheckAutoSwitchZone", 1.0)
end
end
function module:CheckAutoSwitchZone()
local currentZone = GetZoneText()
if currentZone ~= self.autoSwitchLastZone then
addon.Ready:QueueResummon()
self.autoSwitchLastZone = currentZone
end
end