vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[--------------------------------------------------------------------------------- |
2 | locals |
||
3 | ------------------------------------------------------------------------------------]] |
||
4 | |||
5 | BINDING_HEADER_SMARTRES = "SmartRes" |
||
6 | BINDING_NAME_RES = "Resurrect" |
||
7 | |||
8 | local resTable = {} |
||
9 | local resAttempt = {} |
||
10 | local enabled = {} |
||
11 | local isCasting = nil |
||
12 | local resSpell = "" |
||
13 | local corpseCount = 0 |
||
14 | local class = "" |
||
15 | |||
16 | local BS = AceLibrary("Babble-Spell-2.2") |
||
17 | |||
18 | local resSpell = { |
||
19 | PRIEST = BS["Resurrection"], |
||
20 | SHAMAN = BS["Ancestral Spirit"], |
||
21 | PALADIN = BS["Redemption"] |
||
22 | } |
||
23 | |||
24 | local locals = { |
||
25 | NotGrouped = "You're not in a group.", |
||
26 | NotInRange = "No one in range to res or you're out of mana.", |
||
27 | NoDeadUnits = "Coudnt't find any dead (non-released) units.", |
||
28 | AllDeadRessed = "All dead units are already being ressed.", |
||
29 | } |
||
30 | |||
31 | --[[--------------------------------------------------------------------------------- |
||
32 | defaults and AceOptions table |
||
33 | ------------------------------------------------------------------------------------]] |
||
34 | |||
35 | local defaults = { |
||
36 | ResMessage = "Ressing: %s", |
||
37 | ChannelType = "SAY", |
||
38 | CustomChannel = "OFF", |
||
39 | CustomChannelName = nil |
||
40 | } |
||
41 | |||
42 | local options = { |
||
43 | type = 'group', |
||
44 | args = { |
||
45 | res = { |
||
46 | type = 'execute', |
||
47 | name = "Resurrect", |
||
48 | desc = "Will attempt to resurrect a grouped player", |
||
49 | func = function() |
||
50 | SmartRes:Resurrect() |
||
51 | end |
||
52 | }, |
||
53 | msgtype = { |
||
54 | type = 'text', |
||
55 | name = "Message Type", |
||
56 | desc = "Set the Res Message output channel type. (Valid Types: SAY, YELL, PARTY, RAID, GUILD, OFFICER) Setting the channel type to 'OFF' will disable this feature.", |
||
57 | validate = {"SAY", "YELL", "PARTY", "RAID", "GUILD", "OFFICER", "OFF"}, |
||
58 | get = function() return SmartRes.db.profile.ChannelType end, |
||
59 | set = function(text) |
||
60 | SmartRes.db.profile.ChannelType = text |
||
61 | end |
||
62 | }, |
||
63 | msg = { |
||
64 | type = 'text', |
||
65 | name = "Res Message", |
||
66 | desc = "Change the Res Message.", |
||
67 | get = function() |
||
68 | return string.format(SmartRes.db.profile.ResMessage, "%s") |
||
69 | end, |
||
70 | set = function(text) |
||
71 | SmartRes.db.profile.ResMessage = text |
||
72 | end, |
||
73 | usage = "<msg> (Example: Ressing: %s) **Be sure to include %s where you want the target's name to be**" |
||
74 | }, |
||
75 | chan = { |
||
76 | type = 'text', |
||
77 | name = "Custom Channel", |
||
78 | desc = "Send the Res Message to a custom chat channel.", |
||
79 | validate = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "OFF"}, |
||
80 | get = function() |
||
81 | if SmartRes.db.profile.CustomChannel ~= "OFF" then |
||
82 | return SmartRes.db.profile.CustomChannel..". "..SmartRes.db.profile.CustomChannelName |
||
83 | end |
||
84 | end, |
||
85 | set = function(num) |
||
86 | SmartRes:SetCustomChan(num) |
||
87 | end |
||
88 | }, |
||
89 | reset = { |
||
90 | type = 'execute', |
||
91 | name = "Reset", |
||
92 | desc = "Resets SmartRes to the default settings", |
||
93 | func = function() |
||
94 | SmartRes:ResetDB("profile") |
||
95 | SmartRes:Print("All options have been reset to default.") |
||
96 | end |
||
97 | } |
||
98 | } |
||
99 | } |
||
100 | |||
101 | --[[--------------------------------------------------------------------------------- |
||
102 | Initialization |
||
103 | ------------------------------------------------------------------------------------]] |
||
104 | |||
105 | SmartRes = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceDB-2.0", "AceConsole-2.0") |
||
106 | |||
107 | |||
108 | function SmartRes:OnInitialize() |
||
109 | self:RegisterDB("SmartResDB") |
||
110 | self:RegisterDefaults('profile', defaults ) |
||
111 | self:RegisterChatCommand({ "/smartres", "/sr" }, options ) |
||
112 | end |
||
113 | |||
114 | |||
115 | function SmartRes:OnEnable() |
||
116 | _,class = UnitClass("player") |
||
117 | if not resSpell[class] then return end |
||
118 | enabled = true |
||
119 | self:RegisterEvent("SPELLCAST_START", function() isCasting = true end ) |
||
120 | self:RegisterEvent("SPELLCAST_STOP", function() isCasting = false end ) |
||
121 | self:RegisterEvent("SPELLCAST_FAILED", function() isCasting = false end ) |
||
122 | self:RegisterEvent("SPELLCAST_INTERRUPTED", function() isCasting = false end ) |
||
123 | end |
||
124 | |||
125 | |||
126 | function SmartRes:OnDisable() |
||
127 | enabled = nil |
||
128 | end |
||
129 | |||
130 | --[[--------------------------------------------------------------------------------- |
||
131 | The real stuff |
||
132 | ------------------------------------------------------------------------------------]] |
||
133 | |||
134 | function SmartRes:SetCustomChan(num) |
||
135 | if num == "OFF" then |
||
136 | self.db.profile.CustomChannel = "OFF" |
||
137 | self.db.profile.CustomChannelName = nil |
||
138 | return |
||
139 | end |
||
140 | local id, channame = GetChannelName(num) |
||
141 | if id ~= 0 then |
||
142 | self.db.profile.CustomChannel = id |
||
143 | self.db.profile.CustomChannelName = channame |
||
144 | end |
||
145 | end |
||
146 | |||
147 | |||
148 | function SmartRes:Resurrect() |
||
149 | if not enabled then |
||
150 | self:Print("Mod not 'enabled', bypassing function") |
||
151 | return |
||
152 | end |
||
153 | if isCasting then return end |
||
154 | if GetNumPartyMembers() == 0 then |
||
155 | self:Print(locals.NotGrouped) |
||
156 | return |
||
157 | end |
||
158 | resTable = {} |
||
159 | if UnitInRaid("player") then |
||
160 | self:BuildResTable("raid") |
||
161 | else |
||
162 | self:BuildResTable("party") |
||
163 | end |
||
164 | if corpseCount == 0 then |
||
165 | self:Print(locals.NoDeadUnits) |
||
166 | return |
||
167 | end |
||
168 | if corpseCount - corpseCountRessed == 0 then |
||
169 | self:Print(locals.AllDeadRessed) |
||
170 | return |
||
171 | end |
||
172 | table.sort( resTable, function(a,b) return a[2] < b[2] end ) |
||
173 | CastSpellByName(resSpell[class],0) |
||
174 | local corpse = self:ChooseDeadUnitInRange() |
||
175 | if corpse then |
||
176 | SpellTargetUnit(corpse) |
||
177 | resAttempt[UnitName(corpse)] = GetTime() |
||
178 | if not SpellIsTargeting() then |
||
179 | if self.db.profile.ChannelType ~= "OFF" then |
||
180 | SendChatMessage(string.format(self.db.profile.ResMessage, UnitName(corpse)), self.db.profile.ChannelType) |
||
181 | end |
||
182 | if self.db.profile.CustomChannel ~= "OFF" then |
||
183 | local chanid, channame = GetChannelName(self.db.profile.CustomChannel) |
||
184 | if (chanid == self.db.profile.CustomChannel and channame == self.db.profile.CustomChannelName) then |
||
185 | SendChatMessage(string.format(self.db.profile.ResMessage, UnitName(corpse)), "CHANNEL", nil, self.db.profile.CustomChannel) |
||
186 | end |
||
187 | end |
||
188 | else |
||
189 | SpellStopTargeting() |
||
190 | end |
||
191 | else |
||
192 | SpellStopTargeting() |
||
193 | self:Print(locals.NotInRange) |
||
194 | end |
||
195 | end |
||
196 | |||
197 | |||
198 | function SmartRes:BuildResTable(type) |
||
199 | local x |
||
200 | if type == "raid" then x = GetNumRaidMembers() |
||
201 | elseif type == "party" then x = GetNumPartyMembers() |
||
202 | end |
||
203 | corpseCount = 0 |
||
204 | corpseCountRessed = 0 |
||
205 | for i = 1, x do |
||
206 | if UnitIsConnected(type..i) then |
||
207 | if UnitIsDead(type..i) then |
||
208 | corpseCount = corpseCount + 1 |
||
209 | if not self:UnitDoesntNeedRes(UnitName(type..i)) then |
||
210 | tinsert(resTable, { type..i, self:GetResModifier(type..i) }) |
||
211 | else |
||
212 | corpseCountRessed = corpseCountRessed + 1 |
||
213 | end |
||
214 | else |
||
215 | local name = UnitName(type..i) |
||
216 | if resAttempt[name] then |
||
217 | resAttempt[name] = nil |
||
218 | end |
||
219 | end |
||
220 | end |
||
221 | end |
||
222 | end |
||
223 | |||
224 | |||
225 | function SmartRes:GetResModifier(unit) |
||
226 | local m = 0 |
||
227 | local _,c = UnitClass(unit) |
||
228 | if c == "PRIEST" then m = 0 |
||
229 | elseif c == "SHAMAN" then m = 5 |
||
230 | elseif c == "PALADIN" then m = 5 |
||
231 | elseif c == "DRUID" then m = 10 |
||
232 | elseif c == "MAGE" then m = 15 |
||
233 | elseif c == "WARRIOR" then m = 20 |
||
234 | elseif c == "WARLOCK" then m = 25 |
||
235 | elseif c == "HUNTER" then m = 30 |
||
236 | elseif c == "ROGUE" then m = 35 |
||
237 | end |
||
238 | if UnitInParty(unit) then m = m - 1 end |
||
239 | -- we don't want to get stuck on someone out of LOS |
||
240 | m = m + math.random(5) |
||
241 | return m |
||
242 | end |
||
243 | |||
244 | |||
245 | function SmartRes:UnitDoesntNeedRes(name) |
||
246 | -- check who we attempted to res in the past minute: |
||
247 | if resAttempt[name] then |
||
248 | if GetTime() - resAttempt[name] < 60 then |
||
249 | return true |
||
250 | end |
||
251 | end |
||
252 | -- see who is being ressed by others this moment |
||
253 | if CT_RA_Ressers then |
||
254 | for key, val in CT_RA_Ressers do |
||
255 | if val == name then |
||
256 | return true |
||
257 | end |
||
258 | end |
||
259 | end |
||
260 | if oRA_Resurrection and oRA_Resurrection.ressers then |
||
261 | for key, val in oRA_Resurrection.ressers do |
||
262 | if val == name then |
||
263 | return true |
||
264 | end |
||
265 | end |
||
266 | end |
||
267 | if oRAOResurrection and oRAOResurrection.ressers then |
||
268 | for key, val in oRAOResurrection.ressers do |
||
269 | if val == name then |
||
270 | return true |
||
271 | end |
||
272 | end |
||
273 | end |
||
274 | -- see who's ressed already |
||
275 | if CT_RA_Stats and |
||
276 | CT_RA_Stats[name] and |
||
277 | CT_RA_Stats[name]["Ressed"] and |
||
278 | CT_RA_Stats[name]["Ressed"] == 1 then |
||
279 | return true |
||
280 | end |
||
281 | return false |
||
282 | end |
||
283 | |||
284 | |||
285 | function SmartRes:ChooseDeadUnitInRange() |
||
286 | for key, val in resTable do |
||
287 | if SpellCanTargetUnit(val[1]) then |
||
288 | return val[1] |
||
289 | end |
||
290 | end |
||
291 | return nil |
||
292 | end |
||
293 |