comparison Hansgar_And_Franzok_Assist.lua @ 4:1c3534391efb

- Added timeout for stampers.
author Tercio
date Mon, 02 Mar 2015 21:28:33 -0300
parents 23e19ba2b62c
children 789bf9e40966
comparison
equal deleted inserted replaced
3:4a3ffc2ee399 4:1c3534391efb
1 local floor = floor 1 local floor = floor
2 local min = min 2 local min = min
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
7 local abs = abs
6 8
7 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent) 9 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent)
8 f:SetFrameStrata ("DIALOG") 10 f:SetFrameStrata ("DIALOG")
11
12 local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent)
9 13
10 f:SetSize (155, 156) 14 f:SetSize (155, 156)
11 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1}, 15 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
12 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8}) 16 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8})
13 f:SetPoint ("center", UIParent, "center") 17 f:SetPoint ("center", UIParent, "center")
42 player_bar.texture:SetTexture ("Interface\\AddOns\\Hansgar_And_Franzok_Assist\\bar_skyline") 46 player_bar.texture:SetTexture ("Interface\\AddOns\\Hansgar_And_Franzok_Assist\\bar_skyline")
43 player_bar:SetStatusBarTexture (player_bar.texture) 47 player_bar:SetStatusBarTexture (player_bar.texture)
44 48
45 -- 49 --
46 50
51 local player_pos_frame = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_DanceBar", UIParent)
52 player_pos_frame:SetPoint ("topleft", player_bar, "bottomleft", 0, -3)
53 player_pos_frame:SetPoint ("topright", player_bar, "bottomright", 0, -3)
54 player_pos_frame:SetHeight (14)
55 player_pos_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
56 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8})
57 player_pos_frame:SetBackdropColor (0, 0, 0, 1)
58 player_pos_frame:Hide()
59
60 --red
61 local t1 = player_pos_frame:CreateTexture (nil, "artwork")
62 t1:SetPoint ("left", player_pos_frame, "left")
63 t1:SetSize (player_pos_frame:GetWidth()*0.30, 14)
64 t1:SetTexture (1, 1, 1)
65 --t1:SetTexCoord (260/512, 430/512, 29/256, 82/256)
66 t1:SetVertexColor (1, 0.2, 0.2, 0.4)
67
68 --green
69 local t2 = player_pos_frame:CreateTexture (nil, "artwork")
70 t2:SetPoint ("left", t1, "right")
71 t2:SetSize (player_pos_frame:GetWidth()*0.15, 14)
72 t2:SetTexture (0.2, 1, 0.2, 0.4)
73
74 --red
75 local middle = player_pos_frame:CreateTexture (nil, "artwork")
76 middle:SetPoint ("left", t2, "right")
77 middle:SetSize (player_pos_frame:GetWidth()*0.10, 14)
78 middle:SetTexture (1, 1, 1)
79 --middle:SetTexCoord (260/512, 430/512, 29/256, 82/256)
80 middle:SetVertexColor (1, 0.2, 0.2, 0.4)
81
82 --green
83 local t3 = player_pos_frame:CreateTexture (nil, "artwork")
84 t3:SetPoint ("left", middle, "right")
85 t3:SetSize (player_pos_frame:GetWidth()*0.15, 14)
86 t3:SetTexture (0.2, 1, 0.2, 0.4)
87
88 --red
89 local t4 = player_pos_frame:CreateTexture (nil, "artwork")
90 t4:SetPoint ("left", t3, "right")
91 t4:SetSize (player_pos_frame:GetWidth()*0.30, 14)
92 t4:SetTexture (1, 1, 1)
93 --t4:SetTexCoord (260/512, 430/512, 29/256, 82/256)
94 t4:SetVertexColor (1, 0.2, 0.2, 0.4)
95
96 local div = player_pos_frame:CreateTexture (nil, "overlay")
97 div:SetPoint ("left", player_pos_frame, "left", 0, 0)
98 div:SetTexture (1, 1, 1, 1)
99 div:SetSize (1, 16)
100 div:Hide()
101 --
102
103 local AceTimer = LibStub:GetLibrary ("AceTimer-3.0")
104 AceTimer:Embed (f)
105 local AceComm = LibStub:GetLibrary ("AceComm-3.0")
106 AceComm:Embed (f)
107
47 local db 108 local db
109
110 f.block_tracker = {}
48 111
49 frame_event:SetFrameStrata ("FULLSCREEN") 112 frame_event:SetFrameStrata ("FULLSCREEN")
50 113
51 frame_event:SetScript ("OnEvent", function (self, event, ...) 114 frame_event:SetScript ("OnEvent", function (self, event, ...)
52 115
55 db = Hansgar_And_Franzok_DB 118 db = Hansgar_And_Franzok_DB
56 if (not db) then 119 if (not db) then
57 db = {} 120 db = {}
58 Hansgar_And_Franzok_DB = db 121 Hansgar_And_Franzok_DB = db
59 end 122 end
123 --
60 db.STAMPERS_DELAY = db.STAMPERS_DELAY or 5 124 db.STAMPERS_DELAY = db.STAMPERS_DELAY or 5
61 125 if (db.CD_NUMBER == nil) then
126 db.CD_NUMBER = false
127 end
128 if (db.SHOW_DANCE == nil) then
129 db.SHOW_DANCE = true
130 end
131 --
62 SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok" 132 SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok"
63 function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox) 133 function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox)
64 134
65 local command, rest = msg:match ("^(%S*)%s*(.-)$") 135 local command, rest = msg:match ("^(%S*)%s*(.-)$")
66 136
73 print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t) 143 print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t)
74 end 144 end
75 145
76 elseif (command == "test" or command == "show") then 146 elseif (command == "test" or command == "show") then
77 if (f.StampersPhase) then 147 if (f.StampersPhase) then
148 f:EndTrackPlayerPosition()
78 return f:StopTracking() 149 return f:StopTracking()
79 end 150 end
151
80 f:StartTracking() 152 f:StartTracking()
153 f:StartTrackPlayerPosition()
81 154
82 elseif (command == "hide") then 155 elseif (command == "hide") then
83 if (f.StampersPhase) then 156 if (f.StampersPhase) then
84 return f:StopTracking() 157 return f:StopTracking()
85 end 158 end
86 159 f:EndTrackPlayerPosition()
160
161 elseif (command == "dance") then
162 db.SHOW_DANCE = not db.SHOW_DANCE
163 if (db.SHOW_DANCE) then
164 if (f.on_encounter) then
165 f:StartTrackPlayerPosition()
166 end
167 print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars enabled.")
168 else
169 f:EndTrackPlayerPosition()
170 print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars disabled.")
171 end
172
173 elseif (command == "cooldown") then
174 db.CD_NUMBER = not db.CD_NUMBER
175 f:RefreshCooldownSettings()
176
87 else 177 else
88 print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00v0.4|r Commands:") 178 print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00v0.5|r Commands:")
89 print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.") 179 print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.")
180 print ("|cFFFFFF00/hansgar cooldown|r: show the countdown for each stamper go back up to the ceiling.")
181 --print ("|cFFFFFF00/hansgar dance|r: toggle dance bar (used to dodge regular stampers and searing plates).")
90 print ("|cFFFFFF00/hansgar test|r: active the addon on test mode.") 182 print ("|cFFFFFF00/hansgar test|r: active the addon on test mode.")
91 print ("|cFFFFFF00/hansgar show|r: show the window and start test mode.") 183 print ("|cFFFFFF00/hansgar show|r: show the window and start test mode.")
92 print ("|cFFFFFF00/hansgar hide|r: hide the window.") 184 print ("|cFFFFFF00/hansgar hide|r: hide the window.")
93 end 185 end
94 end 186 end
95 187
96 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then 188 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then
97 189
98 local encounterID, encounterName, difficultyID, raidSize = select (1, ...) 190 local encounterID, encounterName, difficultyID, raidSize = select (1, ...)
191
192 if (encounterID == 1693) then
193 if (event == "ENCOUNTER_START") then
194 f.on_encounter = true
195 elseif (event == "ENCOUNTER_END") then
196 f.on_encounter = false
197 end
198 end
199
200 if (encounterID == 1693 and db.SHOW_DANCE) then
201 if (event == "ENCOUNTER_START") then
202 SetMapToCurrentZone()
203 f:StartTrackPlayerPosition()
204 elseif (event == "ENCOUNTER_END") then
205 f:EndTrackPlayerPosition()
206 end
207 end
208
99 if (encounterID == 1693 and difficultyID == 16) then 209 if (encounterID == 1693 and difficultyID == 16) then
100 210
101 if (event == "ENCOUNTER_START") then 211 if (event == "ENCOUNTER_START") then
102 212
103 print ("|cFFFFAA00Hansgar and Franzok Assist|r: addon enabled, good look!") 213 print ("|cFFFFAA00Hansgar and Franzok Assist|r: addon enabled, good look!")
111 f:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") 221 f:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
112 222
113 if (f.StampersPhase) then 223 if (f.StampersPhase) then
114 f:StopTracking() 224 f:StopTracking()
115 end 225 end
226
227 f:EndTrackPlayerPosition()
116 end 228 end
117 end 229 end
118 end 230 end
119 231
120 end) 232 end)
135 end) 247 end)
136 248
137 local frame_tracker = CreateFrame ("frame", "Hansgar_And_Franzok_AssistTracker", UIParent) 249 local frame_tracker = CreateFrame ("frame", "Hansgar_And_Franzok_AssistTracker", UIParent)
138 local on_update_tracker = function (self, elapsed) 250 local on_update_tracker = function (self, elapsed)
139 251
140 for i = 1, GetNumGroupMembers() do 252 local raid_size = GetNumGroupMembers()
253
254 for i = 1, raid_size do
141 local x, y = GetPlayerMapPosition ("raid"..i) 255 local x, y = GetPlayerMapPosition ("raid"..i)
142 if (UnitExists ("raid"..i) and UnitHealth ("raid"..i) > 1 and x and y) then 256 if (UnitExists ("raid"..i) and UnitHealth ("raid"..i) > 1 and x and y) then
143 local block = f:WhichBlock (x, y) 257 local block = f:WhichBlock (x, y)
144 if (block) then 258 if (block) then
145 if (not f.block_tracker [block]) then --> was a clear block 259 if (not f.block_tracker [block]) then --> was a clear block
150 end 264 end
151 end 265 end
152 266
153 local px, py = GetPlayerMapPosition ("player") 267 local px, py = GetPlayerMapPosition ("player")
154 local player_block = f:WhichBlock (px, py) 268 local player_block = f:WhichBlock (px, py)
155 if (player_block) then 269 if (player_block and raid_size > 0) then
156 270
157 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY 271 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY
158 local time_now = GetTime() 272 local time_now = GetTime()
159 273
160 f.player_bar:SetValue ((time_limit_at - time_now) / db.STAMPERS_DELAY * 100) 274 f.player_bar:SetValue ((time_limit_at - time_now) / db.STAMPERS_DELAY * 100)
234 348
235 if (percent == 100) then 349 if (percent == 100) then
236 self:SetScript ("OnUpdate", nil) 350 self:SetScript ("OnUpdate", nil)
237 self.stamper_icon:Show() 351 self.stamper_icon:Show()
238 self.number:Hide() 352 self.number:Hide()
239 end 353 self.cooldown:SetCooldown (GetTime(), 37 - db.STAMPERS_DELAY, 0, 0)
240 end 354 end
355 end
356 end
357
358 function f:UnPaint (block)
359 f:ResetBlock (block)
241 end 360 end
242 function f:Paint (block) 361 function f:Paint (block)
243 block.step = 0 362 block.step = 0
244 block.total_time = 0 363 block.total_time = 0
245 block:SetScript ("OnUpdate", painting) 364 block:SetScript ("OnUpdate", painting)
365 local unpaint = f:ScheduleTimer ("UnPaint", 37, block)
366 block.unpaint_process = unpaint
367 end
368
369 function f:ResetBlock (block)
370 block:SetScript ("OnUpdate", nil)
371 block:SetBackdropColor (.8, .8, .8, 0.5)
372 block.number:SetText (block.id)
373 block.number:SetTextColor (1, 1, 1, 0.5)
374 block.number:Show()
375 block.stamper_icon:Hide()
376 block.cooldown:SetCooldown (0, 0, 0, 0)
377
378 f.block_tracker [block.id] = nil
379 if (block.unpaint_process) then
380 f:CancelTimer (block.unpaint_process)
381 block.unpaint_process = nil
382 end
246 end 383 end
247 384
248 function f:ResetBlocks() 385 function f:ResetBlocks()
249 for _, block in ipairs (f.all_blocks) do 386 for _, block in ipairs (f.all_blocks) do
250 block:SetScript ("OnUpdate", nil) 387 f:ResetBlock (block)
251 block:SetBackdropColor (.8, .8, .8, 0.5) 388 end
252 block.number:SetText (block.id) 389 end
253 block.number:SetTextColor (1, 1, 1, 0.5) 390
254 block.number:Show() 391 function f:RefreshCooldownSettings()
255 block.stamper_icon:Hide() 392 for _, block in ipairs (f.all_blocks) do
393 if (not db.CD_NUMBER) then
394 block.cooldown:SetHideCountdownNumbers (true)
395 block.cooldown:SetDrawEdge (false)
396 else
397 block.cooldown:SetHideCountdownNumbers (false)
398 block.cooldown:SetDrawEdge (true)
399 end
256 end 400 end
257 end 401 end
258 402
259 function f:CreateWindow() 403 function f:CreateWindow()
260 local x = 0 404 local x = 0
278 block:SetPoint ("TopLeft", f, "TopLeft", x, y) 422 block:SetPoint ("TopLeft", f, "TopLeft", x, y)
279 423
280 block:SetScript ("OnMouseDown", on_mouse_down) 424 block:SetScript ("OnMouseDown", on_mouse_down)
281 block:SetScript ("OnMouseUp", on_mouse_up) 425 block:SetScript ("OnMouseUp", on_mouse_up)
282 426
427 local cooldown = CreateFrame ("cooldown", "Hansgar_And_Franzok_Assist_BlockCooldown" .. i, block, "CooldownFrameTemplate")
428 cooldown:SetAllPoints()
429 cooldown:SetFrameLevel (block:GetFrameLevel()+2)
430
431 if (not db.CD_NUMBER) then
432 cooldown:SetHideCountdownNumbers (true)
433 cooldown:SetDrawEdge (false)
434 end
435
436 block.cooldown = cooldown
437
283 block.id = i 438 block.id = i
284 439
285 local number = block:CreateFontString (nil, "artwork", "GameFontHighlight") 440 local number = block:CreateFontString (nil, "artwork", "GameFontHighlight")
286 number:SetPoint ("center", block, "center") 441 number:SetPoint ("center", block, "center")
287 number:SetText (i) 442 number:SetText (i)
306 461
307 end 462 end
308 463
309 f.frames_built = true 464 f.frames_built = true
310 465
466 end
467
468 local safe_track = {
469 --space 1
470 {
471 block = {x1 = 0.50154542922974, x2 = 0.49563668874741},
472 left = {x1 = 0.49963343143463, x2 = 0.49963343143463 - 0.000935000000000},
473 right = {x1 = 0.49710285663605, x2 = 0.49710285663605 + 0.001012229919432},
474 -- {x1 = 0.49963343143463, y1 = 0.73492467403412} -- {x1 = 0.49710285663605, y1 = 0.74445152282715}
475 },
476 --space 2
477 {
478 block = {x1 = 0.4858917593956, x2 = 0.48044270277023},
479 left = {x1 = 0.48433673381805, x2 = 0.48433673381805 - 0.00091059207916},
480 right = {x1 = 0.48206025362015, x2 = 0.48206025362015 + 0.00075059207916},
481 -- {x1 = 0.48433673381805, y1 = 0.74292266368866} -- {x1 = 0.48206025362015, y1 = 0.78930181264877}
482 },
483 --space 3
484 {
485 block = {x1 = 0.47047740221024, x2 = 0.4648859500885},
486 left = {x1 = 0.46893924474716, x2 = 0.46893924474716 - 0.001032948493956},
487 right = {x1 = 0.46635687351227, x2 = 0.46635687351227 + 0.001032948493956},
488 --{x1 = 0.46893924474716, y1 = 0.7981019616127} -- {x1 = 0.46635687351227, y1 = 0.73558133840561}
489 },
490 --space 4
491 {
492 block = {x1 = 0.45503282546997, x2 = 0.44976264238358},
493 left = {x1 = 0.4533554315567, x2 = 0.4533554315567 - 0.000774573974608},
494 right = {x1 = 0.45124399662018, x2 = 0.45124399662018 + 0.000770009999999},
495 --{x1 = 0.4533554315567, y1 = 0.74078941345215} -- {x1 = 0.45124399662018, y1 = 0.74088287353516}
496 }
497 }
498 Hansgar_safe_track = safe_track
499
500 -- /hansgar test
501 -- /run Hansgar_safe_track [1].block.x1 = 0.50154542922974
502
503 local red_alpha_disabled = 0.15
504 local red_alpha_enabled = 0.5
505
506 local green_alpha_disabled = 0.05
507 local green_alpha_enabled = 0.9
508
509 local track_function = function (self, elapsed)
510
511 local x, _ = GetPlayerMapPosition ("player")
512 local block
513
514 for i = 1, #safe_track do
515 local loc = safe_track [i]
516 if (x >= loc.block.x2 and x <= loc.block.x1) then
517 block = i
518 break
519 end
520 end
521
522 if (block) then
523
524 player_pos_frame:Show()
525 block = safe_track [block]
526
527 if (x >= block.left.x2 and x <= block.left.x1) then
528 t2:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
529 t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
530
531 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
532 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
533 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
534
535 elseif (x <= block.right.x2 and x >= block.right.x1) then
536 t3:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
537 t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
538
539 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
540 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
541 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
542
543 else
544 t1:SetVertexColor (1, 0.2, 0.2, red_alpha_enabled) --red
545 t4:SetVertexColor (1, 0.2, 0.2, red_alpha_enabled) --red
546 middle:SetVertexColor (1, 0.2, 0.2, red_alpha_enabled) --red
547
548 t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
549 t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
550
551 end
552
553 --x = x - block.block.x2
554 --local at = abs ((x / (block.block.x1 - block.block.x2) * 100) - 100)
555 --div:SetPoint ("left", player_pos_frame, "left", self.width_pixel * at, 0)
556
557 else
558 player_pos_frame:Hide()
559 end
560 end
561
562 function f:StartTrackPlayerPosition()
563
564 --> under development
565 if (true) then
566 return
567 end
568
569 player_pos_frame:Show()
570 tframe.width = player_pos_frame:GetWidth()
571 tframe.width_pixel = tframe.width / 100
572 tframe:SetScript ("OnUpdate", track_function)
573 end
574 function f:EndTrackPlayerPosition()
575 player_pos_frame:Hide()
576 tframe:SetScript ("OnUpdate", nil)
311 end 577 end
312 578
313 local locs = { 579 local locs = {
314 --block 1: 580 --block 1:
315 {x1 = 0.51103663444519, y1 = 0.79726493358612, x2 = 0.50061076879501, y2 = 0.8241291642189}, 581 {x1 = 0.51103663444519, y1 = 0.79726493358612, x2 = 0.50061076879501, y2 = 0.8241291642189},