Repository navigation
Expand file tree
/
Copy pathWCS_BrainAutoProfiles.lua
More file actions
554 lines (476 loc) · 18.2 KB
/
Copy pathWCS_BrainAutoProfiles.lua
File metadata and controls
554 lines (476 loc) · 18.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
if WCS_Brain and WCS_Brain.ENABLED == false then return end
-- WCS_BrainAutoProfiles.lua
-- Sistema de Perfiles Automáticos para WCS_Brain
-- Detecta la situación del jugador y cambia el perfil automáticamente
WCS_BrainAutoProfiles = {}
-- Variables locales
local currentSituation = "SOLO"
local lastCheck = 0
local pendingProfile = nil
local pendingTime = 0
local isChanging = false
-- Configuración por defecto
local defaultConfig = {
enabled = false, -- Desactivado por defecto para no sorprender al usuario
delay = 3, -- Segundos antes de cambiar perfil
notifications = true,
checkInterval = 2, -- Chequear cada 2 segundos
rules = {
{
name = "Raid",
priority = 1,
condition = "IN_RAID",
profile = "Affliction Raid",
enabled = true
},
{
name = "Dungeon",
priority = 2,
condition = "IN_DUNGEON",
profile = "Destruction Dungeon",
enabled = true
},
{
name = "Battleground",
priority = 3,
condition = "IN_BATTLEGROUND",
profile = "Destruction PvP",
enabled = true
},
{
name = "Party",
priority = 4,
condition = "IN_PARTY",
profile = "Affliction Solo",
enabled = true
},
{
name = "Ciudad",
priority = 5,
condition = "IN_CITY",
profile = "Affliction Solo",
enabled = false -- Desactivado por defecto
},
{
name = "Solo",
priority = 6,
condition = "SOLO",
profile = "Affliction Solo",
enabled = true
}
}
}
-- Inicialización
function WCS_BrainAutoProfiles:Initialize()
-- Crear configuración si no existe
if not WCS_BrainSaved then
WCS_BrainSaved = {}
end
if not WCS_BrainSaved.autoProfiles then
WCS_BrainSaved.autoProfiles = defaultConfig
end
-- Registrar eventos
self:RegisterEvents()
-- Mensaje de inicio
if WCS_BrainSaved.autoProfiles.enabled then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[WCS Brain]|r Sistema de Perfiles Automáticos activado")
end
end
-- Registrar eventos
function WCS_BrainAutoProfiles:RegisterEvents()
local frame = CreateFrame("Frame", "WCS_BrainAutoProfilesFrame")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("RAID_ROSTER_UPDATE")
frame:RegisterEvent("PARTY_MEMBERS_CHANGED")
frame:RegisterEvent("PLAYER_ENTERING_BATTLEGROUND")
frame:SetScript("OnEvent", function()
if event == "PLAYER_ENTERING_WORLD" then
WCS_BrainAutoProfiles:OnPlayerEnteringWorld()
else
WCS_BrainAutoProfiles:OnSituationChanged()
end
end)
-- OnUpdate para chequeo periódico
frame:SetScript("OnUpdate", function()
WCS_BrainAutoProfiles:OnUpdate(arg1)
end)
end
-- OnUpdate
function WCS_BrainAutoProfiles:OnUpdate(elapsed)
if not WCS_BrainSaved.autoProfiles.enabled then
return
end
lastCheck = lastCheck + elapsed
-- Chequear cada X segundos
if lastCheck >= WCS_BrainSaved.autoProfiles.checkInterval then
lastCheck = 0
self:CheckSituation()
end
-- Manejar cambio pendiente
if pendingProfile then
pendingTime = pendingTime + elapsed
if pendingTime >= WCS_BrainSaved.autoProfiles.delay then
self:ApplyPendingProfile()
end
end
end
-- Al entrar al mundo
function WCS_BrainAutoProfiles:OnPlayerEnteringWorld()
-- Esperar 2 segundos antes de evaluar (dar tiempo a que cargue todo)
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 2 then
frame:SetScript("OnUpdate", nil)
WCS_BrainAutoProfiles:CheckSituation()
end
end)
end
-- Cuando cambia la situación
function WCS_BrainAutoProfiles:OnSituationChanged()
if not WCS_BrainSaved.autoProfiles.enabled then
return
end
-- Chequear inmediatamente
self:CheckSituation()
end
-- Chequear situación actual
function WCS_BrainAutoProfiles:CheckSituation()
if isChanging then
return -- Evitar chequeos mientras se está cambiando
end
local newSituation = self:DetectSituation()
if newSituation ~= currentSituation then
currentSituation = newSituation
self:EvaluateRules()
end
end
-- Detectar situación actual
function WCS_BrainAutoProfiles:DetectSituation()
-- Prioridad: Raid > Dungeon > BG > Party > City > Solo
-- Raid
if GetNumRaidMembers() > 0 then
return "IN_RAID"
end
-- Dungeon/Instancia
local inInstance, instanceType = IsInInstance()
if inInstance then
if instanceType == "pvp" then
return "IN_BATTLEGROUND"
elseif instanceType == "party" or instanceType == "raid" then
return "IN_DUNGEON"
end
end
-- Party
if GetNumPartyMembers() > 0 then
return "IN_PARTY"
end
-- Ciudad (detectar por zona)
local zone = GetZoneText()
if self:IsCity(zone) then
return "IN_CITY"
end
-- Solo
return "SOLO"
end
-- Verificar si una zona es ciudad
function WCS_BrainAutoProfiles:IsCity(zone)
local cities = {
-- Horde
["Orgrimmar"] = true,
["Thunder Bluff"] = true,
["Undercity"] = true,
-- Alliance
["Stormwind City"] = true,
["Ironforge"] = true,
["Darnassus"] = true,
-- Neutral
["Shattrath City"] = true,
["Dalaran"] = true,
["Booty Bay"] = true,
["Gadgetzan"] = true,
["Everlook"] = true,
["Ratchet"] = true
}
return cities[zone] == true
end
-- Evaluar reglas y determinar perfil a usar
function WCS_BrainAutoProfiles:EvaluateRules()
local config = WCS_BrainSaved.autoProfiles
local bestRule = nil
local bestPriority = 999
-- Buscar la regla con mayor prioridad que coincida
for i = 1, table.getn(config.rules) do
local rule = config.rules[i]
if rule.enabled and rule.profile and rule.profile ~= "" and self:CheckCondition(rule.condition) then
if rule.priority < bestPriority then
bestPriority = rule.priority
bestRule = rule
end
end
end
if bestRule and bestRule.profile then
self:ScheduleProfileChange(bestRule.profile, bestRule.name)
end
end
-- Verificar si una condición se cumple
function WCS_BrainAutoProfiles:CheckCondition(condition)
if condition == "IN_RAID" then
return GetNumRaidMembers() > 0
elseif condition == "IN_PARTY" then
return GetNumPartyMembers() > 0 and GetNumRaidMembers() == 0
elseif condition == "IN_DUNGEON" then
local inInstance, instanceType = IsInInstance()
return inInstance and (instanceType == "party" or instanceType == "raid")
elseif condition == "IN_BATTLEGROUND" then
local inInstance, instanceType = IsInInstance()
return inInstance and instanceType == "pvp"
elseif condition == "IN_CITY" then
return self:IsCity(GetZoneText())
elseif condition == "IN_COMBAT" then
return UnitAffectingCombat("player")
elseif condition == "SOLO" then
return GetNumPartyMembers() == 0 and GetNumRaidMembers() == 0
elseif condition == "RESTING" then
return IsResting()
end
return false
end
-- Programar cambio de perfil
function WCS_BrainAutoProfiles:ScheduleProfileChange(profileName, ruleName)
-- Verificar que el perfil existe
if not WCS_BrainProfiles then
return
end
-- Verificar que profileName no es nil o vacío
if not profileName or profileName == "" then
return
end
-- Verificar que el perfil existe en la tabla de perfiles
if not WCS_BrainSaved or not WCS_BrainSaved.profiles or not WCS_BrainSaved.profiles[profileName] then
return
end
-- Verificar que no es el perfil actual
local currentProfile = WCS_BrainProfiles:GetCurrentProfileName()
if currentProfile == profileName then
return -- Ya estamos usando este perfil
end
-- Programar cambio
pendingProfile = profileName
pendingTime = 0
if WCS_BrainSaved.autoProfiles.notifications then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"|cFF00FF00[Auto-Perfil]|r Cambiando a |cFFFFFF00%s|r en %d segundos... (Regla: %s)",
profileName,
WCS_BrainSaved.autoProfiles.delay,
ruleName
))
end
end
-- Aplicar perfil pendiente
function WCS_BrainAutoProfiles:ApplyPendingProfile()
if not pendingProfile then
return
end
isChanging = true
-- Cargar perfil
if WCS_BrainProfiles then
WCS_BrainProfiles:LoadProfile(pendingProfile)
if WCS_BrainSaved.autoProfiles.notifications then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"|cFF00FF00[Auto-Perfil]|r Perfil |cFFFFFF00%s|r aplicado",
pendingProfile
))
end
PlaySound("igMainMenuOptionCheckBoxOn")
end
-- Limpiar
pendingProfile = nil
pendingTime = 0
-- Esperar 1 segundo antes de permitir otro cambio
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 1 then
frame:SetScript("OnUpdate", nil)
isChanging = false
end
end)
end
-- Activar sistema
function WCS_BrainAutoProfiles:Enable()
WCS_BrainSaved.autoProfiles.enabled = true
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[WCS Brain]|r Sistema de Perfiles Automáticos |cFF00FF00ACTIVADO|r")
PlaySound("igMainMenuOptionCheckBoxOn")
-- Evaluar inmediatamente
self:CheckSituation()
end
-- Desactivar sistema
function WCS_BrainAutoProfiles:Disable()
WCS_BrainSaved.autoProfiles.enabled = false
pendingProfile = nil
pendingTime = 0
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[WCS Brain]|r Sistema de Perfiles Automáticos |cFFFF0000DESACTIVADO|r")
PlaySound("igMainMenuOptionCheckBoxOff")
end
-- Toggle
function WCS_BrainAutoProfiles:Toggle()
if WCS_BrainSaved.autoProfiles.enabled then
self:Disable()
else
self:Enable()
end
end
-- Obtener estado
function WCS_BrainAutoProfiles:IsEnabled()
return WCS_BrainSaved.autoProfiles.enabled
end
-- Obtener configuración
function WCS_BrainAutoProfiles:GetConfig()
return WCS_BrainSaved.autoProfiles
end
-- Actualizar regla
function WCS_BrainAutoProfiles:UpdateRule(index, profile, enabled)
if not WCS_BrainSaved.autoProfiles.rules[index] then
return false
end
if profile then
WCS_BrainSaved.autoProfiles.rules[index].profile = profile
end
if enabled ~= nil then
WCS_BrainSaved.autoProfiles.rules[index].enabled = enabled
end
return true
end
-- Obtener situación actual
function WCS_BrainAutoProfiles:GetCurrentSituation()
return currentSituation
end
-- Obtener perfil pendiente
function WCS_BrainAutoProfiles:GetPendingProfile()
return pendingProfile
end
-- Cancelar cambio pendiente
function WCS_BrainAutoProfiles:CancelPending()
if pendingProfile then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Cambio cancelado")
pendingProfile = nil
pendingTime = 0
end
end
-- ========================================================================
-- FUNCIONES DE DIAGNÓSTICO Y TESTING
-- ========================================================================
function WCS_BrainAutoProfiles:RunDiagnostics()
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00========================================|r")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00[Auto-Perfiles] DIAGNÓSTICO COMPLETO|r")
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00========================================|r")
-- 1. Estado del sistema
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00\n1. ESTADO DEL SISTEMA:|r")
local enabled = self:IsEnabled()
DEFAULT_CHAT_FRAME:AddMessage(" Sistema: " .. (enabled and "|cFF00FF00ACTIVADO|r" or "|cFFFF0000DESACTIVADO|r"))
if not WCS_BrainSaved or not WCS_BrainSaved.autoProfiles then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF0000 ERROR: Configuración no encontrada|r")
return
end
local config = WCS_BrainSaved.autoProfiles
DEFAULT_CHAT_FRAME:AddMessage(" Delay: " .. config.delay .. " segundos")
DEFAULT_CHAT_FRAME:AddMessage(" Notificaciones: " .. (config.notifications and "|cFF00FF00SÍ|r" or "|cFFFF0000NO|r"))
DEFAULT_CHAT_FRAME:AddMessage(" Intervalo: " .. config.checkInterval .. " segundos")
-- 2. Situación actual
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00\n2. SITUACIÓN ACTUAL:|r")
DEFAULT_CHAT_FRAME:AddMessage(" Detectada: |cFF00FFFF" .. currentSituation .. "|r")
local inRaid = GetNumRaidMembers() > 0
local inParty = GetNumPartyMembers() > 0
local inInstance, instanceType = IsInInstance()
local zoneName = GetRealZoneText() or "Desconocida"
DEFAULT_CHAT_FRAME:AddMessage(" En Raid: " .. (inRaid and "|cFF00FF00SÍ|r (" .. GetNumRaidMembers() .. " miembros)" or "|cFFFF0000NO|r"))
DEFAULT_CHAT_FRAME:AddMessage(" En Party: " .. (inParty and "|cFF00FF00SÍ|r (" .. GetNumPartyMembers() .. " miembros)" or "|cFFFF0000NO|r"))
DEFAULT_CHAT_FRAME:AddMessage(" En Instancia: " .. (inInstance and "|cFF00FF00SÍ|r" or "|cFFFF0000NO|r"))
if inInstance then
DEFAULT_CHAT_FRAME:AddMessage(" Tipo: |cFF00FFFF" .. (instanceType or "unknown") .. "|r")
end
DEFAULT_CHAT_FRAME:AddMessage(" Zona: |cFF00FFFF" .. zoneName .. "|r")
-- 3. Reglas configuradas
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00\n3. REGLAS CONFIGURADAS:|r")
if config.rules then
for i = 1, table.getn(config.rules) do
local rule = config.rules[i]
local status = rule.enabled and "|cFF00FF00✓|r" or "|cFFFF0000✗|r"
DEFAULT_CHAT_FRAME:AddMessage(" " .. status .. " [P" .. rule.priority .. "] " .. rule.condition .. " → " .. rule.profile)
end
end
-- 4. Perfil actual
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00\n4. PERFIL ACTUAL:|r")
if WCS_BrainProfiles and WCS_BrainProfiles.GetCurrentProfileName then
local currentProfile = WCS_BrainProfiles.GetCurrentProfileName()
DEFAULT_CHAT_FRAME:AddMessage(" Activo: |cFF00FFFF" .. currentProfile .. "|r")
else
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF0000 ERROR: WCS_BrainProfiles no disponible|r")
end
-- 5. Cambio pendiente
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00\n5. CAMBIO PENDIENTE:|r")
if pendingProfile then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00 Programado: " .. pendingProfile .. "|r")
DEFAULT_CHAT_FRAME:AddMessage(" Tiempo restante: ~" .. math.floor(pendingTime) .. "s")
else
DEFAULT_CHAT_FRAME:AddMessage("|cFF888888 Ninguno|r")
end
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00========================================|r")
PlaySound("igMainMenuOptionCheckBoxOn")
end
function WCS_BrainAutoProfiles:ForceCheck()
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Forzando verificación...")
if not self:IsEnabled() then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF0000Sistema desactivado. Usa /ap on|r")
return
end
self:CheckAndApply()
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Verificación completada")
end
-- Comando slash
SLASH_AUTOPROFILE1 = "/autoprofile"
SLASH_AUTOPROFILE2 = "/ap"
SlashCmdList["AUTOPROFILE"] = function(msg)
msg = string.lower(msg or "")
if msg == "on" or msg == "enable" then
WCS_BrainAutoProfiles:Enable()
elseif msg == "off" or msg == "disable" then
WCS_BrainAutoProfiles:Disable()
elseif msg == "toggle" or msg == "" then
WCS_BrainAutoProfiles:Toggle()
elseif msg == "status" then
local status = WCS_BrainAutoProfiles:IsEnabled() and "|cFF00FF00ACTIVADO|r" or "|cFFFF0000DESACTIVADO|r"
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Estado: " .. status)
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Situación actual: " .. currentSituation)
if pendingProfile then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Cambio pendiente: " .. pendingProfile)
end
elseif msg == "cancel" then
WCS_BrainAutoProfiles:CancelPending()
elseif msg == "test" or msg == "debug" then
WCS_BrainAutoProfiles:RunDiagnostics()
elseif msg == "force" then
WCS_BrainAutoProfiles:ForceCheck()
else
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[Auto-Perfil]|r Comandos disponibles:")
DEFAULT_CHAT_FRAME:AddMessage(" /ap on - Activar")
DEFAULT_CHAT_FRAME:AddMessage(" /ap off - Desactivar")
DEFAULT_CHAT_FRAME:AddMessage(" /ap toggle - Alternar")
DEFAULT_CHAT_FRAME:AddMessage(" /ap status - Ver estado")
DEFAULT_CHAT_FRAME:AddMessage(" /ap cancel - Cancelar cambio pendiente")
DEFAULT_CHAT_FRAME:AddMessage(" |cFFFFFF00/ap test|r - Diagnóstico completo")
DEFAULT_CHAT_FRAME:AddMessage(" |cFFFFFF00/ap force|r - Forzar verificación")
end
end
-- Inicializar al cargar
local initFrame = CreateFrame("Frame")
initFrame:RegisterEvent("ADDON_LOADED")
initFrame:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == "WCS_Brain" then
WCS_BrainAutoProfiles:Initialize()
end
end)