wow-addons/BigBrother/BigBrother.lua

83 lines
2.6 KiB
Lua
Raw Normal View History

2020-07-10 03:56:08 +02:00
BigBrother = {}
BigBrother.title = GetAddOnMetadata("BigBrother", "Title")
BigBrother.version = GetAddOnMetadata("BigBrother", "Version")
BigBrother.author = GetAddOnMetadata("BigBrother", "Author")
BigBrother.Items = {}
print(("Loaded %s v%s by %s."):format(BigBrother.title, BigBrother.version, BigBrother.author))
BigBrotherDB = {} -- default value, will be overwritten by the game if persistent data exists
2020-09-29 03:40:04 +02:00
local weaponEnchantments = {
["Sharpen Weapon - Critical"] = {22756, 1800}, -- Elemental Sharpening Stone
["Sharpen Blade V"] = {16622, 1800}, -- Dense Sharpening Stone
["Enhance Blunt Weapon V"] = {16622, 1800}, -- Dense Weightstone
["Brilliant Wizard Oil"] = {25122, 1800},
["Brilliant Mana Oil"] = {25123, 1800},
}
local unitWeaponBuffs = {}
local frame, events = CreateFrame("FRAME"), {};
function events:ENCOUNTER_START(encounterID, encounterName, difficultyID, groupSize)
2020-07-10 03:56:08 +02:00
if not IsInRaid() then
return
end
2020-09-29 03:40:04 +02:00
-- remove expired weapon enchantments
local time = GetTime()
for name, v in pairs(unitWeaponBuffs) do
local weaponEnchantmentSpellId, weaponEnchantmentExpireTime = unpack(v)
if time > weaponEnchantmentExpireTime then
unitWeaponBuffs[name] = nil
end
end
2020-07-10 03:56:08 +02:00
local classBuffs = {}
for className, _ in pairs(RAID_CLASS_COLORS) do
classBuffs[className] = {}
end
for m = 1, GetNumGroupMembers() do
local unit = "raid" .. m
2020-09-29 03:40:04 +02:00
local name = UnitName(unit)
2020-07-10 03:56:08 +02:00
local unitBuffs = {}
for b = 1, 40 do
_, _, _, _, _, _, _, _, _, spellId = UnitBuff(unit, b)
if not spellId then
break
end
unitBuffs[b] = spellId
end
2020-09-29 03:40:04 +02:00
if unitWeaponBuffs[name] ~= nil then
local weaponEnchantmentSpellId, weaponEnchantmentExpireTime = unpack(unitWeaponBuffs[name])
table.insert(unitBuffs, weaponEnchantmentSpellId)
end
2020-07-10 03:56:08 +02:00
local _, className = UnitClass(unit)
2020-09-29 03:40:04 +02:00
classBuffs[className][name] = unitBuffs
2020-07-10 03:56:08 +02:00
end
table.insert(BigBrotherDB, {
date = date("%F %T"),
zone = GetRealZoneText(),
encounterID = encounterID,
encounterName = encounterName,
buffs = classBuffs,
})
2020-09-29 03:40:04 +02:00
end
function events:COMBAT_LOG_EVENT_UNFILTERED(...)
local _, event, _, _, name, _, _, _, _, _, _, _, spellName = CombatLogGetCurrentEventInfo()
2020-09-29 03:40:04 +02:00
if event ~= "SPELL_CAST_SUCCESS" then
return
end
if weaponEnchantments[spellName] ~= nil then
local weaponEnchantmentSpellId, weaponEnchantmentDuration = unpack(weaponEnchantments[spellName])
unitWeaponBuffs[name] = {weaponEnchantmentSpellId, GetTime() + weaponEnchantmentDuration}
2020-09-29 03:40:04 +02:00
end
end
frame:SetScript("OnEvent", function(self, event, ...)
events[event](self, ...)
2020-07-10 03:56:08 +02:00
end)
2020-09-29 03:40:04 +02:00
for k, v in pairs(events) do
frame:RegisterEvent(k) -- register all events for which handlers have been defined
end