-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotation.lua
More file actions
198 lines (157 loc) · 4.65 KB
/
Copy pathRotation.lua
File metadata and controls
198 lines (157 loc) · 4.65 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
--[[
cKick
Copyright(c) 2016, Tobias 'Chimaine' Rummelt, kontakt(at)rummelt-software.de
All rights reserved
]]
local ADDON_NAME, addon = ...
-- ----------------------------------------------------
local ROLE_KICKER_ORDER = {
["TANK"] = 1,
["DAMAGER"] = 2,
["HEALER"] = 3,
["NONE"] = 4,
}
local function ComparePlayers( a, b )
addon:Log( "Comparing %q and %q", ( a and a.Name ) or "nil", ( b and b.Name ) or "nil" )
if ( not a ) then return false
elseif ( not b ) then return true end
local result = ROLE_KICKER_ORDER[a.Role] - ROLE_KICKER_ORDER[b.Role]
addon:Log( " Role: %s vs %s: %s", a.Role, b.Role, result )
if ( result ~= 0 ) then
return ( result < 0 ) end
result = a.PrimaryCooldown - b.PrimaryCooldown
addon:Log( " CD: %s vs %s: %s", a.PrimaryCooldown, b.PrimaryCooldown, result )
if ( result ~= 0 ) then
return ( result < 0 ) end
result = b.PrimarySpell.CounterDuration - a.PrimarySpell.CounterDuration
addon:Log( " Duration: %s vs %s: %s", a.PrimarySpell.CounterDuration, b.PrimarySpell.CounterDuration, result )
return ( result < 0 )
end
function addon:SortPlayers( players )
table.sort( players, ComparePlayers )
end
function addon:CreateRotation( id )
local instance = {}
local _playerGUID = UnitGUID( "player" )
local _gui = addon:CreateGroup( id )
local _target
local _players = {}
local _nextPlayer
-- ----------------------------------------------------
local function GetPlayerByGUID( guid )
if ( not _players ) then
return end
for i, player in ipairs( _players ) do
if ( player.Info.GUID == guid ) then
return player end
end
end
-- ----------------------------------------------------
function instance:GetGUI()
return _gui
end
function instance:GetTarget()
return _target
end
function instance:GetCurrentPlayer()
return _nextPlayer
end
-- Returns the first player that is off cooldown
-- or the player with the smallest remaining cooldown
-- or the first player in the rotation
function instance:GetNextPlayer()
local result, cd = nil, math.huge;
for i, player in next, _players do
if ( player.Info.PrimarySpell ) then
local bar = player.Bar
if ( not bar.IsRunning() ) then
return player
elseif ( bar.Remaining() < cd ) then
result, cd = player, bar.Remaining()
end
else
addon:Log( "%q has no primary spell", player.Info.Name )
end
end
return result or _players[1]
end
function instance:GetPlayerGUIDs()
local result = {}
for _, player in next, _players do
table.insert( result, player.Info.GUID )
end
return result
end
function instance:SetTarget( guid )
_target = guid
_gui:ShowLockoutBar( guid or false )
end
function instance:SetPlayers( players )
_players = {}
_nextPlayer = nil
for i, player in next, players do
local bar = _gui:GetBar( i )
bar:SetLabel( player.Name )
bar:SetMinMaxValues( 0, 1 )
bar:SetValue( 1 )
bar:SetEnabled( true )
--bar:SetColor( .31, .41, .53 )
local color = RAID_CLASS_COLORS[player.Class]
bar:SetColor( color.r, color.g, color.b )
_players[i] = {
["Info"] = player,
["Bar"] = bar,
}
end
instance:AdvanceRotation()
end
function instance:SortPlayers()
local players = {}
for _, entry in next, _players do
table.insert( players, entry.Info )
end
addon:SortPlayers( players )
instance:SetPlayers( players )
end
function instance:StartLockout( duration )
addon:Log( "Starting lockout of " .. duration )
_gui:StartLockout( duration )
end
function instance:StartCooldown( guid, spellInfo )
local player = GetPlayerByGUID( guid )
if ( not player ) then
return end
if ( player.Info.PrimarySpell ) and ( spellInfo ~= player.Info.PrimarySpell ) then
addon:Log( "%q used a secondary spell", player.Info.Name )
return end
addon:Log( "Starting cooldown for %q: %s", player.Info.Name, player.Info.PrimaryCooldown )
player.Bar:Start( spellInfo.DefaultCooldown, true )
instance:AdvanceRotation()
end
function instance:AdvanceRotation()
local lastPlayer = _nextPlayer
--if ( lastPlayer ) then
-- lastPlayer.Bar:HideArrows()
--end
_gui:HideAllArrows()
if ( #_players < 1 ) then
return end
_nextPlayer = instance:GetNextPlayer()
_nextPlayer.Bar:ShowArrows()
addon:Log( "Advancing rotation from %q to %q",
lastPlayer and lastPlayer.Info.Name or "None",
_nextPlayer and _nextPlayer.Info.Name or "None" )
if ( _nextPlayer.Info.GUID == _playerGUID ) and ( InCombatLockdown() ) then
addon:ShowTextAlert( "You are next to interrupt!", 3, 1 )
end
end
function instance:Reset()
_players = nil
_nextPlayer = nil
instance:SetTarget( nil )
_gui:HideAllBars()
_gui:HideAllArrows()
_gui:Hide()
end
return instance
end