vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ------------------------------------------------------------------------------ |
2 | -- Utility library for SmartAssist |
||
3 | ------------------------------------------------------------------------------ |
||
4 | |||
5 | -- table.getn is basicly this but it doesn't work on all lists/maps ? |
||
6 | function SA_TableSize(t) |
||
7 | size = 0; |
||
8 | for k,v in t do |
||
9 | size = size + 1; |
||
10 | end |
||
11 | return size; |
||
12 | end |
||
13 | |||
14 | function SA_TableIndex(tbl, value) |
||
15 | for k,v in tbl do |
||
16 | if (v==value) then |
||
17 | return k |
||
18 | end |
||
19 | end |
||
20 | return -1 |
||
21 | end |
||
22 | |||
23 | function SA_GetAccountID() |
||
24 | return UnitName("player").." of "..GetCVar("realmName"); |
||
25 | end |
||
26 | |||
27 | ------------------------------------------------------------------------------ |
||
28 | -- Message methods |
||
29 | ------------------------------------------------------------------------------ |
||
30 | |||
31 | function SA_Verbose(message, color) |
||
32 | local color = color or COLOR_DEFAULT; |
||
33 | if (SCT_Display) then |
||
34 | SCT_Display(message, color); |
||
35 | else |
||
36 | DEFAULT_CHAT_FRAME:AddMessage(message, color.r, color.g, color.b); |
||
37 | end |
||
38 | end |
||
39 | |||
40 | function printInfo(message) |
||
41 | DEFAULT_CHAT_FRAME:AddMessage(message, 0, 0.8, 1); |
||
42 | end |
||
43 | |||
44 | ------------------------------------------------------------------------------ |
||
45 | -- Debug methods |
||
46 | ------------------------------------------------------------------------------ |
||
47 | |||
48 | function SA_Debug(message, level) |
||
49 | local level = level or 5; |
||
50 | if (SA_OPTIONS.DebugLevel >= level) then |
||
51 | DEFAULT_CHAT_FRAME:AddMessage(message, 0, 0.8, 1); |
||
52 | end |
||
53 | end |
||
54 | |||
55 | function SA_DebugCandidates(candidates) |
||
56 | for k,c in candidates do |
||
57 | if (c==nil) then |
||
58 | SA_Debug("THERE IS NIL VALUE ON ARRAY!", 1); |
||
59 | end |
||
60 | SA_DebugCandidate(c); |
||
61 | end |
||
62 | end |
||
63 | |||
64 | function SA_DebugCandidate(c) |
||
65 | SA_Debug("candidate name="..tostring(c.unitName).." | id="..tostring(c.unitId).." | health="..tostring(c.health).." | class="..tostring(c.class).." | pet="..tostring(c.pet), 1); |
||
66 | end |
||
67 | |||
68 | function SA_DebugTable(t) |
||
69 | SA_Debug("table length: "..SA_TableSize(t)); |
||
70 | for k,v in t do |
||
71 | SA_Debug("table: key="..k.." value="..tostring(v), 1); |
||
72 | end |
||
73 | end |
||
74 | |||
75 | ------------------------------------------------------------------------------ |
||
76 | -- Is the target valid for targetting |
||
77 | ------------------------------------------------------------------------------ |
||
78 | |||
79 | function isValidTarget(unit) |
||
80 | if (UnitExists(unit)) then |
||
81 | -- Don't target dead units |
||
82 | if (UnitIsDead(unit)) then |
||
83 | --SA_Debug("Dead, not targeting "..SA_TargetInfo(unit)); |
||
84 | return false; |
||
85 | end |
||
86 | -- Don't target friendlies |
||
87 | if (UnitIsFriend(unit, "player")) then |
||
88 | --SA_Debug("Friendly, not targeting "..SA_TargetInfo(unit)); |
||
89 | return false; |
||
90 | end |
||
91 | -- Don't target if we can't attack it |
||
92 | if (not UnitCanAttack(unit, "player")) then |
||
93 | SA_Debug("Can't attack, not targeting "..tostring(UnitName(unit))); |
||
94 | return false; |
||
95 | end |
||
96 | -- Don't target CCd mobs |
||
97 | if (isUnitCC(unit)) then |
||
98 | SA_Debug("CCd, not targeting "..tostring(UnitName(unit))); |
||
99 | return false; |
||
100 | end |
||
101 | else |
||
102 | return false; |
||
103 | end |
||
104 | return true; |
||
105 | end |
||
106 | |||
107 | ----------------------------------------------------------------------------------------- |
||
108 | -- Check if the targeted unit has any CC methods applied to it (seduce, charm, polymorph) |
||
109 | -- return true if the unit is CCd |
||
110 | -- basic idea taken from pet leash. I've added many more spells to the list tough :) |
||
111 | ----------------------------------------------------------------------------------------- |
||
112 | |||
113 | function isUnitCC(unit) |
||
114 | for i = 1, 20 do |
||
115 | if (UnitDebuff(unit,i)) then |
||
116 | currentDebuff = UnitDebuff(unit,i) |
||
117 | --SA_Debug("currentDebuff "..currentDebuff); |
||
118 | if (currentDebuff == "Interface\\Icons\\Spell_Shadow_Possession") then |
||
119 | SA_Debug("-- Possessed, not valid "..tostring(UnitName(unit))); |
||
120 | return true; |
||
121 | end |
||
122 | -- TODO: report that charmed detection doesn't work! |
||
123 | if (currentDebuff == "Interface\\Icons\\Spell_Shadow_Charm") then |
||
124 | SA_Debug("-- Charmed, not valid "..tostring(UnitName(unit))); |
||
125 | return true; |
||
126 | end |
||
127 | if (currentDebuff == "Interface\\Icons\\Spell_Nature_Polymorph") then |
||
128 | SA_Debug("-- Polymorphed, not valid "..tostring(UnitName(unit))); |
||
129 | return true; |
||
130 | end |
||
131 | -- not sure if this is ingame, nevertheless file exists |
||
132 | if (currentDebuff == "Interface\\Icons\\Spell_Magic_PolymorphChicken") then |
||
133 | SA_Debug("-- Polymorphed, not valid "..tostring(UnitName(unit))); |
||
134 | return true; |
||
135 | end |
||
136 | if (currentDebuff == "Interface\\Icons\\Spell_Magic_PolymorphPig") then |
||
137 | SA_Debug("-- Polymorphed, not valid "..tostring(UnitName(unit))); |
||
138 | return true; |
||
139 | end |
||
140 | if (currentDebuff == "Interface\\Icons\\Spell_Frost_ChainsOfIce") then |
||
141 | SA_Debug("-- Ice trapped, not valid "..tostring(UnitName(unit))); |
||
142 | return true; |
||
143 | end |
||
144 | if (currentDebuff == "Interface\\Icons\\Spell_Nature_Slow") then |
||
145 | SA_Debug("-- Shackle Undead, not valid "..tostring(UnitName(unit))); |
||
146 | return true; |
||
147 | end |
||
148 | if (currentDebuff == "Interface\\Icons\\Spell_Nature_Sleep") then |
||
149 | SA_Debug("-- Sleeped, not valid "..tostring(UnitName(unit))); |
||
150 | return true; |
||
151 | end |
||
152 | if (currentDebuff == "Interface\\Icons\\Ability_Sap") then |
||
153 | SA_Debug("-- Sapped, not valid "..tostring(UnitName(unit))); |
||
154 | return true; |
||
155 | end |
||
156 | if (currentDebuff == "Interface\\Icons\\Spell_Shadow_Cripple") then |
||
157 | SA_Debug("-- Banished, not valid "..tostring(UnitName(unit))); |
||
158 | return true; |
||
159 | end |
||
160 | else |
||
161 | -- no more debuffs on unit, stop the loop |
||
162 | break; |
||
163 | end |
||
164 | end |
||
165 | return false; |
||
166 | end |
||
167 | |||
168 | |||
169 | ------------------------------------------------------------------------------ |
||
170 | -- return true if unit is marked with hunter's mark |
||
171 | ------------------------------------------------------------------------------ |
||
172 | |||
173 | function SA_IsMarked(unit) |
||
174 | for i = 1, 20 do |
||
175 | if (UnitDebuff(unit, i)) then |
||
176 | currentDebuff = UnitDebuff(unit,i) |
||
177 | if (currentDebuff == "Interface\\Icons\\Ability_Hunter_SniperShot") then return true; end |
||
178 | else |
||
179 | -- no more debuffs on unit, stop the loop |
||
180 | break; |
||
181 | end |
||
182 | end |
||
183 | return false; |
||
184 | end |
||
185 | |||
186 | ------------------------------------------------------------------------------ |
||
187 | -- return true if unitName is tank (in smartassist or in ct raidassist) |
||
188 | ------------------------------------------------------------------------------ |
||
189 | |||
190 | function SA_IsTank(unitName) |
||
191 | if (unitName == SA_OPTIONS.puller) then return true; end; |
||
192 | if (CT_RA_MainTanks) then |
||
193 | for _,v in CT_RA_MainTanks do |
||
194 | if (unitName == v) then return true; end |
||
195 | end |
||
196 | end |
||
197 | return false; |
||
198 | end |
||
199 | |||
200 | |||
201 | ------------------------------------------------------------------------------ |
||
202 | -- Convert RGB values to text color values |
||
203 | ------------------------------------------------------------------------------ |
||
204 | |||
205 | function SA_ToTextCol(r,g,b) |
||
206 | return string.lower("|cff"..string.format("%.2X",255*r)..string.format("%.2X",255*g)..string.format("%.2X",255*b)); |
||
207 | end |