-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.lua
111 lines (93 loc) · 3.47 KB
/
Core.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
local AddonName, AddonTable = ...
ArenaLog = LibStub("AceAddon-3.0"):NewAddon(AddonTable, AddonName, "AceConsole-3.0", "AceEvent-3.0")
local UI = ArenaLog.UI
local Game = ArenaLog.Game
local LGIST = LibStub:GetLibrary("LibGroupInSpecT-1.1")
local AceDB = LibStub("AceDB-3.0")
local Logger = ArenaLog.Logger
local Player = ArenaLog.Player
function ArenaLog:HandleSlashCommands(input)
UI:InitiateMainFrame()
end
function ArenaLog:SetUpDb()
if not self.db.char.gameHistory then
self.db.char.gameHistory = {}
end
self.db.char.loggerModes = self.db.char.loggerModes or { error = true, warning = true, info = true, debug = false }
self.db.char.currentMatch = nil
end
function ArenaLog:OnInitialize()
self.db = AceDB:New("ArenaLogDB")
ArenaLog:SetUpDb()
self.db.char.loggerModes.debug = false
end
function ArenaLog:OnEnable()
ArenaLog:RegisterChatCommand("arenalog", "HandleSlashCommands")
ArenaLog:RegisterChatCommand("al", "HandleSlashCommands")
ArenaLog.isInMatch = false
ArenaLog:RegisterEvent("PVP_MATCH_COMPLETE")
ArenaLog:RegisterEvent("PLAYER_ENTERING_WORLD")
ArenaLog:RegisterEvent("PLAYER_JOINED_PVP_MATCH")
ArenaLog:RegisterEvent("ARENA_OPPONENT_UPDATE")
LGIST.RegisterCallback(ArenaLog, "GroupInSpecT_Update", "ARENA_ALLY_UPDATE")
end
-- Events handlers
function ArenaLog:PLAYER_JOINED_PVP_MATCH(event)
Logger:Debug("PLAYER_JOINED_PVP_MATCH")
if ArenaLog.isInMatch then
ArenaLog.isInMatch = false
return
end
ArenaLog:OnArenaStart()
end
function ArenaLog:PLAYER_ENTERING_WORLD(event, _, _)
Logger:Debug("PLAYER_ENTERING_WORLD")
ArenaLog:OnArenaStart()
end
function ArenaLog:PVP_MATCH_COMPLETE(event, winner, duration)
Logger:Debug("PVP_MATCH_COMPLETE")
ArenaLog:OnArenaEnd(winner, duration)
end
function ArenaLog:ARENA_ALLY_UPDATE(event, guid, id, info)
if C_PvP.IsRatedArena() and self.db.char.currentMatch ~= nil then
Logger:Debug("ARENA_ALLY_UPDATE")
if not self.db.char.currentMatch.alliedTeam.players[id] then
self.db.char.currentMatch.alliedTeam.players[id] = Player.New(id)
end
self.db.char.currentMatch.alliedTeam.players[id]:UpdateAllyPlayerInfo(guid, id, info)
end
end
function ArenaLog:ARENA_OPPONENT_UPDATE(event, id, reason)
if C_PvP.IsRatedArena() and reason == "seen" and self.db.char.currentMatch ~= nil then
Logger:Debug("ARENA_OPPONENT_UPDATE")
local isArenaPlayer = false
for i = 1, 3 do
local checkId = "arena" .. i
if id == checkId then
isArenaPlayer = true
end
end
if not isArenaPlayer then
return
end
if not self.db.char.currentMatch.enemyTeam.players[id] then
self.db.char.currentMatch.enemyTeam.players[id] = Player.New(id)
end
self.db.char.currentMatch.enemyTeam.players[id]:UpdateEnemyPlayerInfo()
end
end
function ArenaLog:OnArenaStart()
if self.db.char.currentMatch == nil and C_PvP.IsRatedArena() then
Logger:Info("Arena Started")
self.db.char.currentMatch = Game.New()
end
end
function ArenaLog:OnArenaEnd(winner, duration)
if self.db.char.currentMatch ~= nil then
ArenaLog.isInMatch = true
self.db.char.currentMatch:Finish(winner, duration)
self.db.char.gameHistory[#self.db.char.gameHistory + 1] = self.db.char.currentMatch
self.db.char.currentMatch = nil
Logger:Info("Arena recorded")
end
end