Repository navigation
Expand file tree
/
Copy pathEvents.lua
More file actions
1083 lines (945 loc) · 36.2 KB
/
Copy pathEvents.lua
File metadata and controls
1083 lines (945 loc) · 36.2 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
---@diagnostic disable: undefined-global, undefined-field
-- Event handlers for local-only MVP tracking.
local SC = Softcore
local eventFrame
local WARNING_EVENTS = {
AUCTION_HOUSE_SHOW = { rule = "auctionHouse", detail = "Auction house opened." },
}
local ACCESS_EVENTS = {
BANKFRAME_OPENED = { rule = "bank", detail = "Player bank opened." },
GUILDBANKFRAME_OPENED = { rule = "guildBank", detail = "Guild bank opened." },
VOID_STORAGE_OPEN = { rule = "voidStorage", detail = "Void storage opened." },
CRAFTINGORDERS_SHOW_CUSTOMER = { rule = "craftingOrders", detail = "Crafting orders opened." },
MERCHANT_SHOW = { rule = "vendor", detail = "Vendor opened." },
}
local movementState = {
mounted = false,
flying = false,
vehicleActive = false,
vehicleReason = nil,
mountWarnedAt = 0,
flyingWarnedAt = 0,
flightPathWarnedAt = 0,
}
local MOVEMENT_WARNING_THROTTLE = 30
local ACCESS_WARNING_THROTTLE = 30
local CONSUMABLE_USE_CONFIRM_WINDOW = 4
local accessWarnedAt = {}
local warningWarnedAt = {}
local petBattleActive = false
local pendingConsumableUse = nil
local lastKnownXP = nil
local lastKnownXPLevel = nil
local DRUID_TRAVEL_FORM_ID = 3
local WORGEN_RUNNING_WILD_SPELL_ID = 87840
local DRACTHYR_SOAR_SPELL_ID = 369536
local function Broadcast(reason)
if SC.Sync_BroadcastStatus then
SC:Sync_BroadcastStatus(reason)
end
end
local function HandlePlayerDead()
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active then return end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then return end
local playerKey = SC:GetPlayerKey()
local participant = SC:GetOrCreateParticipant(playerKey)
if participant.status == "FAILED" then return end
db.run.deathCount = (db.run.deathCount or 0) + 1
participant.deathCount = (participant.deathCount or 0) + 1
local announcementDetail
local maxDeaths = db.run.ruleset and db.run.ruleset.maxDeaths
local maxDeathsValue = tonumber(db.run.ruleset and db.run.ruleset.maxDeathsValue) or 1
if maxDeaths and maxDeathsValue > 1 then
if participant.deathCount >= maxDeathsValue then
local detail = "Death limit reached (" .. participant.deathCount .. "/" .. maxDeathsValue .. " deaths)."
announcementDetail = detail
SC:AddLog("DEATH", detail)
SC:MarkParticipantFailed(playerKey, detail)
SC:AddViolation("death", detail, "FATAL", playerKey)
DEFAULT_CHAT_FRAME:AddMessage("|cffff5555Softcore: character failed — death limit reached (" .. participant.deathCount .. "/" .. maxDeathsValue .. ").|r")
else
local remaining = maxDeathsValue - participant.deathCount
local detail = "Died (" .. participant.deathCount .. "/" .. maxDeathsValue .. " deaths, " .. remaining .. " remaining)."
announcementDetail = detail
SC:AddLog("DEATH", detail)
db.run.warningCount = (db.run.warningCount or 0) + 1
if participant.status == "ACTIVE" then
participant.status = "WARNING"
end
SC:AddViolation("death", detail, "WARNING", playerKey)
DEFAULT_CHAT_FRAME:AddMessage("|cfffbbf24Softcore: death recorded — " .. remaining .. " life/lives remaining.|r")
end
else
announcementDetail = "Character died. Character failed permanently."
SC:AddLog("DEATH", "Character died. Run failed permanently.")
SC:ApplyRuleOutcome("death", {
playerKey = playerKey,
detail = announcementDetail,
})
DEFAULT_CHAT_FRAME:AddMessage("|cffff5555Softcore: character failed due to death.|r")
end
if SC.AnnounceLocalDeath then
SC:AnnounceLocalDeath(announcementDetail)
end
Broadcast("PLAYER_DEAD")
end
local function HandleLevelUp(...)
local db = SC.db or SoftcoreDB
if not db then
return
end
-- PLAYER_LEVEL_UP passes the new level as the first payload; prefer it over UnitLevel in this callback.
local previousLevel = tonumber(db.character and db.character.level or 0) or 0
local eventLevel = select(1, ...)
local newLevel = tonumber(eventLevel) or UnitLevel("player") or previousLevel
if newLevel < previousLevel then
if SC.TraceDebug then
SC:TraceDebug("LEVEL_UP_REGRESSED", {
eventLevel = newLevel,
observedLevel = previousLevel,
})
end
newLevel = previousLevel
end
db.character.level = newLevel
if not db.run or not db.run.active or (SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed()) then
return
end
SC:GetOrCreateParticipant(SC:GetPlayerKey()).currentLevel = db.character.level
SC:AddLog("LEVEL_UP", "Reached level " .. tostring(db.character.level) .. ".")
if SC.Achievements_OnLevelChanged then
SC:Achievements_OnLevelChanged(db.character.level)
end
Broadcast("PLAYER_LEVEL_UP")
end
local function CapturePlayerXP()
lastKnownXP = UnitXP and UnitXP("player") or nil
lastKnownXPLevel = UnitLevel and UnitLevel("player") or nil
end
local function HandlePlayerXPUpdate(unit)
if unit and unit ~= "player" then
return
end
local currentXP = UnitXP and UnitXP("player") or nil
local currentLevel = UnitLevel and UnitLevel("player") or nil
if currentXP == nil or currentLevel == nil then
return
end
local gained = false
if lastKnownXP ~= nil and lastKnownXPLevel ~= nil then
gained = currentLevel > lastKnownXPLevel or (currentLevel == lastKnownXPLevel and currentXP > lastKnownXP)
end
lastKnownXP = currentXP
lastKnownXPLevel = currentLevel
if not gained then
return
end
if SC.CheckPartyProgressIntegrity then
SC:CheckPartyProgressIntegrity("Gained XP")
end
end
local function HandleZoneChanged()
local db = SC.db or SoftcoreDB
if not db then return end
db.character.zone = GetRealZoneText() or db.character.zone or "Unknown"
if not db.run or not db.run.active or (SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed()) then
return
end
end
local pvpWarnedAt = 0
local PVP_WARNING_THROTTLE = 60
local PVP_ADVISORY_THROTTLE = 300
local pvpAdvisoryWarnedAt = {}
function SC:ResetEventTracking()
movementState.mounted = false
movementState.flying = false
movementState.vehicleActive = false
movementState.vehicleReason = nil
movementState.mountWarnedAt = 0
movementState.flyingWarnedAt = 0
movementState.flightPathWarnedAt = 0
accessWarnedAt = {}
warningWarnedAt = {}
pvpWarnedAt = 0
pvpAdvisoryWarnedAt = {}
pendingConsumableUse = nil
petBattleActive = false
CapturePlayerXP()
end
local function IsRunActiveForPvpAdvisory()
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active then return false end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then return false end
return true
end
local function IsRunActiveForLocalAudit()
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active then return false end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then return false end
return true
end
local function SafeUnitBoolean(func, unit)
if not func then return false end
local ok, result = pcall(func, unit)
return ok and result == true
end
local function SafeGlobalBoolean(func)
if not func then return false end
local ok, result = pcall(func)
return ok and result == true
end
local function IsPlayerAuraBySpellIdActive(spellId)
if not spellId then return false end
if C_UnitAuras and C_UnitAuras.GetPlayerAuraBySpellID then
local ok, aura = pcall(C_UnitAuras.GetPlayerAuraBySpellID, spellId)
if ok and aura then
return true
end
end
if AuraUtil and AuraUtil.FindAuraByName and GetSpellInfo then
local spellName = GetSpellInfo(spellId)
if spellName then
local aura = AuraUtil.FindAuraByName(spellName, "player", "HELPFUL")
return aura ~= nil
end
end
return false
end
local function AddLocalAudit(kind, message, extra)
if not IsRunActiveForLocalAudit() then return end
extra = extra or {}
extra.suppressAuditSync = true
SC:AddLog(kind, message, extra)
end
local function IsWarModeActive()
if not C_PvP then return false end
if C_PvP.IsWarModeActive then
local ok, active = pcall(C_PvP.IsWarModeActive)
if ok and active then return true end
end
if C_PvP.IsWarModeDesired then
local ok, desired = pcall(C_PvP.IsWarModeDesired)
if ok and desired then return true end
end
return false
end
local function WarnPvpAdvisory(key, detail)
if not IsRunActiveForPvpAdvisory() then return end
local now = time()
if now - (pvpAdvisoryWarnedAt[key] or 0) < PVP_ADVISORY_THROTTLE then
return
end
pvpAdvisoryWarnedAt[key] = now
DEFAULT_CHAT_FRAME:AddMessage("|cfffbbf24Softcore: " .. tostring(detail) .. "|r")
SC:AddLog("PVP_ADVISORY", detail, {
suppressAuditSync = true,
})
end
local function CheckPlayerPvpAdvisory()
if not IsRunActiveForPvpAdvisory() then return end
if IsWarModeActive() then
WarnPvpAdvisory("warMode", "War Mode is enabled during this run.")
elseif UnitIsPVP and UnitIsPVP("player") then
WarnPvpAdvisory("playerPvpFlag", "Your character is PvP flagged during this run.")
end
end
local function CheckInstancedPvP()
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active then return end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then return end
local _, instanceType = GetInstanceInfo()
if instanceType ~= "pvp" and instanceType ~= "arena" then return end
local now = time()
if now - pvpWarnedAt < PVP_WARNING_THROTTLE then return end
pvpWarnedAt = now
SC:ApplyRuleOutcome("instancedPvP", {
playerKey = SC:GetPlayerKey(),
detail = "Entered instanced PvP (" .. tostring(instanceType) .. ").",
})
Broadcast("instancedPvP")
end
local function HandleWarning(event)
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active or (SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed()) then
return
end
local warning = WARNING_EVENTS[event]
local now = time()
if now - (warningWarnedAt[warning.rule] or 0) < ACCESS_WARNING_THROTTLE then
return
end
warningWarnedAt[warning.rule] = now
SC:ApplyRuleOutcome(warning.rule, {
playerKey = SC:GetPlayerKey(),
detail = warning.detail,
})
Broadcast(event)
end
local function HasActiveLocalViolation(ruleName, detail)
local db = SC.db or SoftcoreDB
local playerKey = SC:GetPlayerKey()
for _, violation in ipairs(db and db.violations or {}) do
if violation.status ~= "CLEARED"
and violation.shared ~= true
and violation.playerKey == playerKey
and violation.type == ruleName
and violation.detail == detail then
return true
end
end
return false
end
local function ApplyAccessRule(ruleName, detail, force)
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active or (SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed()) then
return
end
if HasActiveLocalViolation(ruleName, detail) then
return
end
local now = time()
if not force and now - (accessWarnedAt[ruleName] or 0) < ACCESS_WARNING_THROTTLE then
return
end
accessWarnedAt[ruleName] = now
SC:ApplyRuleOutcome(ruleName, {
playerKey = SC:GetPlayerKey(),
detail = detail,
})
Broadcast(ruleName)
end
local function HandleTradeAcceptUpdate(playerAccepted, targetAccepted)
if (playerAccepted ~= 1 and playerAccepted ~= true) or
(targetAccepted ~= 1 and targetAccepted ~= true) then
return
end
ApplyAccessRule("trade", "Trade accepted.")
end
local function ApplyMailboxAction(detail)
ApplyAccessRule("mailbox", detail)
end
local function HandleAccessEvent(event)
local access = ACCESS_EVENTS[event]
if access then
ApplyAccessRule(access.rule, access.detail)
end
end
local function IsWarbandBankUIVisible()
local panel = _G.AccountBankPanel
if panel and panel.IsShown and panel:IsShown() then
return true
end
local bankPanel = _G.BankPanel or (_G.BankFrame and _G.BankFrame.BankPanel)
if bankPanel and bankPanel.IsShown and bankPanel:IsShown() then
if bankPanel.GetActiveBankType and Enum and Enum.BankType and bankPanel:GetActiveBankType() == Enum.BankType.Account then
return true
end
if bankPanel.selectedTabID and Enum and Enum.BagIndex then
for key, value in pairs(Enum.BagIndex) do
if value == bankPanel.selectedTabID and string.find(tostring(key), "AccountBankTab", 1, true) then
return true
end
end
end
end
if C_Bank and C_Bank.IsBankOpen and Enum and Enum.BankType then
local ok, open = pcall(C_Bank.IsBankOpen, Enum.BankType.Account)
if ok and open then
return true
end
end
return false
end
local function IsAccountBankerInteraction()
if C_PlayerInteractionManager
and C_PlayerInteractionManager.IsInteractingWithNpcOfType
and Enum
and Enum.PlayerInteractionType
and Enum.PlayerInteractionType.AccountBanker then
local ok, interacting = pcall(C_PlayerInteractionManager.IsInteractingWithNpcOfType, Enum.PlayerInteractionType.AccountBanker)
return ok and interacting == true
end
return false
end
local function IsWarbandBankAccessEvent(event, ...)
local bankType = ...
-- Warband / account bank (The War Within+). ACCOUNT_BANK_PANEL_OPENED is a direct open signal.
-- PLAYER_ACCOUNT_BANK_TAB_SLOTS_CHANGED and BANK_TABS_CHANGED (Account) can fire from client
-- sync without the bank UI shown — e.g. around flight masters / taxi — so require a visible
-- account-bank panel (or C_Bank.IsBankOpen) for those.
if event == "ACCOUNT_BANK_PANEL_OPENED" then
return true
end
if event == "BANKFRAME_OPENED" then
return IsAccountBankerInteraction() or IsWarbandBankUIVisible()
end
if event == "PLAYER_ACCOUNT_BANK_TAB_SLOTS_CHANGED" then
return IsAccountBankerInteraction() or IsWarbandBankUIVisible()
end
if Enum and Enum.BankType and bankType == Enum.BankType.Account then
return IsAccountBankerInteraction() or IsWarbandBankUIVisible()
end
return false
end
local function IsFrameShown(frameName)
local frame = _G[frameName]
return frame and frame.IsShown and frame:IsShown()
end
local ACCESS_RECHECKS = {
auctionHouse = function()
return IsFrameShown("AuctionHouseFrame") and "Auction house opened."
end,
bank = function()
return IsFrameShown("BankFrame") and "Player bank opened."
end,
guildBank = function()
return IsFrameShown("GuildBankFrame") and "Guild bank opened."
end,
vendor = function()
return IsFrameShown("MerchantFrame") and "Vendor opened."
end,
voidStorage = function()
return IsFrameShown("VoidStorageFrame") and "Void storage opened."
end,
craftingOrders = function()
return (IsFrameShown("ProfessionsCustomerOrdersFrame") or IsFrameShown("CraftingOrderFrame")) and "Crafting orders opened."
end,
warbandBank = function()
return IsWarbandBankUIVisible() and "Warband bank opened or accessed."
end,
}
function SC:RecheckAccessRuleState(ruleName)
local recheck = ACCESS_RECHECKS[ruleName]
local detail = recheck and recheck()
if detail then
ApplyAccessRule(ruleName, detail, true)
end
end
local function SafeRegisterEvent(frame, event)
-- Some storage APIs are expansion/client-version sensitive. pcall keeps older clients
-- from failing addon load while still allowing /etrace verification on Retail.
pcall(frame.RegisterEvent, frame, event)
end
local function GetForcedMovementReason()
if SafeUnitBoolean(UnitOnTaxi, "player") then
return "taxi"
end
if SafeUnitBoolean(UnitInVehicle, "player")
or SafeUnitBoolean(UnitUsingVehicle, "player")
or SafeUnitBoolean(UnitHasVehicleUI, "player")
or SafeGlobalBoolean(CanExitVehicle) then
return "vehicle"
end
if SafeGlobalBoolean(HasOverrideActionBar) then
return "override"
end
return nil
end
local function FormatForcedMovementReason(reason)
if reason == "taxi" then return "taxi or forced flight" end
if reason == "override" then return "override action bar" end
return "vehicle"
end
local function IsDruidGroundTravelFormActive(flying)
if not UnitClass or not GetShapeshiftFormID then
return false
end
local _, classFile = UnitClass("player")
if classFile ~= "DRUID" then
return false
end
local formId = GetShapeshiftFormID()
if formId ~= DRUID_TRAVEL_FORM_ID then
return false
end
if flying or SafeGlobalBoolean(IsSwimming) then
return false
end
return true
end
local function IsWorgenRunningWildActive()
return IsPlayerAuraBySpellIdActive(WORGEN_RUNNING_WILD_SPELL_ID)
end
local function IsDracthyrSoarActive()
return IsPlayerAuraBySpellIdActive(DRACTHYR_SOAR_SPELL_ID)
end
local function ApplyMovementRule(ruleName, detail, throttleField, force)
if not IsRunActiveForLocalAudit() then
return
end
if HasActiveLocalViolation(ruleName, detail) then
return
end
local now = time()
if not force and now - (movementState[throttleField] or 0) < MOVEMENT_WARNING_THROTTLE then
return
end
movementState[throttleField] = now
SC:ApplyRuleOutcome(ruleName, {
playerKey = SC:GetPlayerKey(),
detail = detail,
})
Broadcast(ruleName)
end
local function CheckMovementRules(force)
local db = SC.db or SoftcoreDB
if not db or not db.run or not db.run.active then
return
end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then
return
end
local forcedReason = GetForcedMovementReason()
if forcedReason then
if not movementState.vehicleActive or movementState.vehicleReason ~= forcedReason then
AddLocalAudit("FORCED_MOVEMENT", "Vehicle or forced movement active: " .. FormatForcedMovementReason(forcedReason) .. ".", {
reason = forcedReason,
})
end
movementState.vehicleActive = true
movementState.vehicleReason = forcedReason
movementState.mounted = false
movementState.flying = false
return
elseif movementState.vehicleActive then
AddLocalAudit("FORCED_MOVEMENT_ENDED", "Vehicle or forced movement ended.", {
reason = movementState.vehicleReason,
})
movementState.vehicleActive = false
movementState.vehicleReason = nil
movementState.mounted = false
movementState.flying = false
end
local mounted = IsMounted and IsMounted()
-- In-game verification note: IsFlying() should catch mounted flight and Druid flight form
-- in modern clients, but shapeshift edge cases may need live testing.
local flying = IsFlying and IsFlying()
local druidGroundTravelForm = IsDruidGroundTravelFormActive(flying)
local runningWild = IsWorgenRunningWildActive()
local dracthyrSoar = IsDracthyrSoarActive()
if (mounted or druidGroundTravelForm or runningWild) and (force or not movementState.mounted) then
local detail = runningWild
and "Used Worgen Running Wild while on a Softcore run."
or druidGroundTravelForm
and "Used Druid land Travel Form while on a Softcore run."
or "Mounted while on a Softcore run."
ApplyMovementRule("mounts", detail, "mountWarnedAt", force)
end
if (flying or dracthyrSoar) and (force or not movementState.flying) then
ApplyMovementRule("flying", dracthyrSoar and "Used Dracthyr Soar while on a Softcore run." or "Flying while on a Softcore run.", "flyingWarnedAt", force)
end
movementState.mounted = (mounted or druidGroundTravelForm or runningWild) and true or false
movementState.flying = (flying or dracthyrSoar) and true or false
end
local function ApplyFlightPathRule(detail)
ApplyMovementRule("flightPaths", detail or "Used a flight path while on a Softcore run.", "flightPathWarnedAt")
end
local function GetMonotonicTime()
if GetTime then
return GetTime()
end
return time()
end
local function GetItemInfoCompat(itemRef)
if C_Item and C_Item.GetItemInfo then
local ok, itemName, link, quality, itemLevel, reqLevel, itemType, itemSubType = pcall(C_Item.GetItemInfo, itemRef)
if ok then
return itemName, link, quality, itemLevel, reqLevel, itemType, itemSubType
end
---@diagnostic disable-next-line: deprecated
elseif GetItemInfo then
---@diagnostic disable-next-line: deprecated
local ok, itemName, link, quality, itemLevel, reqLevel, itemType, itemSubType = pcall(GetItemInfo, itemRef)
if ok then
return itemName, link, quality, itemLevel, reqLevel, itemType, itemSubType
end
end
return nil
end
local function GetItemSpellCompat(itemRef)
if C_Item and C_Item.GetItemSpell then
local ok, spellName, spellID = pcall(C_Item.GetItemSpell, itemRef)
if ok then
return spellName, spellID
end
---@diagnostic disable-next-line: deprecated
elseif GetItemSpell then
---@diagnostic disable-next-line: deprecated
local ok, spellName, spellID = pcall(GetItemSpell, itemRef)
if ok then
return spellName, spellID
end
end
return nil
end
local function GetSpellNameCompat(spellID)
if not spellID then return nil end
if C_Spell and C_Spell.GetSpellInfo then
local ok, info = pcall(C_Spell.GetSpellInfo, spellID)
if ok then
return info and info.name
end
elseif GetSpellInfo then
local ok, spellName = pcall(GetSpellInfo, spellID)
if ok then
return spellName
end
end
return nil
end
local function IsPendingConsumableExpired()
return pendingConsumableUse
and GetMonotonicTime() - (pendingConsumableUse.queuedAt or 0) > CONSUMABLE_USE_CONFIRM_WINDOW
end
local function ClearExpiredConsumableUse()
if IsPendingConsumableExpired() then
pendingConsumableUse = nil
end
end
local function ApplyConfirmedConsumableRule(pending)
if not pending then return end
if not SC:IsRunActive() then return end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then return end
local rule = SC:GetRule("consumables")
if not rule or rule == "ALLOWED" then return end
SC:ApplyRuleOutcome("consumables", {
playerKey = SC:GetPlayerKey(),
detail = pending.detail,
})
end
local function PendingConsumableMatchesSpell(spellID)
ClearExpiredConsumableUse()
local pending = pendingConsumableUse
if not pending then
return false
end
if pending.spellID and spellID then
return tonumber(pending.spellID) == tonumber(spellID)
end
if pending.spellName and spellID then
return pending.spellName == GetSpellNameCompat(spellID)
end
return not pending.spellID and not pending.spellName
end
local function QueueConsumableRule(itemRef)
if not SC:IsRunActive() then return end
if SC.IsLocalCharacterFailed and SC:IsLocalCharacterFailed() then return end
local rule = SC:GetRule("consumables")
if not rule or rule == "ALLOWED" then return end
ClearExpiredConsumableUse()
local itemName, link, _, _, _, itemType, itemSubType = GetItemInfoCompat(itemRef)
if itemType ~= "Consumable" or itemSubType == "Other" then return end
local spellName, spellID = GetItemSpellCompat(itemRef)
local pending = {
queuedAt = GetMonotonicTime(),
spellName = spellName,
spellID = spellID,
detail = "Used consumable: " .. tostring(link or itemName or itemRef or "?") .. " (" .. tostring(itemSubType or "?") .. ").",
}
if spellName or spellID then
pendingConsumableUse = pending
else
-- Some item-like consumables do not expose a spell. Keep the previous behavior for
-- those rare cases while confirming normal potion/food uses through spell success.
ApplyConfirmedConsumableRule(pending)
end
end
local function HandleConsumableSpellcastSucceeded(unit, _, spellID)
if unit ~= "player" or not PendingConsumableMatchesSpell(spellID) then
return
end
local pending = pendingConsumableUse
pendingConsumableUse = nil
ApplyConfirmedConsumableRule(pending)
end
local function HandleConsumableSpellcastFailed(unit, _, spellID)
if unit ~= "player" or not PendingConsumableMatchesSpell(spellID) then
return
end
pendingConsumableUse = nil
end
local function HandlePetBattleStarted()
if petBattleActive then return end
petBattleActive = true
AddLocalAudit("PET_BATTLE_STARTED", "Pet battle started.", {
allowedByDefault = true,
})
end
local function HandlePetBattleEnded()
if not petBattleActive then return end
petBattleActive = false
AddLocalAudit("PET_BATTLE_ENDED", "Pet battle ended.", {
allowedByDefault = true,
})
end
function SC:CheckMovementRules(force)
CheckMovementRules(force)
end
function SC:Events_Register()
if eventFrame then
return
end
eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_DEAD")
eventFrame:RegisterEvent("PLAYER_LEVEL_UP")
SafeRegisterEvent(eventFrame, "PLAYER_XP_UPDATE")
eventFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
eventFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
eventFrame:RegisterEvent("BAG_UPDATE_DELAYED")
SafeRegisterEvent(eventFrame, "GET_ITEM_INFO_RECEIVED")
eventFrame:RegisterEvent("TRADE_ACCEPT_UPDATE")
eventFrame:RegisterEvent("AUCTION_HOUSE_SHOW")
eventFrame:RegisterEvent("BANKFRAME_OPENED")
eventFrame:RegisterEvent("GUILDBANKFRAME_OPENED")
eventFrame:RegisterEvent("MERCHANT_SHOW")
SafeRegisterEvent(eventFrame, "VOID_STORAGE_OPEN")
SafeRegisterEvent(eventFrame, "CRAFTINGORDERS_SHOW_CUSTOMER")
SafeRegisterEvent(eventFrame, "ACCOUNT_BANK_PANEL_OPENED")
SafeRegisterEvent(eventFrame, "BANK_TABS_CHANGED")
SafeRegisterEvent(eventFrame, "PLAYER_ACCOUNT_BANK_TAB_SLOTS_CHANGED")
eventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED")
SafeRegisterEvent(eventFrame, "PLAYER_FLAGS_CHANGED")
SafeRegisterEvent(eventFrame, "TAXIMAP_OPENED")
SafeRegisterEvent(eventFrame, "TAXIMAP_CLOSED")
SafeRegisterEvent(eventFrame, "UNIT_ENTERING_VEHICLE")
SafeRegisterEvent(eventFrame, "UNIT_ENTERED_VEHICLE")
SafeRegisterEvent(eventFrame, "UNIT_EXITING_VEHICLE")
SafeRegisterEvent(eventFrame, "UNIT_EXITED_VEHICLE")
SafeRegisterEvent(eventFrame, "UPDATE_OVERRIDE_ACTIONBAR")
SafeRegisterEvent(eventFrame, "VEHICLE_UPDATE")
SafeRegisterEvent(eventFrame, "PLAYER_CONTROL_LOST")
SafeRegisterEvent(eventFrame, "PLAYER_CONTROL_GAINED")
SafeRegisterEvent(eventFrame, "PET_BATTLE_OPENING_START")
SafeRegisterEvent(eventFrame, "PET_BATTLE_CLOSE")
eventFrame:RegisterUnitEvent("UNIT_AURA", "player")
eventFrame:RegisterUnitEvent("UNIT_FACTION", "player")
eventFrame:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
eventFrame:RegisterUnitEvent("UNIT_SPELLCAST_FAILED", "player")
eventFrame:RegisterUnitEvent("UNIT_SPELLCAST_INTERRUPTED", "player")
eventFrame:SetScript("OnEvent", function(_, event, ...)
if event == "PLAYER_DEAD" then
HandlePlayerDead()
elseif event == "PLAYER_LEVEL_UP" then
HandleLevelUp(...)
if SC.CheckMaxLevelGap then
SC:CheckMaxLevelGap(true)
end
if SC.CheckPartyProgressIntegrity then
SC:CheckPartyProgressIntegrity("Leveled up")
end
CapturePlayerXP()
elseif event == "PLAYER_XP_UPDATE" then
HandlePlayerXPUpdate(...)
elseif event == "ZONE_CHANGED_NEW_AREA" then
HandleZoneChanged()
CheckInstancedPvP()
CheckPlayerPvpAdvisory()
if SC.CheckInstanceIntegrity then
SC:CheckInstanceIntegrity()
end
elseif event == "PLAYER_EQUIPMENT_CHANGED" then
if SC.ScanEquippedGear then
SC:ScanEquippedGear(true)
end
elseif event == "BAG_UPDATE_DELAYED" then
if SC.ScanEquippedGear then
SC:ScanEquippedGear(false)
end
elseif event == "GET_ITEM_INFO_RECEIVED" then
if SC.ScanEquippedGear then
SC:ScanEquippedGear(true)
end
elseif event == "TRADE_ACCEPT_UPDATE" then
HandleTradeAcceptUpdate(...)
elseif WARNING_EVENTS[event] then
HandleWarning(event)
elseif IsWarbandBankAccessEvent(event, ...) then
ApplyAccessRule("warbandBank", "Warband bank opened or accessed.")
elseif ACCESS_EVENTS[event] then
HandleAccessEvent(event)
elseif event == "PLAYER_MOUNT_DISPLAY_CHANGED" or event == "UNIT_AURA" or event == "UNIT_ENTERING_VEHICLE" or event == "UNIT_ENTERED_VEHICLE" or event == "UNIT_EXITING_VEHICLE" or event == "UNIT_EXITED_VEHICLE" or event == "UPDATE_OVERRIDE_ACTIONBAR" or event == "VEHICLE_UPDATE" or event == "PLAYER_CONTROL_LOST" or event == "PLAYER_CONTROL_GAINED" then
-- In-game verification note: mount/flying state updates can arrive through either
-- display, aura, vehicle, or override-bar events depending on client build and quest mechanics.
CheckMovementRules()
elseif event == "PET_BATTLE_OPENING_START" then
HandlePetBattleStarted()
elseif event == "PET_BATTLE_CLOSE" then
HandlePetBattleEnded()
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
HandleConsumableSpellcastSucceeded(...)
elseif event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_INTERRUPTED" then
HandleConsumableSpellcastFailed(...)
elseif event == "PLAYER_FLAGS_CHANGED" or event == "UNIT_FACTION" then
local unit = ...
if not unit or unit == "player" then
CheckPlayerPvpAdvisory()
end
elseif event == "TAXIMAP_OPENED" then
-- Presence of the map alone is not a violation; the taxi API hook below
-- records actual flight path use.
elseif event == "TAXIMAP_CLOSED" then
CheckMovementRules()
elseif event == "GROUP_ROSTER_UPDATE" then
if SC.ClearStalePendingProposal then
SC:ClearStalePendingProposal()
end
if SC.ClearStaleRuleAmendments then
SC:ClearStaleRuleAmendments()
end
if SC.Sync_MarkRoster then
SC:Sync_MarkRoster()
end
if SC.RefreshParticipantsFromRoster then
SC:RefreshParticipantsFromRoster()
end
if SC.CheckMaxLevelGap then
SC:CheckMaxLevelGap(true)
end
if SC.CheckPendingProposalOnRosterUpdate then
SC:CheckPendingProposalOnRosterUpdate()
end
if SC.Sync_SendHello then
SC:Sync_SendHello()
end
if SC.Sync_NudgeStatus then
SC:Sync_NudgeStatus("GROUP_ROSTER_UPDATE", { now = true })
end
if C_Timer and C_Timer.After then
C_Timer.After(2, function()
Broadcast("GROUP_ROSTER_UPDATE")
end)
else
Broadcast("GROUP_ROSTER_UPDATE")
end
elseif event == "PLAYER_ENTERING_WORLD" then
if SC.ClearStalePendingProposal then
SC:ClearStalePendingProposal()
end
if SC.ClearStaleRuleAmendments then
SC:ClearStaleRuleAmendments()
end
if SC.RefreshCharacter then
SC:RefreshCharacter()
end
if SC.Achievements_CatchUp then
SC:Achievements_CatchUp()
end
if SC.ScanEquippedGear then
SC:ScanEquippedGear(true)
end
CheckInstancedPvP()
if SC.CheckInstanceIntegrity then
SC:CheckInstanceIntegrity()
end
if SC.CheckMaxLevelGap then
SC:CheckMaxLevelGap(true)
end
if SC.EnforceActionCamSettings then
SC:EnforceActionCamSettings()
end
CheckPlayerPvpAdvisory()
CapturePlayerXP()
Broadcast("PLAYER_ENTERING_WORLD")
end
if SC.HUD_Refresh then
SC:HUD_Refresh()
end
end)
local function OnUseContainerItem(bag, slot)
if not (C_Container and C_Container.GetContainerItemLink) then return end
QueueConsumableRule(C_Container.GetContainerItemLink(bag, slot))
end
local function OnUseAction(slot)
if not GetActionInfo then return end
local actionType, itemId = GetActionInfo(slot)
if actionType == "item" and itemId then
QueueConsumableRule(itemId)
end
end
if C_Container and C_Container.UseContainerItem then
hooksecurefunc(C_Container, "UseContainerItem", OnUseContainerItem)
else