VuhDoSpellEventHandler.lua 3.53 KB
Newer Older
humfras's avatar
humfras committed
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
local _;
--
local smatch = string.match;

local InCombatLockdown = InCombatLockdown;

local VUHDO_updateAllHoTs;
local VUHDO_updateAllCyclicBouquets;
local VUHDO_initGcd;

local VUHDO_ACTIVE_HOTS;
local VUHDO_RAID_NAMES;
local VUHDO_CONFIG = { };

local sIsShowGcd;
local sUniqueSpells = { };
local sFirstRes, sSecondRes;
local sEmpty = { };


function VUHDO_spellEventHandlerInitLocalOverrides()
	VUHDO_updateAllHoTs = _G["VUHDO_updateAllHoTs"];
	VUHDO_updateAllCyclicBouquets = _G["VUHDO_updateAllCyclicBouquets"];
	VUHDO_initGcd = _G["VUHDO_initGcd"];

	VUHDO_ACTIVE_HOTS = _G["VUHDO_ACTIVE_HOTS"];
	VUHDO_RAID_NAMES = _G["VUHDO_RAID_NAMES"];
	VUHDO_CONFIG = _G["VUHDO_CONFIG"];

	sIsShowGcd = VUHDO_isShowGcd();

	table.wipe(sUniqueSpells);
	local tUnique, tUniqueCategs = VUHDO_getAllUniqueSpells();
	for _, tSpellName in pairs(tUnique) do
		sUniqueSpells[tSpellName] = tUniqueCategs[tSpellName];
	end

	sFirstRes, sSecondRes = VUHDO_getResurrectionSpells();
end



--
local function VUHDO_activateSpellForSpec(aSpecId)
	local tName = VUHDO_SPEC_LAYOUTS[aSpecId];
	if not VUHDO_strempty(tName) then
		if VUHDO_SPELL_LAYOUTS[tName] then VUHDO_activateLayout(tName);
		else VUHDO_Msg(format(VUHDO_I18N_SPELL_LAYOUT_NOT_EXIST, tName), 1, 0.4, 0.4); end
	end
end



--
local function VUHDO_activateSpecc(aSpecNum)
	local tProfile = VUHDO_getBestProfileAfterSpecChange();
	if tProfile then VUHDO_loadProfile(tProfile); end
58
	VUHDO_activateSpellForSpec(aSpecNum);
humfras's avatar
humfras committed
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
	VUHDO_aoeUpdateTalents();
end



--
local VUHDO_TALENT_CHANGE_SPELLS = {
	[VUHDO_SPELL_ID.ACTIVATE_FIRST_TALENT] = true,
	[VUHDO_SPELL_ID.ACTIVATE_SECOND_TALENT] = true,
	[VUHDO_SPELL_ID.BUFF_FROST_PRESENCE] = true,
	[VUHDO_SPELL_ID.BUFF_BLOOD_PRESENCE] = true,
	[VUHDO_SPELL_ID.BUFF_UNHOLY_PRESENCE] = true,
}



--
function VUHDO_spellcastSucceeded(aUnit, aSpellName)
	if VUHDO_TALENT_CHANGE_SPELLS[aSpellName] then
		VUHDO_resetTalentScan(aUnit);
		VUHDO_initDebuffs(); -- Talentabhngige Debuff-Fhigkeiten neu initialisieren.
		VUHDO_timeReloadUI(1);
	end

	if "player" ~= aUnit and VUHDO_PLAYER_RAID_ID ~= aUnit then return; end

	if VUHDO_ACTIVE_HOTS[aSpellName] then
		VUHDO_updateAllHoTs();
		VUHDO_updateAllCyclicBouquets(true);
	end

	if VUHDO_SPELL_ID.ACTIVATE_FIRST_TALENT == aSpellName then VUHDO_activateSpecc("1");
	elseif (VUHDO_SPELL_ID.ACTIVATE_SECOND_TALENT == aSpellName) then VUHDO_activateSpecc("2"); end

	VUHDO_aoeUpdateAll();
end



--
local tTargetUnit;
local tCateg;
function VUHDO_spellcastSent(aUnit, aSpellName, aSpellRank, aTargetName)
	if "player" ~= aUnit or not aTargetName then return; end

	if sIsShowGcd then VUHDO_initGcd(); end

	aTargetName = smatch(aTargetName, "^[^-]*");
	tTargetUnit = VUHDO_RAID_NAMES[aTargetName];

109
	if not tTargetUnit then return; end
humfras's avatar
humfras committed
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

	-- Resurrection?
	if aSpellName == sFirstRes or aSpellName == sSecondRes then

		if VUHDO_CONFIG["RES_IS_SHOW_TEXT"] then

			local tChannel = (UnitInBattleground("player") or HasLFGRestrictions()) and "INSTANCE_CHAT"
				or IsInRaid() and "RAID" or IsInGroup() and "PARTY" or nil;

			if tChannel then
				SendChatMessage((gsub(VUHDO_CONFIG["RES_ANNOUNCE_TEXT"], "[Vv][Uu][Hh][Dd][Oo]", aTargetName)), tChannel);
			end

		end
		return;
	end

	tCateg = sUniqueSpells[aSpellName];
	if tCateg and not InCombatLockdown()
		and (VUHDO_BUFF_SETTINGS or sEmpty)[tCateg] and aTargetName ~= VUHDO_BUFF_SETTINGS[tCateg]["name"] then

		VUHDO_BUFF_SETTINGS[tCateg]["name"] = aTargetName;
		VUHDO_reloadBuffPanel();
	end
end