Repository navigation
Expand file tree
/
Copy pathscreenshots.lua
More file actions
211 lines (182 loc) · 8 KB
/
Copy pathscreenshots.lua
File metadata and controls
211 lines (182 loc) · 8 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
local _, ns = ...
local ScreenShots = ns.ScreenShots
-- Blizzard
local Screenshot = _G.Screenshot
local IsInInstance = _G.IsInInstance
local GetAchievementInfo = _G.GetAchievementInfo
local GetDifficultyInfo = _G.GetDifficultyInfo
-- Mine
local EncounterDifficulty = {
[1] = false, -- Dungeon Normal
[2] = false, -- Dungeon Heroic
[3] = false, -- Raid Normal 10-man
[4] = false, -- Raid Normal 25-man
[5] = true, -- Raid Heroic 10-man
[6] = true, -- Raid Heroic 25-man
[7] = false, -- Looking For Raid
[8] = true, -- Mythic Keystone
[9] = true, -- Raid 40-man
[14] = true, -- Raid Normal
[15] = true, -- Raid Heroic
[16] = true, -- Raid Mythic
[17] = false, -- Looking For Raid
[23] = true, -- Dungeon Mythic
[33] = true, -- Timewalking Raid
[172] = true, -- World Boss
}
local ZoneTypes = {
["none"] = false, -- when outside an instance
["pvp"] = false, -- when in a battleground
["arena"] = false, -- when in an arena
["party"]= true, -- when in a 5-man instance
["raid"] = true, -- when in a raid instance
["scenario"] = false, -- when in a scenario
}
local function TakeScreenshot(delay)
if type(delay) == "number" and delay > 0 then
C_Timer.After(delay, function() Screenshot() end)
else
Screenshot()
end
end
local function ChatMessage(message)
if not message then return end
DEFAULT_CHAT_FRAME:AddMessage(message, 1.0, 1.0, 0.0)
end
----------------------------------------------------------------
-- Screen Shots
----------------------------------------------------------------
local events = {
["BOSS_KILL"] = true, -- added in patch 6.1.0 (Fired when an instance or open-world boss is killed)
["ENCOUNTER_START"] = true, -- added in patch 5.4.7
["ENCOUNTER_END"] = true, -- added in patch 5.4.7
["ACHIEVEMENT_EARNED"] = (LE_EXPANSION_LEVEL_CURRENT >= LE_EXPANSION_WRATH_OF_THE_LICH_KING), -- added in patch 3.0.2 (WoLK)
["CHALLENGE_MODE_COMPLETED"] = (LE_EXPANSION_LEVEL_CURRENT >= LE_EXPANSION_MISTS_OF_PANDARIA), -- added in patch 5.0.4 (MoP)
["CHALLENGE_MODE_COMPLETED_REWARDS"] = false, -- added in patch 11.2.0
["PLAYER_LEVEL_UP"] = true,
["PLAYER_DEAD"] = true,
["SCREENSHOT_FAILED"] = true,
["SCREENSHOT_SUCCEEDED"] = true
}
local delays = {
LEVEL_UP = 2.7,
DEAD = 0.25,
DEFAULT = 1
}
local element_proto = {}
function element_proto:SendMessage(message)
if ScreenShots.messages and type(message) == "string" then
ChatMessage(message)
end
end
function element_proto:TakeScreenshot(delay, message)
self:SendMessage(message)
TakeScreenshot(delay)
end
function element_proto:HookEvent(event, callback, enable)
if events[event] and enable then
self[event] = callback
self:RegisterEvent(event)
end
end
function element_proto:OnEnteringWorld()
local inInstance, instanceType = IsInInstance()
local isRegistered = self:IsEventRegistered("BOSS_KILL")
if (inInstance and ZoneTypes[instanceType]) then
if (isRegistered) then
self:UnregisterEvent("BOSS_KILL")
end
self:HookEvent("ENCOUNTER_START", self.OnEncounterStart, ScreenShots.boss_kills)
self:HookEvent("ENCOUNTER_END", self.OnEncounterEnd, ScreenShots.boss_kills)
else
self:HookEvent("BOSS_KILL", self.OnBossKill, ScreenShots.boss_kills)
self:UnregisterEvent("ENCOUNTER_START")
self:UnregisterEvent("ENCOUNTER_END")
end
end
function element_proto:OnAchievementEarned(achievementID, alreadyEarned)
local _, name, points, _, _, _, _, _, _, _, _, isGuild = GetAchievementInfo(achievementID)
if not isGuild and not alreadyEarned then
self:TakeScreenshot(delays.DEFAULT, "Achievement [" .. name .. "] earned (" .. points .. " points)")
end
end
function element_proto:OnChallengeMode()
self:TakeScreenshot(delays.DEFAULT, "Challenge completed")
end
function element_proto:OnBossKill(encounterID, encounterName)
local message = encounterName and ("Boss killed: " .. encounterName) or nil
self:TakeScreenshot(delays.DEFAULT, message)
end
function element_proto:OnEncounterStart(encounterID, encounterName, difficultyID, groupSize)
-- record encounter start time
self.encounter = table.wipe(self.encounter or {})
self.encounter.id = encounterID
self.encounter.name = encounterName
self.encounter.difficultyId = difficultyID
self.encounter.start = time()
end
function element_proto:OnEncounterEnd(encounterID, encounterName, difficultyID, groupSize, success)
-- calculate total time until encounter wipe/success; unknown when ENCOUNTER_START was missed (/reload mid-fight)
local encounter = self.encounter
local elapsed = (encounter and encounter.id == encounterID) and (time() - encounter.start) or nil
local encounterTime = self:GetEncounterTime(elapsed)
-- check if encounter was a wipe
local isWipe = (success == 0)
if isWipe then
local message = "Encounter " .. encounterName .. " wiped"
if (encounterTime) then
message = message .. " in " .. encounterTime
end
self:TakeScreenshot(delays.DEFAULT, message)
elseif EncounterDifficulty[difficultyID] then
-- display encounter info
local difficulty = GetDifficultyInfo(difficultyID)
self:SendMessage("Encounter defeated " .. encounterName .. " on " .. difficulty .. " (" .. groupSize .. "-man)")
self:SendMessage("Date: " .. date("%m/%d/%y %H:%M:%S"))
if (encounterTime) then
self:SendMessage("Time: " .. encounterTime)
end
self:TakeScreenshot(delays.DEFAULT, "Encounter " .. encounterName .. " ended")
end
end
function element_proto:OnPlayerLevelUp(level, healthDelta, powerDelta, numNewTalents, numNewPvpTalentSlots, strengthDelta, agilityDelta, staminaDelta, intellectDelta)
-- delay enough for the golden glow ends.
self:TakeScreenshot(delays.LEVEL_UP, "Player level up to " .. level)
end
function element_proto:OnPlayerDead()
self:TakeScreenshot(delays.DEAD, "Player died")
end
function element_proto:OnScreenshotFailed(...)
self:SendMessage("Screenshot Failed")
end
function element_proto:OnScreenshotSucceeded(...)
self:SendMessage("Screenshot Taken")
end
function element_proto:OnEvent(event, ...)
if type(self[event]) == "function" then
self[event](self, ...)
end
end
-- options are read once, after every addon (and its host) has loaded
function element_proto:PLAYER_LOGIN()
self:UnregisterEvent("PLAYER_LOGIN")
self:HookEvent("PLAYER_ENTERING_WORLD", self.OnEnteringWorld, true)
self:HookEvent("ACHIEVEMENT_EARNED", self.OnAchievementEarned, ScreenShots.achievements)
self:HookEvent("CHALLENGE_MODE_COMPLETED", self.OnChallengeMode, ScreenShots.challenge_mode)
self:HookEvent("CHALLENGE_MODE_COMPLETED_REWARDS", self.OnChallengeMode, ScreenShots.challenge_mode)
self:HookEvent("PLAYER_LEVEL_UP", self.OnPlayerLevelUp, ScreenShots.levelup)
self:HookEvent("PLAYER_DEAD", self.OnPlayerDead, ScreenShots.dead)
self:HookEvent("SCREENSHOT_FAILED", self.OnScreenshotFailed, ScreenShots.tracer)
self:HookEvent("SCREENSHOT_SUCCEEDED", self.OnScreenshotSucceeded, ScreenShots.tracer)
end
function element_proto:GetEncounterTime(elapsed)
if type(elapsed) ~= "number" then
return nil
end
local minutes = math.floor(elapsed / 60)
local seconds = math.floor(elapsed % 60)
return string.format("%d minutes %d seconds", minutes, seconds)
end
local frame = Mixin(CreateFrame("Frame"), element_proto)
frame:RegisterEvent("PLAYER_LOGIN")
frame:SetScript("OnEvent", frame.OnEvent)