annotate Turok/Turok.lua @ 9:9400a0ff8540

Ugh Timer: - container update directionality - talent update iterates over a non-volatile table to carry out updates - index management steps organized - talentRow status implemented, returns the spell associated with the talent chosen from that row CombatLog: - sort out font controls and unbork arguments
author Nenue
date Sun, 21 Feb 2016 13:08:30 -0500
parents a9b8b0866ece
children
rev   line source
Nenue@6 1 --- Turok
Nenue@6 2 -- @file-author@
Nenue@6 3 -- @project-revision@ @project-hash@
Nenue@6 4 -- @file-revision@ @file-hash@
Nenue@6 5 --- Defines the mechanisms for the storage and dispatch of events data.
Nenue@6 6 --@debug@
Nenue@6 7 --@end-debug@
Nenue@6 8 -- GLOBALS: LibStub, Turok, TurokData, ReloadUI
Nenue@6 9 local ADDON, Tk = ...
Nenue@6 10 local db, L
Nenue@6 11 local MAJOR, MINOR = "Turok", "@project-revision@"
Nenue@6 12 local T, LGIST, _G = Tk.Addon, Tk.LGIST, _G
Nenue@6 13
Nenue@6 14
Nenue@6 15 local pcall, type, ipairs, pairs, format, tinsert, match, strpad, error = pcall, type, ipairs, pairs, string.format, table.insert, string.match, string.rep, error
Nenue@6 16 local PlaySoundFile, LoadAddOn, IsAddOnLoaded, UnitName, UnitGUID, UnitPowerMax = PlaySoundFile, LoadAddOn, IsAddOnLoaded, UnitName, UnitGUID, UnitPowerMax
Nenue@6 17 local GetSpecializationInfo, GetSpecialization, UnitSpellHaste, GetActiveSpecGroup = GetSpecializationInfo, GetSpecialization, UnitSpellHaste, GetActiveSpecGroup
Nenue@6 18 local UnitInfo, UnitCastingInfo, UnitChannelInfo = UnitInfo, UnitCastingInfo, UnitChannelInfo
Nenue@6 19 local rawset, unpack, tostring, setmetatable, xpcall, unpack = rawset, unpack, tostring, setmetatable, xpcall, unpack
Nenue@6 20
Nenue@6 21 --@debug@
Nenue@6 22 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
Nenue@6 23 local print = function(...)
Nenue@6 24 if _G.Devian and _G.DevianDB.workspace ~= 1 then
Nenue@6 25 _G.print('Turok', ...)
Nenue@6 26 end
Nenue@6 27 end
Nenue@9 28 local uprint = function(...)
Nenue@9 29 if _G.Devian and _G.DevianDB.workspace ~= 1 then
Nenue@9 30 _G.print('Update', ...)
Nenue@9 31 end
Nenue@9 32 end
Nenue@6 33 local GetPrint = function(trace)
Nenue@6 34 return trace and print or function() end
Nenue@6 35 end
Nenue@6 36 --@end-debug@
Nenue@6 37
Nenue@6 38
Nenue@6 39
Nenue@6 40 --- Pull saved variables and make them sane
Nenue@6 41 function T.OnInitialize(T)
Nenue@6 42
Nenue@6 43 --@debug@
Nenue@6 44 local tmpidx
Nenue@6 45 if TurokData and TurokData.spirit and TurokData.spirit.timerindex then
Nenue@6 46 tmpidx = TurokData.spirit.timerindex
Nenue@6 47 end
Nenue@6 48 TurokData = Turok.defaults
Nenue@6 49 if tmpidx then
Nenue@6 50 TurokData.spirit.timerindex = tmpidx
Nenue@6 51 end
Nenue@6 52 --@end-debug@
Nenue@6 53 T.db = _G.TurokData
Nenue@6 54 LibStub("LibFog-1.0"):Embed(T)
Nenue@6 55 if T.db.queue_for_wipe then
Nenue@6 56 T:Print("db reset flag received")
Nenue@6 57 local index = _G.TurokData.spirit.timerindex
Nenue@6 58 _G.TurokData = T.defaults
Nenue@6 59 T.db = _G.TurokData
Nenue@6 60 T.db.spirit.timerindex = index
Nenue@6 61 end
Nenue@6 62
Nenue@6 63 T:RegisterChatCommand("tkr", function()
Nenue@6 64 T.db.queue_for_wipe = true
Nenue@6 65 ReloadUI()
Nenue@6 66 end)
Nenue@6 67
Nenue@6 68 -- db hierarchy
Nenue@6 69 for k, v in pairs(T.db) do
Nenue@6 70 if type(v) == 'table' then
Nenue@6 71 --@debug@
Nenue@6 72 --print('|cFF44FF88loading stored db|r: db.|cFF44AAFF'.. k ..'|r')--@end-debug@
Nenue@6 73 T.LinkTable(T.db, v, 'db', k)
Nenue@6 74 end
Nenue@6 75 end
Nenue@6 76 setmetatable(T.db,
Nenue@6 77 {__newindex = function (t, k, v)
Nenue@6 78 rawset(t,k,v)
Nenue@6 79 if type(v) == 'table' then
Nenue@6 80 --@debug@
Nenue@6 81 --print('|cFF44FF88creating new db|r: db.|cFF44AAFF'.. k ..'|r')--@end-debug@
Nenue@6 82 T.LinkTable(T.db, v, 'db', k)
Nenue@6 83 end
Nenue@6 84 end})
Nenue@6 85 T.L = setmetatable({}, {__call = function(t, s) return t[s] or s end})
Nenue@6 86 end
Nenue@6 87
Nenue@6 88 --- Get everything rolling
Nenue@6 89 function T:OnEnable()
Nenue@6 90 db = TurokData
Nenue@6 91 L = T.L
Nenue@6 92
Nenue@6 93 self.dispatchQueue = {}
Nenue@6 94 self.sharedTables = {}
Nenue@6 95 local skip = {modules = true, db = true, defaultModuleLibraries = true, orderedModules = true, prototype = true, events = true} -- local data that exists before init
Nenue@6 96 for id, mod in pairs(self.orderedModules) do
Nenue@6 97 mod.ID = id
Nenue@6 98 mod.RegisterCallback = self.RegisterCallback
Nenue@6 99 print('load', mod:GetName())
Nenue@6 100 for k, v in pairs(mod) do
Nenue@6 101 if not skip[k] then
Nenue@6 102 if match(k, '^[%u_]+$') then
Nenue@6 103 if not self.dispatchQueue[k] then
Nenue@6 104 self.dispatchQueue[k] = {}
Nenue@6 105 end
Nenue@6 106 self:RegisterEvent(k, 'Dispatch')
Nenue@6 107 self.dispatchQueue[k][id] = mod:GetName()
Nenue@6 108 end
Nenue@6 109 end
Nenue@6 110 end
Nenue@6 111 end
Nenue@6 112
Nenue@6 113 print('events')
Nenue@6 114 for k, v in pairs(self.dispatchQueue) do
Nenue@6 115 print(' ',k,'->', unpack(v))
Nenue@6 116 end
Nenue@6 117
Nenue@6 118 print('shared')
Nenue@6 119 for k, v in pairs(self.sharedTables) do
Nenue@6 120 print(' ',k)
Nenue@6 121 end
Nenue@6 122 --@debug@
Nenue@6 123 self:Print(MAJOR, MINOR, 'enabled.')--@end-debug@
Nenue@6 124 self:RegisterChatCommand("tkl", function()
Nenue@6 125 PlaySoundFile([[Interface\Addons\Turok\Media\sound\wilhelm.ogg]])
Nenue@6 126 if not IsAddOnLoaded("Turok_Config") then
Nenue@6 127 local loaded, message = LoadAddOn("Turok_Config")
Nenue@6 128 if not loaded then
Nenue@6 129 return T:Print("|cFFFF0000Load-on-Demand failed!|r Reason: " .. message)
Nenue@6 130 end
Nenue@6 131 --self.config = LibStub('AceConfigDialog-3.0'):AddToBlizOptions(MAJOR)
Nenue@6 132 end
Nenue@6 133 InterfaceOptionsFrame_OpenToCategory(MAJOR)
Nenue@6 134 InterfaceOptionsFrame_OpenToCategory(MAJOR)
Nenue@6 135 end)
Nenue@6 136
Nenue@6 137 self:RegisterChatCommand("unlock", function()
Nenue@6 138 T.unlocked = (not T.unlocked) and true or nil
Nenue@6 139 if T.unlocked then
Nenue@6 140 self:Print('frames unlocked')
Nenue@6 141 else
Nenue@6 142 self:Print('frames locked')
Nenue@6 143 end
Nenue@6 144 for k, v in pairs(self.orderedModules) do
Nenue@6 145 if v.UpdateLocked then
Nenue@6 146 v:UpdateLocked()
Nenue@6 147 end
Nenue@6 148 end
Nenue@6 149 end)
Nenue@6 150
Nenue@6 151 self:RegisterChatCommand("lsm", function(input)
Nenue@6 152 local a1, n = self:GetArgs(input, 1,0)
Nenue@6 153 local a2 = self:GetArgs(input, 1, n)
Nenue@6 154 self:Print(self.LSM:Fetch(a1, a2))
Nenue@6 155 end)
Nenue@6 156
Nenue@6 157 local name, realm = UnitFullName('player')
Nenue@6 158 LGIST.RegisterCallback(self, "GroupInSpecT_InspectReady", 'GIST_InspectReady')
Nenue@6 159 LGIST.RegisterCallback(self, "GroupInSpecT_Update", 'GIST_Update')
Nenue@6 160 self:RegisterCharacterInfo(name, realm)
Nenue@6 161
Nenue@6 162 if InCombatLockdown() then
Nenue@6 163 T.inCombat = true
Nenue@6 164 end
Nenue@6 165
Nenue@6 166 T:PLAYER_SPECIALIZATION_CHANGED('PLAYER_SPECIALIZATION_CHANGED','player')
Nenue@6 167 for order, event in ipairs(self.events) do
Nenue@6 168 self:RegisterEvent(event, 'Dispatch')
Nenue@6 169 end
Nenue@6 170 end
Nenue@6 171
Nenue@6 172 do
Nenue@6 173 local bucket_events = {['PLAYER_SPECIALIZATION_CHANGED'] = {}, ['PLAYER_TALENT_UPDATE'] = {}}
Nenue@6 174 local bucket_start = {}
Nenue@6 175 local event_queue = {}
Nenue@6 176 local wipe, debugstack = table.wipe, debugstack
Nenue@6 177
Nenue@6 178 --- Passes event data to the appropriate handlers, and runs any callback returned
Nenue@6 179 -- @param e event name
Nenue@6 180 -- @param ... event arguments as given by WoW Lua
Nenue@6 181 -- @return callback1 runs after its corresponding method has been dispatched to
Nenue@6 182 -- @return callback2 runs after all dispatching has completed, in the order that dispatches occurred
Nenue@6 183 function T:Dispatch(event, ...)
Nenue@6 184 if not (self[event] or self.dispatchQueue[event]) then
Nenue@6 185 return
Nenue@6 186 end
Nenue@6 187
Nenue@6 188
Nenue@6 189 if bucket_events[event] then
Nenue@6 190 local unit = ...
Nenue@6 191 if unit and unit ~= 'player' then
Nenue@6 192 return
Nenue@6 193 end
Nenue@6 194
Nenue@6 195 print(cText('*** Bucket Event:'), cWord(event))
Nenue@6 196 if not bucket_start[event] then
Nenue@6 197 self['TKBATCH_'..event] = {}
Nenue@6 198 bucket_start[event] = GetTime()
Nenue@6 199 T:ScheduleTimer( function()
Nenue@6 200 print('*** Firing bucketed event ('..#bucket_events[event]..'):', event, unpack(bucket_events[event][#bucket_events[event]]))
Nenue@6 201 T:Dispatch('TKBATCH_'..event, unpack(bucket_events[event][#bucket_events[event]]))
Nenue@6 202 bucket_start[event] = nil
Nenue@6 203
Nenue@6 204 self['TKBATCH_'..event] = nil
Nenue@6 205 end,0.1)
Nenue@6 206 end
Nenue@6 207 tinsert(bucket_events[event], {...})
Nenue@6 208 return
Nenue@6 209 else
Nenue@6 210 event = event:gsub('^TKBATCH_', '')
Nenue@6 211 end
Nenue@6 212
Nenue@6 213
Nenue@6 214 if event ~= 'COMBAT_LOG_EVENT_UNFILTERED' then print('|cFFFF0088received|r', event, ...) end
Nenue@6 215 local args = {event, ...}
Nenue@6 216
Nenue@6 217 -- if addon is listening directly
Nenue@6 218 if self[event] then
Nenue@6 219 print(cWord(event))
Nenue@6 220 local reg = function() print(unpack(args)) self[event](self, unpack(args)) end
Nenue@6 221 tinsert(event_queue, {self, event, reg})
Nenue@6 222
Nenue@6 223
Nenue@6 224 -- if modules want this event directly
Nenue@6 225 end
Nenue@6 226 if self.dispatchQueue[event] then
Nenue@6 227 for id, name in pairs(self.dispatchQueue[event]) do
Nenue@6 228 local mod = self.orderedModules[id]
Nenue@6 229 local reg = function() print(unpack(args)) mod[event](mod, unpack(args)) end
Nenue@6 230 tinsert(event_queue, {mod, event, reg})
Nenue@6 231 end
Nenue@6 232 else
Nenue@6 233 print("Received", event, "but nothing is listening to it.")
Nenue@6 234 end
Nenue@6 235
Nenue@6 236 for i, entry in ipairs(event_queue) do
Nenue@6 237 local handler, event, func = unpack(entry)
Nenue@6 238 print('->', cWord(handler:GetName()), cBool(result), cText(message))
Nenue@6 239 local result, message = xpcall(func, function(m) print(m, debugstack()) return debugstack() end)
Nenue@6 240
Nenue@6 241 if bucket_events[event] then
Nenue@6 242 wipe(bucket_events[event])
Nenue@6 243 bucket_events[event].history = {}
Nenue@6 244 end
Nenue@6 245 end
Nenue@6 246 wipe(event_queue)
Nenue@6 247 end
Nenue@6 248 end
Nenue@6 249 --- Store character data to speed up spec-specific load time
Nenue@6 250 function T:RegisterCharacterInfo(name,realm)
Nenue@6 251 local classLocalized, classEnglish, classID = UnitClass('player')
Nenue@6 252
Nenue@6 253 -- set savedvars
Nenue@6 254 self.playerName = name
Nenue@6 255 self.playerRealm = realm
Nenue@6 256 self.playerClass = classEnglish
Nenue@6 257 self.playerClassLocalized = classLocalized
Nenue@6 258 self.playerClassID = classID
Nenue@6 259 self.GUID = UnitGUID('player')
Nenue@6 260 local namerealm = name..'-'..realm
Nenue@6 261 if not db.char[namerealm] then
Nenue@6 262 db.char[namerealm] = {
Nenue@6 263 spellBook = {}
Nenue@6 264 }
Nenue@6 265 end
Nenue@6 266 T.spellBook = db.char[namerealm].spellBook
Nenue@6 267
Nenue@6 268 -- push combat ratings calc
Nenue@6 269 self:COMBAT_RATING_UPDATE()
Nenue@6 270 end
Nenue@6 271
Nenue@6 272 --- Polls for specialization info until it's available
Nenue@6 273 function T:RegisterSpecEvents()
Nenue@6 274 local specPage = GetSpecialization()
Nenue@6 275 if specPage then
Nenue@6 276
Nenue@6 277 local specID, specName, specDesc, specTexture = GetSpecializationInfo(specPage)
Nenue@6 278 local specGroup = GetActiveSpecGroup()
Nenue@6 279 print('Turok', cText('* Spec Info:'), GetSpecializationInfo(GetSpecialization()))
Nenue@6 280 if T.specID and specID ~= T.specID then
Nenue@6 281 print('pushing out old spec data')
Nenue@6 282 T.previousSpec = {
Nenue@6 283 specPage = T.specPage,
Nenue@6 284 specGroup = T.specGroup,
Nenue@6 285 specID = T.specID,
Nenue@6 286 specName = T.specName,
Nenue@6 287 specTexture = T.specTexture
Nenue@6 288 }
Nenue@6 289 elseif not T.previousSpec then
Nenue@6 290 print('first run probably')
Nenue@6 291 T.previousSpec = {}
Nenue@6 292 end
Nenue@6 293
Nenue@6 294
Nenue@6 295 T.specUpdate = (specID ~= T.specID)
Nenue@6 296 T.talentsChanged = (T.specGroup ~= specGroup)
Nenue@6 297 T.specPage = specPage
Nenue@6 298 T.specGroup = specGroup
Nenue@6 299 T.specID = specID
Nenue@6 300 T.specName = specName
Nenue@6 301 T.specTexture = specTexture
Nenue@6 302 else
Nenue@6 303 print('Turok', cText('* No Spec Info yet, start polling'))
Nenue@6 304 -- repeat until we get something to update with
Nenue@6 305 T:ScheduleTimer('RegisterSpecEvents', 1)
Nenue@6 306 end
Nenue@6 307
Nenue@6 308 if T.specID and not T.__specevents then
Nenue@6 309 T.__specevents = true
Nenue@6 310 T:PLAYER_SPECIALIZATION_CHANGED('PLAYER_SPECIALIZATION_CHANGED','player')
Nenue@6 311 T:RegisterEvent('PLAYER_TALENT_UPDATE', 'Dispatch')
Nenue@6 312 T:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED', 'Dispatch')
Nenue@6 313 T:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED', 'Dispatch')
Nenue@6 314 T:RegisterEvent('UNIT_SPELLCAST_INTERRUPTED', 'Dispatch')
Nenue@6 315 end
Nenue@6 316 end
Nenue@6 317
Nenue@6 318 --- Event handler wrapper for the Specialization getter used at load time
Nenue@6 319 local GetSpecializationSpells, GetSpellInfo = GetSpecializationSpells, GetSpellInfo
Nenue@6 320 function T:PLAYER_SPECIALIZATION_CHANGED(event, unit)
Nenue@6 321 -- make sure this was fired for player
Nenue@6 322 if (unit ~= 'player') then
Nenue@6 323 return
Nenue@6 324 end
Nenue@6 325
Nenue@6 326
Nenue@6 327 print('Turok', '|cFF00FF00'.. event)
Nenue@6 328 -- Set current spec values and fill out previousSpec table
Nenue@6 329 T:RegisterSpecEvents()
Nenue@6 330 local ot = T.previousSpec
Nenue@6 331
Nenue@6 332 -- Is the new spec different?
Nenue@6 333 if T.specUpdate then
Nenue@6 334 print(cText('Spec changed from'), cWord(ot.specName), cText('to'), cKey(T.specName))
Nenue@6 335
Nenue@6 336 if ot.specPage and not T.spellBook[ot.specPage] then
Nenue@6 337 T.spellBook[ot.specPage] = {}
Nenue@6 338 end
Nenue@6 339
Nenue@6 340 local spellBook = {GetSpecializationSpells(T.specPage)}
Nenue@6 341 if not T.spellBook[T.specPage] then
Nenue@6 342 T.spellBook[T.specPage] = {}
Nenue@6 343 for i = 1, #spellBook, 2 do
Nenue@6 344 T.spellBook[T.specPage][spellBook[i]] = GetSpellInfo(spellBook[i])
Nenue@6 345 if (not ot.specPage) or (T.spellBook[ot.specPage] and not T.spellBook[ot.specPage][spellBook[i]]) then
Nenue@6 346 print(cText('activating for spell'), T.spellBook[T.specPage][spellBook[i]])
Nenue@6 347 end
Nenue@6 348 end
Nenue@6 349 end
Nenue@6 350
Nenue@6 351
Nenue@6 352
Nenue@6 353 -- list changed spells for use by spell posession checks
Nenue@6 354 local diff = {
Nenue@6 355 gained = {},
Nenue@6 356 lost = {}
Nenue@6 357 }
Nenue@6 358
Nenue@6 359 --- Check against current for removed spells
Nenue@6 360 if T.spellBook[ot.specPage] then
Nenue@6 361 for id, spellInfo in pairs(T.spellBook[ot.specPage]) do
Nenue@6 362 if not T.spellBook[ot.specPage] then
Nenue@6 363 tinsert(diff.lost, spellInfo)
Nenue@6 364 print('lost', spellInfo.spellName)
Nenue@6 365 else
Nenue@6 366 print('keep', spellInfo.spellName)
Nenue@6 367 end
Nenue@6 368 end
Nenue@6 369 end
Nenue@6 370
Nenue@6 371 T.spellBook.change = diff
Nenue@6 372 end
Nenue@6 373 end
Nenue@6 374
Nenue@6 375 local GetInventoryItemID, GetItemSpell, GetSpellInfo, GetItemInfo = GetInventoryItemID, GetItemSpell, GetSpellInfo, GetItemInfo
Nenue@6 376 function T:PLAYER_EQUIPMENT_CHANGED(event, slot, hasItem)
Nenue@6 377 print('Equip slot #', slot, ' has?', hasItem)
Nenue@6 378 if hasItem then
Nenue@6 379 local itemID = GetInventoryItemID('player', slot)
Nenue@6 380 print('itemID?', itemID)
Nenue@6 381 local spellName = GetItemSpell(itemID)
Nenue@6 382 print('spell?', spellName)
Nenue@6 383 local _, spellID
Nenue@6 384 if spellName then
Nenue@6 385 _, _, _, _, _, _, spellID = GetSpellInfo(spellName)
Nenue@6 386 end
Nenue@6 387
Nenue@6 388 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID)
Nenue@6 389 T.equipped[slot] = {
Nenue@6 390 itemID = itemID,
Nenue@6 391 spellName = spellName,
Nenue@6 392 spellID = spellID,
Nenue@6 393 name = name,
Nenue@6 394 link = link,
Nenue@6 395 equipSlot = equipSlot,
Nenue@6 396 texture = texture,
Nenue@6 397 }
Nenue@6 398 print('equipped', name)
Nenue@6 399
Nenue@6 400 else
Nenue@6 401 self.equipped[slot] = nil
Nenue@6 402 end
Nenue@6 403 end
Nenue@6 404
Nenue@6 405 local GetPowerRegen, UnitPowerType = GetPowerRegen, UnitPowerType
Nenue@6 406 function T:COMBAT_RATING_UPDATE(t,e)
Nenue@6 407 --@debug@
Nenue@6 408 print('|cFF00FFFFCOMBAT_RATING_UPDATE')--@end-debug@
Nenue@6 409 self.haste = UnitSpellHaste('player')
Nenue@6 410 self.powerRegen = GetPowerRegen()
Nenue@6 411 self.powerType = UnitPowerType('player')
Nenue@6 412 self.castTimeMod = 1+ self.haste/100
Nenue@6 413 self.GCD = 1.5 * self.castTimeMod
Nenue@6 414
Nenue@6 415 L.haste = format('%.2f', self.haste)
Nenue@6 416 L.focusregen = format('%.2f', self.powerRegen)
Nenue@6 417 L.castingmod = format('%.2f', self.castTimeMod)
Nenue@6 418 end
Nenue@6 419
Nenue@6 420 function T:UNIT_SPELLCAST_INTERRUPTED(e, unit, spellName, rank, target, castID)
Nenue@9 421 if not T.unit[unit] then
Nenue@6 422 return
Nenue@6 423 end
Nenue@6 424 T.spellevent[unit] = {unit, spellName, rank, target, castID, nil }
Nenue@6 425 end
Nenue@6 426
Nenue@6 427 function T:UNIT_SPELLCAST_SENT(e,unit, spellName, rank, target, castID)
Nenue@9 428 if not T.unit[unit] then
Nenue@6 429 return
Nenue@6 430 end
Nenue@6 431 T.unit[unit].spellEventString = e
Nenue@6 432 T.unit[unit].spellevent = {unit, spellName, rank, target, castID}
Nenue@6 433 end
Nenue@6 434
Nenue@6 435 function T:UNIT_SPELLCAST (e, unit, spellName, rank, castID, spellID)
Nenue@9 436 if not T.unit[unit] then
Nenue@6 437 return
Nenue@6 438 end
Nenue@6 439 --name, subText, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible
Nenue@6 440 local q = {UnitCastingInfo(unit)}
Nenue@6 441 T.unit[unit].casting = q[1] and q or false
Nenue@6 442 T.unit[unit].spellEventString = e
Nenue@6 443 T.unit[unit].spellevent = {unit, spellName, rank, nil,castID, spellID }
Nenue@6 444 print(e, unit)
Nenue@6 445 end
Nenue@6 446
Nenue@6 447 function T:UNIT_CHANNEL(e, unit, spellName, rank, castID, spellID)
Nenue@9 448 if not T.unit[unit] then
Nenue@6 449 return
Nenue@6 450 end
Nenue@6 451 --name, subText, text, texture, startTime, endTime, isTradeSkill, notInterruptible
Nenue@6 452 local q = {UnitChannelInfo(unit) }
Nenue@6 453 T.unit[unit].channeling = q[1] and q or false
Nenue@6 454 T.unit[unit].spellEventString = e
Nenue@6 455 T.unit[unit].spellevent = {unit, spellName, rank, nil, castID, spellID }
Nenue@6 456 print(e, unit)
Nenue@6 457 end
Nenue@6 458
Nenue@6 459 T.UNIT_SPELLCAST_START = T.UNIT_SPELLCAST
Nenue@6 460 T.UNIT_SPELLCAST_STOP = T.UNIT_SPELLCAST
Nenue@6 461 T.UNIT_SPELLCAST_DELAYED = T.UNIT_SPELLCAST
Nenue@6 462 T.UNIT_SPELLCAST_INTERRUPTED = T.UNIT_SPELLCAST
Nenue@6 463 T.UNIT_SPELLCAST_FAILED = T.UNIT_SPELLCAST
Nenue@6 464 T.UNIT_SPELLCAST_SUCCEEDED = T.UNIT_SPELLCAST
Nenue@6 465 T.UNIT_SPELLCAST_CHANNEL_START = T.UNIT_CHANNEL
Nenue@6 466 T.UNIT_SPELLCAST_CHANNEL_UPDATE= T.UNIT_CHANNEL
Nenue@6 467 T.UNIT_SPELLCAST_CHANNEL_STOP= T.UNIT_CHANNEL
Nenue@6 468
Nenue@6 469 local UnitExists, GetRealmName, UnitClassification, UnitClass, UnitIsFriend, UnitIsEnemy, UnitIsFeignDeath
Nenue@6 470 = UnitExists, GetRealmName, UnitClassification, UnitClass, UnitIsFriend, UnitIsEnemy, UnitIsFeignDeath
Nenue@6 471 function T:UnitChanged(e, unit)
Nenue@6 472 local u = T.unit[unit]
Nenue@6 473 local exists = UnitExists(unit)
Nenue@6 474 local realm
Nenue@9 475 uprint(cText(' '..unit..' change:'), cText(unit), cText(exists and UnitName(unit)))
Nenue@6 476
Nenue@6 477 u.exists = exists
Nenue@6 478 u.name, realm = UnitName(unit)
Nenue@6 479 u.realm = realm or GetRealmName()
Nenue@6 480 u.classification = UnitClassification(unit)
Nenue@6 481 u.class = UnitClass(unit)
Nenue@6 482 u.isFriendly = UnitIsFriend('player', unit)
Nenue@6 483 u.isEnemy = UnitIsEnemy('player', unit)
Nenue@6 484 u.isFeign = UnitIsFeignDeath(unit)
Nenue@6 485 u.isNeutral = not(u.isHostile or u.isFriendly)
Nenue@6 486
Nenue@6 487 local castinfo, channelinfo = {UnitCastingInfo(unit)}, {UnitChannelInfo(unit)}
Nenue@6 488 u.casting = (u.exists and castinfo[1]) and castinfo or false
Nenue@6 489 u.channeling = (u.exists and channelinfo[1]) and channelinfo or false
Nenue@6 490 u.isCasting = (u.casting or u.channeling) and true or false
Nenue@6 491
Nenue@6 492
Nenue@6 493 for k,v in pairs(T.unit[unit]) do
Nenue@9 494 uprint(cText(' -'), cText(k),'->', cText(v))
Nenue@6 495 end
Nenue@6 496 end
Nenue@6 497 function T:PLAYER_TARGET_CHANGED(e)
Nenue@6 498 T:UnitChanged(e, 'target')
Nenue@6 499 end
Nenue@6 500 function T:PLAYER_FOCUS_CHANGED(e)
Nenue@6 501 T:UnitChanged(e, 'focus')
Nenue@6 502 end
Nenue@6 503 function T:UNIT_PET(e, unit,...)
Nenue@6 504 if unit == 'player' then
Nenue@6 505 print(e, unit, ...)
Nenue@6 506 T:UnitChanged(e, 'pet')
Nenue@6 507 end
Nenue@6 508 end
Nenue@6 509
Nenue@6 510 local Turok_OnCombat = function(inCombat)
Nenue@6 511 print(cText('* CombatToggle:'), cBool(inCombat))
Nenue@6 512 PlaySoundFile(db['battle_noise'.. (inCombat and '_start' or '_end')])
Nenue@6 513
Nenue@6 514 for _, region in pairs(Tk.LibFog.animate_regions) do
Nenue@6 515 if region.combatFade then
Nenue@6 516 print(' |cFFFFFF00+|r', region:GetName())
Nenue@6 517 region:UpdateAlpha(inCombat)
Nenue@6 518 else
Nenue@6 519 print(' |cFFFF4400-|r', region:GetName())
Nenue@6 520 end
Nenue@6 521 end
Nenue@6 522 end
Nenue@6 523
Nenue@6 524 --- InCombatLockdown() isn't updated immediately, so we have to assume
Nenue@6 525 function T:PLAYER_REGEN_DISABLED(e,...)
Nenue@6 526 T.inCombat = true
Nenue@6 527 Turok_OnCombat(true)
Nenue@6 528 end
Nenue@6 529 function T:PLAYER_REGEN_ENABLED(e,...)
Nenue@6 530 T.inCombat = nil
Nenue@6 531 Turok_OnCombat(false)
Nenue@6 532 end
Nenue@6 533
Nenue@6 534 -- GIST datas
Nenue@6 535 function T:GIST_InspectReady (event, guid, unit)
Nenue@6 536 print('GIST barf', guid, unit)
Nenue@6 537 end
Nenue@6 538
Nenue@6 539 function T:GIST_Update(event, guid, unit, info)
Nenue@6 540
Nenue@6 541 if info.class_id and info.global_spec_id and info.guid and info.lku then
Nenue@6 542 --_G.print('GIST', 'Update', unit)
Nenue@6 543 --_G.print('GIST',' class:', info.class_id, 'specid:', info.global_spec_id, 'guid:', info.guid)
Nenue@6 544
Nenue@6 545 self.units[info.guid] = info
Nenue@6 546 self.unitsBySlot[info.lku] = info
Nenue@6 547 end
Nenue@6 548 end
Nenue@6 549
Nenue@6 550 -- todo: re-locate these
Nenue@6 551
Nenue@6 552 T.PLAY_MOVIE = function (e, id)
Nenue@6 553 MovieFrame:Hide()
Nenue@6 554 T:Print('skipped a shitty movie', e, id)
Nenue@6 555 end
Nenue@6 556 T.CINEMATIC_START = function(...)
Nenue@6 557 CinematicFrame_CancelCinematic()
Nenue@6 558 T:Print('skipped a shitty cinematic', ...)
Nenue@6 559 end