Repository navigation
Expand file tree
/
Copy pathWCS_BrainMemory.lua
More file actions
657 lines (560 loc) · 22.7 KB
/
Copy pathWCS_BrainMemory.lua
File metadata and controls
657 lines (560 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
--[[
WCS_BrainMemory.lua - Sistema de Recuerdos v6.6.0
Compatible con Lua 5.0 (WoW 1.12 / Turtle WoW)
El Brain recuerda encuentros anteriores y aprende de ellos
Autor: Elnazzareno (DarckRovert)
Twitch: twitch.tv/darckrovert
Kick: kick.com/darckrovert
]]--
if WCS_Brain and WCS_Brain.ENABLED == false then return end
WCS_BrainMemory = WCS_BrainMemory or {}
WCS_BrainMemory.VERSION = "6.6.0"
-- ============================================================================
-- ESTRUCTURA DE MEMORIA
-- ============================================================================
WCS_BrainMemory.Encounters = {}
WCS_BrainMemory.Config = {
maxEncounters = 500,
autoSave = true,
saveInterval = 300, -- 5 minutos
trackRotations = true,
trackDifficulty = true
}
-- ============================================================================
-- INTEGRACIÓN CON WCS_BrainMetrics
-- ============================================================================
-- Sincronizar con WCS_BrainMetrics (sistema existente)
function WCS_BrainMemory:SyncWithMetrics()
if not WCS_BrainMetrics or not WCS_BrainMetrics.Data then
return
end
-- Obtener datos de enemigos desde WCS_BrainMetrics
if WCS_BrainMetrics.Data.enemyTypes then
for enemyName, enemyData in pairs(WCS_BrainMetrics.Data.enemyTypes) do
if enemyData.encounters and enemyData.encounters > 0 then
-- Crear o actualizar memoria
if not self.Encounters[enemyName] then
self.Encounters[enemyName] = {
name = enemyName,
firstSeen = time(),
lastSeen = time(),
encounters = 0,
kills = 0,
deaths = 0,
totalDamage = 0,
totalTime = 0,
avgTTK = 0,
avgDPS = 0,
bestRotation = {},
worstRotation = {},
notes = "",
difficulty = "Unknown",
level = 0,
type = "Unknown",
classification = "normal",
abilities = {},
weaknesses = {},
resistances = {}
}
end
local memory = self.Encounters[enemyName]
memory.encounters = enemyData.encounters or memory.encounters
memory.kills = enemyData.kills or memory.kills
memory.deaths = enemyData.deaths or memory.deaths
memory.lastSeen = time()
-- Calcular dificultad
if self.Config.trackDifficulty then
memory.difficulty = self:CalculateDifficulty(memory)
end
end
end
end
if WCS_BrainLogger then
WCS_BrainLogger:Debug("Memory", "Sincronizado con WCS_BrainMetrics")
end
end
-- ============================================================================
-- INICIALIZACIÓN
-- ============================================================================
function WCS_BrainMemory:Initialize()
-- Cargar desde SavedVariables
if WCS_BrainSaved and WCS_BrainSaved.memory then
self.Encounters = WCS_BrainSaved.memory
else
self.Encounters = {}
end
-- Iniciar auto-save
if self.Config.autoSave then
self:StartAutoSave()
end
-- Sincronizar con WCS_BrainMetrics al iniciar
self:SyncWithMetrics()
if WCS_BrainLogger then
local count = 0
for _ in pairs(self.Encounters) do count = count + 1 end
WCS_BrainLogger:Info("Memory", "Sistema de recuerdos inicializado (" .. count .. " encuentros)")
end
end
-- ============================================================================
-- RECORDAR ENCUENTRO
-- ============================================================================
function WCS_BrainMemory:Remember(mobName, outcome, data)
if not mobName then return end
-- Crear entrada si no existe
if not self.Encounters[mobName] then
self.Encounters[mobName] = {
name = mobName,
firstSeen = time(),
lastSeen = time(),
encounters = 0,
kills = 0,
deaths = 0,
totalDamage = 0,
totalTime = 0,
avgTTK = 0,
avgDPS = 0,
bestRotation = {},
worstRotation = {},
notes = "",
difficulty = "Unknown",
level = 0,
type = "Unknown",
classification = "normal",
abilities = {},
weaknesses = {},
resistances = {}
}
end
local memory = self.Encounters[mobName]
memory.encounters = memory.encounters + 1
memory.lastSeen = time()
-- Actualizar datos básicos
if data then
if data.level then memory.level = data.level end
if data.type then memory.type = data.type end
if data.classification then memory.classification = data.classification end
end
-- Actualizar resultado
if outcome == "kill" then
memory.kills = memory.kills + 1
if data and data.duration then
memory.totalTime = memory.totalTime + data.duration
memory.avgTTK = memory.totalTime / memory.kills
end
if data and data.damage then
memory.totalDamage = memory.totalDamage + data.damage
memory.avgDPS = memory.totalDamage / memory.totalTime
end
-- Actualizar mejor rotación
if data and data.rotation and self.Config.trackRotations then
self:UpdateBestRotation(memory, data.rotation, data.duration)
end
elseif outcome == "death" then
memory.deaths = memory.deaths + 1
-- Actualizar peor rotación
if data and data.rotation and self.Config.trackRotations then
memory.worstRotation = data.rotation
end
end
-- Calcular dificultad
if self.Config.trackDifficulty then
memory.difficulty = self:CalculateDifficulty(memory)
end
-- Verificar límite de memoria
self:CheckMemoryLimit()
if WCS_BrainLogger then
WCS_BrainLogger:Debug("Memory", "Encuentro recordado: " .. mobName .. " (" .. outcome .. ")")
end
end
-- ============================================================================
-- RECUPERAR MEMORIA
-- ============================================================================
function WCS_BrainMemory:Recall(mobName)
return self.Encounters[mobName]
end
function WCS_BrainMemory:HasMemory(mobName)
return self.Encounters[mobName] ~= nil
end
function WCS_BrainMemory:GetAllMemories()
local memories = {}
for name, data in pairs(self.Encounters) do
table.insert(memories, data)
end
return memories
end
function WCS_BrainMemory:GetRecentMemories(count)
count = count or 10
local memories = self:GetAllMemories()
-- Ordenar por última vez visto
table.sort(memories, function(a, b)
return a.lastSeen > b.lastSeen
end)
-- Retornar top N
local result = {}
for i = 1, count do
if memories[i] then
table.insert(result, memories[i])
end
end
return result
end
function WCS_BrainMemory:GetDangerousMobs(count)
count = count or 10
local memories = self:GetAllMemories()
-- Filtrar solo mobs con muertes
local dangerous = {}
for i = 1, table.getn(memories) do
if memories[i].deaths > 0 then
table.insert(dangerous, memories[i])
end
end
-- Ordenar por ratio de muertes
table.sort(dangerous, function(a, b)
local ratioA = a.deaths / a.encounters
local ratioB = b.deaths / b.encounters
return ratioA > ratioB
end)
-- Retornar top N
local result = {}
for i = 1, count do
if dangerous[i] then
table.insert(result, dangerous[i])
end
end
return result
end
-- ============================================================================
-- ANÁLISIS DE ROTACIONES
-- ============================================================================
function WCS_BrainMemory:UpdateBestRotation(memory, rotation, duration)
if not rotation or table.getn(rotation) == 0 then return end
-- Si no hay mejor rotación, usar esta
if not memory.bestRotation or table.getn(memory.bestRotation) == 0 then
memory.bestRotation = rotation
memory.bestRotationTTK = duration
return
end
-- Si esta rotación es más rápida, reemplazar
if duration < memory.bestRotationTTK then
memory.bestRotation = rotation
memory.bestRotationTTK = duration
end
end
function WCS_BrainMemory:GetBestRotation(mobName)
local memory = self:Recall(mobName)
if memory and memory.bestRotation then
return memory.bestRotation
end
return nil
end
-- ============================================================================
-- CÁLCULO DE DIFICULTAD
-- ============================================================================
function WCS_BrainMemory:CalculateDifficulty(memory)
if memory.encounters == 0 then return "Unknown" end
local deathRate = memory.deaths / memory.encounters
local avgTTK = memory.avgTTK
-- Clasificación basada en muerte rate y TTK
if deathRate >= 0.5 then
return "Very Hard"
elseif deathRate >= 0.25 then
return "Hard"
elseif avgTTK > 30 then
return "Medium"
elseif avgTTK > 15 then
return "Easy"
else
return "Very Easy"
end
end
function WCS_BrainMemory:GetDifficultyColor(difficulty)
if difficulty == "Very Hard" then
return "|cFFFF0000" -- Rojo
elseif difficulty == "Hard" then
return "|cFFFF8800" -- Naranja
elseif difficulty == "Medium" then
return "|cFFFFFF00" -- Amarillo
elseif difficulty == "Easy" then
return "|cFF00FF00" -- Verde
elseif difficulty == "Very Easy" then
return "|cFF00FFFF" -- Cyan
else
return "|cFFFFFFFF" -- Blanco
end
end
-- ============================================================================
-- NOTAS Y ANOTACIONES
-- ============================================================================
function WCS_BrainMemory:AddNote(mobName, note)
local memory = self:Recall(mobName)
if memory then
if memory.notes == "" then
memory.notes = note
else
memory.notes = memory.notes .. "; " .. note
end
if WCS_BrainLogger then
WCS_BrainLogger:Info("Memory", "Nota agregada a " .. mobName)
end
end
end
function WCS_BrainMemory:ClearNotes(mobName)
local memory = self:Recall(mobName)
if memory then
memory.notes = ""
end
end
-- ============================================================================
-- GESTIÓN DE MEMORIA
-- ============================================================================
function WCS_BrainMemory:CheckMemoryLimit()
local count = 0
for _ in pairs(self.Encounters) do
count = count + 1
end
if count > self.Config.maxEncounters then
self:EvictOldest()
end
end
function WCS_BrainMemory:EvictOldest()
local oldest = nil
local oldestTime = nil
for name, memory in pairs(self.Encounters) do
if not oldestTime or memory.lastSeen < oldestTime then
oldest = name
oldestTime = memory.lastSeen
end
end
if oldest then
self.Encounters[oldest] = nil
if WCS_BrainLogger then
WCS_BrainLogger:Debug("Memory", "Memoria más antigua eliminada: " .. oldest)
end
end
end
function WCS_BrainMemory:Clear()
self.Encounters = {}
if WCS_BrainLogger then
WCS_BrainLogger:Info("Memory", "Todas las memorias borradas")
end
end
function WCS_BrainMemory:Forget(mobName)
if self.Encounters[mobName] then
self.Encounters[mobName] = nil
if WCS_BrainLogger then
WCS_BrainLogger:Info("Memory", "Memoria olvidada: " .. mobName)
end
return true
end
return false
end
-- ============================================================================
-- GUARDADO AUTOMÁTICO
-- ============================================================================
function WCS_BrainMemory:StartAutoSave()
if not self.saveFrame then
self.saveFrame = CreateFrame("Frame")
self.saveFrame.elapsed = 0
self.saveFrame:SetScript("OnUpdate", function()
this.elapsed = this.elapsed + arg1
if this.elapsed >= WCS_BrainMemory.Config.saveInterval then
this.elapsed = 0
WCS_BrainMemory:Save()
end
end)
end
end
function WCS_BrainMemory:Save()
if not WCS_BrainSaved then
WCS_BrainSaved = {}
end
WCS_BrainSaved.memory = self.Encounters
if WCS_BrainLogger then
local count = 0
for _ in pairs(self.Encounters) do count = count + 1 end
WCS_BrainLogger:Debug("Memory", "Memorias guardadas (" .. count .. " encuentros)")
end
end
-- ============================================================================
-- EXPORTACIÓN
-- ============================================================================
function WCS_BrainMemory:ExportMemory(mobName)
local memory = self:Recall(mobName)
if not memory then return nil end
local output = "Memory: " .. mobName .. "\n"
output = output .. "Encounters: " .. memory.encounters .. "\n"
output = output .. "Kills: " .. memory.kills .. " | Deaths: " .. memory.deaths .. "\n"
output = output .. "Avg TTK: " .. string.format("%.1f", memory.avgTTK) .. "s\n"
output = output .. "Avg DPS: " .. string.format("%.1f", memory.avgDPS) .. "\n"
output = output .. "Difficulty: " .. memory.difficulty .. "\n"
if memory.notes ~= "" then
output = output .. "Notes: " .. memory.notes .. "\n"
end
return output
end
-- ============================================================================
-- COMANDOS SLASH
-- ============================================================================
SLASH_WCSMEMORY1 = "/wcsmemory"
SLASH_WCSMEMORY2 = "/brainmemory"
SlashCmdList["WCSMEMORY"] = function(msg)
local args = {}
for word in string.gfind(msg, "%S+") do
table.insert(args, word)
end
local cmd = args[1]
if not cmd or cmd == "help" then
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Comandos:")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFCC00/brainmemory [mobname]|r - Ver memoria de un mob")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFCC00/brainmemory list [count]|r - Listar memorias recientes")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFCC00/brainmemory dangerous [count]|r - Mobs más peligrosos")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFCC00/brainmemory forget [mobname]|r - Olvidar un mob")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFCC00/brainmemory clear|r - Borrar todas las memorias")
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFCC00/brainmemory save|r - Guardar memorias")
return
end
if cmd == "list" then
local count = tonumber(args[2]) or 10
local memories = WCS_BrainMemory:GetRecentMemories(count)
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Memorias recientes:")
for i = 1, table.getn(memories) do
local m = memories[i]
local color = WCS_BrainMemory:GetDifficultyColor(m.difficulty)
DEFAULT_CHAT_FRAME:AddMessage(string.format(" %s%s|r: %d/%d K/D, %.1fs TTK, %s",
color, m.name, m.kills, m.deaths, m.avgTTK, m.difficulty))
end
elseif cmd == "dangerous" then
local count = tonumber(args[2]) or 10
local dangerous = WCS_BrainMemory:GetDangerousMobs(count)
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Mobs más peligrosos:")
for i = 1, table.getn(dangerous) do
local m = dangerous[i]
local deathRate = m.deaths / m.encounters * 100
DEFAULT_CHAT_FRAME:AddMessage(string.format(" |cFFFF0000%s|r: %.0f%% muerte rate (%d/%d)",
m.name, deathRate, m.deaths, m.encounters))
end
elseif cmd == "forget" then
local mobName = table.concat(args, " ", 2)
if mobName and mobName ~= "" then
if WCS_BrainMemory:Forget(mobName) then
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Memoria olvidada: " .. mobName)
else
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r No hay memoria de: " .. mobName)
end
end
elseif cmd == "clear" then
WCS_BrainMemory:Clear()
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Todas las memorias borradas")
elseif cmd == "save" then
WCS_BrainMemory:Save()
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Memorias guardadas")
else
-- Buscar memoria por nombre
local mobName = msg
local memory = WCS_BrainMemory:Recall(mobName)
if memory then
local color = WCS_BrainMemory:GetDifficultyColor(memory.difficulty)
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r Memoria: " .. color .. mobName .. "|r")
DEFAULT_CHAT_FRAME:AddMessage(" Encuentros: " .. memory.encounters)
DEFAULT_CHAT_FRAME:AddMessage(" Kills: " .. memory.kills .. " | Deaths: " .. memory.deaths)
DEFAULT_CHAT_FRAME:AddMessage(" Avg TTK: " .. string.format("%.1f", memory.avgTTK) .. "s")
DEFAULT_CHAT_FRAME:AddMessage(" Avg DPS: " .. string.format("%.1f", memory.avgDPS))
DEFAULT_CHAT_FRAME:AddMessage(" Dificultad: " .. color .. memory.difficulty .. "|r")
if memory.notes ~= "" then
DEFAULT_CHAT_FRAME:AddMessage(" Notas: " .. memory.notes)
end
if memory.bestRotation and table.getn(memory.bestRotation) > 0 then
local rotation = table.concat(memory.bestRotation, " -> ")
DEFAULT_CHAT_FRAME:AddMessage(" Mejor rotación: " .. rotation)
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r No hay memoria de: " .. mobName)
end
end
end
-- ============================================================================
-- TRACKING AUTOMÁTICO DE COMBATE
-- ============================================================================
WCS_BrainMemory.CurrentCombat = {
active = false,
targetName = nil,
targetLevel = nil,
targetType = nil,
targetClassification = nil,
startTime = 0,
rotation = {}
}
function WCS_BrainMemory:StartCombatTracking()
if self.CurrentCombat.active then return end
local targetName = UnitName("target")
if not targetName then return end
self.CurrentCombat.active = true
self.CurrentCombat.targetName = targetName
self.CurrentCombat.targetLevel = UnitLevel("target") or 0
self.CurrentCombat.targetType = UnitCreatureType("target") or "Unknown"
self.CurrentCombat.targetClassification = UnitClassification("target") or "normal"
self.CurrentCombat.startTime = GetTime()
self.CurrentCombat.rotation = {}
end
function WCS_BrainMemory:EndCombatTracking(outcome)
if not self.CurrentCombat.active then return end
local duration = GetTime() - self.CurrentCombat.startTime
local targetName = self.CurrentCombat.targetName
local combatData = {
duration = duration,
damage = 0,
rotation = self.CurrentCombat.rotation,
level = self.CurrentCombat.targetLevel,
type = self.CurrentCombat.targetType,
classification = self.CurrentCombat.targetClassification
}
self:Remember(targetName, outcome, combatData)
self.CurrentCombat.active = false
self.CurrentCombat.targetName = nil
self.CurrentCombat.rotation = {}
end
function WCS_BrainMemory:RecordSpellCast(spellName)
if not self.CurrentCombat.active then return end
if not spellName then return end
table.insert(self.CurrentCombat.rotation, spellName)
if table.getn(self.CurrentCombat.rotation) > 20 then
table.remove(self.CurrentCombat.rotation, 1)
end
end
-- ============================================================================
-- AUTO-INICIALIZACIÓN
-- ============================================================================
local function OnLoad()
WCS_BrainMemory:Initialize()
DEFAULT_CHAT_FRAME:AddMessage("|cFF9482C9[WCS Memory]|r v" .. WCS_BrainMemory.VERSION .. " - Sistema de recuerdos activo")
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_LOGOUT")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_DEAD")
frame:RegisterEvent("CHAT_MSG_COMBAT_HOSTILE_DEATH")
frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
frame:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == "WCS_Brain" then
OnLoad()
elseif event == "PLAYER_LOGOUT" then
WCS_BrainMemory:Save()
elseif event == "PLAYER_REGEN_DISABLED" then
WCS_BrainMemory:StartCombatTracking()
elseif event == "PLAYER_REGEN_ENABLED" then
WCS_BrainMemory:EndCombatTracking("kill")
elseif event == "PLAYER_DEAD" then
WCS_BrainMemory:EndCombatTracking("death")
elseif event == "CHAT_MSG_COMBAT_HOSTILE_DEATH" then
local targetName = WCS_BrainMemory.CurrentCombat.targetName
if targetName and arg1 and string.find(arg1, targetName) then
WCS_BrainMemory:EndCombatTracking("kill")
end
elseif event == "UNIT_SPELLCAST_SUCCEEDED" and arg1 == "player" then
if arg2 then
WCS_BrainMemory:RecordSpellCast(arg2)
end
end
end)