comparison Hansgar_And_Franzok_Assist.lua @ 6:3121ac72fcda

- Added auto facing for safe track feature.
author Tercio
date Sat, 07 Mar 2015 18:17:16 -0300
parents 789bf9e40966
children fe47845b3f17
comparison
equal deleted inserted replaced
5:789bf9e40966 6:3121ac72fcda
3 local UnitExists = UnitExists 3 local UnitExists = UnitExists
4 local GetPlayerMapPosition = GetPlayerMapPosition 4 local GetPlayerMapPosition = GetPlayerMapPosition
5 local UnitHealth = UnitHealth 5 local UnitHealth = UnitHealth
6 local GetNumGroupMembers = GetNumGroupMembers 6 local GetNumGroupMembers = GetNumGroupMembers
7 local abs = abs 7 local abs = abs
8 local GetPlayerFacing = GetPlayerFacing
8 9
9 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent) 10 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent)
10 f:SetFrameStrata ("DIALOG") 11 f:SetFrameStrata ("DIALOG")
11 f.version = "v0.6" 12 f.version = "v0.7"
12 13
13 local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent) 14 local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent)
14 15
15 f:SetSize (155, 156) 16 f:SetSize (155, 156)
16 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1}, 17 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
108 AceComm:Embed (f) 109 AceComm:Embed (f)
109 110
110 function f:CommReceived (_, data, _, source) 111 function f:CommReceived (_, data, _, source)
111 if (data == "US") then 112 if (data == "US") then
112 f:SendCommMessage ("HAFR", UnitName ("player") .. " " .. f.version, "RAID") 113 f:SendCommMessage ("HAFR", UnitName ("player") .. " " .. f.version, "RAID")
113 else 114 elseif (f.users) then
114 f.users [data] = true 115 f.users [data] = true
115 end 116 end
116 end 117 end
117 function f:ShowUsers() 118 function f:ShowUsers()
118 f.users_schedule = nil
119 119
120 local users_frame = Hansgar_And_Franzok_Assist_UsersPanel 120 local users_frame = Hansgar_And_Franzok_Assist_UsersPanel
121 if (not users_frame) then 121 if (not users_frame) then
122 users_frame = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_UsersPanel", UIParent) 122 users_frame = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_UsersPanel", UIParent)
123 users_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1}, 123 users_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
153 end 153 end
154 154
155 users_frame.text:SetText (s) 155 users_frame.text:SetText (s)
156 156
157 users_frame:Show() 157 users_frame:Show()
158
159 f.users = nil
160 f.users_schedule = nil
158 161
159 end 162 end
160 f:RegisterComm ("HAFR", "CommReceived") 163 f:RegisterComm ("HAFR", "CommReceived")
161 164
162 local db 165 local db
183 db.SHOW_DANCE = true 186 db.SHOW_DANCE = true
184 end 187 end
185 if (db.FRAME_LOCK == nil) then 188 if (db.FRAME_LOCK == nil) then
186 db.FRAME_LOCK = false 189 db.FRAME_LOCK = false
187 end 190 end
191 if (db.AUTO_FACING == nil) then
192 db.AUTO_FACING = true
193 end
194 if (db.FACING_SIDE == nil) then
195 db.FACING_SIDE = 1
196 end
188 -- 197 --
189 SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok" 198
190 function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox)
191
192 local command, rest = msg:match ("^(%S*)%s*(.-)$")
193
194 if (command == "users") then
195 if (f.users_schedule) then
196 print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
197 elseif (IsInRaid()) then
198 f.users = {}
199 f:SendCommMessage ("HAFR", "US", "RAID")
200 f.users_schedule = f:ScheduleTimer ("ShowUsers", 5)
201 print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
202 else
203 print ("|cFFFFAA00Hansgar and Franzok Assist|r you aren't in a raid group.")
204 end
205
206 elseif (command == "delay") then
207 local t = tonumber (rest)
208 if (t) then
209 db.STAMPERS_DELAY = t
210 print ("|cFFFFAA00Hansgar and Franzok Assist|r delay set to: ", t)
211 else
212 print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t)
213 end
214
215 elseif (command == "test" or command == "show") then
216 if (f.StampersPhase) then
217 f:EndTrackPlayerPosition()
218 return f:StopTracking()
219 end
220
221 f:StartTracking()
222 f:StartTrackPlayerPosition()
223
224 elseif (command == "hide") then
225 if (f.StampersPhase) then
226 return f:StopTracking()
227 end
228 f:EndTrackPlayerPosition()
229
230 elseif (command == "lock") then
231 f:SetLockState()
232
233 if (db.FRAME_LOCK) then
234 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame locked.")
235 else
236 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame unlocked.")
237 end
238
239 elseif (command == "dance") then
240 db.SHOW_DANCE = not db.SHOW_DANCE
241 if (db.SHOW_DANCE) then
242 if (f.on_encounter) then
243 f:StartTrackPlayerPosition()
244 end
245 print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars enabled.")
246 else
247 f:EndTrackPlayerPosition()
248 print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars disabled.")
249 end
250
251 elseif (command == "cooldown") then
252 db.CD_NUMBER = not db.CD_NUMBER
253 f:RefreshCooldownSettings()
254
255 else
256 print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00" .. f.version .. "|r Commands:")
257 print ("|cFFFFFF00/hansgar lock|r: toggle lock and unlock on the frame.")
258 print ("|cFFFFFF00/hansgar test show hide|r: active the addon on test mode or hide it.")
259 print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.")
260 print ("|cFFFFFF00/hansgar dance|r: toggle dance bar (used to dodge regular stampers and searing plates).")
261 print ("|cFFFFFF00/hansgar users|r: show who is using the addon in the raid.")
262 print ("|cFFFFFF00/hansgar cooldown|r: show the countdown text for each stamper go back up to the ceiling.")
263 end
264 end
265
266 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then 199 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then
267 200
268 local encounterID, encounterName, difficultyID, raidSize = select (1, ...) 201 local encounterID, encounterName, difficultyID, raidSize = select (1, ...)
269 202
270 if (encounterID == 1693) then 203 if (encounterID == 1693) then
307 end 240 end
308 end 241 end
309 242
310 end) 243 end)
311 244
245 SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok"
246 function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox)
247
248 local command, rest = msg:match ("^(%S*)%s*(.-)$")
249
250 if (command == "users") then
251 if (f.users_schedule) then
252 print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
253 elseif (IsInRaid()) then
254 f.users = {}
255 f:SendCommMessage ("HAFR", "US", "RAID")
256 f.users_schedule = f:ScheduleTimer ("ShowUsers", 5)
257 print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
258 else
259 print ("|cFFFFAA00Hansgar and Franzok Assist|r you aren't in a raid group.")
260 end
261
262 elseif (command == "delay") then
263 local t = tonumber (rest)
264 if (t) then
265 db.STAMPERS_DELAY = t
266 print ("|cFFFFAA00Hansgar and Franzok Assist|r delay set to: ", t)
267 else
268 print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t)
269 end
270
271 elseif (command == "test" or command == "show") then
272 if (f.StampersPhase) then
273 f:EndTrackPlayerPosition()
274 return f:StopTracking()
275 end
276
277 f:StartTracking()
278 f:StartTrackPlayerPosition()
279
280 elseif (command == "hide") then
281 if (f.StampersPhase) then
282 return f:StopTracking()
283 end
284 f:EndTrackPlayerPosition()
285
286 elseif (command == "lock") then
287 f:SetLockState()
288
289 if (db.FRAME_LOCK) then
290 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame locked.")
291 else
292 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame unlocked.")
293 end
294
295 elseif (command == "facing") then
296 if (rest == "1") then
297 db.FACING_SIDE = 1
298 tframe.facing = true
299 print ("|cFFFFAA00Hansgar and Franzok Assist|r facing set to south.")
300
301 elseif (rest == "2") then
302 db.FACING_SIDE = 2
303 tframe.facing = false
304 print ("|cFFFFAA00Hansgar and Franzok Assist|r facing set to north.")
305
306 elseif (rest == "auto") then
307 db.AUTO_FACING = true
308 print ("|cFFFFAA00Hansgar and Franzok Assist|r auto facing enabled.")
309
310 else
311 print ("|cFFFFFF00/hansgar facing|r: |cFF00FF001|r = south |cFF00FF002|r = north, use to set the dance bar when auto facing is disabled.")
312 end
313
314 elseif (command == "autofacing") then
315 db.AUTO_FACING = not db.AUTO_FACING
316 if (db.AUTO_FACING) then
317 print ("|cFFFFAA00Hansgar and Franzok Assist|r auto facing enabled.")
318 else
319 print ("|cFFFFAA00Hansgar and Franzok Assist|r auto facing disabled.")
320 tframe.facing = db.FACING_SIDE == 1
321 end
322
323 elseif (command == "dance") then
324 db.SHOW_DANCE = not db.SHOW_DANCE
325 if (db.SHOW_DANCE) then
326 if (f.on_encounter) then
327 f:StartTrackPlayerPosition()
328 end
329 print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars enabled.")
330 else
331 f:EndTrackPlayerPosition()
332 print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars disabled.")
333 end
334
335 elseif (command == "cooldown") then
336 db.CD_NUMBER = not db.CD_NUMBER
337 f:RefreshCooldownSettings()
338
339 else
340 print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00" .. f.version .. "|r Commands:")
341 print ("|cFFFFFF00/hansgar lock|r: toggle lock and unlock on the frame.")
342 print ("|cFFFFFF00/hansgar test show hide|r: active the addon on test mode or hide it.")
343 print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.")
344 print ("|cFFFFFF00/hansgar dance|r: toggle dance bar (used to dodge regular stampers and searing plates).")
345 print ("|cFFFFFF00/hansgar autofacing|r: toggle if the dance bar auto switch left and right when looking to north or south.")
346 print ("|cFFFFFF00/hansgar facing|r: |cFF00FF001|r = south |cFF00FF002|r = north, use to set the dance bar when auto facing is disabled.")
347 print ("|cFFFFFF00/hansgar users|r: show who is using the addon in the raid.")
348 print ("|cFFFFFF00/hansgar cooldown|r: show the countdown text for each stamper go back up to the ceiling.")
349 end
350 end
351
312 -- 352 --
313 --f:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") 353 --f:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
314 354
315 f:SetScript ("OnEvent", function (self, event, time, token, _, who_serial, who_name, who_flags, _, target_serial, target_name, target_flags, _, spellid, spellname, spellschool, buff_type, ...) 355 f:SetScript ("OnEvent", function (self, event, time, token, _, who_serial, who_name, who_flags, _, target_serial, target_name, target_flags, _, spellid, spellname, spellschool, buff_type, ...)
316 356
346 end 386 end
347 end 387 end
348 388
349 local px, py = GetPlayerMapPosition ("player") 389 local px, py = GetPlayerMapPosition ("player")
350 local player_block = f:WhichBlock (px, py) 390 local player_block = f:WhichBlock (px, py)
351 if (player_block and raid_size > 0) then 391 if (player_block and f.block_tracker [player_block] and raid_size > 0) then
352 392
353 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY 393 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY
354 local time_now = GetTime() 394 local time_now = GetTime()
355 395
356 f.player_bar:SetValue ((time_limit_at - time_now) / db.STAMPERS_DELAY * 100) 396 f.player_bar:SetValue ((time_limit_at - time_now) / db.STAMPERS_DELAY * 100)
606 local red_alpha_enabled = 0.5 646 local red_alpha_enabled = 0.5
607 647
608 local green_alpha_disabled = 0.05 648 local green_alpha_disabled = 0.05
609 local green_alpha_enabled = 0.9 649 local green_alpha_enabled = 0.9
610 650
651 -- true north -> south
652 -- false south -> north
653 function f:ChangePlayerTrackerFace()
654
655 end
656
611 local track_function = function (self, elapsed) 657 local track_function = function (self, elapsed)
612 658
613 local x, _ = GetPlayerMapPosition ("player") 659 local x, _ = GetPlayerMapPosition ("player")
614 local block 660 local block
615 661
616 for i = 1, #safe_track do 662 if (db.AUTO_FACING and x) then
617 local loc = safe_track [i] 663 local facing = GetPlayerFacing()
618 if (x >= loc.block.x2 and x <= loc.block.x1) then 664
619 block = i 665 if (self.facing and (facing > 5.3 or facing < 1.053)) then --north -> south -- ~30º tolerance
620 break 666 self.facing = false
621 end 667 --print ("changing face to south")
622 end 668 elseif (not self.facing and (facing > 2.3 and facing < 4.3)) then --south -> north -- ~30º tolerance
623 669 self.facing = true
624 if (block) then 670 --print ("changing face to north")
671 end
672 end
673
674 if (x) then
675 for i = 1, #safe_track do
676 local loc = safe_track [i]
677 if (x >= loc.block.x2 and x <= loc.block.x1) then
678 block = i
679 break
680 end
681 end
682 end
683
684 if (block and safe_track [block]) then
625 685
626 player_pos_frame:Show() 686 player_pos_frame:Show()
627 block = safe_track [block] 687 block = safe_track [block]
628 688
629 if (x >= block.left.x2 and x <= block.left.x1) then 689 if (x >= block.left.x2 and x <= block.left.x1) then
630 t2:SetTexture (0.1, 1, 0.1, green_alpha_enabled) 690 if (self.facing) then
631 t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled) 691 t2:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
692 t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
693 else
694 t3:SetTexture (0.2, 232/255, 1, green_alpha_enabled)
695 t2:SetTexture (0.2, 232/255, 1, green_alpha_disabled)
696 end
632 697
633 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 698 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
634 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 699 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
635 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 700 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
636 701
637 elseif (x <= block.right.x2 and x >= block.right.x1) then 702 elseif (x <= block.right.x2 and x >= block.right.x1) then
638 t3:SetTexture (0.1, 1, 0.1, green_alpha_enabled) 703 if (self.facing) then
639 t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled) 704 t3:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
705 t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
706 else
707 t2:SetTexture (0.2, 232/255, 1, green_alpha_enabled)
708 t3:SetTexture (0.2, 232/255, 1, green_alpha_disabled)
709 end
640 710
641 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 711 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
642 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 712 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
643 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 713 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
644 714
660 player_pos_frame:Hide() 730 player_pos_frame:Hide()
661 end 731 end
662 end 732 end
663 733
664 function f:StartTrackPlayerPosition() 734 function f:StartTrackPlayerPosition()
665
666 --> under development
667 --if (true) then
668 -- return
669 --end
670
671 player_pos_frame:Show() 735 player_pos_frame:Show()
672 tframe.width = player_pos_frame:GetWidth() 736 tframe.width = player_pos_frame:GetWidth()
673 tframe.width_pixel = tframe.width / 100 737 tframe.width_pixel = tframe.width / 100
738 tframe.facing = db.FACING_SIDE == 1
674 tframe:SetScript ("OnUpdate", track_function) 739 tframe:SetScript ("OnUpdate", track_function)
675 end 740 end
676 function f:EndTrackPlayerPosition() 741 function f:EndTrackPlayerPosition()
677 player_pos_frame:Hide() 742 player_pos_frame:Hide()
678 tframe:SetScript ("OnUpdate", nil) 743 tframe:SetScript ("OnUpdate", nil)