-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
469 lines (412 loc) · 15.9 KB
/
Core.lua
File metadata and controls
469 lines (412 loc) · 15.9 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
-- Change implicit globla scope to our addon "namespace":
setfenv(1, _G.SlackHacks)
--[[
General API Documentation:
- https://warcraft.wiki.gg/wiki/World_of_Warcraft_API
- https://warcraft.wiki.gg/wiki/Events
- https://github.com/BigWigsMods/WoWUI/tree/live/AddOns
- https://github.com/Gethe/wow-ui-source/tree/live/Interface/AddOns/Blizzard_APIDocumentationGenerated
- https://www.townlong-yak.com/framexml/live/Blizzard_APIDocumentation
Lua type-checking via VSCode extension:
- https://luals.github.io/wiki/type-checking/
Common data structures:
- ItemLink: https://warcraft.wiki.gg/wiki/ItemLink
Common functions:
- Item functions (take an ItemLink as "ItemInfo"):
- GetItemInfo(): https://warcraft.wiki.gg/wiki/API_C_Item.GetItemInfo
- GetContainerItemInfo(): https://warcraft.wiki.gg/wiki/API_C_Container.GetContainerItemInfo
- GetItemIDForItemInfo(): https://warcraft.wiki.gg/wiki/API_C_Item.GetItemIDForItemInfo
]]--
--Event Handlers
function Self:OnEnable()
self:RegisterEvent("MERCHANT_SHOW")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
-- self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
self:RegisterEvent("BAG_UPDATE_DELAYED")
-- self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
-- self:RegisterEvent("VIGNETTE_MINIMAP_UPDATED")
end
function Self:OnDisable()
end
function Self:BAG_UPDATE_DELAYED() -- Fires after all BAG_UPDATE's are done
bindBestUseItems()
end
-- GAME_READY = false
function Self:PLAYER_ENTERING_WORLD(eventName, isLogin, isReload) -- Out of combat
-- GAME_READY = true
setCVars()
setupEkil()
handleDragonriding()
end
function Self:MERCHANT_SHOW(eventName)
repairAllItems()
sellGreyItems()
end
function Self:PLAYER_REGEN_ENABLED(eventName) -- Out of combat
handleDragonriding()
runAfterCombatActions()
end
function Self:PLAYER_REGEN_DISABLED(eventName) -- In combat
end
function Self:ACTIVE_TALENT_GROUP_CHANGED(currentSpecID, previousSpecID)
setBindings()
end
function Self:UNIT_AURA(eventName, unitTarget, updateInfo) -- https://warcraft.wiki.gg/wiki/UNIT_AURA
if unitTarget == "player" then
handleDragonriding()
end
end
-- --- "Vignettes" are pop-up events on the minimap or world map like rare mobs or treasures: https://warcraft.wiki.gg/wiki/Vignette
-- --- https://warcraft.wiki.gg/wiki/VIGNETTE_MINIMAP_UPDATED
-- --- @param vignetteGUID string
-- --- @param onMinimap boolean
-- function Self:VIGNETTE_MINIMAP_UPDATED(eventName, vignetteGUID, onMinimap)
-- findDruidRareMobs(vignetteGUID)
-- end
afterCombatActions = {}
function runAfterCombat(f)
table.insert(afterCombatActions, f)
end
function runAfterCombatActions()
while #afterCombatActions > 0 do
if not InCombatLockdown() then
table.remove(afterCombatActions)()
end
end
end
function inVehicle()
return UnitHasVehicleUI("player")
end
function isEkil()
return getBattletag() == "ekil#1612" or false
end
function getClassName()
return select(2, UnitClass("player"))
end
function getSpecName()
local specIndex = GetSpecialization()
if specIndex then
log("specIndex = " .. (specIndex or "nil"))
local specID, specName = GetSpecializationInfo(specIndex)
log("specID = " .. (specID or "nil"))
log("specName = " .. (specName or "nil"))
if specName then
return strupper(specName)
end
end
return nil
end
function setCVars()
SetCVar("cameraDistanceMaxZoomFactor", 2.6) -- Max out camera zoon
SetCVar("minimapTrackingShowAll", 1) -- Show all minimap tracking options (including turning off target tracking!)
if isSlackwise() then
SetCVar("test_cameraDynamicPitch", 1) -- Equal to `/console ActionCam basic`
SetCVar("nameplateShowOnlyNameForFriendlyPlayerUnits", 1) -- Enable name-only nameplates for friendlies
SetCVar("nameplateUseClassColorForFriendlyPlayerUnitNames", 1) -- Class-color friendly nameplates
-- Floating Combat Text
SetCVar("floatingCombatTextCombatDamage", 0) -- Disable Direct Damage (White/Yellow Hits)
SetCVar("floatingCombatTextCombatDamage_v2", 0) -- Disable Direct Damage (White/Yellow Hits) v2 ?
SetCVar("floatingCombatTextCombatHealing", 0) -- Disable All Healing
SetCVar("floatingCombatTextCombatHealing_v2", 0) -- Disable All Healing v2 ?
SetCVar("floatingCombatTextCombatLogPeriodicSpells", 1) -- Enable Periodic Damage (DoTs)
SetCVar("floatingCombatTextPetMeleeDamage", 1) -- Enable Pet Melee Damage
SetCVar("floatingCombatTextPetSpellDamage", 1) -- Enable Pet Spell Damage
end
end
function repairAllItems()
if CanMerchantRepair() then
RepairAllItems() -- #TODO: pass `true` for guild repairs if currently raiding with guild
end
end
function canCollectTransmog(itemInfo) -- itemID, itemLink, or Name
if isClassic() then
return false
end
-- local itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType = C_Item.GetItemInfo(itemInfo)
-- if itemType ~= "Armor" then
-- log(itemLink)
-- return false
-- end
local itemAppearanceID, sourceID = C_TransmogCollection.GetItemInfo(itemInfo) -- https://warcraft.wiki.gg/wiki/API_C_TransmogCollection.GetItemInfo
if sourceID then
local categoryID, visualID, canEnchant, icon, isCollected, itemLink, transmogLink, unknown1, itemSubTypeIndex = C_TransmogCollection.GetAppearanceSourceInfo(sourceID)
return not isCollected
end
return false
end
ITEM_QUALITY_GREY = 0
function sellGreyItems()
for bag = 0, NUM_BAG_SLOTS do
for slot = 0, C_Container.GetContainerNumSlots(bag) do
local link = C_Container.GetContainerItemLink(bag, slot)
if link then
local itemName, itemLink, itemQuality = C_Item.GetItemInfo(link)
if itemQuality == ITEM_QUALITY_GREY then
if canCollectTransmog(itemLink) then
print("[SlackHacks] Not selling transmog-able item: " .. itemLink)
else
C_Container.UseContainerItem(bag, slot)
end
end
end
end
end
end
function isSpellKnown(spellName)
local link, spellID = GetSpellLink(spellName)
if spellID then
return IsSpellKnown(spellID)
end
return false
end
--- Get all keys from a given `targetTable`.
---@param targetTable table - The table to extract keys from.
---@param value object - The `value` to key off of.
---@return array - First key matching value.
function getKeyByValue(targetTable, targetValue)
for key, value in pairs(targetTable) do
if value == targetValue then
return key
end
end
return nil
end
--- Get all keys from a given `targetTable`.
---@param targetTable table - The table to extract keys from.
---@return array - Array of keys.
function keys(targetTable)
local collectedKeys = {}
for key, value in pairs(targetTable) do
table.insert(collectedKeys, key)
end
return collectedKeys
end
--- Find the first table element that match `kvPredicate` function.
---@param targetTable table - The table to find the first element from.
---@param kvPredicate Function(key, value) - A predicate function that takes in `(key, value)` and returns `true` or `false` if it matches.
---@return key, value - First element that matches `kvPredicate`.
function findFirstElement(targetTable, kvPredicate)
for key, value in pairs(targetTable) do
if kvPredicate(key, value) then
return key, value
end
end
return nil, nil
end
--- Find all table elements that match `kvPredicate` function.
---@param targetTable table - The table to find the first element from.
---@param kvPredicate Function(key, value) - A predicate function that takes in `(key, value)` and returns `true` or `false` if it matches.
---@return object[] - Array of all elements that matched `kvPredicate`.
function findElements(targetTable, kvPredicate)
local found = {}
for key, value in pairs(targetTable) do
if kvPredicate(key, value) then
found[key] = value
end
end
return found
end
--- Returns array of `ContainerItemInfo` tables found in bags that match any of a given array of `itemIDs`
---@param array itemIDs - Array of itemIDs
---@return ContainerItemInfo[] Array of ContainerItemInfo
function findItemsByItemIDs(itemIDs)
local found = {}
for bag = 0, NUM_BAG_SLOTS do
for slot = 0, C_Container.GetContainerNumSlots(bag) do
local containerItemInfo = C_Container.GetContainerItemInfo(bag, slot)
if containerItemInfo then
local itemName = C_Item.GetItemInfo(containerItemInfo.hyperlink)
if itemName and tContains(itemIDs, containerItemInfo.itemID) then
table.insert(found, containerItemInfo)
end
end
end
end
return found
end
--- Returns array of `ContainerItemInfo` tables found in bags that match Lua regex `pattern`
---@param regex string Lua regexp pattern: https://warcraft.wiki.gg/wiki/Pattern_matching
---@return ContainerItemInfo[] Array of ContainerItemInfo
function findItemsByRegex(regex)
local found = {}
for bag = 0, NUM_BAG_SLOTS do
for slot = 0, C_Container.GetContainerNumSlots(bag) do
local containerItemInfo = C_Container.GetContainerItemInfo(bag, slot)
if containerItemInfo then
local itemName = C_Item.GetItemInfo(containerItemInfo.hyperlink)
if itemName and string.match(itemName, regex) then
table.insert(found, containerItemInfo)
end
end
end
end
return found
end
--- Group array items into a table by the output of a function.
---@param Array - The array to group.
---@param Function(object) - Takes in an object, and returns new `key, value` which will be grouped by `key`.
---@return Array - The grouped array.
function groupBy(array, groupingFunction)
local grouped = {}
for key, value in pairs(array) do
local groupingKey, newValue = groupingFunction(value)
if grouped[value] then
table.insert(grouped[groupingKey], newValue)
else
grouped[groupingKey] = { newValue }
end
end
return grouped
end
--- Find the largest (numeric) index of an array.
---@param Array - The array to search.
---@return Integer - Largest numeric index.
function findLargestIndex(array)
local largestIndex = 0
for key, value in pairs(array) do
if tonumber(key) and key >= largestIndex then
largestIndex = key
end
end
return largestIndex
end
--- Recursively search up the map hierarchy to find a specific map type.
---@param map The map to start at.
---@param upMapType An Enum.UIMapType of the map you're trying to find.
---@return UiMapDetails
function findParentMapByType(map, uiMapType)
if not map then
return nil
end
if map.mapType == uiMapType or map.mapType == Enum.UIMapType.Cosmic then
return map
end
return findParentMapByType(C_Map.GetMapInfo(map.parentMapID), uiMapType)
end
function getCurrentMap()
return C_Map.GetMapInfo(C_Map.GetBestMapForUnit("player") or 0)
end
function getCurrentContinent()
local map = getCurrentMap()
if map then
return findParentMapByType(map, Enum.UIMapType.Continent)
end
return nil
end
function getCurrentZone()
local map = getCurrentMap()
if map then
return findParentMapByType(map, Enum.UIMapType.Zone)
end
return nil
end
function isActuallyFlyableArea()
local continent = getCurrentContinent()
local continentID = continent and continent.mapID or 0
local zone = getCurrentZone()
local zoneID = zone and zone.mapID or 0
local map = getCurrentMap()
local mapID = map and map.mapID or 0
local listedFlyableContinent = not not tContains( ACTUALLY_FLYABLE_MAP_IDS.CONTINENTS, continentID )
local listedFlyableZone = not not tContains( ACTUALLY_FLYABLE_MAP_IDS.ZONES, zoneID )
local listedFlyableMap = not not tContains( ACTUALLY_FLYABLE_MAP_IDS.MAPS, mapID )
local listedNonFlyableContinent = not not tContains( NOT_ACTUALLY_FLYABLE_MAP_IDS.CONTINENTS, continentID )
local listedNonFlyableZone = not not tContains( NOT_ACTUALLY_FLYABLE_MAP_IDS.ZONES, zoneID )
local listedNonFlyableMap = not not tContains( NOT_ACTUALLY_FLYABLE_MAP_IDS.MAPS, mapID )
if listedFlyableMap then return true end
if listedNonFlyableMap then return false end
if listedFlyableZone then return true end
if listedNonFlyableZone then return false end
if listedFlyableContinent then return true end
if listedNonFlyableContinent then return false end
return IsFlyableArea()
end
function printDebugMapInfo()
local map = getCurrentMap()
local zone = getCurrentZone()
local continent = getCurrentContinent()
local parentMap = C_Map.GetMapInfo(map.parentMapID) or "nil"
if isDebugging() then
p = log
else
p = print
end
p("===============================")
p(map.name .. ", " .. (parentMap.name or "nil"))
p("Zone: " .. zone.name .. " (" .. zone.mapID .. ')')
if continent then
p("Continent: " .. continent.name .. " (" .. continent.mapID .. ')')
end
p("-------------------------------------------------------") -- Chat window does not used fixed width; trying to match header
p("mapID: " .. map.mapID)
p("parentMapID: " .. map.parentMapID)
p("mapType: " .. (getKeyByValue(Enum.UIMapType, map.mapType) or "nil") .. " (" .. (map.mapType or "nil") .. ")")
p("Outdoor: " .. tostring(IsOutdoors()))
p("Submerged: " .. tostring(IsSubmerged()))
p("Flyable: " .. tostring(IsFlyableArea()))
p("AdvancedFlyable: " .. tostring(IsAdvancedFlyableArea()))
p("ActuallyFlyable: " .. tostring(isActuallyFlyableArea()))
p("===============================")
end
DRUID_RARE_MOBS = {
"Keen-eyed Cian",
"Matriarch Keevah",
"Moragh the Slothful",
"Mosa Umbramane",
"Ristar the Rabid",
"Talthonei Ashwhisper"
}
function findDruidRareMobs(vignetteGUID)
if getClassName() ~= "DRUID" then return end
log("VIGNETTE ID: " .. vignetteGUID)
local vignetteInfo = C_VignetteInfo.GetVignetteInfo(vignetteGUID) -- https://warcraft.wiki.gg/wiki/API_C_VignetteInfo.GetVignetteInfo
if not vignetteInfo then return end
local name = vignetteInfo.name
log("VIGNETTE NAME: " .. (name or ""))
if tContains(DRUID_RARE_MOBS, name) then
foundDruidRare(name)
end
end
foundDruidRares = {}
function foundDruidRare(name)
local currentUnixTimestamp = GetServerTime()
local currentHour, currentMinute = GetGameTime()
local lastTimeFound = foundDruidRares[name]
if not lastTimeFound or isTimeWithin(lastTimeFound, 5 * 60, GetServerTime()) then
foundDruidRares[name] = { currentUnixTimestamp, currentHour, currentMinute }
end
end
function announceFoundDruidRare(name)
log("Found druid rare: " .. name)
SendChatMessage(name ".. spotted!", "CHANNEL", nil, 5)
end
--- Checks if a time is within a given time of another time
--- @param originUnixTimestamp integer
--- @param secondsToBeWithin integer
--- @param currentUnixTimestamp integer
--- @return boolean
function isTimeWithin(originUnixTimestamp, secondsToBeWithin, currentUnixTimestamp)
return currentUnixTimestamp >= (originUnixTimestamp + (secondsToBeWithin * 1000))
end
--[[ -- TODO: Update broken fishing pole right-click handler
function events:PLAYER_EQUIPMENT_CHANGED(slot, hasItem)
if InCombat() then return
if select(6, GetItemInfo(GetInventoryItemID("player", slot))) == "Fishing Poles" then
--Right-click to cast.
if not frame:IsHooked(WorldFrame, "OnMouseDown") then
frame:HookScript(WorldFrame, "OnMouseDown",
function()
end
)
end
else
--Undo right-click casting.
if frame:IsHooked(WorldFrame, "OnMouseDown") then
frame:Unhook(WorldFrame, "OnMouseDown")
end
end
end
]]