VuhDoSpellEventHandler.lua 3.48 KB
Newer Older
humfras's avatar
humfras committed
1 2 3 4 5 6 7 8 9
local _;
--
local smatch = string.match;

local InCombatLockdown = InCombatLockdown;

local VUHDO_updateAllHoTs;
local VUHDO_updateAllCyclicBouquets;
local VUHDO_initGcd;
10
local VUHDO_strempty;
humfras's avatar
humfras committed
11 12 13 14 15 16 17

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

local sIsShowGcd;
local sUniqueSpells = { };
18
local sFirstRes, sSecondRes, sThirdRes;
humfras's avatar
humfras committed
19 20 21 22 23 24 25
local sEmpty = { };


function VUHDO_spellEventHandlerInitLocalOverrides()
	VUHDO_updateAllHoTs = _G["VUHDO_updateAllHoTs"];
	VUHDO_updateAllCyclicBouquets = _G["VUHDO_updateAllCyclicBouquets"];
	VUHDO_initGcd = _G["VUHDO_initGcd"];
26
	VUHDO_strempty = _G["VUHDO_strempty"];
humfras's avatar
humfras committed
27 28 29 30 31 32 33 34 35 36 37 38 39

	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

40
	sFirstRes, sSecondRes, sThirdRes = VUHDO_getResurrectionSpells();
humfras's avatar
humfras committed
41 42 43 44 45
end



--
46
function VUHDO_activateSpellForSpec(aSpecId)
humfras's avatar
humfras committed
47 48 49 50 51 52 53 54 55 56
	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



--
57
function VUHDO_activateSpecc(aSpecNum)
humfras's avatar
humfras committed
58 59
	local tProfile = VUHDO_getBestProfileAfterSpecChange();
	if tProfile then VUHDO_loadProfile(tProfile); end
60
	VUHDO_activateSpellForSpec(aSpecNum);
humfras's avatar
humfras committed
61 62 63 64 65 66
	VUHDO_aoeUpdateTalents();
end



--
67 68 69
local tSpellName;
function VUHDO_spellcastSucceeded(aUnit, aSpellId)

70
	if "player" ~= aUnit and VUHDO_PLAYER_RAID_ID ~= aUnit then 
71 72 73
		return;
	end

74 75
	if aSpellId then
		tSpellName = GetSpellInfo(aSpellId);
humfras's avatar
humfras committed
76 77
	end

78
	if tSpellName and VUHDO_ACTIVE_HOTS[tSpellName] then
humfras's avatar
humfras committed
79 80 81 82 83
		VUHDO_updateAllHoTs();
		VUHDO_updateAllCyclicBouquets(true);
	end

	VUHDO_aoeUpdateAll();
84

humfras's avatar
humfras committed
85 86 87 88 89 90 91
end



--
local tTargetUnit;
local tCateg;
92 93 94 95 96
local tSpellName;
function VUHDO_spellcastSent(aUnit, aTargetName, aSpellId)
	if "player" ~= aUnit then 
		return;
	end
humfras's avatar
humfras committed
97

98 99 100 101 102 103 104 105 106 107 108
	if sIsShowGcd then 
		VUHDO_initGcd(); 
	end

	if aSpellId then
		tSpellName = GetSpellInfo(aSpellId);
	end

	if not tSpellName then
		return;
	end
humfras's avatar
humfras committed
109 110

	-- Resurrection?
111
	if tSpellName == sFirstRes or tSpellName == sSecondRes or tSpellName == sThirdRes then
112 113
		if aTargetName and not VUHDO_strempty(aTargetName) then 
			aTargetName = smatch(aTargetName, "^[^-]*");
humfras's avatar
humfras committed
114

115 116 117 118
			if not VUHDO_RAID_NAMES[aTargetName] then
				return;
			end
		end
humfras's avatar
humfras committed
119

120
		if VUHDO_CONFIG["RES_IS_SHOW_TEXT"] then
humfras's avatar
humfras committed
121 122 123 124
			local tChannel = (UnitInBattleground("player") or HasLFGRestrictions()) and "INSTANCE_CHAT"
				or IsInRaid() and "RAID" or IsInGroup() and "PARTY" or nil;

			if tChannel then
125
				SendChatMessage((gsub(VUHDO_strempty(aTargetName) and VUHDO_CONFIG["RES_ANNOUNCE_MASS_TEXT"] or VUHDO_CONFIG["RES_ANNOUNCE_TEXT"], "[Vv][Uu][Hh][Dd][Oo]", aTargetName or "")), tChannel);
humfras's avatar
humfras committed
126 127
			end
		end
128

humfras's avatar
humfras committed
129 130 131
		return;
	end

132 133 134 135 136 137 138
	if not aTargetName then return; end

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

	if not tTargetUnit then return; end

139
	tCateg = sUniqueSpells[tSpellName];
humfras's avatar
humfras committed
140 141 142 143 144 145 146
	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