-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSpeedrunExtra.lua
More file actions
1191 lines (1008 loc) · 37.7 KB
/
SpeedrunExtra.lua
File metadata and controls
1191 lines (1008 loc) · 37.7 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
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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Speedrun = Speedrun or {}
local Speedrun = Speedrun
local sV
local cV
Speedrun.slash = "/speed" or "/SPEED"
Speedrun.prefix = "|cffffffSpeed|r|cdf4242Run|r: "
Speedrun.trialDifficulty = 1
Speedrun.groupIsHidden = false
Speedrun.npChanged = false
Speedrun.hbChanged = false
Speedrun.npHlChanged = false
Speedrun.hbHlChanged = false
Speedrun.isLocalChange = false
local LS = LoadingScreen_Base
local EM = EVENT_MANAGER
local SM = SCENE_MANAGER
--[[ Loading Screen ]]
local changes = 0
local isLoading = false
local hasChanged = false
local portStart = 0
local portFailed = false
local loadingStart = 0
local loadingEnd = 0
local deactivated = false
local normals = 0
local vets = 0
local lastDiffChange = 0
--[[ Hide Group ]]
local subzone = ""
local inPortalZone = false
local portalZones = {
-- effects related to portal enter / exit
-- enter inside exit
[1051] = { 103489, 108045, 105218 }, -- 105218 }, --{ 103489, 105218 },
[1121] = { 121213, 121254 },
[1263] = { 153423, 105218 }
}
local necromodeOn = false
local inPortal = false
local changedInPortal = false
local changedOutOfPortal = false
local portalTime = 0
local isReset = false
local isBoss = false
local bChanges = {}
local atBoss = false
local inBossFight = false
local bossFightStart = 0
local bosses = {}
local currentBosses = 0
local bossesReset = false
local shouldChange = false
local hasChanged = false
local hasEffect = false
local died = false
-------------------------
---- Functions -------
-------------------------
--[[ stuff
/script JumpToSpecificHouse("@playername", houseid)
/script for houseid = 1, 100 do d("["..houseid .."] "..GetCollectibleName(GetCollectibleIdForHouse(houseid))) end
/script JumpToSpecificHouse("@player", 3)
SCENE_MANAGER:GetCurrentScene()
CanSpinPreviewCharacter()
]]
local function OnSubzoneChanged()
local z = GetPlayerActiveSubzoneName()
if z ~= "" and z ~= subzone then
subzone = z
zo_callLater(function()
Speedrun:dbg(2, "Subzone Changed to: <<1>>", subzone)
end, 200)
end
end
function Speedrun.SlashCommand(string)
local command = string.lower(string)
-- Debug Options ----------------------------------------------------------
if command == "track 0" then
d(Speedrun.prefix .. "Tracking: Off")
cV.debugMode = 0
elseif command == "track 1" then
d(Speedrun.prefix .. "Tracking: low (only checkpoints)")
cV.debugMode = 1
elseif command == "track 2" then
d(Speedrun.prefix .. "Tracking: medium (checkpoints and some function updates)")
cV.debugMode = 2
elseif command == "track 3" then
d(Speedrun.prefix .. "Tracking: high (everything. can be a lot of spam.)")
cV.debugMode = 3
elseif command == "time" then
d(Speedrun.prefix .. "Game time - start = <<1>>. Duration = <<2>>.", GetGameTimeSeconds() - Speedrun.timeStarted, GetRaidDuration() / 1000)
-- UI Options -------------------------------------------------------------
elseif command == "move" or command == "lock" then
Speedrun.ToggleUILocked()
elseif command == "hideui" then
Speedrun.SetUIHidden(true)
elseif command == "showui" then
Speedrun.SetUIHidden(false)
elseif command == "ui" then
Speedrun.ToggleUIVisibility()
-- Hide Group -------------------------------------------------------------
elseif command == "hg" or command == "hidegroup" then
Speedrun.HideGroupToggle()
-- Adds -------------------------------------------------------------------
elseif command == "score" then
Speedrun.PrintScoreReasons()
elseif command == "lastscore" then
Speedrun.PrintLastScoreReasons()
-- Travel -----------------------------------------------------------------
elseif command == "home" then
RequestJumpToHouse(GetHousingPrimaryHouse(), false)
elseif (command == "h" and GetDisplayName() == "@nogetrandom") then
RequestJumpToHouse(38)
elseif (command == "bisse" and GetDisplayName() == "@Mille_W") then
JumpToSpecificHouse("@nogetrandom", 70)
-- Default ----------------------------------------------------------------
else
d(Speedrun.prefix .. " Command not recognized!\n[ |cffffff/speed|r (|cffffffcommand|r) ] options are:\n[ |cffffffshow|r or |cffffffhide|r ]: To toggle UI.\n[ |cffffffmove|r or |cfffffflock|r ]: Both will toggle the UI's current lock state.\n[ |cfffffftrack (|cffffff0|r - |cffffff3|r) ]: Chat notification.\n(|cffffff0|r): Only settings change confirmations.\n(|cffffff1|r): Trial checkpoint updates.\n(|cffffff2|r): Checkpoint and internal function updates.\n(|cffffff3|r): Everything the addon is set to register (|cff0000Spam Warning|r).\n[ |cffffffhg|r ] or [ |cffffffhidegroup|r ]: Toggle function on/off.\n[ |cffffffscore|r ]: List current trial score variables in chat.\n[ |cfffffflastscore|r ]: List previous trial score variables in chat (only stores 1 trial, and only if completed).")
end
end
function Speedrun.LoadUtils()
sV = Speedrun.savedVariables
cV = Speedrun.savedSettings
Speedrun.trialDifficulty = ZO_GetEffectiveDungeonDifficulty()
SLASH_COMMANDS[Speedrun.slash] = Speedrun.SlashCommand
if WritCreater then WritCreater.hidePets = function() return end end
Speedrun.ConfigureNameplates()
Speedrun.ConfigureHideGroup()
Speedrun.UpdateNecroMode()
Speedrun.ConfigureCombatInteractBlocker()
Speedrun.RegisterDifficultyChange()
-- if GetDisplayName() == "@nogetrandom" then
-- EM:RegisterForEvent(Speedrun.name .. "Subzone", EVENT_CURRENT_SUBZONE_LIST_CHANGED, OnSubzoneChanged)
-- end
end
function Speedrun:dbg( debugLevel, ... )
if debugLevel <= Speedrun.savedSettings.debugMode then
local message = zo_strformat( ...)
d( Speedrun.prefix .. message )
end
end
function Speedrun:post( ... )
local message = zo_strformat( ... )
d( message )
end
local lastUpdate = ""
function Speedrun.GetDifficulty(string)
local diff
local isVet = Speedrun.ResolveTrialDiffculty()
if string == true then diff = isVet == true and "Veteran" or "Normal"
else diff = isVet == true and 2 or 1 end
return diff
end
function Speedrun.UpdateDifficulty(difficulty)
Speedrun.UpdateDifficultySwitch()
local changed = false
if difficulty ~= nil and difficulty ~= Speedrun.trialDifficulty then
changed = true
Speedrun.trialDifficulty = difficulty
changes = 0
end
if changed then
local d = Speedrun.GetDifficulty(true)
lastUpdate = d
if sV.printDiffChange == true then Speedrun:dbg(0, "Difficulty changed to: |cffffff<<1>>|r.", d) end
end
end
function Speedrun.RegisterDifficultyChange()
local function OnGroupJoined(eventCode, characterName, displayName, isPlayer)
if not isPlayer then return end
Speedrun.UpdateDifficulty(Speedrun.GetDifficulty(false))
end
local function OnGroupLeft(eventCode, characterName, reason, isPlayer, isLeader, displayName, requiredVote)
if not isPlayer then return end
Speedrun.UpdateDifficulty(Speedrun.GetDifficulty(false))
end
local function OnVeteranDifficultyChanged(eventCode, unitTag, isDifficult)
if AreUnitsEqual("player", unitTag) then return end
if deactivated then
if isDifficult then
vets = vets + 1
else
normals = normals + 1
end
changes = changes + 1
end
local diff = isDifficult and 2 or 1
-- if diff ~= Speedrun.trialDifficulty then
Speedrun.UpdateDifficulty(diff)
-- end
-- Speedrun:dbg(2, "Changed by |cffffff<<1>>|r(|cffffff<<3>>|r) to |cffffff<<2>>|r.", GetUnitDisplayName(unitTag), isDifficult and "Veteran" or "Normal", unitTag)
end
local function OnGroupVeteranDifficultyChanged(_, isVeteranDifficulty)
Speedrun.UpdateDifficulty(isVeteranDifficulty)
if deactivated then
if isVeteranDifficulty then
vets = vets + 1
else
normals = normals + 1
end
changes = changes + 1
end
-- Speedrun:dbg(2, "Changed to |cffffff<<1>>|r.", isVeteranDifficulty and "Veteran" or "Normal")
end
local function OnDeactivated()
deactivated = true
loadingStart = GetGameTimeMilliseconds()
end
EM:RegisterForEvent(Speedrun.name .. "Deactivated", EVENT_PLAYER_DEACTIVATED, OnDeactivated)
EM:RegisterForEvent( Speedrun.name .. "IsVet1", EVENT_VETERAN_DIFFICULTY_CHANGED, OnVeteranDifficultyChanged)
EM:RegisterForEvent( Speedrun.name .. "IsVet2", EVENT_GROUP_VETERAN_DIFFICULTY_CHANGED, OnGroupVeteranDifficultyChanged)
EM:RegisterForEvent( Speedrun.name .. "JoinedGroup", EVENT_GROUP_MEMBER_JOINED, OnGroupJoined)
EM:AddFilterForEvent(Speedrun.name .. "JoinedGroup", EVENT_GROUP_MEMBER_JOINED, REGISTER_FILTER_UNIT_TAG, "player")
EM:RegisterForEvent( Speedrun.name .. "LeftGroup", EVENT_GROUP_MEMBER_LEFT, OnGroupLeft)
EM:AddFilterForEvent(Speedrun.name .. "LeftGroup", EVENT_GROUP_MEMBER_LEFT, REGISTER_FILTER_UNIT_TAG, "player")
end
-- SetVeteranDifficulty(boolean isVeteranDifficulty)
local function ShouldHideGroup()
if not cV.groupHidden then return false end
if (not Speedrun.IsInTrialZone() and sV.hgTrialOnly) then return false end
-- if cV.hgNecro then return wasDeativated == true and wasDeactiveted or (not IsUnitInCombat("player")) end
return true
end
function Speedrun.IsActivated( _, initial )
if initial then
zo_callLater(function()
Speedrun.trialDifficulty = Speedrun.GetDifficulty(false)
end, 1000)
end
Speedrun.ChaosIsABellend()
Speedrun.groupIsHidden = false
shouldChange = true
Speedrun.ConfigureHideGroup()
zo_callLater(function()
Speedrun.UpdateDifficultySwitch()
end, 1000)
if deactivated then
deactivated = false
-- Speedrun:dbg(2, "Was Deactivated")
loadingEnd = GetGameTimeMilliseconds()
local time = string.format("%.2f",(loadingEnd - loadingStart) / 1000)
Speedrun:dbg(2, "Load Time: <<1>> sec.", time)
if changes == 0 then
Speedrun:dbg(2, "No changes.")
else
if sV.printDiffChange == true then
Speedrun:dbg(0, "Instances have been reset. Difficulty is currently set to: |cffffff<<1>>|r.", Speedrun.GetDifficulty(true))
end
Speedrun:dbg(2, "Normal = <<1>>. Vet = <<2>>", normals, vets)
end
normals = 0
vets = 0
changes = 0
end
end
local function StoreNameplateSettings()
if not Speedrun.npChanged then
sV.nameplates = GetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_NAMEPLATES)
end
if not Speedrun.npHlChanged then
sV.nameplatesHL = GetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_NAMEPLATES_HIGHLIGHT)
end
if not Speedrun.hbChanged then
sV.healthBars = GetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_HEALTHBARS)
end
if not Speedrun.hbHlChanged then
sV.healthBarsHL = GetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_HEALTHBARS_HIGHLIGHT)
end
end
function Speedrun.AlterNameplateSettings()
if cV.groupHidden and sV.changeNameplates == true then
Speedrun.ApplyNameplateGroupHiddenChoice()
Speedrun.ApplyNameplateHighlightGroupHiddenChoice()
Speedrun.npChanged = true
end
end
function Speedrun.AlterHealthBarSettings()
if cV.groupHidden and sV.changeHealthBars == true then
Speedrun.ApplyHealthbarGroupHiddenChoice()
Speedrun.ApplyHealthbarHighlightGroupHiddenChoice()
Speedrun.hbChanged = true
end
end
function Speedrun.RestoreNameplateSettings()
if cV.groupHidden and sV.changeNameplates then return end
if Speedrun.npChanged then
Speedrun.isLocalChange = true
SetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_NAMEPLATES, tostring(sV.nameplates))
Speedrun.npChanged = false
end
if Speedrun.npHlChanged then
Speedrun.isLocalChange = true
SetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_NAMEPLATES_HIGHLIGHT, tostring(sV.nameplatesHL))
Speedrun.npHlChanged = false
end
end
function Speedrun.RestoreHealthBarSettings()
if cV.groupHidden and sV.changeHealthBars then return end
if Speedrun.hbChanged then
Speedrun.isLocalChange = true
SetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_HEALTHBARS, tostring(sV.healthBars))
Speedrun.hbChanged = false
end
if Speedrun.hbHlChanged then
Speedrun.isLocalChange = true
SetSetting(SETTING_TYPE_NAMEPLATES, NAMEPLATE_TYPE_GROUP_MEMBER_HEALTHBARS_HIGHLIGHT, tostring(sV.healthBarsHL))
Speedrun.hbHlChanged = false
end
end
local function ShowGroup()
SetCrownCrateNPCVisible(false)
Speedrun.RestoreNameplateSettings()
Speedrun.RestoreHealthBarSettings()
if Speedrun.isLocalChange == true then
zo_callLater(function() Speedrun.isLocalChange = false end, 500)
end
if not cV.hgNecro then
Speedrun:dbg(0, "Showing Group Members")
end
end
local function ForceGroupVisible()
if not IsPlayerActivated() then return end
local scene = SM.currentScene:GetName()
if scene == "stats" then ShowGroup() return end
SM:Show("stats")
zo_callLater(function()
ShowGroup()
if scene == "hudui" then SM:Show("hud")
else
if scene ~= "" then SM:Show(scene) end
end
end, 20)
end
-- currently not used. no good results
-- local function NecroModePortal(_, result, _, _, _, _, _, _, _, targetType, _, _, _, _, _, _, abilityId)
-- local shouldToggle = false
-- if (result == ACTION_RESULT_EFFECT_GAINED and not inPortal) then
-- inPortal = true
-- if not Speedrun.groupIsHidden and not changedInPortal then
-- changedInPortal = true
-- shouldToggle = true
-- end
-- elseif (result == ACTION_RESULT_EFFECT_FADED and inPortal) then
-- inPortal = false
-- if Speedrun.groupIsHidden and not changedOutOfPortal then
-- changedOutOfPortal = true
-- shouldToggle = true
-- end
-- end
--
-- if shouldToggle then
-- SetCrownCrateNPCVisible(true)
-- Speedrun.groupIsHidden = true
--
-- zo_callLater(function()
-- -- Manually show group again once inside.
-- SetCrownCrateNPCVisible(false)
-- Speedrun.groupIsHidden = false
-- if inPortal then
-- changedOutOfPortal = false
-- else
-- changedInPortal = false
-- end
-- end, 500)
-- end
--
-- --
-- -- -- Effect of being transported gained. Show cat.
-- -- -- Don't hide group if they are already hidden.
-- -- if (--[[Speedrun.groupIsHidden == false and]] result == ACTION_RESULT_EFFECT_GAINED) then
-- --
-- -- -- Show cat when transport effect is gained regardless of enter or exit to keep group members hidden.
-- -- -- groupHidden will be updated in the function itself to filter duplicate events.
-- -- -- Speedrun.HideGroup(true)
-- -- SetCrownCrateNPCVisible(true)
-- -- Speedrun.groupIsHidden = true
-- -- Speedrun:dbg(2, "In Portal")
-- --
-- -- zo_callLater(function()
-- -- -- Manually show group again once inside.
-- -- SetCrownCrateNPCVisible(false)
-- -- Speedrun.groupIsHidden = false
-- -- -- Speedrun.HideGroup(false)
-- -- end, 500)
-- --
-- -- -- Id matching one that puts player inside the portal.
-- -- -- Players can't enter portal if they are already inside portal.
-- -- if inPortal == false and abilityId == 103489 or abilityId == 121213 or abilityId == 153423 then
-- --
-- -- -- Prevent duplicate events from interfering.
-- -- inPortal = true
-- --
-- -- -- No effect or id found for being transported inside the portal in Rockgrove.
-- -- -- if abilityId == 153423 then
-- -- -- zo_callLater(function()
-- -- -- -- Manually show group again once inside.
-- -- -- SetCrownCrateNPCVisible(false)
-- -- -- Speedrun.groupIsHidden = false
-- -- -- -- Speedrun.HideGroup(false)
-- -- -- end, 1000)
-- -- -- end
-- -- end
-- --
-- -- -- Effect of being transported fades. Hide cat.
-- -- -- elseif (--[[Speedrun.groupIsHidden == true and]] result == ACTION_RESULT_EFFECT_FADED) then
-- --
-- -- -- SetCrownCrateNPCVisible(true)
-- -- -- Speedrun.groupIsHidden = true
-- -- -- Speedrun:dbg(2, "Out of Portal")
-- -- --
-- -- -- zo_callLater(function()
-- -- -- -- Manually show group again once inside.
-- -- -- SetCrownCrateNPCVisible(false)
-- -- -- Speedrun.groupIsHidden = false
-- -- -- -- Speedrun.HideGroup(false)
-- -- -- end, 1000)
-- --
-- -- --
-- -- -- -- Transportation complete. Hide cat to enable use of corpses.
-- -- -- Speedrun.HideGroup(false)
-- -- --
-- -- -- -- Id matching one that brings player back from the portal.
-- -- -- if inPortal == true and abilityId == 105218 or abilityId == 121254 then
-- -- -- inPortal = false
-- -- -- end
-- -- end
-- end
local function RefreshHideGroupForNecroMode( delay )
SetCrownCrateNPCVisible(true)
Speedrun.groupIsHidden = true
zo_callLater(function()
SetCrownCrateNPCVisible(false)
Speedrun.groupIsHidden = false
end, delay)
end
local function OnNecroEffectChanged( eventCode, change, effectSlot, effectName, unitTag, beginTime, endTime, stackCount, iconName, buffType, effectType, abilityType, statusEffectType, unitName, unitId, abilityId, sourceType )
if abilityId == 105218 or abilityId == 103489 then
if change ~= EFFECT_RESULT_FADED then
Speedrun:dbg(2, "[<<1>>] change = <<2>> at: <<3>>.", effectName, tostring(change), GetGameTimeSeconds())
else
Speedrun:dbg(2, "[<<1>>] Faded at: <<2>>.", effectName, GetGameTimeSeconds())
end
return
end
if change == EFFECT_RESULT_GAINED then
if not hasEffect then
hasEffect = true
Speedrun:dbg(2, "[<<1>>] Gained at: <<2>>. Hiding Group", effectName, GetGameTimeSeconds())
RefreshHideGroupForNecroMode( 1500 )
end
elseif change == EFFECT_RESULT_FADED then
if hasEffect then
hasEffect = false
Speedrun:dbg(2, "[<<1>>] Faded at: <<2>>.", effectName, GetGameTimeSeconds())
RefreshHideGroupForNecroMode( 1500 )
end
end
end
local function OnPortalDeath( eventCode, unitTag, isDead )
if not AreUnitsEqual("player", unitTag) or not hasEffect then return end
local dead = IsUnitDead("player")
if dead then
died = true
Speedrun:dbg(2, "[<<1>>] at: <<2>>.", dead and "Dead" or "Alive", GetGameTimeSeconds())
RefreshHideGroupForNecroMode( 5000 )
elseif died and not dead then
died = false
Speedrun:dbg(2, "[<<1>>] at: <<2>>.", dead and "Dead" or "Alive", GetGameTimeSeconds())
RefreshHideGroupForNecroMode( 5000 )
end
end
-- debug function for finding solution to trial portals
-- EVENT_PLAYER_COMBAT_STATE seemed to be the better option for non-portal situations.
-- will keep testing for finding better triggers
local function NecroBossChanged( eventCode, forceReset )
if cV.debugMode < 2 then return end
local exist = DoesUnitExist("boss1")
if isBoss ~= exist then
isBoss = exist
local r = forceReset
if isReset ~= r then
isReset = r
Speedrun:dbg(2, "Necro Mode Boss Changed: <<1>>, <<2>>", DoesUnitExist("boss1") and "true" or "false", r and "true" or "false")
end
end
for i = 1, MAX_BOSSES do
if DoesUnitExist("boss" .. i) then
local n = GetUnitName("boss" .. i)
if not bChanges[n] then
bChanges[n] = n
Speedrun:post("[<<1>>] detected", n)
end
end
end
end
local function ToggleInPortal( time )
SetCrownCrateNPCVisible(true)
Speedrun.groupIsHidden = true
portalTime = time + 500
hasChanged = true
end
-- debug function for finding solution to trial portals
local function NecroBossUpdate()
for i = 1, MAX_BOSSES do
if DoesUnitExist("boss" .. i) then
local n = GetUnitName("boss" .. i)
if not IsUnitDead("boss" .. i) then
local current, max, effectiveMax = GetUnitPower("boss" .. i, POWERTYPE_HEALTH)
if current < max and IsUnitInCombat("player") then
if not bosses[n] then
bossesReset = false
bossFightStart = GetGameTimeMilliseconds()
local b = { name = n, hp = current }
bosses[n] = b
currentBosses = currentBosses + 1
Speedrun:dbg(2, "Boss [<<1>>] added. Active: <<2>>", n, currentBosses)
end
elseif current == max and not IsUnitInCombat("player") then
if not bossesReset then
bossesReset = true
bosses = {}
currentBosses = 0
Speedrun:dbg(2, "Bosses reset.")
end
end
else
if bosses[n] then
local boss = bosses[n].name
bosses[n] = nil
currentBosses = currentBosses - 1
Speedrun:dbg(2, "Boss [<<1>>] removed. Active: <<2>>", boss, currentBosses)
end
end
end
if currentBosses >= 1 and not IsUnitInCombat("player") and not Speedrun.groupIsHidden then
if hasEffect then return end
local t = GetGameTimeMilliseconds()
local timer = string.format("%0.3s", (t - bossFightStart) / 1000)
Speedrun:dbg(2, "In Portal Update: <<1>>.", timer)
-- ToggleInPortal( t )
-- if t > portalTime then
-- Speedrun:dbg(2, "In Portal: Showing Group.")
-- SetCrownCrateNPCVisible(false)
-- Speedrun.groupIsHidden = false
-- end
end
--[[
if not atBoss then Speedrun:dbg(2, "At Boss") end
atBoss = true
if IsUnitInCombat("player") then
if not inBossFight then
Speedrun:dbg(2, "In Boss Fight")
inBossFight = true
end
else
if inBossFight then
Speedrun:dbg(2, "Not In Boss Fight")
inBossFight = false
end
end
else
if atBoss then Speedrun:dbg(2, "Not At Boss") end
atBoss = false
end
if inBossFight then
local t = GetGameTimeMilliseconds()
for i = 1, GetNumBuffs("player"), 1 do
local buffName = GetUnitBuffInfo(unitTag, i) -- abilityId = 102271
if (buffName == "Shadow World" or buffName == "Time Breach" or buffName == "Bitter Marrow") then
if not inPortal then
Speedrun:dbg(2, "In Portal")
inPortal = true
shouldChange = true
end
else
if inPortal then
Speedrun:dbg(2, "Not in Portal")
inPortal = false
shouldChange = true
end
end
end
if shouldChange then
if not hasChanged then
Speedrun:dbg(2, "Hiding")
ToggleInPortal( t )
else
Speedrun:dbg(2, "Unhiding")
if t > portalTime then
SetCrownCrateNPCVisible(false)
Speedrun.groupIsHidden = false
hasChanged = false
shouldChange = false
end
end
end
]]
--[[
if not atBoss then
if not Speedrun.groupIsHidden and not inPortal then
inPortal = true
SetCrownCrateNPCVisible(true)
Speedrun.groupIsHidden = true
Speedrun:dbg(2, "In Portal")
portalTime = t + 500
end
if inPortal and Speedrun.groupIsHidden then
if t > portalTime then
SetCrownCrateNPCVisible(false)
Speedrun.groupIsHidden = false
end
end
else
if Speedrun.groupIsHidden and inPortal then
inPortal = false
SetCrownCrateNPCVisible(true)
Speedrun.groupIsHidden = true
Speedrun:dbg(2, "Out of Portal")
portalTime = t + 500
end
if not inPortal and Speedrun.groupIsHidden then
if t > portalTime then
SetCrownCrateNPCVisible(false)
Speedrun.groupIsHidden = false
end
end
end
]]
end
end
local function RegisterNecroEvents()
-- if hide group is enabled: turn it off when entering combat.
-- turn it on again when needed.
EM:RegisterForEvent( Speedrun.name .. "NecroCombat", EVENT_PLAYER_COMBAT_STATE, function()
local inCombat = IsUnitInCombat("player")
-- only do something if needed
if inCombat and shouldChange and Speedrun.groupIsHidden then
shouldChange = false
SetCrownCrateNPCVisible(false)
Speedrun.groupIsHidden = false
end
-- for testing how to work around portals in trials
if currentBosses >= 1 and not inCombat then -- can only be true in CR, SS and RG
Speedrun:dbg(2, "Portal Trasition at: <<1>>.", GetGameTimeMilliseconds())
end
end )
local zone = GetZoneId(GetUnitZoneIndex("player"))
-- if setting is on: hide group on death before being brought back to the group
if zone == 1051 or zone == 1263 then
-- CR and RG (you don't get ported out on death in SS, so ignore)
EM:RegisterForEvent( Speedrun.name .. "PortalDeath", EVENT_UNIT_DEATH_STATE_CHANGED, OnPortalDeath )
EM:AddFilterForEvent( Speedrun.name .. "PortalDeath", EVENT_UNIT_DEATH_STATE_CHANGED, REGISTER_FILTER_COMBAT_UNIT_TYPE, COMBAT_UNIT_TYPE_PLAYER )
end
-- very messy testing. no good answers yet
if GetDisplayName() ~= "@nogetrandom" then return end
EM:UnregisterForEvent( Speedrun.name .. "NecroBossChanged", EVENT_BOSSES_CHANGED )
EM:UnregisterForUpdate( Speedrun.name .. "NecroBossUpdate" )
for id, effect in pairs(portalZones) do
for i = 1, #portalZones[id] do
local e = portalZones[id][i]
if e then
EM:UnregisterForEvent(Speedrun.name .. "NecroEffectChanged" .. e, EVENT_EFFECT_CHANGED)
-- EM:UnregisterForEvent(Speedrun.name .. "Portal" .. e, EVENT_COMBAT_EVENT)
end
end
if id == zone then
inPortalZone = true
for i = 1, #portalZones[id] do
local e = portalZones[id][i]
if e then
EM:RegisterForEvent(Speedrun.name .. "NecroEffectChanged" .. e, EVENT_EFFECT_CHANGED, OnNecroEffectChanged)
EM:AddFilterForEvent(Speedrun.name .. "NecroEffectChanged" .. e, EVENT_EFFECT_CHANGED,
REGISTER_FILTER_ABILITY_ID, e)
-- REGISTER_FILTER_UNIT_TAG_PREFIX, "player",
-- EM:RegisterForEvent( Speedrun.name .. "Portal" .. e, EVENT_COMBAT_EVENT, NecroModePortal )
-- EM:AddFilterForEvent( Speedrun.name .. "Portal" .. e, EVENT_COMBAT_EVENT,
-- REGISTER_FILTER_TARGET_COMBAT_UNIT_TYPE, COMBAT_UNIT_TYPE_PLAYER,
-- REGISTER_FILTER_ABILITY_ID, e )
end
Speedrun:dbg(2, "Necro Mode check for: <<1>>", GetAbilityName(e))
end
end
end
if inPortalZone then
EM:RegisterForEvent( Speedrun.name .. "NecroBossChanged", EVENT_BOSSES_CHANGED, NecroBossChanged)
EM:RegisterForUpdate( Speedrun.name .. "NecroBossUpdate", 50, NecroBossUpdate )
end
end
function Speedrun.UpdateNecroMode()
EM:UnregisterForEvent( Speedrun.name .. "PortalDeath", EVENT_UNIT_DEATH_STATE_CHANGED )
EM:UnregisterForEvent( Speedrun.name .. "NecroCombat", EVENT_PLAYER_COMBAT_STATE )
if cV.hgNecro then
RegisterNecroEvents()
if not necromodeOn then necromodeOn = true end
else
if necromodeOn then necromodeOn = false
-- currently for testing
if GetDisplayName() == "@nogetrandom" then
for id, effect in pairs(portalZones) do
for i = 1, #portalZones[id] do
local e = portalZones[id][i]
if e then EM:UnregisterForEvent( Speedrun.name .. "Portal" .. e, EVENT_COMBAT_EVENT ) end
end
end
end
end
end
end
function Speedrun.ConfigureHideGroup()
Speedrun.HideGroup(ShouldHideGroup())
if cV.hgNecro then Speedrun.UpdateNecroMode() end
end
function Speedrun.HideGroupToggle()
cV.groupHidden = not cV.groupHidden
Speedrun.HideGroup(cV.groupHidden)
end
function Speedrun.HideGroup(hide) --copied from HideGroup by Wheels - thanks!
if hide == true then
SetCrownCrateNPCVisible(true)
if Speedrun.groupIsHidden ~= hide then StoreNameplateSettings() end
if cV.groupHidden ~= hide then Speedrun:dbg(0, "Hiding Group Members") end
if sV.changeNameplates then Speedrun.AlterNameplateSettings() end
if sV.changeHealthBars then Speedrun.AlterHealthBarSettings() end
else
if Speedrun.groupIsHidden ~= hide then
if not cV.hgNecro and cV.hgAutoShow then ForceGroupVisible()
else ShowGroup() end
end
end
Speedrun.groupIsHidden = hide
end
function Speedrun.ConfigureCombatInteractBlocker()
ZO_PreHook(PLAYER_TO_PLAYER, "ShowPlayerInteractMenu", function(shouldBlock)
if IsUnitInCombat("player") then
local block = false
if cV.interactBlockAny then
block = cV.interactBlockAny
else
if (IsInCampaign() or IsActiveWorldBattleground()) then
block = cV.interactBlockPvP
elseif Speedrun.IsInTrialZone() then
block = cV.interactBlockTrial
end
end
if block then
return true
end
end
end)
end
function Speedrun.PrintScoreReasons()
Speedrun:dbg(0, "[|cffffffCurrent Trial|r |cdf4242Score|r |cffffffFactors|r]")
for k, v in pairs(Speedrun.scores) do
local score = Speedrun.scores[k]
if score.id ~= RAID_POINT_REASON_LIFE_REMAINING then
if score.times > 0 then
Speedrun:post('|cdf4242' .. score.name .. '|r' .. ' x ' .. score.times .. ' = ' .. score.total .. ' points.')
end
else
zo_callLater(function()
if score.times > 0 then Speedrun:post('|cdf4242' .. score.name .. '|r' .. ' x ' .. score.times) end
end, 50)
end
end
end
function Speedrun.UpdateScoreFactors(profile, raid)
for k, v in pairs(Speedrun.scores) do
local score = Speedrun.scores[k]
if (score.id ~= RAID_POINT_REASON_LIFE_REMAINING and score.times > 0) then
if sV.profiles[profile].raidList[raid].scoreFactors.scoreReasons[k] == nil then
sV.profiles[profile].raidList[raid].scoreFactors.scoreReasons[k] = score
else
local factor = sV.profiles[profile].raidList[raid].scoreFactors.scoreReasons[k]
if (factor.times < score.times) then
factor.times = score.times
sV.profiles[profile].raidList[raid].scoreFactors.scoreReasons[k].times = factor.times
end
if factor.total < score.total then
factor.total = score.total
sV.profiles[profile].raidList[raid].scoreFactors.scoreReasons[k].total = factor.total
end
end
end
end
local best = sV.profiles[profile].raidList[raid].scoreFactors
if ((best.bestTime == nil) or (best.bestTime > sV.totalTime)) then
best.bestTime = sV.totalTime
end
if ((best.bestScore == nil) or (best.bestScore < sV.finalScore)) then
best.bestScore = sV.finalScore
end
if not Speedrun.IsInTrialZone() then return end
local vit = GetRaidReviveCountersRemaining()
if vit > 0 then
if ((best.vitality < vit) or (best.vitality == nil)) then
best.vitality = vit
end
end
end
function Speedrun.GetTrialMaxVitality(raidID)
local vitality
if raidID == 638 or raidID == 636 or raidID == 639 or raidID == 1082 or raidID == 635 then
vitality = 24
elseif raidID == 725 or raidID == 975 or raidID == 1000 or raidID == 1051 or raidID == 1121 or raidID == 1196 or raidID == 1263 then
vitality = 36
elseif raidID == 677 or raidID == 1227 then
vitality = 15
else
viatality = 0
end
return vitality
end
function Speedrun.ResolveTrialDiffculty()
local inTrial = false
local zone = GetZoneId(GetUnitZoneIndex("player"))
for id in pairs(Speedrun.Data.raidList) do
if id == zone then inTrial = true end
end
if inTrial then
if GetCurrentZoneDungeonDifficulty() == DUNGEON_DIFFICULTY_VETERAN then
return true
else
return false
end
else
if IsUnitGrouped("player") then return IsGroupUsingVeteranDifficulty()
else return IsUnitUsingVeteranDifficulty("player") end
end
end
function Speedrun.BestPossible(raidID)
local timer = 0
local vitality = Speedrun.GetTrialMaxVitality(raidID)
for i, x in pairs(Speedrun.customTimerSteps[raidID]) do
if Speedrun.GetSavedTimer(raidID, i) then
timer = Speedrun.GetSavedTimer(raidID, i) + timer
end
end
local t = timer > 0 and (timer / 1000) or 0
local score = math.floor(Speedrun.GetScore(t, vitality, raidID)) --= 0
if score <= 0 then return "0" end
local scoreString = Speedrun.FormatRaidScore(score)
-- TODO Calculate the score using saved score factors if any exists.
Speedrun.isScoreSet = true
return scoreString
end
-- functions for debugging and maybe useful for new functions
function Speedrun.SetLastTrial()