vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | |||
3 | SelfCast: Adds self-targeting, either by use of the alt key or automatically |
||
4 | copyright 2004 by Telo |
||
5 | |||
6 | - If selfcast is enabled, positive spells cast without a friendly target will |
||
7 | automatically target the player |
||
8 | - Otherwise, if alt-casting is enabled, holding the alt key when activating a |
||
9 | button will target the player |
||
10 | |||
11 | ]] |
||
12 | |||
13 | -------------------------------------------------------------------------------------------------- |
||
14 | -- Localizable strings |
||
15 | -------------------------------------------------------------------------------------------------- |
||
16 | |||
17 | SELFCAST_HELP = "help"; -- must be lowercase; displays help |
||
18 | SELFCAST_STATUS = "status"; -- must be lowercase; shows status |
||
19 | SELFCAST_ON = "on"; -- must be lowercase; for historical reasons, turns self-targeting on |
||
20 | SELFCAST_OFF = "off"; -- must be lowercase; for historical reasons, turns self-trageting off |
||
21 | SELFCAST_SELFON = "selfon"; -- must be lowercase; turns self-targeting on |
||
22 | SELFCAST_SELFOFF = "selfoff"; -- must be lowercase; turns self-targeting off |
||
23 | SELFCAST_ALTON = "alton"; -- must be lowercase; turns alt-casting on |
||
24 | SELFCAST_ALTOFF = "altoff"; -- must be lowercase; turns alt-casting off |
||
25 | |||
26 | SELFCAST_STATUS_HEADER = "|cffffff00SelfCast status:|r"; |
||
27 | SELFCAST_STATUS_SELFON = "SelfCast: |cff00ff00Auto self casting is -ON-. Beneficial spells will be cast on yourself if you don't have an ally targeted.|r"; |
||
28 | SELFCAST_STATUS_SELFOFF = "SelfCast: |cff00ff00Auto self casting is -OFF-. Beneficial spells must be explicitly targeted.|r"; |
||
29 | SELFCAST_STATUS_ALTON = "SelfCast: Alt-casting is on. Holding Alt while using an action button will target you, if possible."; |
||
30 | SELFCAST_STATUS_ALTOFF = "SelfCast: Alt-casting is off."; |
||
31 | |||
32 | SELFCAST_HELP_TEXT0 = " "; |
||
33 | SELFCAST_HELP_TEXT1 = "|cffffff00SelfCast command help:|r"; |
||
34 | SELFCAST_HELP_TEXT2 = "|cff00ff00Use |r|cffffffff/selfcast <command>|r|cff00ff00 or |r|cffffffff/sc <command>|r|cff00ff00 to perform the following commands:|r"; |
||
35 | SELFCAST_HELP_TEXT3 = "|cffffffff"..SELFCAST_HELP.."|r|cff00ff00: displays this message.|r"; |
||
36 | SELFCAST_HELP_TEXT4 = "|cffffffff"..SELFCAST_STATUS.."|r|cff00ff00: displays status information about the current option settings.|r"; |
||
37 | SELFCAST_HELP_TEXT5 = "|cffffffff"..SELFCAST_SELFON.."|r|cff00ff00: turns on auto self casting. When on, beneficial spells will be cast on yourself if you don't have an ally targeted.|r"; |
||
38 | SELFCAST_HELP_TEXT6 = "|cffffffff"..SELFCAST_SELFOFF.."|r|cff00ff00: turns off auto self casting.|r"; |
||
39 | SELFCAST_HELP_TEXT7 = "|cffffffff"..SELFCAST_ALTON.."|r|cff00ff00: turns on Alt-casting. When on, holding Alt while using an action button will target you, if possible.|r"; |
||
40 | SELFCAST_HELP_TEXT8 = "|cffffffff"..SELFCAST_ALTOFF.."|r|cff00ff00: turns off Alt-casting.|r"; |
||
41 | SELFCAST_HELP_TEXT9 = " "; |
||
42 | SELFCAST_HELP_TEXT10 = "|cff00ff00For example: |r|cffffffff/selfcast selfon|r|cff00ff00 will turn on auto self casting.|r"; |
||
43 | SELFCAST_HELP_TEXT11 = " "; |
||
44 | SELFCAST_HELP_TEXT12 = "|cff00ff00Using just |r|cffffffff/selfcast|r|cff00ff00 or |r|cffffffff/sc|r|cff00ff00 without any options will toggle auto-self casting between on and off."; |
||
45 | |||
46 | -------------------------------------------------------------------------------------------------- |
||
47 | -- Local variables |
||
48 | -------------------------------------------------------------------------------------------------- |
||
49 | |||
50 | -- The list of desired self-cast spells |
||
51 | local localSelfCast = { }; |
||
52 | -- Druid |
||
53 | localSelfCast["Abolish Poison"] = 1; |
||
54 | localSelfCast["Cure Poison"] = 1; |
||
55 | localSelfCast["Healing Touch"] = 1; |
||
56 | localSelfCast["Innervate"] = 1; |
||
57 | localSelfCast["Mark of the Wild"] = 1; |
||
58 | localSelfCast["Regrowth"] = 1; |
||
59 | localSelfCast["Rejuvenation"] = 1; |
||
60 | localSelfCast["Remove Curse"] = 1; |
||
61 | localSelfCast["Thorns"] = 1; |
||
62 | -- Mage |
||
63 | localSelfCast["Amplify Magic"] = 1; |
||
64 | localSelfCast["Arcane Intellect"] = 1; |
||
65 | localSelfCast["Dampen Magic"] = 1; |
||
66 | localSelfCast["Remove Lesser Curse"] = 1; |
||
67 | -- Paladin |
||
68 | localSelfCast["Cleanse"] = 1; |
||
69 | localSelfCast["Flash of Light"] = 1; |
||
70 | localSelfCast["Holy Light"] = 1; |
||
71 | localSelfCast["Purify"] = 1; |
||
72 | localSelfCast["Lay on Hands"] = 1; |
||
73 | localSelfCast["Blessing of Freedom"] = 1; |
||
74 | localSelfCast["Blessing of Fury"] = 1; |
||
75 | localSelfCast["Blessing of Kings"] = 1; |
||
76 | localSelfCast["Blessing of Light"] = 1; |
||
77 | localSelfCast["Blessing of Might"] = 1; |
||
78 | localSelfCast["Blessing of Protection"] = 1; |
||
79 | localSelfCast["Blessing of Reckoning"] = 1; |
||
80 | localSelfCast["Blessing of Righteousness"] = 1; |
||
81 | localSelfCast["Blessing of Salvation"] = 1; |
||
82 | localSelfCast["Blessing of Sanctuary"] = 1; |
||
83 | localSelfCast["Blessing of Wisdom"] = 1; |
||
84 | -- Priest |
||
85 | localSelfCast["Abolish Disease"] = 1; |
||
86 | localSelfCast["Cure Disease"] = 1; |
||
87 | localSelfCast["Dispel Magic"] = 2; |
||
88 | localSelfCast["Divine Spirit"] = 1; |
||
89 | localSelfCast["Fear Ward"] = 1; |
||
90 | localSelfCast["Flash Heal"] = 1; |
||
91 | localSelfCast["Greater Heal"] = 1; |
||
92 | localSelfCast["Lesser Heal"] = 1; |
||
93 | localSelfCast["Heal"] = 1; |
||
94 | localSelfCast["Power Word: Fortitude"] = 1; |
||
95 | localSelfCast["Power Word: Shield"] = 1; |
||
96 | localSelfCast["Renew"] = 1; |
||
97 | localSelfCast["Shadow Protection"] = 1; |
||
98 | localSelfCast["Power Infusion"] = 1; |
||
99 | -- Shaman |
||
100 | localSelfCast["Chain Heal"] = 1; |
||
101 | localSelfCast["Cure Disease"] = 1; |
||
102 | localSelfCast["Cure Poison"] = 1; |
||
103 | localSelfCast["Healing Wave"] = 1; |
||
104 | localSelfCast["Lesser Healing Wave"] = 1; |
||
105 | localSelfCast["Water Breathing"] = 1; |
||
106 | localSelfCast["Water Walking"] = 1; |
||
107 | -- Warlock |
||
108 | localSelfCast["Detect Greater Invisibility"] = 1; |
||
109 | localSelfCast["Detect Invisibility"] = 1; |
||
110 | localSelfCast["Detect Lesser Invisibility"] = 1; |
||
111 | localSelfCast["Unending Breath"] = 1; |
||
112 | -- First Aid |
||
113 | localSelfCast["Linen Bandage"] = 1; |
||
114 | localSelfCast["Heavy Linen Bandage"] = 1; |
||
115 | localSelfCast["Wool Bandage"] = 1; |
||
116 | localSelfCast["Heavy Wool Bandage"] = 1; |
||
117 | localSelfCast["Silk Bandage"] = 1; |
||
118 | localSelfCast["Heavy Silk Bandage"] = 1; |
||
119 | localSelfCast["Mageweave Bandage"] = 1; |
||
120 | localSelfCast["Heavy Mageweave Bandage"] = 1; |
||
121 | localSelfCast["Anti-Venom"] = 1; |
||
122 | localSelfCast["Strong Anti-Venom"] = 1; |
||
123 | localSelfCast["Runecloth Bandage"] = 1; |
||
124 | localSelfCast["Heavy Runecloth Bandage"] = 1; |
||
125 | -- Miscellaneous |
||
126 | localSelfCast["Crystal Force"] = 1; |
||
127 | localSelfCast["Crystal Restore"] = 1; |
||
128 | localSelfCast["Crystal Spire"] = 1; |
||
129 | localSelfCast["Crystal Ward"] = 1; |
||
130 | |||
131 | -- Function hooks |
||
132 | local lOriginal_UseAction; |
||
133 | local lOriginal_GameTooltip_ClearMoney; |
||
134 | |||
135 | -------------------------------------------------------------------------------------------------- |
||
136 | -- Internal functions |
||
137 | -------------------------------------------------------------------------------------------------- |
||
138 | |||
139 | local function SelfCast_MoneyToggle() |
||
140 | if( lOriginal_GameTooltip_ClearMoney ) then |
||
141 | GameTooltip_ClearMoney = lOriginal_GameTooltip_ClearMoney; |
||
142 | lOriginal_GameTooltip_ClearMoney = nil; |
||
143 | else |
||
144 | lOriginal_GameTooltip_ClearMoney = GameTooltip_ClearMoney; |
||
145 | GameTooltip_ClearMoney = SelfCast_GameTooltip_ClearMoney; |
||
146 | end |
||
147 | end |
||
148 | |||
149 | local function SelfCastStatus() |
||
150 | if( DEFAULT_CHAT_FRAME ) then |
||
151 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_HEADER); |
||
152 | if( SelfCastState ) then |
||
153 | if( SelfCastState.AutoSelfCast ) then |
||
154 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_SELFON); |
||
155 | else |
||
156 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_SELFOFF); |
||
157 | end |
||
158 | if( SelfCastState.AltOff ) then |
||
159 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_ALTOFF); |
||
160 | else |
||
161 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_ALTON); |
||
162 | end |
||
163 | else |
||
164 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_SELFOFF); |
||
165 | DEFAULT_CHAT_FRAME:AddMessage(SELFCAST_STATUS_ALTON); |
||
166 | end |
||
167 | end |
||
168 | end |
||
169 | |||
170 | function SelfCast(msg) |
||
171 | if( msg ) then |
||
172 | local command = string.lower(msg); |
||
173 | if( command == "" ) then |
||
174 | if( SelfCastState.AutoSelfCast ) then |
||
175 | SelfCastState.AutoSelfCast = nil; |
||
176 | else |
||
177 | SelfCastState.AutoSelfCast = 1; |
||
178 | end |
||
179 | SelfCastStatus(); |
||
180 | elseif( command == SELFCAST_HELP ) then |
||
181 | local index = 0; |
||
182 | local value = getglobal("SELFCAST_HELP_TEXT"..index); |
||
183 | while( value ) do |
||
184 | DEFAULT_CHAT_FRAME:AddMessage(value); |
||
185 | index = index + 1; |
||
186 | value = getglobal("SELFCAST_HELP_TEXT"..index); |
||
187 | end |
||
188 | elseif( command == SELFCAST_STATUS ) then |
||
189 | SelfCastStatus(); |
||
190 | elseif( command == SELFCAST_SELFON or command == SELFCAST_ON ) then |
||
191 | SelfCastState.AutoSelfCast = 1; |
||
192 | SelfCastStatus(); |
||
193 | elseif( command == SELFCAST_SELFOFF or command == SELFCAST_OFF ) then |
||
194 | SelfCastState.AutoSelfCast = nil; |
||
195 | SelfCastStatus(); |
||
196 | elseif( command == SELFCAST_ALTON ) then |
||
197 | SelfCastState.AltOff = nil; |
||
198 | SelfCastStatus(); |
||
199 | elseif( command == SELFCAST_ALTOFF ) then |
||
200 | SelfCastState.AltOff = 1; |
||
201 | SelfCastStatus(); |
||
202 | end |
||
203 | end |
||
204 | end |
||
205 | |||
206 | -------------------------------------------------------------------------------------------------- |
||
207 | -- OnFoo functions |
||
208 | -------------------------------------------------------------------------------------------------- |
||
209 | |||
210 | function SelfCast_OnLoad() |
||
211 | -- Register our slash command |
||
212 | SLASH_SELFCAST1 = "/selfcast"; |
||
213 | SLASH_SELFCAST2 = "/sc"; |
||
214 | SlashCmdList["SELFCAST"] = function(msg) |
||
215 | SelfCast(msg); |
||
216 | end |
||
217 | |||
218 | -- Hook UseAction |
||
219 | lOriginal_UseAction = UseAction; |
||
220 | UseAction = SelfCast_UseAction; |
||
221 | |||
222 | this:RegisterEvent("VARIABLES_LOADED"); |
||
223 | |||
224 | if( DEFAULT_CHAT_FRAME ) then |
||
225 | DEFAULT_CHAT_FRAME:AddMessage("Telo's SelfCast AddOn loaded"); |
||
226 | end |
||
227 | UIErrorsFrame:AddMessage("Telo's SelfCast AddOn loaded", 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME); |
||
228 | end |
||
229 | |||
230 | function SelfCast_OnEvent() |
||
231 | if( event == "VARIABLES_LOADED" ) then |
||
232 | if( not SelfCastState ) then |
||
233 | SelfCastState = { }; |
||
234 | end |
||
235 | if( AutoSelfCast ) then |
||
236 | SelfCastState.AutoSelfCast = 1; |
||
237 | end |
||
238 | SelfCastStatus(); |
||
239 | end |
||
240 | end |
||
241 | |||
242 | function SelfCast_UseAction(id, type, self) |
||
243 | local fSelfCast; |
||
244 | local fSelfCastable; |
||
245 | |||
246 | if( not SelfCastState.AltOff and IsAltKeyDown() ) then |
||
247 | fSelfCast = 1; |
||
248 | elseif( SelfCastState.AutoSelfCast ) then |
||
249 | -- protect money frame while we set hidden tooltip |
||
250 | SelfCast_MoneyToggle(); |
||
251 | SelfCastTooltip:SetOwner(UIParent, "ANCHOR_NONE"); |
||
252 | SelfCastTooltip:SetAction(id); |
||
253 | SelfCast_MoneyToggle(); |
||
254 | |||
255 | local name = getglobal("SelfCastTooltipTextLeft1"):GetText(); |
||
256 | if( name and localSelfCast[name] ) then |
||
257 | -- This spell is self-castable |
||
258 | fSelfCastable = 1; |
||
259 | |||
260 | if( not UnitExists("target") or UnitCanAttack("player", "target") or |
||
261 | (not UnitIsPVP("target") and (not UnitPlayerControlled("target") or UnitLevel("target") == 1)) ) then |
||
262 | fSelfCast = 1; |
||
263 | end |
||
264 | |||
265 | -- Don't self-cast certain spells if you have any target at all |
||
266 | if( localSelfCast[name] == 2 and UnitExists("target") ) then |
||
267 | fSelfCast = nil; |
||
268 | end |
||
269 | end |
||
270 | end |
||
271 | |||
272 | if( fSelfCast ) then |
||
273 | lOriginal_UseAction(id, type, 1); |
||
274 | else |
||
275 | lOriginal_UseAction(id, type, self); |
||
276 | end |
||
277 | |||
278 | if( fSelfCast or fSelfCastable ) then |
||
279 | if( SpellIsTargeting() ) then |
||
280 | SpellTargetUnit("player"); |
||
281 | end |
||
282 | if( SpellIsTargeting() ) then |
||
283 | TargetUnit("player"); |
||
284 | end |
||
285 | end |
||
286 | end |
||
287 | |||
288 | -------------------------------------------------------------------------------------------------- |
||
289 | -- Hooked functions |
||
290 | -------------------------------------------------------------------------------------------------- |
||
291 | |||
292 | function SelfCast_GameTooltip_ClearMoney() |
||
293 | -- Intentionally empty; don't clear money while we use hidden tooltips |
||
294 | end |