forked from Zarant/WoW_Hardcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardcore.lua
More file actions
1611 lines (1402 loc) · 51.4 KB
/
Copy pathHardcore.lua
File metadata and controls
1611 lines (1402 loc) · 51.4 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
--[[
Copyright 2020 Sean Kennedy
The Hardcore AddOn is distributed under the terms of the GNU General Public License (or the Lesser GPL).
This file is part of Hardcore.
The Hardcore AddOn is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Hardcore AddOn is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Hardcore AddOn. If not, see <http://www.gnu.org/licenses/>.
--]]
--[[ Const variables ]]--
local GRIEF_WARNING_OFF = 0
local GRIEF_WARNING_SAME_FACTION = 1
local GRIEF_WARNING_ENEMY_FACTION = 2
local GRIEF_WARNING_BOTH_FACTIONS = 3
local CLASSES = {
-- Classic:
[1] = "Warrior",
[2] = "Paladin",
[3] = "Hunter",
[4] = "Rogue",
[5] = "Priest",
[7] = "Shaman",
[8] = "Mage",
[9] = "Warlock",
[11] = "Druid",
}
--[[ Global saved variables ]]--
Hardcore_Settings = {
level_list = {},
notify = true,
debug_log = {},
monitor = false,
}
--[[ Character saved variables ]]--
Hardcore_Character = {
guid = "",
time_tracked = 0, -- seconds
time_played = 0, -- seconds
accumulated_time_diff = 0, -- seconds
tracked_played_percentage = 0,
deaths = {},
bubble_hearth_incidents = {},
played_time_gap_warnings = {},
trade_partners = {},
grief_warning_conditions = GRIEF_WARNING_BOTH_FACTIONS,
}
--[[ Local variables ]]--
local debug = false
local pulses = {}
local alert_msg_time = {
PULSE = {},
ADD = {},
DEAD = {},
}
local monitor_msg_throttle = {
PULSE = {},
ADD = {},
DEAD = {},
}
local online_pulsing = {}
local guild_versions = {}
local guild_versions_status = {}
local guild_online = {}
local guild_highest_version = '0.0.0'
local guild_roster_loading = false
local bubble_hearth_vars = {
spell_id = 8690,
bubble_name = "Divine Shield",
light_of_elune_name = "Light of Elune",
}
-- addon communication
local CTL = _G.ChatThrottleLib
local COMM_NAME = "HardcoreAddon"
local COMM_PULSE_FREQUENCY = 10
local COMM_PULSE_CHECK_FREQUENCY = COMM_PULSE_FREQUENCY * 2
local COMM_UPDATE_BREAK = 4
local COMM_DELAY = 5
local COMM_BATCH_SIZE = 4
local COMM_COMMAND_DELIM = "$"
local COMM_FIELD_DELIM = "|"
local COMM_RECORD_DELIM = "^"
local COMM_COMMANDS = {
"PULSE",
"ADD", -- depreciated, we can only handle receiving
"DEAD" -- new death command
}
local COMM_SPAM_THRESHOLD = { -- msgs received within durations (s) are flagged as spam
PULSE = 3,
ADD = 180,
DEAD = 180,
}
local DEPRECATED_COMMANDS = {
UPDATE = 1,
SYNC = 1,
}
-- stuff
local PLAYER_NAME, _ = nil
local PLAYER_GUID = nil
local PLAYER_FACTION = nil
local GENDER_GREETING = {"guildmate", "brother", "sister"}
local GENDER_POSSESSIVE_PRONOUN = {"Their", "His", "Her"}
local recent_levelup = nil
local recent_msg = {}
local Last_Attack_Source = nil
local PICTURE_DELAY = .65
local HIDE_RTP_CHAT_MSG_BUFFER = 0 -- number of messages in queue
local HIDE_RTP_CHAT_MSG_BUFFER_MAX = 2 -- number of maximum messages to wait for
local STARTED_BUBBLE_HEARTH_INFO = nil
local RECEIVED_FIRST_PLAYED_TIME_MSG = false
local PLAYED_TIME_GAP_THRESH = 600 -- seconds
local PLAYED_TIME_PERC_THRESH = 98 -- [0, 100] (2 minutes every 2 hours)
local PLAYED_TIME_MIN_PLAYED_THRESH = 7200 -- seconds (2 hours)
local TIME_TRACK_PULSE = 1
local TIME_PLAYED_PULSE = 60
local COLOR_RED = "|c00ff0000"
local COLOR_GREEN = "|c0000ff00"
local COLOR_YELLOW = "|c00ffff00"
local STRING_ADDON_STATUS_SUBTITLE = "Guild Addon Status"
local STRING_ADDON_STATUS_SUBTITLE_LOADING = "Guild Addon Status (Loading)"
local THROTTLE_DURATION = 5
-- frame display
local display = "Rules"
local displaylist = Hardcore_Settings.level_list
local icon = nil
-- available alert frame/icon styles
local MEDIA_DIR = "Interface\\AddOns\\Hardcore\\Media\\"
local ALERT_STYLES = {
logo = {
frame = Hardcore_Alert_Frame, -- frame object
text = Hardcore_Alert_Text, -- text layer
icon = Hardcore_Alert_Icon, -- icon layer
file = "logo-emblem.blp", -- string
delay = COMM_DELAY, -- int seconds
alertSound = 8959
},
death = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-death.blp",
delay = COMM_DELAY,
alertSound = 8959
},
hc_green = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-hc-green.blp",
delay = COMM_DELAY,
alertSound = 8959
},
hc_red = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-hc-red.blp",
delay = COMM_DELAY,
alertSound = 8959
},
spirithealer = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-spirithealer.blp",
delay = COMM_DELAY,
alertSound = 8959
},
bubble = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-hc-red.blp",
delay = 8,
alertSound = 8959
},
hc_enabled = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-hc-red.blp",
delay = 10,
alertSound = nil
},
hc_pvp_warning = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "hc-pvp-alert.blp",
delay = 10,
alertSound = 8192
},
videre_warning = {
frame = Hardcore_Alert_Frame,
text = Hardcore_Alert_Text,
icon = Hardcore_Alert_Icon,
file = "alert-hc-red.blp",
delay = 10,
alertSound = 8959
},
}
Hardcore_Alert_Frame:SetScale(0.7)
-- the big frame object for our addon
local Hardcore = CreateFrame("Frame", "Hardcore", nil, "BackdropTemplate")
Hardcore.ALERT_STYLES = ALERT_STYLES
Hardcore_Frame:ApplyBackdrop()
--[[ Command line handler ]]--
local function SlashHandler(msg, editbox)
local _, _, cmd, args = string.find(msg, "%s?(%w+)%s?(.*)")
if cmd == "levels" then
Hardcore:Levels()
elseif cmd == "alllevels" then
Hardcore:Levels(true)
elseif cmd == "show" then
Hardcore_Frame:Show()
elseif cmd == "hide" then
-- they can click the hide button, dont really need a command for this
Hardcore_Frame:Hide()
elseif cmd == "debug" then
debug = not debug
Hardcore:Print("Debugging set to " .. tostring(debug))
elseif cmd == "alerts" then
Hardcore_Toggle_Alerts()
if Hardcore_Settings.notify then
Hardcore:Print("Alerts enabled.")
else
Hardcore:Print("Alerts disabled.")
end
elseif cmd == "monitor" then
Hardcore_Settings.monitor = not Hardcore_Settings.monitor
if Hardcore_Settings.monitor then
Hardcore:Monitor("Monitoring malicious users enabled.")
else
Hardcore:Print("Monitoring malicious users disabled.")
end
elseif cmd == "griefalert" then
local grief_alert_option = ""
for substring in args:gmatch("%S+") do
grief_alert_option = substring
end
if grief_alert_option == "off" then
Hardcore_Character.grief_warning_conditions = GRIEF_WARNING_OFF
Hardcore:Print("Grief alert set to off.")
elseif grief_alert_option == "horde" then
if PLAYER_FACTION == "Horde" then
Hardcore_Character.grief_warning_conditions = GRIEF_WARNING_SAME_FACTION
Hardcore:Print("Grief alert set to same faction.")
else
Hardcore_Character.grief_warning_conditions = GRIEF_WARNING_ENEMY_FACTION
Hardcore:Print("Grief alert set to enemy faction.")
end
elseif grief_alert_option == "alliance" then
if PLAYER_FACTION == "Alliance" then
Hardcore_Character.grief_warning_conditions = GRIEF_WARNING_SAME_FACTION
Hardcore:Print("Grief alert set to same faction.")
else
Hardcore_Character.grief_warning_conditions = GRIEF_WARNING_ENEMY_FACTION
Hardcore:Print("Grief alert set to enemy faction.")
end
elseif grief_alert_option == "both" then
Hardcore_Character.grief_warning_conditions = GRIEF_WARNING_BOTH_FACTIONS
Hardcore:Print("Grief alert set to both factions.")
else
local grief_alert_setting_msg = ""
if Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_OFF then
grief_alert_setting_msg = "off"
elseif Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_SAME_FACTION then
if PLAYER_FACTION == "Alliance" then
grief_alert_setting_msg = "same faction (alliance)"
else
grief_alert_setting_msg = "same faction (horde)"
end
elseif Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_ENEMY_FACTION then
if PLAYER_FACTION == "Alliance" then
grief_alert_setting_msg = "enemy faction (horde)"
else
grief_alert_setting_msg = "enemy faction (alliance)"
end
elseif Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_BOTH_FACTIONS then
grief_alert_setting_msg = "both factions"
end
Hardcore:Print("Grief alert is currently set to: " .. grief_alert_setting_msg)
Hardcore:Print("|cff00ff00Grief alert options:|r off horde alliance both")
end
-- Alert debug code
elseif cmd == "alert" and debug == true then
local head, tail = "", {}
for substring in args:gmatch("%S+") do
if head == "" then
head = substring
else
table.insert(tail, substring)
end
end
local style, message = head, table.concat(tail, " ")
local styleConfig
if ALERT_STYLES[style] then
styleConfig = ALERT_STYLES[style]
else
styleConfig = ALERT_STYLES.hc_red
end
Hardcore:ShowAlertFrame(styleConfig, message)
-- End Alert debug code
else
-- If not handled above, display some sort of help message
Hardcore:Print("|cff00ff00Syntax:|r/hardcore [command] [options]")
Hardcore:Print("|cff00ff00Commands:|r show hide levels alllevels alerts monitor griefalert")
end
end
SLASH_HARDCORE1, SLASH_HARDCORE2 = '/hardcore', '/hc'
SlashCmdList["HARDCORE"] = SlashHandler
local saved_variable_meta = {
{ key = "guid", initial_data = UnitGUID("player") },
{ key = "time_tracked", initial_data = 0 },
{ key = "time_played", initial_data = 0 },
{ key = "accumulated_time_diff", initial_data = 0 },
{ key = "tracked_played_percentage", initial_data = 0 },
{ key = "deaths", initial_data = {} },
{ key = "bubble_hearth_incidents", initial_data = {} },
{ key = "played_time_gap_warnings", initial_data = {} },
{ key = "trade_partners", initial_data = {} },
{ key = "grief_warning_conditions", initial_data = GRIEF_WARNING_BOTH_FACTIONS }
}
function Hardcore:InitializeSavedVariables()
if Hardcore_Character == nil then
Hardcore_Character = {}
end
for i, v in ipairs(saved_variable_meta) do
if Hardcore_Character[v.key] == nil then
Hardcore_Character[v.key] = v.initial_data
end
end
end
function Hardcore:ForceResetSavedVariables()
for i, v in ipairs(saved_variable_meta) do
Hardcore_Character[v.key] = v.initial_data
end
end
--[[ Override default WoW UI ]]--
TradeFrameTradeButton:SetScript("OnClick", function()
table.insert(Hardcore_Character.trade_partners, TradeFrameRecipientNameText:GetText())
Hardcore_Character.trade_partners = Hardcore_FilterUnique(Hardcore_Character.trade_partners)
AcceptTrade()
end)
--[[ Startup ]]--
function Hardcore:Startup()
-- the entry point of our addon
-- called inside loading screen before player sees world, some api functions are not available yet.
-- event handling helper
self:SetScript("OnEvent", function(self, event, ...)
self[event](self, ...)
end)
-- actually start loading the addon once player ui is loading
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_LOGIN")
end
--[[ Events ]]--
function Hardcore:PLAYER_LOGIN()
Hardcore:HandleLegacyDeaths()
-- cache player data
_, class, _ = UnitClass("player")
PLAYER_NAME, _ = UnitName("player")
PLAYER_GUID = UnitGUID("player")
PLAYER_FACTION, _ = UnitFactionGroup("player")
local PLAYER_LEVEL = UnitLevel("player")
-- fires on first loading
self:RegisterEvent("PLAYER_UNGHOST")
self:RegisterEvent("PLAYER_ALIVE")
self:RegisterEvent("PLAYER_DEAD")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("CHAT_MSG_ADDON")
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("GUILD_ROSTER_UPDATE")
self:RegisterEvent("MAIL_SHOW")
self:RegisterEvent("AUCTION_HOUSE_SHOW")
self:RegisterEvent("PLAYER_LEVEL_UP")
self:RegisterEvent("TIME_PLAYED_MSG")
self:RegisterEvent("QUEST_ACCEPTED") -- For Videre Elixir quest.
self:RegisterEvent("QUEST_TURNED_IN") -- For Videre Elixir quest.
self:RegisterEvent("CHAT_MSG_PARTY")
self:RegisterEvent("CHAT_MSG_SAY")
self:RegisterEvent("CHAT_MSG_GUILD")
-- Register spell cast events for paladin for checking bubble hearth
self:RegisterEvent("UNIT_SPELLCAST_START")
self:RegisterEvent("UNIT_SPELLCAST_STOP")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
Hardcore:InitializeSavedVariables()
-- different guid means new character with the same name
if Hardcore_Character.guid ~= PLAYER_GUID then
Hardcore:ForceResetSavedVariables()
end
-- cache player name
PLAYER_NAME, _ = UnitName("player")
PLAYERGUID = UnitGUID("player")
-- Show recording reminder
Hardcore:RecordReminder()
-- minimap button
Hardcore:initMinimapButton()
-- initiate pulse heartbeat
Hardcore:InitiatePulse()
-- initiate pulse heartbeat check
Hardcore:InitiatePulseCheck()
-- initiate pulse played time
Hardcore:InitiatePulsePlayed()
-- check players version against highest version
local FULL_PLAYER_NAME = Hardcore_GetPlayerPlusRealmName()
Hardcore:CheckVersionsAndUpdate(FULL_PLAYER_NAME, GetAddOnMetadata('Hardcore', 'Version'))
-- reset debug log; To view debug log, log out and see saved variables before logging back in
Hardcore_Settings.debug_log = {}
end
local function GiveVidereWarning()
Hardcore:Print("|cFFFF0000WARNING:|r drinking the Videre Elixir will kill you. You cannot appeal this death.")
Hardcore:ShowAlertFrame(ALERT_STYLES.videre_warning, "WARNING: drinking the Videre Elixir will kill you. You cannot appeal this death.")
end
function Hardcore:QUEST_ACCEPTED(_, questID)
if questID == 3912 then
GiveVidereWarning()
end
end
function Hardcore:QUEST_TURNED_IN(questID)
if questID == 4041 then
GiveVidereWarning()
end
end
function Hardcore:UNIT_SPELLCAST_START(...)
local unit, _, spell_id, _, _ = ...
if unit == "player" and spell_id == bubble_hearth_vars.spell_id then
for i = 1, 40 do
name, _, _, _, _, _, _, _, _, _, _ = UnitBuff("player", i)
if name == nil then
STARTED_BUBBLE_HEARTH_INFO = nil
return
elseif name == bubble_hearth_vars.bubble_name or name == bubble_hearth_vars.light_of_elune_name then
STARTED_BUBBLE_HEARTH_INFO = {}
STARTED_BUBBLE_HEARTH_INFO.start_cast = date("%m/%d/%y %H:%M:%S")
STARTED_BUBBLE_HEARTH_INFO.aura_type = name
Hardcore:Print("WARNING: Bubble-hearth Detected\nCancel or risk invalidation")
Hardcore:ShowAlertFrame(ALERT_STYLES.hc_red, "Bubble-hearth Detected\nCancel or risk invalidation")
return
end
end
end
end
function Hardcore:UNIT_SPELLCAST_STOP(...)
local unit, _, spell_id, _, _ = ...
-- 8690 is hearth spellid
if STARTED_BUBBLE_HEARTH_INFO ~= nil then
if unit == "player" and spell_id == bubble_hearth_vars.spell_id then
Hardcore:Print("NOTE: Bubble-hearth Cancelled")
Hardcore:ShowAlertFrame(ALERT_STYLES.hc_green, "Bubble-hearth Cancelled")
STARTED_BUBBLE_HEARTH_INFO = nil
end
end
end
function Hardcore:UNIT_SPELLCAST_SUCCEEDED(...)
local unit, _, spell_id, _, _ = ...
-- 8690 is hearth spellid
if STARTED_BUBBLE_HEARTH_INFO ~= nil then
if unit == "player" and spell_id == bubble_hearth_vars.spell_id then
Hardcore:Print("Completed Bubble-hearth")
local bubble_hearth_info = {}
bubble_hearth_info.start_cast = STARTED_BUBBLE_HEARTH_INFO.start_cast
bubble_hearth_info.finish_cast = date("%m/%d/%y %H:%M:%S")
bubble_hearth_info.guid = PLAYER_GUID
bubble_hearth_info.aura_type = STARTED_BUBBLE_HEARTH_INFO.aura_type
if Hardcore_Character.bubble_hearth_incidents == nil then
Hardcore_Character.bubble_hearth_incidents = {}
Hardcore_Character.bubble_hearth_incidents[1] = bubble_hearth_info
else
table.insert(Hardcore_Character.bubble_hearth_incidents, bubble_hearth_info)
end
Hardcore:PrintBubbleHearthInfractions()
local message = PLAYER_NAME .. " just received a Bubble-hearth infraction at " ..
bubble_hearth_info.start_cast
SendChatMessage(message, "GUILD", nil, nil)
Hardcore:ShowAlertFrame(ALERT_STYLES.hc_red, "Bubble-hearth Infraction\nContact a Mod immediately.")
STARTED_BUBBLE_HEARTH_INFO = nil
end
end
end
function Hardcore:PLAYER_ENTERING_WORLD()
Hardcore_Frame:RegisterForDrag("LeftButton")
Hardcore_Alerts_Button:SetText(Hardcore_Settings.notify and "Disable alerts" or "Enable alerts")
-- cache player name
PLAYER_NAME, _ = UnitName("player")
Hardcore:PrintBubbleHearthInfractions()
Hardcore:Monitor("Monitoring malicious users enabled.")
-- initialize addon communication
if (not C_ChatInfo.IsAddonMessagePrefixRegistered(COMM_NAME)) then
C_ChatInfo.RegisterAddonMessagePrefix(COMM_NAME)
end
end
function Hardcore:PLAYER_ALIVE()
if #Hardcore_Character.deaths == 0 then
return
end
if Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger == nil then
Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger = date("%m/%d/%y %H:%M:%S")
end
end
function Hardcore:PLAYER_DEAD()
-- Screenshot
C_Timer.After(PICTURE_DELAY, Screenshot)
-- Update deaths
if #Hardcore_Character.deaths == 0 or (#Hardcore_Character.deaths > 0 and Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger ~= nil) then
table.insert(Hardcore_Character.deaths, {
player_dead_trigger = date("%m/%d/%y %H:%M:%S"),
player_alive_trigger = nil
})
end
-- Send message to guild
local playerGreet = GENDER_GREETING[UnitSex("player")]
local name = UnitName("player")
local _, _, classID = UnitClass("player")
local class = CLASSES[classID]
local level = UnitLevel("player")
local zone, mapID
if IsInInstance() then
zone = GetInstanceInfo()
else
mapID = C_Map.GetBestMapForUnit("player")
zone = C_Map.GetMapInfo(mapID).name
end
local messageFormat = "Our brave %s, %s the %s, has died at level %d in %s"
local messageString = messageFormat:format(playerGreet, name, class, level, zone)
if not (Last_Attack_Source == nil) then
messageString = string.format("%s to a %s", messageString, Last_Attack_Source)
Last_Attack_Source = nil
end
if not (recent_msg["text"] == nil) then
local playerPronoun = GENDER_POSSESSIVE_PRONOUN[UnitSex("player")]
messageString = string.format("%s. %s last words were \"%s\"", messageString, playerPronoun, recent_msg["text"])
end
SendChatMessage(messageString, "GUILD")
-- Send addon message
local deathData = string.format("%s%s%s", level, COMM_FIELD_DELIM, mapID and mapID or "")
local commMessage = COMM_COMMANDS[3] .. COMM_COMMAND_DELIM .. deathData
if CTL then
CTL:SendAddonMessage("ALERT", COMM_NAME, commMessage, "GUILD")
end
end
function Hardcore:PLAYER_TARGET_CHANGED()
if UnitGUID("target") ~= PLAYER_GUID and UnitIsPVP("target") then
if Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_BOTH_FACTIONS then
local faction, _ = UnitFactionGroup("target")
if faction ~= nil and (faction ~= PLAYER_FACTION or (faction == PLAYER_FACTION and UnitPlayerControlled("target"))) then
local target_name, _ = UnitName("target")
Hardcore:ShowAlertFrame(ALERT_STYLES.hc_pvp_warning, "Target " .. target_name .. " is PvP enabled!")
end
elseif Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_ENEMY_FACTION then
local faction, _ = UnitFactionGroup("target")
if faction ~= nil and faction ~= PLAYER_FACTION then
local target_name, _ = UnitName("target")
Hardcore:ShowAlertFrame(ALERT_STYLES.hc_pvp_warning, "Target " .. target_name .. " is PvP enabled!")
end
elseif Hardcore_Character.grief_warning_conditions == GRIEF_WARNING_SAME_FACTION then
local faction, _ = UnitFactionGroup("target")
if faction ~= nil and faction == PLAYER_FACTION and UnitPlayerControlled("target") then
local target_name, _ = UnitName("target")
Hardcore:ShowAlertFrame(ALERT_STYLES.hc_pvp_warning, "Target " .. target_name .. " is PvP enabled!")
end
end
end
end
function Hardcore:PLAYER_UNGHOST()
if UnitIsDeadOrGhost("player") == 1 then
return
end -- prevent message on ghost login or zone
local playerName, _ = UnitName("player")
local message = playerName .. " has resurrected!"
SendChatMessage(message, "GUILD", nil, nil)
Hardcore:ShowAlertFrame(ALERT_STYLES.spirithealer, message)
end
function Hardcore:MAIL_SHOW()
Hardcore:Print("Hardcore mode is enabled, mailbox access is blocked.")
CloseMail()
end
function Hardcore:AUCTION_HOUSE_SHOW()
Hardcore:Print("Hardcore mode is enabled, auction house access is blocked.")
CloseAuctionHouse()
end
function Hardcore:PLAYER_LEVEL_UP(...)
-- store the recent level up to use in TIME_PLAYED_MSG
local level, healthDelta, powerDelta, numNewTalents, numNewPvpTalentSlots, strengthDelta, agilityDelta,
staminaDelta, intellectDelta = ...
recent_levelup = level
-- just in case... make sure recent level up gets reset after 3 secs
C_Timer.After(3, function()
recent_levelup = nil
end)
-- get time played, see TIME_PLAYED_MSG
RequestTimePlayed()
-- take screenshot (got this idea from DingPics addon)
-- wait a bit so the yellow animation appears
C_Timer.After(PICTURE_DELAY, Screenshot)
-- send a message to the guild if the player's level is divisible by 10
local landmarkLevel = (level % 10) == 0
if (landmarkLevel) then
local playerName = UnitName("player")
local localizedClass = UnitClass("player")
local messageFormat = "%s the %s has reached level %s!"
local messageString = string.format(messageFormat, playerName, localizedClass, level)
SendChatMessage(messageString, "GUILD", nil, nil)
end
end
function Hardcore:TIME_PLAYED_MSG(...)
local totalTimePlayed, _ = ...
Hardcore_Character.time_played = totalTimePlayed or 1
-- Check playtime gap percentage
Hardcore_Character.tracked_played_percentage = Hardcore_Character.time_tracked / Hardcore_Character.time_played * 100.0
Hardcore:Debug(Hardcore_Character.tracked_played_percentage)
-- Check to see if the gap since the last recording is too long. When receiving played time for the first time.
if RECEIVED_FIRST_PLAYED_TIME_MSG == false and Hardcore_Character.accumulated_time_diff ~= nil then
local debug_message = "Playtime gap percentage: " .. Hardcore_Character.tracked_played_percentage .. "%."
Hardcore:Debug(debug_message)
-- Only warn user about playtime percentage if percentage is low enough and enough playtime is logged.
local level = UnitLevel("player")
local percentage = Hardcore_Character.tracked_played_percentage
if Hardcore:ShouldShowPlaytimeWarning(level, percentage) then
Hardcore:DisplayPlaytimeWarning(level)
end
-- Check playtime gap since last session
local duration_since_last_recording = Hardcore_Character.time_played - Hardcore_Character.time_tracked -
Hardcore_Character.accumulated_time_diff
debug_message = "Playtime gap duration: " .. duration_since_last_recording .. " seconds."
Hardcore:Debug(debug_message)
if duration_since_last_recording > PLAYED_TIME_GAP_THRESH then
local played_time_gap_info = {}
played_time_gap_info.duration_since_last_recording = duration_since_last_recording
played_time_gap_info.date = date("%m/%d/%y %H:%M:%S")
if Hardcore_Character.played_time_gap_warnings == nil then
Hardcore_Character.played_time_gap_warnings = {}
Hardcore_Character.played_time_gap_warnings[1] = played_time_gap_info
else
table.insert(Hardcore_Character.played_time_gap_warnings, played_time_gap_info)
end
local message = "\124cffFF0000Addon/Playtime gap detected at date" ..
Hardcore_Character.played_time_gap_warnings[#Hardcore_Character.played_time_gap_warnings]
.date .. " with a duration: " ..
Hardcore_Character.played_time_gap_warnings[#Hardcore_Character.played_time_gap_warnings]
.duration_since_last_recording .. " seconds."
Hardcore:Print(message)
end
end
RECEIVED_FIRST_PLAYED_TIME_MSG = true
if recent_levelup ~= nil then
-- cache this to make sure it doesn't disapeer
local recent = recent_levelup
-- nil this to ensure it's not called twice
recent_levelup = nil
-- make sure list is initialized
if Hardcore_Settings.level_list == nil then
Hardcore_Settings.level_list = {}
end
-- info for level up record
local totalTimePlayed, timePlayedThisLevel = ...
local playerName, _ = UnitName("player")
-- create the record
local mylevelup = {}
mylevelup["level"] = recent
mylevelup["playedtime"] = totalTimePlayed
mylevelup["realm"] = GetRealmName()
mylevelup["player"] = playerName
mylevelup["localtime"] = date()
-- clear existing records if someone deleted / remade character
-- since this is level 2, this must be a brand new character
if recent == 2 then
for i, v in ipairs(Hardcore_Settings.level_list) do
-- find previous records with same name / realm and rename them so we don't misidentify them
if v["realm"] == mylevelup["realm"] and v["player"] == mylevelup["player"] then
-- copy the record and rename it
local renamed = v
renamed["player"] = renamed["player"] .. "-old"
Hardcore_Settings.level_list[i] = renamed
end
end
end
-- if we found previous level, show the last level time
for i, v in ipairs(Hardcore_Settings.level_list) do
-- find last level up
if v["realm"] == mylevelup["realm"] and v["player"] == mylevelup["player"] and v["level"] == recent - 1 then
-- show message to user with calculated time between levels
Hardcore:Print("Level " .. (recent - 1) .. "-" .. recent .. " time played: " ..
SecondsToTime(totalTimePlayed - v["playedtime"]))
end
end
-- store level record
table.insert(Hardcore_Settings.level_list, mylevelup)
end
end
local Cached_ChatFrame_DisplayTimePlayed = ChatFrame_DisplayTimePlayed
ChatFrame_DisplayTimePlayed = function(...)
if HIDE_RTP_CHAT_MSG_BUFFER > 0 then
HIDE_RTP_CHAT_MSG_BUFFER = HIDE_RTP_CHAT_MSG_BUFFER - 1
return
end
return Cached_ChatFrame_DisplayTimePlayed(...)
end
function Hardcore:RequestTimePlayed()
HIDE_RTP_CHAT_MSG_BUFFER = HIDE_RTP_CHAT_MSG_BUFFER + 1
if HIDE_RTP_CHAT_MSG_BUFFER > HIDE_RTP_CHAT_MSG_BUFFER_MAX then
HIDE_RTP_CHAT_MSG_BUFFER = HIDE_RTP_CHAT_MSG_BUFFER_MAX
end
RequestTimePlayed()
end
function Hardcore:ShouldShowPlaytimeWarning(level, percentage)
if level <= 5 then
return false
elseif level <= 15 then
return percentage <= 40
elseif level <= 20 then
return percentage <= 70
elseif level <= 25 then
return percentage <= 80
elseif level <= 30 then
return percentage <= 90
elseif level <= 35 then
return percentage <= 93
else
return percentage <= 95
end
end
function Hardcore:DisplayPlaytimeWarning(level)
local messageprefix = "\124cffFF0000"
if level <= 20 then
Hardcore:Print(messageprefix.."Detected that the player's addon active time is much lower than played time. If you have just installed the addon, start a new character.")
else
Hardcore:Print(messageprefix.."Detected that the player's addon active time is much lower than played time. If you have just installed the addon: consider starting a new character. Continuing on means you risk your lv 60, HC Verified Status.")
Hardcore:Print(messageprefix.."If you have had Hardcore 0.5.0 or greater installed since level 1, contact a mod and record the rest of your run.")
end
end
function Hardcore:CHAT_MSG_ADDON(prefix, datastr, scope, sender)
-- Ignore messages that are not ours
if COMM_NAME == prefix then
-- Get the command
local command, data = string.split(COMM_COMMAND_DELIM, datastr)
if DEPRECATED_COMMANDS[command] or alert_msg_time[command] == nil then return end
if alert_msg_time[command][sender] and (time() - alert_msg_time[command][sender] < COMM_SPAM_THRESHOLD[command]) then
local debug_info = {command, data, sender}
table.insert(Hardcore_Settings.debug_log, debug_info)
alert_msg_time[command][sender] = time()
-- Display that someone is trying to send spam messages; notifies mods to look at saved_vars and remove player from guild
if monitor_msg_throttle[command][sender] == nil or (time() - monitor_msg_throttle[command][sender] > THROTTLE_DURATION) then
Hardcore:Monitor("|cffFF0000Received spam from " .. sender .. ", using the " .. command .. " command.")
monitor_msg_throttle[command][sender] = time()
end
return
end
alert_msg_time[command][sender] = time()
-- Determine what command was sent
-- COMM_COMMANDS[2] is deprecated, but its backwards compatible so we still can handle
if command == COMM_COMMANDS[2] or command == COMM_COMMANDS[3] then
Hardcore:Add(data, sender)
elseif command == COMM_COMMANDS[1] then
Hardcore:ReceivePulse(data, sender)
else
-- Hardcore:Debug("Unknown command :"..command)
end
end
end
function Hardcore:COMBAT_LOG_EVENT_UNFILTERED(...)
-- local time, token, hidding, source_serial, source_name, caster_flags, caster_flags2, target_serial, target_name, target_flags, target_flags2, ability_id, ability_name, ability_type, extraSpellID, extraSpellName, extraSchool = CombatLogGetCurrentEventInfo()
local _, ev, _, _, source_name, _, _, _, _, _, _, _, _, _, _, _, _ = CombatLogGetCurrentEventInfo()
if not (source_name == PLAYER_NAME) then
if not (source_name == nil) then
if string.find(ev, "DAMAGE") ~= nil then
Last_Attack_Source = source_name
end
end
end
end
function Hardcore:CHAT_MSG_SAY(...)
if self:SetRecentMsg(...) then
recent_msg["type"] = 0
end
end
function Hardcore:CHAT_MSG_GUILD(...)
if self:SetRecentMsg(...) then
recent_msg["type"] = 2
end
end
function Hardcore:CHAT_MSG_PARTY(...)
if self:SetRecentMsg(...) then
recent_msg["type"] = 1
end
end
function Hardcore:SetRecentMsg(...)
local text, sn, LN, CN, p2, sF, zcI, cI, cB, unu, lI, senderGUID = ...
if PLAYERGUID == nil then
PLAYERGUID = UnitGUID("player")
end
if senderGUID == PLAYERGUID then
recent_msg["text"] = text
return true
end
return false
end
function Hardcore:GUILD_ROSTER_UPDATE(...)
guild_roster_loading = false
-- Create a new dictionary of just online people every time roster is updated
guild_online = {}
-- Hardcore:Debug('guild roster update')
local numTotal, numOnline, numOnlineAndMobile = GetNumGuildMembers();
for i = 1, numOnline, 1 do
local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status,
class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, GUID = GetGuildRosterInfo(i)
-- name is nil after a gquit, so nil check here
if name then
guild_online[name] = {
name = name,
level = level,
classDisplayName = classDisplayName
}
end
end
Hardcore:UpdateGuildRosterRows()
if display == "AddonStatus" then
Hardcore_SubTitle:SetText(STRING_ADDON_STATUS_SUBTITLE)
end
end
--[[ Utility Methods ]]--
function Hardcore:Print(msg)
print("|cffed9121Hardcore|r: " .. (msg or ""))
end
function Hardcore:Debug(msg)
if true == debug then
print("|cfffd9122HCDebug|r: " .. (msg or ""))
end
end
function Hardcore:Monitor(msg)
if true == Hardcore_Settings.monitor then
print("|cff00ffffHCMonitor|r: " .. (msg or ""))
end
end
-- Alert UI
function Hardcore:ShowAlertFrame(styleConfig, message)
-- message is any text accepted by FontString:SetText(message)
message = message or ""
local data = styleConfig or ALERT_STYLES["hc_red"]
local frame, text, icon, file, delay, alertSound = data.frame, data.text, data.icon, data.file, data.delay, data.alertSound
filename = MEDIA_DIR .. file
icon:SetTexture(filename)
text:SetText(message)
frame:Show()
if alertSound then PlaySound(alertSound) end
-- HACK:
-- There's a bug here where a sequence of overlapping notifications share one 'hide' timer
-- There should be a step here that unbinds all-but-the-last notification's Hide() callback
C_Timer.After(delay, function()
frame:Hide()
end)
end
function Hardcore:Add(data, sender)
-- Display the death locally if alerts are not toggled off.
if Hardcore_Settings.notify then
local level = 0
local mapID
if data then
level, mapID = string.split(COMM_FIELD_DELIM, data)
level = tonumber(level)
mapID = tonumber(mapID)
end
if type(level) == "number" then
for i = 1, GetNumGuildMembers() do
local name, _, _, guildLevel, _, zone, _, _, _, _, class = GetGuildRosterInfo(i)
if name == sender then
if mapID then
local mapData = C_Map.GetMapInfo(mapID) -- In case some idiot sends an invalid map ID, it won't cause mass lua errors.
zone = mapData and mapData.name or zone -- If player is in an instance, will have to get zone from guild roster.
end
level = level > 0 and level < 61 and level or guildLevel -- If player is using an older version of the addon, will have to get level from guild roster.