Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
982 lines (878 loc) · 39.5 KB
/
Copy pathCore.lua
File metadata and controls
982 lines (878 loc) · 39.5 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
--[[
ProjectJaina_Companion — Core.lua
Motor central del hub social de Project Jaina.
Funcionalidades:
1. Detecta qué addons Project Jaina tiene activo cada miembro del grupo vía P2P (WP_COMP).
2. Anuncia en el canal de grupo cuando un jugador sube de nivel en el BattlePass.
3. Muestra el badge de modo de juego (Hardcore/Ironman/Normal) del jugador local.
4. Resiliencia contra reseteo de WTF en cabinas de internet mediante escaneo de auras.
RESTRICCIONES 3.3.5a:
- RegisterAddonMessagePrefix es defensivo.
- Sin C_Timer.After: usa OnUpdate con elapsed.
- SetTexture de color usa WHITE8X8 + SetVertexColor.
- Zero heap thrashing: reuso de timers, sin CreateFrame dinámico en cada evento.
]]
-- ================================================================
-- SYSTEM HOTFIX: FrameXML / ChatFrame CHANNEL_NOTICE Nil Guard
-- Protege contra crash en ChatFrame.lua:2802 si el servidor envía notices no definidas en GlobalStrings
-- ================================================================
if not _G.CHAT_NOT_IN_LFG_NOTICE then
_G.CHAT_NOT_IN_LFG_NOTICE = "|Hchannel:%d|h[%s]|h Debes unirte a la cola de Buscar grupo para poder participar en este canal."
end
if not _G.CHAT_NOT_IN_LFG_NOTICE_BN then
_G.CHAT_NOT_IN_LFG_NOTICE_BN = "|Hchannel:CHANNEL:%d|h[%s]|h Debes unirte a la cola de Buscar grupo para poder participar en este canal."
end
local _Orig_ChatFrame_MessageEventHandler = _G.ChatFrame_MessageEventHandler
if _Orig_ChatFrame_MessageEventHandler then
_G.ChatFrame_MessageEventHandler = function(self, event, ...)
if event == "CHAT_MSG_CHANNEL_NOTICE" or event == "CHAT_MSG_CHANNEL_NOTICE_USER" then
local noticeType = ...
if noticeType then
local bnKey = "CHAT_" .. tostring(noticeType) .. "_NOTICE_BN"
local stdKey = "CHAT_" .. tostring(noticeType) .. "_NOTICE"
if not _G[bnKey] and not _G[stdKey] then
_G[stdKey] = "|Hchannel:%d|h[%s]|h [" .. tostring(noticeType) .. "]"
end
end
end
return _Orig_ChatFrame_MessageEventHandler(self, event, ...)
end
end
ProjectJaina_Companion = ProjectJaina_Companion or {}
local C = ProjectJaina_Companion
-- ================================================================
-- ESTADO EN MEMORIA
-- ================================================================
local groupAddonStatus = {} -- [playerName] = { addons = {...}, mode = "...", time = GetTime() }
local lastBPLevel = 0 -- nivel propio en BattlePass
local addonLoaded = false
-- Timers defensivos (reutilizados en el OnUpdate principal)
local tickElapsed = 0
local TICK_INTERVAL = 5
local rosterTimer = 0
local rosterDebounceActive = false
-- ================================================================
-- UTILIDADES
-- ================================================================
local function CPrint(msg)
local f = DEFAULT_CHAT_FRAME or ChatFrame1
if f and f.AddMessage then
f:AddMessage("|cFFD4AF37[Project Jaina]|r " .. tostring(msg))
end
end
local function IsAddonLoaded(name)
if not name or not _G.IsAddOnLoaded then return false end
local loaded = _G.IsAddOnLoaded(name)
if not loaded and not name:find("^ProjectJaina_") then
loaded = _G.IsAddOnLoaded("ProjectJaina_" .. name)
end
return (loaded and true) or false
end
local function GetLocalGameMode()
if ProjectJaina_GameModes_CharDB
and ProjectJaina_GameModes_CharDB.hasSelectedMode
and ProjectJaina_GameModes_CharDB.selectedMode then
return ProjectJaina_GameModes_CharDB.selectedMode
end
-- Fallback resiliente a cabinas de internet (WTF reseteado): Escanear auras del servidor
for i = 1, 40 do
local auraName = UnitAura("player", i)
if not auraName then break end
local lower = auraName:lower()
if lower:find("hardcore") then
if ProjectJaina_GameModes_CharDB then
ProjectJaina_GameModes_CharDB.hasSelectedMode = true
ProjectJaina_GameModes_CharDB.selectedMode = "HARDCORE"
end
return "HARDCORE"
elseif lower:find("ironman") then
if ProjectJaina_GameModes_CharDB then
ProjectJaina_GameModes_CharDB.hasSelectedMode = true
ProjectJaina_GameModes_CharDB.selectedMode = "IRONMAN"
end
return "IRONMAN"
end
end
return "NORMAL"
end
-- ================================================================
-- DETECCIÓN UNIFICADA DE CANAL DE GRUPO (PVE + PVP BATTLEGROUNDS)
-- ================================================================
local function GetGroupChannel()
if IsInInstance then
local inInstance, instanceType = IsInInstance()
if inInstance and instanceType == "pvp" then
return "BATTLEGROUND"
end
end
if GetNumRaidMembers and GetNumRaidMembers() > 0 then
return "RAID"
elseif GetNumPartyMembers and GetNumPartyMembers() > 0 then
return "PARTY"
end
return nil
end
-- ================================================================
-- ANUNCIO AL GRUPO (LIMPIO DE CÓDIGOS DE COLOR |c)
-- ================================================================
local function AnnounceToGroup(msg)
local ch = C.Config.AnnounceChannel
if not ch or ch == "" or ch == "OFF" or ch == "NONE" then return end
if (ch == "GROUP" or ch == "PARTY") then
local target = GetGroupChannel()
if target then
SendChatMessage(msg, target)
end
elseif ch == "SAY" then
SendChatMessage(msg, "SAY")
end
end
-- ================================================================
-- LIMPIEZA DE MIEMBROS DESCONECTADOS / GRUPO DISUELTO
-- ================================================================
local function PruneGroupStatus()
local targetChannel = GetGroupChannel()
if not targetChannel then
for k in pairs(groupAddonStatus) do
groupAddonStatus[k] = nil
end
return
end
local currentMembers = {}
local myName = UnitName("player")
if myName then currentMembers[myName] = true end
if targetChannel == "RAID" or targetChannel == "BATTLEGROUND" then
local count = GetNumRaidMembers()
for i = 1, count do
local name = UnitName("raid" .. i)
if name then currentMembers[name] = true end
end
elseif targetChannel == "PARTY" then
local count = GetNumPartyMembers()
for i = 1, count do
local name = UnitName("party" .. i)
if name then currentMembers[name] = true end
end
end
for sender in pairs(groupAddonStatus) do
local baseName = sender:match("^[^-]+") or sender
if not currentMembers[sender] and not currentMembers[baseName] then
groupAddonStatus[sender] = nil
end
end
end
-- ================================================================
-- SECCIÓN 1: BROADCAST DE ADDONS ACTIVOS
-- ================================================================
local function BuildMyAddonPayload()
local active = {}
for _, entry in ipairs(C.Config.EcosystemAddons) do
if IsAddonLoaded(entry.name) then
table.insert(active, entry.label)
end
end
local mode = GetLocalGameMode()
return string.format("WP_ADDONS:%s|%s", table.concat(active, ","), mode)
end
local function BroadcastStatus()
local playerName = UnitName("player")
if not playerName or playerName == "" then return end
local targetChannel = GetGroupChannel()
if not targetChannel then return end
local payload = BuildMyAddonPayload()
if #payload > 200 then return end -- guardia estricta de 255 bytes
if RegisterAddonMessagePrefix then
RegisterAddonMessagePrefix(C.Config.AddonPrefix)
end
SendAddonMessage(C.Config.AddonPrefix, payload, targetChannel)
end
-- ================================================================
-- SECCIÓN 2: RECEPCIÓN DE STATUS Y PROTOCOLO P2P BIDIRECCIONAL
-- ================================================================
local responseJitterTimer = 0
local responseJitterTarget = 0
local responsePending = false
local function ParseAddonMessage(sender, message)
if not sender or sender == "" or not message then return end
local myName = UnitName("player")
local baseSender = sender:match("^[^-]+") or sender
if baseSender == myName or sender == myName then return end
-- 1. Solicitud de escaneo P2P proveniente de un compañero de grupo/banda
if message == "WP_SCAN_REQ" then
-- Responder con jitter defensivo aleatorio para evitar colisiones en bandas de 25/40
responseJitterTimer = 0
responseJitterTarget = 0.05 + (math.random(1, 30) / 100)
responsePending = true
return
end
-- 2. Recepción de estado de un compañero
-- Formato esperado: "WP_ADDONS:<addon1>,<addon2>|<MODE>"
local addonList, mode = message:match("^WP_ADDONS:([^|]*)|(.+)$")
if not addonList then return end
local addons = {}
for label in addonList:gmatch("[^,]+") do
addons[label] = true
end
groupAddonStatus[sender] = {
addons = addons,
mode = mode or "NORMAL",
time = GetTime(),
}
end
local function RequestGroupScan()
local targetChannel = GetGroupChannel()
if not targetChannel then
CPrint("No estás en un grupo o banda para escanear.")
return
end
if RegisterAddonMessagePrefix then
RegisterAddonMessagePrefix(C.Config.AddonPrefix)
end
-- Primero transmitimos nuestro estado
BroadcastStatus()
-- Solicitamos a todos los clientes del grupo responder con el suyo
SendAddonMessage(C.Config.AddonPrefix, "WP_SCAN_REQ", targetChannel)
CPrint("Escaneando addons del grupo (solicitud P2P enviada)...")
end
-- ================================================================
-- SECCIÓN 3: DETECCIÓN DE LEVEL-UP EN BATTLEPASS (LOGIN SEGURO)
-- ================================================================
local function CheckBattlePassLevelUp()
if not Jaina_BattlePass then return end
local bp = Jaina_BattlePass
if not bp.Data then return end
-- Blindaje: Si el BattlePass aún no completa su sincronización inicial con el servidor, no evaluar
if not bp.Data.hasSyncedOnce then
return
end
local newLevel = bp.Data.level or 0
if lastBPLevel == 0 then
-- Primer registro tras sincronización exitosa: no emitir anuncio de login
lastBPLevel = newLevel
return
end
if newLevel > lastBPLevel then
local playerName = UnitName("player") or "Desconocido"
local msg = string.format(
"[BattlePass] %s alcanzo el Nivel %d del Pase de Batalla! (/bp)",
playerName, newLevel
)
AnnounceToGroup(msg)
lastBPLevel = newLevel
end
end
-- ================================================================
-- FORMATO CANÓNICO DE MODOS DE JUEGO (NORMAL, HC, IM, RETO X1)
-- ================================================================
local function FormatModeBadge(mode, short)
if not mode or mode == "NORMAL" or mode == "NONE" then
return short and "" or " |cFF888888[NORMAL]|r"
elseif mode == "HARDCORE" then
return short and " |cFFFF3333[HC]|r" or " |cFFFF3333[HARDCORE]|r"
elseif mode == "IRONMAN" then
return short and " |cFFFF9900[IM]|r" or " |cFFFF9900[IRONMAN]|r"
elseif mode == "SLOW_X1" or mode == "X1" then
return short and " |cFFFFD100[X1]|r" or " |cFFFFD100[RETO X1]|r"
end
return short and string.format(" |cFF00CCFF[%s]|r", tostring(mode)) or string.format(" |cFF00CCFF[%s]|r", tostring(mode))
end
-- ================================================================
-- SECCIÓN 4: INTERFAZ DE COMANDO /companion
-- ================================================================
local function PrintGroupStatus()
PruneGroupStatus()
local targetChannel = GetGroupChannel()
if not targetChannel then
local myMode = GetLocalGameMode()
CPrint("No estas en un grupo o banda actualmente.")
CPrint("Tu modo activo:" .. FormatModeBadge(myMode, false))
return
end
CPrint("--- Estado del Ecosistema Project Jaina en el grupo ---")
-- Mostrar primero al jugador local
local myName = UnitName("player") or "Jugador"
local myMode = GetLocalGameMode()
local myModeStr = FormatModeBadge(myMode, true)
local myActive = {}
for _, entry in ipairs(C.Config.EcosystemAddons) do
if IsAddonLoaded(entry.name) then
table.insert(myActive, entry.label)
end
end
table.sort(myActive)
local myList = (#myActive > 0) and table.concat(myActive, ", ") or "(solo Companion)"
CPrint(string.format(" %s%s (Tu): %s", myName, myModeStr, myList))
-- Mostrar compañeros
local count = 0
for name, data in pairs(groupAddonStatus) do
local baseName = name:match("^[^-]+") or name
if baseName ~= myName and name ~= myName then
count = count + 1
local addonNames = {}
for label in pairs(data.addons) do
table.insert(addonNames, label)
end
table.sort(addonNames)
local modeStr = FormatModeBadge(data.mode, true)
local listStr = (#addonNames > 0) and table.concat(addonNames, ", ") or "(solo Companion)"
CPrint(string.format(" %s%s: %s", name, modeStr, listStr))
end
end
if count == 0 then
CPrint(" No hay datos de companeros aun. (Usa /companion scan para solicitar)")
end
end
-- ================================================================
-- CENTRO DE CONTROL: MENÚ DESPLEGABLE NATIVO DEL ECOSISTEMA
-- ================================================================
local hubDropDown = CreateFrame("Frame", "ProjectJainaHubDropDown", UIParent, "UIDropDownMenuTemplate")
local function ExecuteOrWarn(slashKey, fallbackKey, moduleName)
if SlashCmdList and SlashCmdList[slashKey] then
SlashCmdList[slashKey]("")
elseif fallbackKey and SlashCmdList and SlashCmdList[fallbackKey] then
SlashCmdList[fallbackKey]("")
elseif moduleName == "MultiBot" and MultiBot and MultiBot.ToggleMainUIVisibility then
MultiBot.ToggleMainUIVisibility()
elseif moduleName == "Chatter LLM" and Chatter and Chatter.Toggle then
Chatter:Toggle()
else
CPrint(string.format("|cFFFF4444El modulo %s no esta activo o instalado.|r", moduleName))
end
end
local function OpenHubMenu(anchor)
local headerTitle = (C.Progression and C.Progression.name)
and string.format("|cFFD4AF37Project Jaina|r - %s (Cap %d)", C.Progression.name, C.Progression.levelCap or 60)
or "|cFFD4AF37Project Jaina|r - Centro de Control"
local menuList = {
{ text = headerTitle, isTitle = true, notCheckable = true },
{ text = "|cFFFFD100Pase de Batalla|r (/bp)", notCheckable = true, func = function()
ExecuteOrWarn("WOWPERUBP", "BP", "BattlePass")
end },
{ text = "|cFFFFD100Guardarropa (Transfiguración)|r (/armario)", notCheckable = true, func = function()
ExecuteOrWarn("WP_WARDROBEV2", "ARMARIO", "Guardarropa")
end },
{ text = "|cFFFFD100Modos de Juego|r (/modos)", notCheckable = true, func = function()
ExecuteOrWarn("WOWPERU_MODES", "MODOS", "Modos de Juego")
end },
{ text = "|cFFFFD100Suite Gráfica HD|r (/graficos)", notCheckable = true, func = function()
ExecuteOrWarn("WOWPERU_GRAPHICS", nil, "Graficos HD")
end },
{ text = "|cFF00FFCCGestor de Bots con IA|r (/bots)", notCheckable = true, func = function()
ExecuteOrWarn("CHATTER", "LLMC", "Chatter LLM")
end },
{ text = "|cFFFFD100Playerbots (MultiBot)|r (/multibot)", notCheckable = true, func = function()
ExecuteOrWarn("MULTIBOT", "ACECONSOLE_MULTIBOT", "MultiBot")
end },
{ text = "|cFFD4AF37Barra Táctica de Bots|r (/botbar)", notCheckable = true, func = function()
if C.ToggleTacticalBar then C.ToggleTacticalBar() end
end },
{ text = "|cFFFFD100Tienda de Visuales|r (/tienda)", notCheckable = true, func = function()
ExecuteOrWarn("WOWPERU_VISUAL", nil, "Tienda Visual")
end },
{ text = "|cFFFFD100LoreHUD (Subtítulos 3D)|r (/lorehud)", notCheckable = true, func = function()
ExecuteOrWarn("LOREHUD", nil, "LoreHUD")
end },
{ text = "|cFF00CCFFVoz Espacial 3D|r (/voz)", notCheckable = true, func = function()
ExecuteOrWarn("PROJECTJAINA_VOZ", "VOZ", "Voz 3D")
end },
{ text = " ", notCheckable = true, disabled = true },
{ text = "Herramientas de Grupo", hasArrow = true, notCheckable = true,
menuList = {
{ text = "Solicitar Escaneo P2P", notCheckable = true, func = RequestGroupScan },
{ text = "Imprimir Estado de Companeros", notCheckable = true, func = PrintGroupStatus },
}
},
{ text = " ", notCheckable = true, disabled = true },
{ text = "|cFF888888Cerrar|r", notCheckable = true, func = function() end },
}
EasyMenu(menuList, hubDropDown, anchor or "cursor", 0, 0, "MENU")
end
SLASH_WPCOMP1 = "/companion"
SLASH_WPCOMP2 = "/wpcomp"
SLASH_WPCOMP3 = "/hub"
SLASH_WPCOMP4 = "/menu"
SlashCmdList["WPCOMP"] = function(msg)
local cmd, arg = (msg or ""):lower():match("^(%S+)%s*(%S*)$")
cmd = cmd or ""
if cmd == "menu" or cmd == "hub" or cmd == "" then
OpenHubMenu("cursor")
elseif cmd == "scan" then
RequestGroupScan()
elseif cmd == "status" then
PrintGroupStatus()
elseif cmd == "debug" then
C.Config.Debug = not C.Config.Debug
if ProjectJainaCompanion_DB then ProjectJainaCompanion_DB.Debug = C.Config.Debug end
CPrint("Debug: " .. (C.Config.Debug and "ON" or "OFF"))
elseif cmd == "channel" then
if arg == "group" or arg == "party" or arg == "say" then
C.Config.AnnounceChannel = arg:upper()
if ProjectJainaCompanion_DB then ProjectJainaCompanion_DB.AnnounceChannel = C.Config.AnnounceChannel end
CPrint("Canal de anuncios configurado en: " .. C.Config.AnnounceChannel)
elseif arg == "off" or arg == "none" then
C.Config.AnnounceChannel = ""
if ProjectJainaCompanion_DB then ProjectJainaCompanion_DB.AnnounceChannel = "" end
CPrint("Anuncios desactivados.")
else
local cur = (C.Config.AnnounceChannel ~= "") and C.Config.AnnounceChannel or "OFF"
CPrint("Canal actual: " .. cur)
CPrint("Uso: /companion channel [group|party|say|off]")
end
else
CPrint("Uso: /companion [status|scan|channel|debug]")
CPrint("Comandos Cross-Faction: /comerciar y /invitar [Nombre]")
end
end
-- ================================================================
-- UTILIDADES CROSS-FACTION (Alianza <-> Horda)
-- Permite comerciar e invitar entre facciones opuestas de forma limpia
-- sin modificar UnitPopupMenus de Blizzard (CERO TAINT).
-- ================================================================
SLASH_WPCOMERCIAR1 = "/comerciar"
SLASH_WPCOMERCIAR2 = "/comercio"
SlashCmdList["WPCOMERCIAR"] = function()
if not UnitExists("target") then
CPrint("Selecciona a un jugador y escribe |cFFD4AF37/comerciar|r")
return
end
InitiateTrade("target")
end
SLASH_WPINVITAR1 = "/invitar"
SlashCmdList["WPINVITAR"] = function(nombre)
if nombre and nombre ~= "" then
InviteUnit(nombre)
return
end
if UnitExists("target") and UnitIsPlayer("target") then
InviteUnit(UnitName("target"))
return
end
CPrint("Escribe |cFFD4AF37/invitar Nombre|r, o selecciona a un jugador primero.")
end
-- ================================================================
-- BOTÓN DE MINIMAPA OFICIAL CON EL LOGO DE WOW PERÚ
-- ================================================================
local minimapBtn = nil
local DEFAULT_COMPANION_ANGLE = 165
local MINIMAP_RADIUS = 80
local function UpdateMinimapBtnPosition(button, angle)
local rad = math.rad(angle)
local x = math.cos(rad) * MINIMAP_RADIUS
local y = math.sin(rad) * MINIMAP_RADIUS
button:ClearAllPoints()
button:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
local function CreateMinimapButton()
if minimapBtn then return minimapBtn end
local btn = CreateFrame("Button", "ProjectJaina_CompanionMinimapBtn", Minimap)
btn:SetSize(31, 31)
btn:SetFrameStrata("MEDIUM")
btn:SetFrameLevel(8)
btn:EnableMouse(true)
btn:SetMovable(true)
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
btn:RegisterForDrag("LeftButton", "RightButton")
btn:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
local icon = btn:CreateTexture(nil, "BACKGROUND")
icon:SetSize(20, 20)
icon:SetPoint("CENTER", btn, "CENTER", 0, 0)
icon:SetTexture("Interface\\AddOns\\ProjectJaina_Companion\\Textures\\jaina_icon.tga")
local border = btn:CreateTexture(nil, "OVERLAY")
border:SetSize(52, 52)
border:SetPoint("TOPLEFT", btn, "TOPLEFT", 0, 0)
border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
local wasDragged = false
local function OnDragUpdate(self)
local mx, my = Minimap:GetCenter()
local px, py = GetCursorPosition()
local scale = Minimap:GetEffectiveScale()
px, py = px / scale, py / scale
local angle = math.deg(math.atan2(py - my, px - mx))
if angle < 0 then angle = angle + 360 end
ProjectJaina_Companion_DB = ProjectJaina_Companion_DB or ProjectJainaCompanion_DB or {}
ProjectJainaCompanion_DB = ProjectJaina_Companion_DB
ProjectJainaCompanion_DB.minimapAngle = angle
UpdateMinimapBtnPosition(self, angle)
wasDragged = true
end
btn:SetScript("OnDragStart", function(self)
wasDragged = false
self:LockHighlight()
self:SetScript("OnUpdate", OnDragUpdate)
end)
btn:SetScript("OnDragStop", function(self)
self:UnlockHighlight()
self:SetScript("OnUpdate", nil)
end)
btn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("|cFFD4AF37Project Jaina Companion|r", 1, 1, 1)
GameTooltip:AddLine("Centro de Control del Ecosistema", 0.8, 0.8, 0.8)
if C.Progression and C.Progression.name then
GameTooltip:AddLine(" ")
GameTooltip:AddLine(string.format("|cFFD4AF37Era del Reino:|r |cff39d353%s|r", C.Progression.name), 1, 1, 1)
GameTooltip:AddLine(string.format("|cFFD4AF37Tope de Nivel:|r |cffffd700%d|r", C.Progression.levelCap or 60), 0.9, 0.9, 0.9)
end
GameTooltip:AddLine("|cFF888888Desarrollo: DarckRovert (Elnazzareno)|r", 0.7, 0.7, 0.7)
GameTooltip:AddLine(" ")
GameTooltip:AddLine("|cFFFFD100Click Izquierdo:|r Abrir Menú Central de Project Jaina", 0.2, 1, 0.2)
GameTooltip:AddLine("|cFFFFD100Click Derecho:|r Imprimir estado de compañeros P2P", 0.2, 0.8, 1)
GameTooltip:AddLine("|cFF888888Arrastrar para reposicionar|r", 0.7, 0.7, 0.7)
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
btn:SetScript("OnClick", function(self, button)
if wasDragged then
wasDragged = false
return
end
if button == "RightButton" then
PrintGroupStatus()
else
OpenHubMenu("cursor")
end
end)
local savedAngle = (ProjectJainaCompanion_DB and ProjectJainaCompanion_DB.minimapAngle) or DEFAULT_COMPANION_ANGLE
UpdateMinimapBtnPosition(btn, savedAngle)
minimapBtn = btn
return btn
end
-- ================================================================
-- EVENTO FRAME PRINCIPAL (ZERO HEAP ALLOCATION)
-- ================================================================
local eventFrame = CreateFrame("Frame", "ProjectJainaCompanion_Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("CHAT_MSG_ADDON")
eventFrame:RegisterEvent("RAID_ROSTER_UPDATE")
eventFrame:RegisterEvent("PARTY_MEMBERS_CHANGED")
eventFrame:SetScript("OnUpdate", function(self, elapsed)
if not addonLoaded then return end
-- Ticker liviano para revisar BattlePass level-up (cada 5 seg)
tickElapsed = tickElapsed + elapsed
if tickElapsed >= TICK_INTERVAL then
tickElapsed = 0
CheckBattlePassLevelUp()
end
-- Debounce de Roster Update (Zero heap allocation, cero fugas de frames)
if rosterDebounceActive then
rosterTimer = rosterTimer + elapsed
if rosterTimer >= 2.0 then
rosterDebounceActive = false
rosterTimer = 0
PruneGroupStatus()
BroadcastStatus()
end
end
-- Despacho con jitter para respuesta a solicitud WP_SCAN_REQ
if responsePending then
responseJitterTimer = responseJitterTimer + elapsed
if responseJitterTimer >= responseJitterTarget then
responsePending = false
responseJitterTimer = 0
BroadcastStatus()
end
end
end)
eventFrame:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" then
local name = ...
if name == "ProjectJaina_Companion" or name == "ProjectJaina_Companion" then
addonLoaded = true
-- Cargar DB persistente
ProjectJaina_Companion_DB = ProjectJaina_Companion_DB or ProjectJainaCompanion_DB or {}
ProjectJainaCompanion_DB = ProjectJaina_Companion_DB
if ProjectJainaCompanion_DB.AnnounceChannel ~= nil then
C.Config.AnnounceChannel = ProjectJainaCompanion_DB.AnnounceChannel
end
if ProjectJainaCompanion_DB.Debug ~= nil then
C.Config.Debug = ProjectJainaCompanion_DB.Debug
end
if ProjectJainaCompanion_DB.Progression then
C.Progression = ProjectJainaCompanion_DB.Progression
end
CreateMinimapButton()
if C.CreateTacticalBar then C.CreateTacticalBar() end
CPrint("v" .. C.Config.Version .. " cargado. Usa /companion o /botbar")
end
elseif event == "PLAYER_ENTERING_WORLD" then
if RegisterAddonMessagePrefix then
RegisterAddonMessagePrefix(C.Config.AddonPrefix)
RegisterAddonMessagePrefix("JAINA_PHASE_SYNC")
end
-- Solicitar estado de progresión temporal del reino al servidor
local pName = UnitName("player")
if pName and pName ~= "" and pName ~= UNKNOWNOBJECT then
SendAddonMessage("JAINA_PHASE_SYNC", "REQ_SYNC", "WHISPER", pName)
end
-- Inicializar nivel base de BattlePass si ya completó sync
if Jaina_BattlePass and Jaina_BattlePass.Data and Jaina_BattlePass.Data.hasSyncedOnce then
lastBPLevel = Jaina_BattlePass.Data.level or 0
else
lastBPLevel = 0
end
-- Anunciar status si entra al mundo en grupo
BroadcastStatus()
elseif event == "CHAT_MSG_ADDON" then
local prefix, message, channel, sender = ...
if prefix == C.Config.AddonPrefix then
ParseAddonMessage(sender, message)
end
-- Escuchar confirmación autoritativa de modo de juego para actualizar grupo de inmediato
if prefix == "WP_GAMEMODE" and message then
local mode = message:match("^STATUS:(.+)$") or message:match("^ACK:(.+)$")
if mode then
if ProjectJaina_GameModes_CharDB then
if mode == "NONE" then
ProjectJaina_GameModes_CharDB.hasSelectedMode = false
ProjectJaina_GameModes_CharDB.selectedMode = nil
else
ProjectJaina_GameModes_CharDB.hasSelectedMode = true
ProjectJaina_GameModes_CharDB.selectedMode = mode
end
end
BroadcastStatus()
end
end
-- Escuchar paquetes de BattlePass para sincronizar inmediato tras XP real
if prefix == "WP_BP" and message then
local opcode = message:match("^([^:]+)")
if opcode == "BP_RES_XP" then
-- Acelerar ticker para comprobar inmediatamente tras procesar el levelup
tickElapsed = TICK_INTERVAL - 0.1
end
end
-- Escuchar sincronización autoritativa de fase del reino
if prefix == "JAINA_PHASE_SYNC" and message then
local op, phaseId, levelCap, phaseName = message:match("^([^:]+):([^:]+):([^:]+):(.+)$")
if op == "SYNC" then
C.Progression = {
phase = phaseId,
levelCap = tonumber(levelCap) or 60,
name = phaseName or "World of Warcraft Classic"
}
ProjectJaina_Companion_DB = ProjectJaina_Companion_DB or {}
ProjectJaina_Companion_DB.Progression = C.Progression
end
end
elseif event == "RAID_ROSTER_UPDATE" or event == "PARTY_MEMBERS_CHANGED" then
PruneGroupStatus()
-- Resetear el timer de debounce para no spamear en formaciones masivas de raid
rosterTimer = 0
rosterDebounceActive = true
end
end)
-- ================================================================
-- CONTROL TÁCTICO DE PLAYERBOTS (Project Jaina v2.0)
-- Barra flotante de comandos rápidos, keybindings nativos y reclutamiento por rol
-- ================================================================
_G["BINDING_HEADER_PROJECTJAINA_COMPANION"] = "|cFFD4AF37Project Jaina|r - Control Táctico"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_FOLLOW"] = "Bots: Seguir"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_STAY"] = "Bots: Quedarse / Alto"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_ATTACK"] = "Bots: Atacar objetivo"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_PULL"] = "Bots: Auto-Pull (Tanque)"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_PASSIVE"] = "Bots: Modo Pasivo"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_RECRUIT_TANK"] = "Reclutar Bot: Tanque"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_RECRUIT_HEALER"] = "Reclutar Bot: Sanador"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_RECRUIT_DPS"] = "Reclutar Bot: DPS"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_REGEAR"] = "Bots: Reequipar / Actualizar Equipo"
_G["BINDING_NAME_PROJECTJAINA_COMPANION_TOGGLEBAR"] = "Alternar Barra Táctica de Bots"
function C.SendCommand(action, arg)
if not action then return end
local groupChannel = GetGroupChannel() or "PARTY"
if action == "follow" then
SendChatMessage("follow", groupChannel)
elseif action == "stay" then
SendChatMessage("stay", groupChannel)
elseif action == "attack" then
SendChatMessage("attack", groupChannel)
elseif action == "pull" then
SendChatMessage("pull", groupChannel)
elseif action == "passive" then
SendChatMessage("flee", groupChannel)
elseif action == "recruit_tank" then
SendChatMessage(".bot role tank", "SAY")
elseif action == "recruit_healer" then
SendChatMessage(".bot role heal", "SAY")
elseif action == "recruit_dps" then
SendChatMessage(".bot role dps", "SAY")
elseif action == "regear" then
SendChatMessage(".bot regear", "SAY")
elseif action == "raid" then
local size = arg or "5"
SendChatMessage(".bot raid " .. tostring(size), "SAY")
end
end
local tacticalBar = nil
local recruitMenu = nil
function C.ToggleTacticalBar()
if not tacticalBar then
C.CreateTacticalBar()
end
if tacticalBar:IsShown() then
tacticalBar:Hide()
if ProjectJaina_Companion_DB then ProjectJaina_Companion_DB.BarHidden = true end
else
tacticalBar:Show()
if ProjectJaina_Companion_DB then ProjectJaina_Companion_DB.BarHidden = false end
end
end
function C.ToggleRecruitMenu(anchorFrame)
if not recruitMenu then
recruitMenu = CreateFrame("Frame", "ProjectJaina_RecruitMenu", UIParent)
recruitMenu:SetSize(140, 164)
recruitMenu:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 10,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
})
recruitMenu:SetBackdropColor(0.04, 0.05, 0.08, 0.95)
recruitMenu:SetBackdropBorderColor(0.83, 0.69, 0.22, 1.0)
recruitMenu:SetFrameStrata("DIALOG")
local items = {
{ text = "|cFF0070DETanque (Tank)|r", cmd = "recruit_tank" },
{ text = "|cFF00FF00Sanador (Healer)|r", cmd = "recruit_healer" },
{ text = "|cFFFF2020DPS|r", cmd = "recruit_dps" },
{ text = "|cFFFFD100Grupo 5 (5-man)|r", cmd = "raid", arg = 5 },
{ text = "|cFFFF8000Banda 10 (10-man)|r", cmd = "raid", arg = 10 },
{ text = "|cFF9932CCBanda 25 (25-man)|r", cmd = "raid", arg = 25 },
}
for i, item in ipairs(items) do
local b = CreateFrame("Button", nil, recruitMenu)
b:SetSize(130, 22)
b:SetPoint("TOP", recruitMenu, "TOP", 0, -6 - (i - 1) * 24)
local fontStr = b:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
fontStr:SetPoint("LEFT", b, "LEFT", 8, 0)
fontStr:SetText(item.text)
local highlight = b:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
highlight:SetAlpha(0.35)
b:SetScript("OnClick", function()
C.SendCommand(item.cmd, item.arg)
recruitMenu:Hide()
end)
end
end
if recruitMenu:IsShown() then
recruitMenu:Hide()
else
recruitMenu:ClearAllPoints()
recruitMenu:SetPoint("BOTTOMLEFT", anchorFrame, "TOPLEFT", 0, 8)
recruitMenu:Show()
end
end
function C.CreateTacticalBar()
if tacticalBar then return end
tacticalBar = CreateFrame("Frame", "ProjectJaina_TacticalBar", UIParent)
tacticalBar:SetSize(250, 46)
tacticalBar:SetPoint("CENTER", UIParent, "CENTER", 0, -220)
tacticalBar:SetMovable(true)
tacticalBar:EnableMouse(true)
tacticalBar:RegisterForDrag("LeftButton")
tacticalBar:SetScript("OnDragStart", tacticalBar.StartMoving)
tacticalBar:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, relPoint, x, y = self:GetPoint()
ProjectJaina_Companion_DB = ProjectJaina_Companion_DB or {}
ProjectJaina_Companion_DB.TacticalPos = { point, relPoint, x, y }
end)
tacticalBar:SetClampedToScreen(true)
tacticalBar:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
})
tacticalBar:SetBackdropColor(0.04, 0.06, 0.10, 0.90)
tacticalBar:SetBackdropBorderColor(0.83, 0.69, 0.22, 0.95)
local title = tacticalBar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
title:SetPoint("TOPLEFT", tacticalBar, "TOPLEFT", 8, -4)
title:SetText("|cFFD4AF37JAINA|r Táctico")
local btnDefs = {
{ name = "Follow", tip = "Seguir (Follow)\n|cFF888888Ordena a los bots seguirte de cerca.|r", icon = "Interface\\Icons\\Ability_Tracking", cmd = "follow" },
{ name = "Stay", tip = "Alto / Esperar (Stay)\n|cFF888888Mantiene a los bots en su posición actual.|r", icon = "Interface\\Icons\\Spell_Nature_StoneClawTotem", cmd = "stay" },
{ name = "Attack", tip = "Atacar Objetivo (Attack)\n|cFF888888Ordena a los bots atacar a tu objetivo actual.|r", icon = "Interface\\Icons\\Ability_DualWield", cmd = "attack" },
{ name = "Pull", tip = "Auto-Pull del Tanque\n|cFF888888El bot tanque inicia el pull de forma táctica.|r", icon = "Interface\\Icons\\Ability_Hunter_SniperShot", cmd = "pull" },
{ name = "Passive", tip = "Modo Pasivo\n|cFF888888Detiene el combate de los bots inmediatamente.|r", icon = "Interface\\Icons\\Spell_Holy_Peace", cmd = "passive" },
{ name = "Recruit", tip = "Reclutar Bot\n|cFF888888Click izquierdo: Menú de roles.\nClick derecho: Reclutar Tanque.|r", icon = "Interface\\Icons\\Achievement_GuildPerk_MassResurrection", isRecruit = true },
{ name = "Regear", tip = "Reequipar (Regear)\n|cFF888888Actualiza y optimiza el equipo del bot seleccionado.|r", icon = "Interface\\Icons\\INV_Hammer_20", cmd = "regear" },
}
local btnSize = 28
local startX = 6
for i, def in ipairs(btnDefs) do
local btn = CreateFrame("Button", "PJ_TacticalBtn_" .. def.name, tacticalBar)
btn:SetSize(btnSize, btnSize)
btn:SetPoint("BOTTOMLEFT", tacticalBar, "BOTTOMLEFT", startX + (i - 1) * (btnSize + 6), 5)
local tex = btn:CreateTexture(nil, "BACKGROUND")
tex:SetAllPoints()
tex:SetTexture(def.icon)
btn.icon = tex
local highlight = btn:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetTexture("Interface\\Buttons\\ButtonHilight-Square")
highlight:SetBlendMode("ADD")
btn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:ClearLines()
GameTooltip:AddLine("|cFFD4AF37" .. def.name .. "|r")
GameTooltip:AddLine(def.tip, 1, 1, 1, true)
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
if def.isRecruit then
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
btn:SetScript("OnClick", function(self, button)
if button == "RightButton" then
C.SendCommand("recruit_tank")
else
C.ToggleRecruitMenu(self)
end
end)
else
btn:SetScript("OnClick", function()
C.SendCommand(def.cmd)
end)
end
end
local closeBtn = CreateFrame("Button", nil, tacticalBar, "UIPanelCloseButton")
closeBtn:SetSize(20, 20)
closeBtn:SetPoint("TOPRIGHT", tacticalBar, "TOPRIGHT", 2, 2)
closeBtn:SetScript("OnClick", function()
tacticalBar:Hide()
if ProjectJaina_Companion_DB then ProjectJaina_Companion_DB.BarHidden = true end
end)
if ProjectJaina_Companion_DB and ProjectJaina_Companion_DB.TacticalPos then
local pos = ProjectJaina_Companion_DB.TacticalPos
tacticalBar:ClearAllPoints()
tacticalBar:SetPoint(pos[1], UIParent, pos[2], pos[3], pos[4])
end
if ProjectJaina_Companion_DB and ProjectJaina_Companion_DB.BarHidden then
tacticalBar:Hide()
else
tacticalBar:Show()
end
end
SLASH_PROJECTJAINA_BOTBAR1 = "/jainabot"
SLASH_PROJECTJAINA_BOTBAR2 = "/jainacompanion"
SLASH_PROJECTJAINA_BOTBAR3 = "/botbar"
SlashCmdList["PROJECTJAINA_BOTBAR"] = function(msg)
local cmd = (msg or ""):lower():match("^%s*(%S+)")
if cmd == "follow" or cmd == "stay" or cmd == "attack" or cmd == "pull" or cmd == "passive" or cmd == "regear" then
C.SendCommand(cmd)
elseif cmd == "recruit" then
local sub = (msg or ""):lower():match("recruit%s+(%S+)")
if sub == "tank" then C.SendCommand("recruit_tank")
elseif sub == "healer" or sub == "heal" then C.SendCommand("recruit_healer")
elseif sub == "dps" then C.SendCommand("recruit_dps")
else C.ToggleRecruitMenu(tacticalBar or UIParent)
end
else
C.ToggleTacticalBar()
end
end