forked from astralguild/AstralKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AstralKeys.lua
166 lines (142 loc) · 5.25 KB
/
AstralKeys.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
local _, addon = ...
addon.Week = 0
addon.EXPANSION_LEVEL = 60
if not AstralKeys then AstralKeys = {} end
if not AstralCharacters then AstralCharacters = {} end
local initializeTime = {}
initializeTime[1] = 1500390000 -- US Tuesday at reset
initializeTime[2] = 1500447600 -- EU Wednesday at reset
initializeTime[3] = 1500505200 -- CN Thursday at reset
initializeTime[4] = 0
function addon.WeekTime()
local region = GetCurrentRegion()
if region ~= 3 then
return GetServerTime() - initializeTime[1] - 604800 * addon.Week
else
return GetServerTime() - initializeTime[2] - 604800 * addon.Week
end
end
AstralEvents:Register('PLAYER_LOGIN', function()
local major, minor = string.match(GetAddOnMetadata('AstralKeys', 'version'), '(%d+).(%d+)')
if tonumber(major) == 3 and tonumber(minor) > 25 and not AstralKeysSettings.wipedOldTables then -- Changed to single table in 3.26
wipe(AstralKeys)
AstralFriends = nil
AstralKeysSettings.wipedOldTables = true
end
if IsInGuild() then
C_GuildInfo.GuildRoster()
end
if UnitFactionGroup('player') == 'Alliance' then
addon.FACTION = 0
else
addon.FACTION = 1
end
local region = GetCurrentRegion()
local currentTime = GetServerTime()
local d = date('*t', currentTime)
local hourOffset = math.modf(difftime(currentTime, time(date('!*t', currentTime))))/3600
if region ~= 3 then -- Non EU
addon.Week = math.floor((GetServerTime() - initializeTime[1]) / 604800)
else
addon.Week = math.floor((GetServerTime() - initializeTime[2]) / 604800)
end
addon.SetPlayerNameRealm()
addon.SetPlayerClass()
if currentTime > AstralKeysSettings.general.init_time then
wipe(AstralCharacters)
wipe(AstralKeys)
AstralKeysSettings.general.init_time = addon.DataResetTime()
end
if d.wday == 3 and d.hour < (16 + hourOffset + (d.isdst and 1 or 0)) and region ~= 3 then
local frame = CreateFrame('FRAME')
frame.elapsed = 0
frame.first = true
frame.interval = 60 - d.sec
frame:SetScript('OnUpdate', function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed > self.interval then
if self.first then
self.interval = 60
self.first = false
end
if time(date('*t', GetServerTime())) > AstralKeysSettings.general.init_time then
addon.WipeCharacterList()
addon.WipeUnitList()
addon.WipeFriendList()
C_MythicPlus.RequestRewards()
AstralCharacters = {}
AstralKeys = {}
AstralKeysSettings.general.init_time = addon.DataResetTime()
addon.Week = math.floor((GetServerTime() - initializeTime[1]) / 604800)
addon.FindKeyStone(true, false)
addon.UpdateAffixes()
self:SetScript('OnUpdate', nil)
self = nil
return nil
end
self.elapsed = 0
end
end)
elseif d.wday == 4 and d.hour < (7 + hourOffset + (d.isdst and 1 or 0)) and region == 3 then
local frame = CreateFrame('FRAME')
frame.elapsed = 0
frame.first = true
frame.interval = 60 - d.sec
frame:SetScript('OnUpdate', function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed > self.interval then
if self.first then
self.interval = 60
self.first = false
end
if time(date('*t', GetServerTime())) > AstralKeysSettings.general.init_time then
addon.WipeCharacterList()
addon.WipeUnitList()
addon.WipeFriendList()
C_MythicPlus.RequestRewards()
AstralCharacters = {}
AstralKeys = {}
AstralKeysSettings.general.init_time = addon.DataResetTime()
addon.FindKeyStone(true, false)
addon.Week = math.floor((GetServerTime() - initializeTime[2]) / 604800)
addon.UpdateAffixes()
self:SetScript('OnUpdate', nil)
self = nil
return nil
end
self.elapsed = 0
end
end)
end
-- Check over saved variables, remove any entries that are incorrect
-- if any of these fields, remove it
-- unit, class, dungeon_id, key_level, faction
for i = #AstralKeys, 1, -1 do
if not (AstralKeys[i].unit and AstralKeys[i].class and AstralKeys[i].dungeon_id and AstralKeys[i].key_level) then -- Missing information from an entry, remove the entry
table.remove(AstralKeys, i)
end
end
-- Clean up any bad information for personal characters
for i = #AstralCharacters, 1, -1 do
if not (AstralCharacters[i].unit) then
table.remove(AstralCharacters, i)
end
end
for i = 1, #AstralKeys do -- index guild units
if AstralKeys[i] and AstralKeys[i].unit then
addon.SetUnitID(AstralKeys[i].unit, i)
addon.AddUnitToSortTable(AstralKeys[i].unit, AstralKeys[i].btag, AstralKeys[i].class, AstralKeys[i].faction, AstralKeys[i].dungeon_id, AstralKeys[i].key_level, AstralKeys[i].weekly_best)
--e.AddUnitToTable(AstralKeys[i].unit, AstralKeys[i].class, AstralKeys[i].faction, 'GUILD', AstralKeys[i].dungeon_id, AstralKeys[i].key_level, AstralKeys[i].weekly_best)
end
end
for i = 1, #AstralCharacters do -- index player's characters
if AstralCharacters[i] and AstralCharacters[i].unit then
addon.SetCharacterID(AstralCharacters[i].unit, i)
end
end
if AstralAffixes.season_start_week == 0 then -- Addon has just initialized for the fisrt time or saved variables have been lost.
AstralAffixes.season_start_week = addon.Week
end
C_MythicPlus.RequestMapInfo() -- Gets info on affixes and current season...
C_MythicPlus.RequestCurrentAffixes() -- Who knows what this actually does...
end, 'login')