-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCKsScript.lua
More file actions
336 lines (287 loc) · 12 KB
/
CKsScript.lua
File metadata and controls
336 lines (287 loc) · 12 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
-- CKsScript
-- Create addon table and initialize saved variables
local addonName, addon = ...
local CKS = CreateFrame("Frame", "CKsScript")
CKS:RegisterEvent("ADDON_LOADED")
-- Default settings
CKS.defaults = {
disableLootWarnings = false,
fasterAutoLoot = false,
needOnRunes = false,
needOnScourgestones = false,
useCharacterAlias = false,
characterAlias = ""
}
-- Table to store roll choices
CKS.rollChoices = {}
-- Initialize variables
CKS.isLoaded = false
-- Main initialization function
function CKS:Init()
-- Create saved variables if they don't exist
if CKsScriptDB == nil then
CKsScriptDB = CopyTable(self.defaults)
end
-- Update CKsScriptDB with any new fields that might not exist
for key, value in pairs(self.defaults) do
if CKsScriptDB[key] == nil then
CKsScriptDB[key] = value
end
end
-- Store player name
CKS.playerName = UnitName("player")
-- Create options panel
self:CreateOptionsPanel()
-- Register events
self:RegisterEvents()
-- Hook chat functions - after initialization is complete
self:HookChatFunctions()
-- Mark as loaded
self.isLoaded = true
-- Show message
print("|cFF00FF00CKsScript|r: Addon loaded. Type /cks to open options.")
end
-- Hook chat message functions to add character alias
-- Hook chat message functions to add character alias
function CKS:HookChatFunctions()
-- Store original SendChatMessage function
CKS.originalSendChatMessage = SendChatMessage
-- Replace SendChatMessage with our own version
SendChatMessage = function(msg, chatType, language, channel)
if CKsScriptDB.useCharacterAlias and CKsScriptDB.characterAlias ~= "" and CKsScriptDB.characterAlias ~= CKS.playerName then
-- Debug print to see the chat type and channel
-- print("Debug - chatType: " .. tostring(chatType) .. ", channel: " .. tostring(channel))
-- Only add character alias prefix for PARTY, RAID, GUILD, INSTANCE_CHAT, and OFFICER
if chatType == "PARTY" or
chatType == "RAID" or
chatType == "GUILD" or
chatType == "RAID_WARNING" or
chatType == "INSTANCE_CHAT" or
chatType == "OFFICER" then
-- Add character alias prefix
local newMsg = "(" .. CKsScriptDB.characterAlias .. ") " .. msg
-- Call original function with modified message
CKS.originalSendChatMessage(newMsg, chatType, language, channel)
else
-- Call original function with unmodified message for other chat types
CKS.originalSendChatMessage(msg, chatType, language, channel)
end
else
-- Call original function with unmodified message
CKS.originalSendChatMessage(msg, chatType, language, channel)
end
end
end
-- Event handling
function CKS:OnEvent(event, arg1, ...)
if event == "ADDON_LOADED" and arg1 == addonName then
self:Init()
self:UnregisterEvent("ADDON_LOADED")
elseif event == "CONFIRM_LOOT_ROLL" then
-- print("|cFFFF8C00[CKsScript]|r CONFIRM_LOOT_ROLL event triggered with rollID: " .. tostring(arg1))
if CKsScriptDB.needOnRunes and self.rollChoices[arg1] == 1 then
print("|cFFFF8C00[CKsScript]|r Auto-confirming Need roll for rollID: " .. tostring(arg1))
-- Confirm the Need roll
ConfirmLootRoll(arg1, 1)
-- Hide the confirmation popup
StaticPopup_Hide("CONFIRM_LOOT_ROLL")
return
elseif CKsScriptDB.disableLootWarnings then
-- Auto-confirm loot dialogs
for i = 1, STATICPOPUP_NUMDIALOGS do
local dialog = _G["StaticPopup" .. i]
if dialog:IsShown() and dialog.which == "CONFIRM_LOOT_ROLL" then
StaticPopup_OnClick(dialog, 1)
end
end
end
elseif event == "LOOT_BIND_CONFIRM" then
if CKsScriptDB.disableLootWarnings then
-- Auto-confirm bind on pickup loot directly
ConfirmLootSlot(arg1, arg2)
StaticPopup_Hide("LOOT_BIND")
StaticPopup_Hide("LOOT_BIND_CONFIRM")
end
elseif event == "START_LOOT_ROLL" then
-- Need on Necrotic Runes feature
-- print("|cFF00FFFF[CKsScript]|r START_LOOT_ROLL event triggered with rollID: " .. tostring(arg1))
if CKsScriptDB.needOnRunes or CKsScriptDB.needOnScourgestones then
self:AutoNeedRunes(arg1)
end
elseif event == "LOOT_READY" then
-- Faster auto loot feature
if CKsScriptDB.fasterAutoLoot then
self:FastLoot()
end
end
end
-- Register necessary events based on enabled features
function CKS:RegisterEvents()
-- If disable loot warnings is enabled
if CKsScriptDB.disableLootWarnings then
self:RegisterEvent("CONFIRM_LOOT_ROLL")
-- CONFIRM_DISENCHANT_ROLL removed as it's not valid in Classic Era
self:RegisterEvent("LOOT_BIND_CONFIRM")
else
self:UnregisterEvent("CONFIRM_LOOT_ROLL")
-- CONFIRM_DISENCHANT_ROLL removed as it's not valid in Classic Era
self:UnregisterEvent("LOOT_BIND_CONFIRM")
end
-- If faster auto loot is enabled
if CKsScriptDB.fasterAutoLoot then
self:RegisterEvent("LOOT_READY")
else
self:UnregisterEvent("LOOT_READY")
end
-- If need on runes or scourgestones is enabled
if CKsScriptDB.needOnRunes or CKsScriptDB.needOnScourgestones then
self:RegisterEvent("START_LOOT_ROLL")
self:RegisterEvent("CONFIRM_LOOT_ROLL")
else
self:UnregisterEvent("START_LOOT_ROLL")
-- Only unregister CONFIRM_LOOT_ROLL if disableLootWarnings is also disabled
if not CKsScriptDB.disableLootWarnings then
self:UnregisterEvent("CONFIRM_LOOT_ROLL")
end
end
end
-- Fast loot function
function CKS:FastLoot()
if GetCVarBool("autoLootDefault") ~= IsModifiedClick("AUTOLOOTTOGGLE") then
for i = GetNumLootItems(), 1, -1 do
LootSlot(i)
end
end
end
-- Auto-need Necrotic Runes and Invader Scourgestones function
function CKS:AutoNeedRunes(rollID)
-- Print diagnostic message at the beginning
-- print("|cFF00FF00[CKsScript]|r AutoNeedRunes called for rollID: " .. tostring(rollID))
-- Get roll info for name display
local texture, name = GetLootRollItemInfo(rollID)
-- Get item link directly using GetLootRollItemLink (more reliable method)
local itemLink = GetLootRollItemLink(rollID)
-- Print item info
-- print("|cFF00FF00[CKsScript]|r Item info - Name: " .. tostring(name) .. ", Link: " .. tostring(itemLink))
-- Extract item ID from item link if available
local itemID = itemLink and tonumber(itemLink:match("item:(%d+)"))
-- print("|cFF00FF00[CKsScript]|r Extracted itemID: " .. tostring(itemID))
-- Check if the item is a Necrotic Rune (ID 22484) or Invader Scourgestone (ID 40753)
if itemID then
if itemID == 22484 and CKsScriptDB.needOnRunes then
-- print("|cFF00FFFF[CKsScript]|r DETECTED NECROTIC RUNE! Rolling need...")
-- Roll need on Necrotic Rune
RollOnLoot(rollID, 1) -- 1 = Need, 2 = Greed, 3 = Pass
-- Store our roll choice
self.rollChoices[rollID] = 1
-- Print message to chat
print("|cFF00FF00CKsScript|r: Auto-rolled |cFFFF0000Need|r on " .. name .. " (ID: " .. itemID .. ")")
elseif itemID == 40753 and CKsScriptDB.needOnScourgestones then
-- Roll need on Invader Scourgestone
RollOnLoot(rollID, 1) -- 1 = Need, 2 = Greed, 3 = Pass
-- Store our roll choice
self.rollChoices[rollID] = 1
-- Print message to chat
print("|cFF00FF00CKsScript|r: Auto-rolled |cFFFF0000Need|r on " .. name .. " (ID: " .. itemID .. ")")
else
print("|cFFFF9900[CKsScript]|r Item is not configured for auto-need. No auto-roll performed.")
end
end
end
-- Create the options panel
function CKS:CreateOptionsPanel()
-- Get a reference to the frame defined in XML
local mainFrame = _G["CKsScriptFrame"]
-- Ensure the frame has proper scripts for movement
mainFrame:SetScript("OnDragStart", mainFrame.StartMoving)
mainFrame:SetScript("OnDragStop", mainFrame.StopMovingOrSizing)
mainFrame:Hide()
-- Get references to existing XML elements (checkboxes)
local disableLootWarnings = _G["CKsScriptDisableLootWarningsCheckbox"]
local fasterAutoLoot = _G["CKsScriptFasterAutoLootCheckbox"]
local needOnRunes = _G["CKsScriptNeedOnRunesCheckbox"]
local needOnScourgestones = _G["CKsScriptNeedOnScourgestonesCheckbox"]
local useCharacterAlias = _G["CKsScriptCharacterAliasCheckbox"]
local characterAliasEditBox = _G["CKsScriptCharacterAliasEditBox"]
-- Set their checked state based on the saved variables
disableLootWarnings:SetChecked(CKsScriptDB.disableLootWarnings)
fasterAutoLoot:SetChecked(CKsScriptDB.fasterAutoLoot)
needOnRunes:SetChecked(CKsScriptDB.needOnRunes)
needOnScourgestones:SetChecked(CKsScriptDB.needOnScourgestones)
useCharacterAlias:SetChecked(CKsScriptDB.useCharacterAlias)
-- Set the edit box text
characterAliasEditBox:SetText(CKsScriptDB.characterAlias or "")
-- Connect the toggle functions to the checkboxes
disableLootWarnings:SetScript("OnClick", function(self)
CKsScript_ToggleDisableLootWarnings()
self:SetChecked(CKsScriptDB.disableLootWarnings)
end)
fasterAutoLoot:SetScript("OnClick", function(self)
CKsScript_ToggleFasterAutoLoot()
self:SetChecked(CKsScriptDB.fasterAutoLoot)
end)
needOnRunes:SetScript("OnClick", function(self)
CKsScript_ToggleNeedOnRunes()
self:SetChecked(CKsScriptDB.needOnRunes)
end)
needOnScourgestones:SetScript("OnClick", function(self)
CKsScript_ToggleNeedOnScourgestones()
self:SetChecked(CKsScriptDB.needOnScourgestones)
end)
useCharacterAlias:SetScript("OnClick", function(self)
CKsScript_ToggleCharacterAlias()
self:SetChecked(CKsScriptDB.useCharacterAlias)
end)
-- Connect the edit box to the set function
characterAliasEditBox:SetScript("OnEnterPressed", function(self)
CKsScript_SetCharacterAlias(self:GetText())
self:ClearFocus()
end)
-- Save the main frame
self.optionsFrame = mainFrame
end
-- Toggle options panel visibility
function CKS:ToggleOptionsPanel()
if self.optionsFrame:IsShown() then
self.optionsFrame:Hide()
else
self.optionsFrame:Show()
end
end
-- Set up slash command
SLASH_CKSSCRIPT1 = "/cks"
SlashCmdList["CKSSCRIPT"] = function()
CKS:ToggleOptionsPanel()
end
-- Toggle Need on Necrotic Runes setting
function CKsScript_ToggleNeedOnRunes()
CKsScriptDB.needOnRunes = not CKsScriptDB.needOnRunes
CKS:RegisterEvents()
end
-- Set up event handling
CKS:SetScript("OnEvent", CKS.OnEvent)
-- Toggle Disable Loot Warnings setting
function CKsScript_ToggleDisableLootWarnings()
CKsScriptDB.disableLootWarnings = not CKsScriptDB.disableLootWarnings
CKS:RegisterEvents()
end
-- Toggle Faster Auto Loot setting
function CKsScript_ToggleFasterAutoLoot()
CKsScriptDB.fasterAutoLoot = not CKsScriptDB.fasterAutoLoot
CKS:RegisterEvents()
end
-- Toggle Need on Invader Scourgestones setting
function CKsScript_ToggleNeedOnScourgestones()
CKsScriptDB.needOnScourgestones = not CKsScriptDB.needOnScourgestones
CKS:RegisterEvents()
end
-- Toggle Character Alias setting
function CKsScript_ToggleCharacterAlias()
CKsScriptDB.useCharacterAlias = not CKsScriptDB.useCharacterAlias
print("|cFF00FF00CKsScript|r: Character alias " .. (CKsScriptDB.useCharacterAlias and "enabled" or "disabled"))
end
-- Set Character Alias
function CKsScript_SetCharacterAlias(alias)
CKsScriptDB.characterAlias = alias
print("|cFF00FF00CKsScript|r: Character alias set to '" .. alias .. "'")
end