forked from FabysGames/mythicplustimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infos.lua
729 lines (588 loc) · 21.9 KB
/
infos.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
local _, addon = ...
local infos = addon.new_module("infos")
-- ---------------------------------------------------------------------------------------------------------------------
local main
local criteria
-- ---------------------------------------------------------------------------------------------------------------------
local deathcounter_frame
local reaping_frame
local current_reaping_in
local prideful_frame
local current_prideful_in
local pull_frame
-- ---------------------------------------------------------------------------------------------------------------------
local function create_deathcounter_frame()
if deathcounter_frame then
return deathcounter_frame
end
-- frame
local frame = CreateFrame("Frame", nil, main.get_frame())
frame:ClearAllPoints()
-- text
frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
local font_path, _, font_flags = frame.text:GetFont()
frame.text:SetFont(font_path, 12, font_flags)
if addon.c("align_right") then
frame.text:SetPoint("TOPRIGHT")
frame.text:SetJustifyH("RIGHT")
else
frame.text:SetPoint("TOPLEFT")
frame.text:SetJustifyH("LEFT")
end
-- tooltip
local on_enter = function()
if not deathcounter_frame.tooltip then
return
end
GameTooltip:Hide()
GameTooltip:ClearLines()
if addon.c("align_right") then
GameTooltip:SetOwner(deathcounter_frame, "ANCHOR_TOPRIGHT")
else
GameTooltip:SetOwner(deathcounter_frame, "ANCHOR_TOPLEFT")
end
for _, v in pairs(deathcounter_frame.tooltip) do
GameTooltip:AddLine(v)
end
GameTooltip:Show()
end
frame:SetScript("OnEnter", on_enter)
frame:SetScript("OnLeave", GameTooltip_Hide)
deathcounter_frame = frame
return deathcounter_frame
end
-- ---------------------------------------------------------------------------------------------------------------------
local function create_reaping_frame()
if reaping_frame then
return reaping_frame
end
local frame = CreateFrame("Frame", nil, main.get_frame())
frame:ClearAllPoints()
frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
local font_path, _, font_flags = frame.text:GetFont()
frame.text:SetFont(font_path, 12, font_flags)
if addon.c("align_right") then
frame.text:SetPoint("TOPRIGHT")
frame.text:SetJustifyH("RIGHT")
else
frame.text:SetPoint("TOPLEFT")
frame.text:SetJustifyH("LEFT")
end
reaping_frame = frame
return reaping_frame
end
-- ---------------------------------------------------------------------------------------------------------------------
local function create_prideful_frame()
if prideful_frame then
return prideful_frame
end
local frame = CreateFrame("Frame", nil, main.get_frame())
frame:ClearAllPoints()
frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
local font_path, _, font_flags = frame.text:GetFont()
frame.text:SetFont(font_path, 12, font_flags)
if addon.c("align_right") then
frame.text:SetPoint("TOPRIGHT")
frame.text:SetJustifyH("RIGHT")
else
frame.text:SetPoint("TOPLEFT")
frame.text:SetJustifyH("LEFT")
end
prideful_frame = frame
return prideful_frame
end
-- ---------------------------------------------------------------------------------------------------------------------
local function create_pull_frame()
if pull_frame then
return pull_frame
end
local frame = CreateFrame("Frame", nil, main.get_frame())
frame:ClearAllPoints()
frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
local font_path, _, font_flags = frame.text:GetFont()
frame.text:SetFont(font_path, 12, font_flags)
if addon.c("align_right") then
frame.text:SetPoint("TOPRIGHT")
frame.text:SetJustifyH("RIGHT")
else
frame.text:SetPoint("TOPLEFT")
frame.text:SetJustifyH("LEFT")
end
pull_frame = frame
return pull_frame
end
-- ---------------------------------------------------------------------------------------------------------------------
local function on_config_change()
local current_run = main.get_current_run()
if not current_run then
return
end
-- update demo
if current_run.is_demo then
-- deathcounter
current_run.deathcount = -1
infos.update_deathcounter_info(current_run, 2, 10)
-- prideful
current_prideful_in = nil
infos.update_prideful_info(current_run)
-- reaping
current_reaping_in = nil
infos.update_reaping_info(current_run)
return
end
-- update deathcounter
current_run.deathcount = -1 -- reset count in cache to trigger the rerender
infos.update_deathcounter()
-- update prideful
current_prideful_in = nil -- reset current to trigger the rerender
infos.update_prideful()
-- update reaping
current_reaping_in = nil -- reset current to trigger the rerender
infos.update_reaping()
end
-- ---------------------------------------------------------------------------------------------------------------------
local function update_deathcounter_tooltip(current_run)
if not deathcounter_frame then
return
end
if current_run.death_names then
local tooltip = {}
table.insert(tooltip, addon.t("lbl_deaths"))
for name, count in pairs(current_run.death_names) do
table.insert(tooltip, "|cFFFFFFFF" .. name .. ": " .. count)
end
deathcounter_frame.tooltip = tooltip
else
deathcounter_frame.tooltip = nil
end
end
-- ---------------------------------------------------------------------------------------------------------------------
local function update_deathcounter(current_run, deathcount, death_timelost)
-- check deathcount
if not death_timelost or death_timelost == 0 or not deathcount or deathcount == 0 or not addon.c("show_deathcounter") then
current_run.deathcount_visible = false
if deathcounter_frame then
deathcounter_frame:Hide()
end
return
end
-- check if we can skip the update
local last_criteria_frame = criteria.get_last_frame(current_run)
if current_run.deathcount == deathcount and deathcounter_frame and deathcounter_frame.ref_frame == last_criteria_frame and current_run.deathcount_visible then
return
end
current_run.deathcount = deathcount
current_run.deathcount_visible = true
-- update
create_deathcounter_frame()
local deathcounter_text = string.format("|c%s%s %s|r|c%s -%s", addon.c("color_deathcounter"), deathcount, addon.t("lbl_deaths"), addon.c("color_deathcounter_timelost"), main.format_seconds(death_timelost))
local current_deathcounter_text = deathcounter_frame.text:GetText()
if current_deathcounter_text ~= deathcounter_text then
deathcounter_frame.text:SetText(deathcounter_text)
-- update size (needed for tooltip)
if not current_deathcounter_text or not deathcounter_text or string.len(current_deathcounter_text) ~= string.len(deathcounter_text) then
deathcounter_frame:SetHeight(deathcounter_frame.text:GetStringHeight())
deathcounter_frame:SetWidth(deathcounter_frame.text:GetStringWidth())
end
end
-- update point (last criteria frame can be different in every dungeon)
if not deathcounter_frame.ref_frame or deathcounter_frame.ref_frame ~= last_criteria_frame then
if addon.c("align_right") then
deathcounter_frame:SetPoint("TOPRIGHT", last_criteria_frame, "BOTTOMRIGHT", 0, -5)
else
deathcounter_frame:SetPoint("TOPLEFT", last_criteria_frame, "BOTTOMLEFT", 0, -5)
end
deathcounter_frame.ref_frame = last_criteria_frame
end
-- show
deathcounter_frame:Show()
-- update tooltip
update_deathcounter_tooltip(current_run)
-- update prideful frame point
if prideful_frame and (not prideful_frame.ref_frame or prideful_frame.ref_frame ~= deathcounter_frame) then
if addon.c("align_right") then
prideful_frame:SetPoint("TOPRIGHT", deathcounter_frame, "BOTTOMRIGHT", 0, -5)
else
prideful_frame:SetPoint("TOPLEFT", deathcounter_frame, "BOTTOMLEFT", 0, -5)
end
prideful_frame.ref_frame = deathcounter_frame
end
-- update reaping frame point
if reaping_frame and (not reaping_frame.ref_frame or reaping_frame.ref_frame ~= deathcounter_frame) then
if addon.c("align_right") then
reaping_frame:SetPoint("TOPRIGHT", deathcounter_frame, "BOTTOMRIGHT", 0, -5)
else
reaping_frame:SetPoint("TOPLEFT", deathcounter_frame, "BOTTOMLEFT", 0, -5)
end
reaping_frame.ref_frame = deathcounter_frame
end
end
-- ---------------------------------------------------------------------------------------------------------------------
local function update_reaping(current_run)
-- is called at criteria update
if current_run.is_reaping == nil then
current_run.is_reaping = false
current_reaping_in = nil
for _, affix_id in ipairs(current_run.affixes) do
if affix_id == 117 then
current_run.is_reaping = true
break
end
end
end
-- check if reaping / done
if not current_run.is_reaping or not addon.c("show_reapingtimer") or current_run.quantity_completed then
if reaping_frame then
reaping_frame:Hide()
end
return
end
-- update
create_reaping_frame()
-- skip if enemy forces is not known (criterias are not always known on cm start ... update gets called anyway)
if current_run.final_quantity_number == nil then
reaping_frame:Hide()
return
end
-- update point
local ref_frame = nil
if deathcounter_frame and current_run.deathcount_visible then
ref_frame = deathcounter_frame
else
ref_frame = criteria.get_last_frame(current_run)
end
if not reaping_frame.ref_frame or reaping_frame.ref_frame ~= ref_frame then
if addon.c("align_right") then
reaping_frame:SetPoint("TOPRIGHT", ref_frame, "BOTTOMRIGHT", 0, -5)
else
reaping_frame:SetPoint("TOPLEFT", ref_frame, "BOTTOMLEFT", 0, -5)
end
reaping_frame.ref_frame = ref_frame
end
-- absolute number
local reaping_quantity = current_run.final_quantity_number / 5
local reaping_in = reaping_quantity - current_run.quantity_number % reaping_quantity
if current_reaping_in == reaping_in then
return
end
current_reaping_in = reaping_in
-- percent
local reaping_in_percent = (reaping_in / current_run.final_quantity_number) * 100
local mult = 10 ^ 2
reaping_in_percent = math.floor(reaping_in_percent * mult + 0.5) / mult
-- resolve text
local color_string = "|c" .. addon.c("color_prideful_value")
if reaping_in_percent < 4 then
color_string = "|c" .. addon.c("color_prideful_value_alert")
elseif reaping_in_percent < 10 then
color_string = "|c" .. addon.c("color_prideful_value_warning")
end
local reaping_text = "|c" .. addon.c("color_prideful") .. addon.t("lbl_reapingin") .. " " .. color_string .. reaping_in_percent .. "%" .. "|r"
if addon.c("show_absolute_numbers") then
reaping_text = reaping_text .. " (" .. math.ceil(reaping_in) .. ")"
end
-- set text
local current_reaping_text = reaping_frame.text:GetText()
if current_reaping_text ~= reaping_text then
reaping_frame.text:SetText(reaping_text)
if not current_reaping_text or not reaping_text or string.len(current_reaping_text) ~= string.len(reaping_text) then
reaping_frame:SetHeight(reaping_frame.text:GetStringHeight())
reaping_frame:SetWidth(reaping_frame.text:GetStringWidth())
end
end
reaping_frame:Show()
end
-- ---------------------------------------------------------------------------------------------------------------------
local function update_prideful(current_run)
-- is called at criteria update
if current_run.is_prideful == nil then
current_run.is_prideful = false
current_prideful_in = nil
for _, affix_id in ipairs(current_run.affixes) do
if affix_id == 121 then
current_run.is_prideful = true
break
end
end
end
-- check if prideful / done
if not current_run.is_prideful or not addon.c("show_pridefultimer") or current_run.quantity_completed then
if prideful_frame then
prideful_frame:Hide()
end
return
end
-- update
create_prideful_frame()
-- skip if enemy forces is not known (criterias are not always known on cm start ... update gets called anyway)
if current_run.final_quantity_number == nil then
prideful_frame:Hide()
return
end
-- update point
local ref_frame = nil
if deathcounter_frame and current_run.deathcount_visible then
ref_frame = deathcounter_frame
else
ref_frame = criteria.get_last_frame(current_run)
end
if not prideful_frame.ref_frame or prideful_frame.ref_frame ~= ref_frame then
if addon.c("align_right") then
prideful_frame:SetPoint("TOPRIGHT", ref_frame, "BOTTOMRIGHT", 0, -5)
else
prideful_frame:SetPoint("TOPLEFT", ref_frame, "BOTTOMLEFT", 0, -5)
end
prideful_frame.ref_frame = ref_frame
end
-- absolute number
local prideful_quantity = current_run.final_quantity_number / 5
local prideful_in = prideful_quantity - current_run.quantity_number % prideful_quantity
local missing_absolute = current_run.final_quantity_number - current_run.quantity_number
if prideful_in > missing_absolute then
prideful_in = missing_absolute
end
if current_prideful_in == prideful_in then
return
end
current_prideful_in = prideful_in
-- percent
local prideful_in_percent = (prideful_in / current_run.final_quantity_number) * 100
local mult = 10 ^ 2
prideful_in_percent = math.floor(prideful_in_percent * mult + 0.5) / mult
-- resolve text
local color_string = "|c" .. addon.c("color_prideful_value")
if prideful_in_percent < 4 then
color_string = "|c" .. addon.c("color_prideful_value_alert")
elseif prideful_in_percent < 10 then
color_string = "|c" .. addon.c("color_prideful_value_warning")
end
local prideful_text = "|c" .. addon.c("color_prideful") .. addon.t("lbl_pridefulin") .. " " .. color_string
if addon.c("show_percent_numbers") then
prideful_text = prideful_text .. prideful_in_percent .. "%"
end
if addon.c("show_absolute_numbers") then
if addon.c("show_percent_numbers") then
prideful_text = prideful_text .. "|r (" .. math.ceil(prideful_in) .. ")"
else
prideful_text = prideful_text .. math.ceil(prideful_in) .. "|r"
end
end
-- set text
local current_prideful_text = prideful_frame.text:GetText()
if current_prideful_text ~= prideful_text then
prideful_frame.text:SetText(prideful_text)
if not current_prideful_text or not prideful_text or string.len(current_prideful_text) ~= string.len(prideful_text) then
prideful_frame:SetHeight(prideful_frame.text:GetStringHeight())
prideful_frame:SetWidth(prideful_frame.text:GetStringWidth())
end
end
prideful_frame:Show()
end
-- ---------------------------------------------------------------------------------------------------------------------
local function update_pull(current_run)
-- is called at criteria update
if not current_run.pull then
return
end
-- update
create_pull_frame()
-- skip if enemy forces is not known (criterias are not always known on cm start ... update gets called anyway)
if current_run.final_quantity_number == nil then
pull_frame:Hide()
return
end
-- update point
local ref_frame = nil
if deathcounter_frame and current_run.deathcount_visible then
ref_frame = deathcounter_frame
else
ref_frame = criteria.get_last_frame(current_run)
end
if not pull_frame.ref_frame or pull_frame.ref_frame ~= ref_frame then
if addon.c("align_right") then
pull_frame:SetPoint("TOPRIGHT", ref_frame, "BOTTOMRIGHT", 0, -5)
else
pull_frame:SetPoint("TOPLEFT", ref_frame, "BOTTOMLEFT", 0, -5)
end
pull_frame.ref_frame = ref_frame
end
-- resolve pull value
local enemies = 0
local value = 0
local in_percent = 0
for _, v in pairs(current_run.pull) do
enemies = enemies + 1
value = value + v[1]
in_percent = in_percent + v[2]
end
if enemies == 0 then
pull_frame:Hide()
return
end
-- update text
local text = "|c" .. addon.c("color_current_pull") .. addon.t("lbl_currentpull") .. " |c" .. addon.c("color_current_pull") .. "" .. in_percent .. "%"
if addon.c("show_absolute_numbers") then
text = text .. " (" .. value .. ")"
end
-- set text
local current_text = pull_frame.text:GetText()
if current_text ~= text then
pull_frame.text:SetText(text)
if not current_text or not text or string.len(current_text) ~= string.len(text) then
pull_frame:SetHeight(pull_frame.text:GetStringHeight())
pull_frame:SetWidth(pull_frame.text:GetStringWidth())
end
end
pull_frame:Show()
end
-- ---------------------------------------------------------------------------------------------------------------------
local surrendered_soul
local function on_combat_log_event_unfiltered()
local _, sub_event, _, _, _, _, _, dest_guid, dest_name = CombatLogGetCurrentEventInfo()
-- skip if not a unit death event
if sub_event ~= "UNIT_DIED" then
return
end
-- skip if not in cm
if not main.is_in_cm() then
return
end
-- skip if not a player
local is_player = strfind(dest_guid, "Player")
if not is_player then
return
end
-- skip if feign death
local is_feign = UnitIsFeignDeath(dest_name)
if is_feign then
return
end
-- skip if surrendered_soul debuff is active on dest
if not surrendered_soul then
surrendered_soul = GetSpellInfo(212570)
end
for i = 1, 40 do
local debuff_name = UnitDebuff(dest_name, i)
if debuff_name == nil then
break
end
if debuff_name == surrendered_soul then
return
end
end
-- player death happened
local current_run = main.get_current_run()
if not current_run then
return
end
if not current_run.death_names then
current_run.death_names = {}
end
if current_run.death_names[dest_name] == nil then
current_run.death_names[dest_name] = 1
else
current_run.death_names[dest_name] = current_run.death_names[dest_name] + 1
end
-- update tooltip
update_deathcounter_tooltip(current_run)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.hide_frames()
-- prideful frame
if prideful_frame then
prideful_frame:Hide()
end
-- reaping frame
if reaping_frame then
reaping_frame:Hide()
end
-- deathcounter frame
if deathcounter_frame then
deathcounter_frame:Hide()
end
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_deathcounter()
-- is called every second by the timer
local current_run = main.get_current_run()
if not current_run then
return
end
-- skip if run is completed
if current_run.is_completed then
return
end
-- update demo
if current_run.is_demo then
current_run.deathcount = -1
infos.update_deathcounter_info(current_run, 2, 10)
return
end
-- update from C_ChallengeMode
local deathcount, death_timelost = C_ChallengeMode.GetDeathCount()
update_deathcounter(current_run, deathcount, death_timelost)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_deathcounter_info(current_run, deathcount, death_timelost)
-- used to update the deathcounter directly (demo)
update_deathcounter(current_run, deathcount, death_timelost)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_reaping()
local current_run = main.get_current_run()
if not current_run then
return
end
update_reaping(current_run)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_reaping_info(current_run)
-- used to update the reaping directly (demo)
update_reaping(current_run)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_prideful()
local current_run = main.get_current_run()
if not current_run then
return
end
update_prideful(current_run)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_prideful_info(current_run)
-- used to update the prideful directly (demo)
update_prideful(current_run)
end
-- ---------------------------------------------------------------------------------------------------------------------
function infos.update_pull()
local current_run = main.get_current_run()
if not current_run then
return
end
update_pull(current_run)
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Init
function infos:init()
main = addon.get_module("main")
criteria = addon.get_module("criteria")
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Enable
function infos:enable()
-- register events
addon.register_event("COMBAT_LOG_EVENT_UNFILTERED", on_combat_log_event_unfiltered)
-- config listeners
addon.register_config_listener("show_deathcounter", on_config_change)
addon.register_config_listener("show_reapingtimer", on_config_change)
addon.register_config_listener("show_pridefultimer", on_config_change)
addon.register_config_listener("show_absolute_numbers", on_config_change)
addon.register_config_listener("show_enemy_forces_bar", on_config_change)
addon.register_config_listener("color_deathcounter", on_config_change)
addon.register_config_listener("color_deathcounter_timelost", on_config_change)
addon.register_config_listener("color_prideful", on_config_change)
addon.register_config_listener("color_prideful_value", on_config_change)
addon.register_config_listener("color_prideful_value_alert", on_config_change)
addon.register_config_listener("color_prideful_value_warning", on_config_change)
addon.register_config_listener("show_percent_numbers", on_config_change)
end