-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.lua
124 lines (117 loc) · 4.96 KB
/
Main.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
local addonName, addon = ...
local eventHandler = CreateFrame("Frame")
addon.CreateNewMap = function(mapID, mapName)
ExpBuddyDataDB[mapID] = {}
ExpBuddyDataDB[mapID].mapName = mapName
ExpBuddyDataDB[mapID].entryLevel = addon.playerLevel
ExpBuddyDataDB[mapID].exitLevel = 0
ExpBuddyDataDB[mapID].Exploration = 0
ExpBuddyDataDB[mapID].Monsters = 0
ExpBuddyDataDB[mapID].Nodes = 0
ExpBuddyDataDB[mapID].Rested = 0
ExpBuddyDataDB[mapID].Quests = 0
end
eventHandler:RegisterEvent("ADDON_LOADED")
eventHandler:RegisterEvent("PLAYER_LEVEL_CHANGED")
eventHandler:RegisterEvent("PLAYER_LOGIN")
eventHandler:RegisterEvent("QUEST_ACCEPTED")
eventHandler:RegisterEvent("ZONE_CHANGED")
eventHandler:RegisterEvent("ZONE_CHANGED_NEW_AREA")
eventHandler:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" then
local addonLoaded = ...
if addonLoaded == addonName then
-- Make a table for the entire addon to use, namely for functions
-- but other stuff can be put in here too.
ExpBuddy = {}
-- Initialize the addon's saved variables.
if ExpBuddyQuestDB == nil then
ExpBuddyQuestDB = {}
end
if ExpBuddyPositionDB == nil then
ExpBuddyPositionDB = {}
end
if ExpBuddyDataDB == nil then
ExpBuddyDataDB = {}
end
-- Unregister the event for performance.
eventHandler:UnregisterEvent("ADDON_LOADED")
end
end
if event == "PLAYER_LEVEL_CHANGED" then
local _, newLevel = ...
if newLevel then
addon.playerLevel = newLevel
end
if newLevel == GetMaxLevelForPlayerExpansion() then
-- The player is max level, so unregister the event.
eventHandler:UnregisterEvent("PLAYER_LEVEL_CHANGED")
end
end
if event == "PLAYER_LOGIN" then
C_Timer.After(0.5, function()
local mapID = C_Map.GetBestMapForUnit("player")
-- If the mapID is valid, then set addon.mapID and
-- create the map table if it doesn't exist.
if mapID then
local mapInfo = C_Map.GetMapInfo(mapID)
if mapInfo.mapType == 3 then -- It's a zone!
addon.mapID = mapID
if not ExpBuddyDataDB[addon.mapID] then
addon.CreateNewMap(addon.mapID, mapInfo.name)
end
addon.RefreshFrame(addon.mapID)
elseif mapInfo.mapType == 5 or mapInfo.mapType == 6 then
addon.mapID = mapInfo.parentMapID
local name = C_Map.GetMapInfo(addon.mapID).name
if not ExpBuddyDataDB[addon.mapID] then
addon.CreateNewMap(addon.mapID, name)
end
addon.RefreshFrame(addon.mapID)
end
else
ExpBuddy.Print("The current map could not be added. Please leave the zone and return or try a reload.")
end
-- Get some information about the current character.
addon.playerLevel = UnitLevel("player")
-- Unregister the event for performance.
eventHandler:UnregisterEvent("PLAYER_LOGIN")
if addon.playerLevel == GetMaxLevelForPlayerExpansion() then
-- The player is max level, so unregister the event.
eventHandler:UnregisterEvent("PLAYER_LEVEL_CHANGED")
end
end)
end
if event == "QUEST_ACCEPTED" then
local questID = ...
if not ExpBuddyQuestDB[questID] then
ExpBuddyQuestDB[questID] = addon.mapID
end
end
if event == "ZONE_CHANGED" or event == "ZONE_CHANGED_NEW_AREA" then
C_Timer.After(0.5, function()
local mapID = C_Map.GetBestMapForUnit("player")
-- If the mapID is valid, then set addon.mapID and
-- create the map table if it doesn't exist.
if mapID then
local mapInfo = C_Map.GetMapInfo(mapID)
if mapInfo.mapType == 3 then -- It's a zone!
addon.mapID = mapID
if not ExpBuddyDataDB[addon.mapID] then
addon.CreateNewMap(addon.mapID, mapInfo.name)
end
addon.RefreshFrame(addon.mapID)
elseif mapInfo.mapType == 5 or mapInfo.mapType == 6 then
addon.mapID = mapInfo.parentMapID
local name = C_Map.GetMapInfo(addon.mapID).name
if not ExpBuddyDataDB[addon.mapID] then
addon.CreateNewMap(addon.mapID, name)
end
addon.RefreshFrame(addon.mapID)
end
else
ExpBuddy.Print("The current map could not be added. Please leave the zone and return or try a reload.")
end
end)
end
end)