Repository navigation
Expand file tree
/
Copy pathWCS_BrainAutoCapture.lua
More file actions
187 lines (159 loc) · 6.98 KB
/
Copy pathWCS_BrainAutoCapture.lua
File metadata and controls
187 lines (159 loc) · 6.98 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
--[[
WCS_BrainAutoCapture.lua - Captura Automatica de Transiciones
Compatible con Lua 5.0 (Turtle WoW)
Version: 6.4.2 - Sin spam de mensajes
]]--
if WCS_Brain and WCS_Brain.ENABLED == false then return end
WCS_BrainAutoCapture = WCS_BrainAutoCapture or {}
WCS_BrainAutoCapture.VERSION = "6.4.2"
WCS_BrainAutoCapture.Enabled = false
WCS_BrainAutoCapture.CaptureFrame = nil
WCS_BrainAutoCapture.LastCaptureTime = 0
WCS_BrainAutoCapture.CaptureInterval = 0.5
WCS_BrainAutoCapture.PreviousState = nil
WCS_BrainAutoCapture.CurrentAction = nil
WCS_BrainAutoCapture.LastDetectedAction = 30
WCS_BrainAutoCapture.TransitionsThisCombat = 0
-- Mapeo por defecto (sera actualizado por WCS_BrainActions)
WCS_BrainAutoCapture.SpellToAction = {
["Shadow Bolt"] = 1, ["Corruption"] = 2, ["Curse of Agony"] = 3,
["Immolate"] = 4, ["Siphon Life"] = 5, ["Drain Life"] = 6,
["Drain Soul"] = 7, ["Searing Pain"] = 8, ["Soul Fire"] = 9,
["Shadowburn"] = 10, ["Conflagrate"] = 11, ["Rain of Fire"] = 12,
["Hellfire"] = 13, ["Fear"] = 14, ["Howl of Terror"] = 15,
["Death Coil"] = 16, ["Banish"] = 17, ["Curse of Tongues"] = 18,
["Curse of Weakness"] = 19, ["Curse of the Elements"] = 20,
["Curse of Shadow"] = 21, ["Curse of Doom"] = 22,
["Curse of Exhaustion"] = 23, ["Curse of Recklessness"] = 24,
["Life Tap"] = 25, ["Dark Pact"] = 26, ["Drain Mana"] = 27,
["Health Funnel"] = 28, ["Healthstone"] = 29
}
function WCS_BrainAutoCapture:DetectAction()
if CastingBarFrame and CastingBarFrame:IsVisible() then
local spellName = CastingBarFrame.spellName
if spellName and self.SpellToAction[spellName] then
self.LastDetectedAction = self.SpellToAction[spellName]
return self.LastDetectedAction
end
end
if ChannelBarFrame and ChannelBarFrame:IsVisible() then
local spellName = ChannelBarFrame.spellName
if spellName and self.SpellToAction[spellName] then
self.LastDetectedAction = self.SpellToAction[spellName]
return self.LastDetectedAction
end
end
return self.LastDetectedAction or 30
end
function WCS_BrainAutoCapture:CaptureTransition()
if not WCS_BrainDQN or not WCS_BrainDQN.enabled then return end
if not UnitAffectingCombat("player") then return end
if not WCS_BrainState then return end
local currentState = WCS_BrainState:CaptureState()
if not currentState then return end
local detectedAction = self:DetectAction()
if self.PreviousState and self.CurrentAction then
local reward = 0
if WCS_BrainReward and WCS_BrainReward.CalculateImmediateReward then
reward = WCS_BrainReward:CalculateImmediateReward(self.CurrentAction, self.PreviousState, currentState)
end
if WCS_BrainDQN.ReplayBuffer and WCS_BrainDQN.ReplayBuffer.Add then
WCS_BrainDQN.ReplayBuffer:Add(self.PreviousState, self.CurrentAction, reward, currentState, false)
self.TransitionsThisCombat = self.TransitionsThisCombat + 1
end
end
self.PreviousState = currentState
self.CurrentAction = detectedAction
end
function WCS_BrainAutoCapture:Start()
if not WCS_BrainDQN or not WCS_BrainDQN.enabled then return end
self.Enabled = true
self.TransitionsThisCombat = 0
self.LastCaptureTime = GetTime()
self.PreviousState = nil
self.CurrentAction = nil
self.LastDetectedAction = 30
if WCS_BrainState then
self.PreviousState = WCS_BrainState:CaptureState()
end
self.CurrentAction = self:DetectAction()
if not self.CaptureFrame then
self.CaptureFrame = CreateFrame("Frame", "WCS_AutoCaptureFrame")
end
self.CaptureFrame:SetScript("OnUpdate", function()
if not WCS_BrainAutoCapture.Enabled then return end
local now = GetTime()
if now - WCS_BrainAutoCapture.LastCaptureTime >= WCS_BrainAutoCapture.CaptureInterval then
WCS_BrainAutoCapture:CaptureTransition()
WCS_BrainAutoCapture.LastCaptureTime = now
end
end)
end
function WCS_BrainAutoCapture:Stop()
self.Enabled = false
if self.CaptureFrame then
self.CaptureFrame:SetScript("OnUpdate", nil)
end
end
function WCS_BrainAutoCapture:OnCombatEnd(won)
self:Stop()
if not WCS_BrainDQN or not WCS_BrainDQN.enabled then return end
local finalState = WCS_BrainState and WCS_BrainState:CaptureState()
if not finalState then return end
local finalReward = 0
if WCS_BrainReward and WCS_BrainReward.CalculateFinalReward then
finalReward = WCS_BrainReward:CalculateFinalReward(won, finalState)
else
finalReward = won and 10 or -10
end
if self.PreviousState and self.CurrentAction then
if WCS_BrainDQN.ReplayBuffer and WCS_BrainDQN.ReplayBuffer.Add then
WCS_BrainDQN.ReplayBuffer:Add(self.PreviousState, self.CurrentAction, finalReward, finalState, true)
self.TransitionsThisCombat = self.TransitionsThisCombat + 1
end
end
self.PreviousState = nil
self.CurrentAction = nil
self.TransitionsThisCombat = 0
end
function WCS_BrainAutoCapture:SetupCombatHooks()
if self.CombatFrame then return end
self.CombatFrame = CreateFrame("Frame")
self.CombatFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
self.CombatFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
self.CombatFrame:RegisterEvent("PLAYER_DEAD")
self.CombatFrame:RegisterEvent("SPELLCAST_START")
self.CombatFrame:RegisterEvent("SPELLCAST_CHANNEL_START")
self.CombatFrame:SetScript("OnEvent", function()
if event == "PLAYER_REGEN_DISABLED" then
WCS_BrainAutoCapture:Start()
elseif event == "PLAYER_REGEN_ENABLED" then
WCS_BrainAutoCapture:OnCombatEnd(true)
elseif event == "PLAYER_DEAD" then
WCS_BrainAutoCapture:OnCombatEnd(false)
elseif event == "SPELLCAST_START" or event == "SPELLCAST_CHANNEL_START" then
if arg1 and WCS_BrainAutoCapture.SpellToAction[arg1] then
WCS_BrainAutoCapture.LastDetectedAction = WCS_BrainAutoCapture.SpellToAction[arg1]
WCS_BrainAutoCapture.CurrentAction = WCS_BrainAutoCapture.LastDetectedAction
end
end
end)
end
function WCS_BrainAutoCapture:Initialize()
self:SetupCombatHooks()
end
local initFrame = CreateFrame("Frame")
initFrame:RegisterEvent("ADDON_LOADED")
initFrame:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == "WCS_Brain" then
local delayFrame = CreateFrame("Frame")
local elapsed = 0
delayFrame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed > 2 then
WCS_BrainAutoCapture:Initialize()
delayFrame:SetScript("OnUpdate", nil)
end
end)
end
end)