vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | IMBA_Tracker_Enabled=false; |
2 | IMBA_Tracker_UpdateTime=0; |
||
3 | IMBA_Tracker_StopTimeGuild=0; |
||
4 | IMBA_Tracker_StopTimeRaid=0; |
||
5 | |||
6 | IMBA_Tracker_LastPos={x=0;y=0}; |
||
7 | IMBA_Tracker_PingDelta={x=0;y=0}; |
||
8 | |||
9 | IMBA_Tracker_Calibration={} |
||
10 | |||
11 | IMBA_TRACKER_UPDATE_RATE = 0.5 |
||
12 | |||
13 | local minimapPlayerModel; |
||
14 | |||
15 | IMBA_Minimap_Zoom={}; |
||
16 | IMBA_Minimap_Zoom[0]={} |
||
17 | IMBA_Minimap_Zoom[1]={} |
||
18 | --For Outside of WMO's |
||
19 | IMBA_Minimap_Zoom[0][0]=1; |
||
20 | IMBA_Minimap_Zoom[0][1]=6/7; |
||
21 | IMBA_Minimap_Zoom[0][2]=5/7; |
||
22 | IMBA_Minimap_Zoom[0][3]=4/7; |
||
23 | IMBA_Minimap_Zoom[0][4]=3/7; |
||
24 | IMBA_Minimap_Zoom[0][5]=2/7; |
||
25 | |||
26 | --For Inside of WMO's |
||
27 | IMBA_Minimap_Zoom[1][0]=1*0.643; |
||
28 | IMBA_Minimap_Zoom[1][1]=4/5*0.643; |
||
29 | IMBA_Minimap_Zoom[1][2]=3/5*0.643; |
||
30 | IMBA_Minimap_Zoom[1][3]=2/5*0.643; |
||
31 | IMBA_Minimap_Zoom[1][4]=4/15*0.643; |
||
32 | IMBA_Minimap_Zoom[1][5]=1/6*0.643; |
||
33 | |||
34 | IMBA_Tracker_Preset=false |
||
35 | |||
36 | |||
37 | function IMBA_Tracker_OnLoad() |
||
38 | DEFAULT_CHAT_FRAME:AddMessage("Tracker Loaded"); |
||
39 | this:RegisterEvent("MINIMAP_PING"); |
||
40 | this:RegisterEvent("CHAT_MSG_ADDON"); |
||
41 | this:RegisterEvent("RAID_ROSTER_UPDATE"); |
||
42 | this:RegisterEvent("PLAYER_LOGIN"); |
||
43 | |||
44 | -- Create a table of all the Minimap's children objectSimpleCompass_Saved. |
||
45 | local children = {Minimap:GetChildren()}; |
||
46 | |||
47 | for i=getn(children), 1, -1 do |
||
48 | -- Iterate over them all, starting from the end of the list to see if the object reference is a model. |
||
49 | -- If it is, and it has no name (in case some addon attached a model to it), it's probably the right one. |
||
50 | if children[i]:IsObjectType("Model") and not children[i]:GetName() and not minimapPlayerModel then |
||
51 | -- Found, setting as the addon's local to keep the reference. |
||
52 | minimapPlayerModel = children[i]; |
||
53 | return; |
||
54 | end |
||
55 | end |
||
56 | end |
||
57 | |||
58 | |||
59 | function IMBA_Tracker_OnEvent(event) |
||
60 | if event=="MINIMAP_PING" then |
||
61 | local x,y=Minimap:GetPingPosition(); |
||
62 | local zoom = IMBA_Minimap_Zoom[IMBA_isMinimapInsideWMO()][Minimap:GetZoom()]; |
||
63 | IMBA_Tracker_PingDelta.x=IMBA_Tracker_PingDelta.x+IMBA_Tracker_LastPos.x-x*zoom; |
||
64 | IMBA_Tracker_PingDelta.y=IMBA_Tracker_PingDelta.y+IMBA_Tracker_LastPos.y-y*zoom; |
||
65 | |||
66 | IMBA_Tracker_LastPos.x=x; |
||
67 | IMBA_Tracker_LastPos.y=y; |
||
68 | |||
69 | if not IMBA_TrackerData then |
||
70 | IMBA_TrackerData={}; |
||
71 | end |
||
72 | |||
73 | if IMBA_Tracker_Calibrating then |
||
74 | IMBA_Tracker_CalibratePing.x=IMBA_Tracker_CalibratePing.x+IMBA_Tracker_LastPos.x-x*zoom; |
||
75 | IMBA_Tracker_CalibratePing.y=IMBA_Tracker_CalibratePing.y+IMBA_Tracker_LastPos.y-y*zoom; |
||
76 | end |
||
77 | |||
78 | IMBA_TrackerData.Delta=IMBA_Tracker_PingDelta |
||
79 | elseif event=="CHAT_MSG_ADDON" then |
||
80 | if arg1=="IMBA_TRACKER_UPDATE" then |
||
81 | if arg2=="TRANSMIT" then |
||
82 | if arg3=="RAID" then |
||
83 | IMBA_Tracker_EnabledRaid=true; |
||
84 | IMBA_Tracker_StopTimeRaid=GetTime()+15; |
||
85 | elseif arg3=="GUILD" then |
||
86 | IMBA_Tracker_EnabledGuild=true; |
||
87 | IMBA_Tracker_StopTimeGuild=GetTime()+15; |
||
88 | end |
||
89 | elseif arg2=="CALIBRATE" then |
||
90 | local score=2 |
||
91 | if IMBA_Tracker_ValidatePos then |
||
92 | score=1 |
||
93 | IMBA_Tracker_ValidateTime=GetTime()+60; |
||
94 | IMBA_Tracker_Calibrating=true |
||
95 | IMBA_Tracker_CountTime=GetTime()+10; |
||
96 | IMBA_Tracker_CalibratePing={x=0;y=0} |
||
97 | end |
||
98 | --DEFAULT_CHAT_FRAME:AddMessage("Calibration Request Received") |
||
99 | SendAddonMessage("IMBA_TRACKER_UPDATE","CALIBRATION "..score.." "..IMBA_Tracker_PingDelta.x.." "..IMBA_Tracker_PingDelta.y,"RAID"); |
||
100 | IMBA_Tracker_Calibration={} |
||
101 | |||
102 | elseif string.find(arg2,"CALIBRATION") and IMBA_Tracker_ValidatePos then |
||
103 | local score, deltax, deltay |
||
104 | _,_,score, deltax, deltay =string.find(arg2,"CALIBRATION (%d+) (-?%d+.?%d*) (-?%d+.?%d*)") |
||
105 | score=tonumber(score) |
||
106 | deltax=tonumber(deltax) |
||
107 | deltay=tonumber(deltay) |
||
108 | --DEFAULT_CHAT_FRAME:AddMessage("Received Calibration Vote "..score.." Delta "..deltax.." "..deltay); |
||
109 | for k,v in IMBA_Tracker_Calibration do |
||
110 | if IMBA_Tracker_CompareNumber(v.x,deltax) and IMBA_Tracker_CompareNumber(v.y,deltay) then |
||
111 | v.totalx=v.totalx+score*deltax; |
||
112 | v.totaly=v.totaly+score*deltay; |
||
113 | v.score=v.score+score; |
||
114 | |||
115 | v.x=v.totalx/v.score |
||
116 | v.y=v.totaly/v.score |
||
117 | return |
||
118 | end |
||
119 | end |
||
120 | tinsert(IMBA_Tracker_Calibration,{x=deltax;y=deltay;totalx=deltax*score;totaly=deltay*score;score=score}) |
||
121 | end |
||
122 | end |
||
123 | elseif event=="RAID_ROSTER_UPDATE" then |
||
124 | if IMBA_Tracker_EnabledRaid and GetNumRaidMembers()==0 then |
||
125 | IMBA_Tracker_EnabledRaid=false; |
||
126 | end |
||
127 | elseif event=="PLAYER_LOGIN" then |
||
128 | IMBA_Tracker_Loaded=true |
||
129 | |||
130 | IMBA_Tracker_ValidatePos=true; |
||
131 | IMBA_Tracker_ValidateTime=GetTime()+0.2; |
||
132 | |||
133 | --DEFAULT_CHAT_FRAME:AddMessage("Validating Coords"); |
||
134 | if IMBA_SavedVariables.LastPlayerPos then |
||
135 | local curX,curY; |
||
136 | local oldX,oldY; |
||
137 | curX, curY = IMBA_Tracker_GetPostion() |
||
138 | |||
139 | |||
140 | oldX=IMBA_SavedVariables.LastPlayerPos.x; |
||
141 | oldY=IMBA_SavedVariables.LastPlayerPos.y; |
||
142 | |||
143 | if (not IMBA_Tracker_CompareNumber(curX,oldX)) or (not IMBA_Tracker_CompareNumber(curY,oldY)) then |
||
144 | if IMBA_TrackerData then |
||
145 | --DEFAULT_CHAT_FRAME:AddMessage("Incorrect - Testing with saved Delta's") |
||
146 | curX=curX+IMBA_TrackerData.Delta.x |
||
147 | curY=curY+IMBA_TrackerData.Delta.y |
||
148 | if IMBA_Tracker_CompareNumber(curX,oldX) and IMBA_Tracker_CompareNumber(curY,oldY) then |
||
149 | --DEFAULT_CHAT_FRAME:AddMessage("Correct Delta and Set") |
||
150 | IMBA_Tracker_PingDelta=IMBA_TrackerData.Delta |
||
151 | end |
||
152 | end |
||
153 | end |
||
154 | end |
||
155 | end |
||
156 | end |
||
157 | |||
158 | function IMBA_Tracker_CompareNumber(v1,v2) |
||
159 | return math.abs(v1-v2)<0.015; |
||
160 | end |
||
161 | |||
162 | function IMBA_Tracker_GetPostion() |
||
163 | local x,y = Minimap:GetPingPosition(); |
||
164 | local zoom = IMBA_Minimap_Zoom[IMBA_isMinimapInsideWMO()][Minimap:GetZoom()]; |
||
165 | |||
166 | x=x*zoom+IMBA_Tracker_PingDelta.x; |
||
167 | y=y*zoom+IMBA_Tracker_PingDelta.y; |
||
168 | return x, y |
||
169 | end |
||
170 | |||
171 | --The various equations to convert map coordinates to Ping coordinates |
||
172 | --Linear equations fitted via linear least squares of a decent sampling of numbers ~25 |
||
173 | --Introduces error on the order of +/-0.005 of ping coordinates |
||
174 | IMBA_MapEquations={} |
||
175 | IMBA_MapEquations[2]={mx=-75.42874908;bx=34.2859094;my=50.2865016;by=-16.00008308} |
||
176 | IMBA_MapEquations[1]={mx=-78.85670491;bx=36.57127371;my=52.57102443;by=-27.42828408} |
||
177 | |||
178 | function IMBA_Tracker_GetPostion_ViaMap() |
||
179 | SetMapToCurrentZone() |
||
180 | local continent=GetCurrentMapContinent(); |
||
181 | SetMapZoom(continent) |
||
182 | local x, y = GetPlayerMapPosition("player"); |
||
183 | local equ=IMBA_MapEquations[continent] |
||
184 | if not equ then |
||
185 | equ={mx=1;bx=0;my=1;by=0} |
||
186 | end |
||
187 | x=x*equ.mx+equ.bx |
||
188 | y=y*equ.my+equ.by |
||
189 | return x, y |
||
190 | end |
||
191 | |||
192 | function IMBA_Tracker_Calibration_Sort(v1,v2) |
||
193 | return v1.score>v2.score |
||
194 | end |
||
195 | |||
196 | |||
197 | function IMBA_Tracker_OnUpdate() |
||
198 | local x,y = Minimap:GetPingPosition(); |
||
199 | local zoom = IMBA_Minimap_Zoom[IMBA_isMinimapInsideWMO()][Minimap:GetZoom()]; |
||
200 | |||
201 | IMBA_Tracker_LastPos.x=x*zoom |
||
202 | IMBA_Tracker_LastPos.y=y*zoom |
||
203 | |||
204 | --Position Validation |
||
205 | if IMBA_Tracker_ValidatePos and IMBA_Tracker_ValidateTime<GetTime() then |
||
206 | SetMapToCurrentZone() |
||
207 | if GetCurrentMapContinent()>0 then |
||
208 | if not IMBA_Tracker_Preset then |
||
209 | --DEFAULT_CHAT_FRAME:AddMessage("Preset Map") |
||
210 | SetMapZoom(GetCurrentMapContinent()) |
||
211 | IMBA_Tracker_ValidateTime=GetTime()+0.1 |
||
212 | IMBA_Tracker_Preset=true; |
||
213 | else |
||
214 | --DEFAULT_CHAT_FRAME:AddMessage("Correcting Map") |
||
215 | local wrongX,wrongY=IMBA_Tracker_GetPostion(); |
||
216 | local rightX,rightY=IMBA_Tracker_GetPostion_ViaMap(); |
||
217 | |||
218 | if (not IMBA_Tracker_CompareNumber(wrongX,rightX)) or (not IMBA_Tracker_CompareNumber(wrongY,rightY)) then |
||
219 | IMBA_Tracker_PingDelta.x=IMBA_Tracker_PingDelta.x+(rightX-wrongX); |
||
220 | IMBA_Tracker_PingDelta.y=IMBA_Tracker_PingDelta.y+(rightY-wrongY); |
||
221 | end |
||
222 | |||
223 | IMBA_Tracker_ValidatePos=false; |
||
224 | end |
||
225 | elseif GetNumRaidMembers()>0 then |
||
226 | --Lets try to calibrate if we can with other raid members |
||
227 | if not IMBA_Tracker_PrePinged then |
||
228 | Minimap:PingLocation(0,0); --Send a ping that we can all agree on |
||
229 | IMBA_Tracker_ValidateTime=GetTime()+0.5; |
||
230 | IMBA_Tracker_PrePinged=true |
||
231 | else |
||
232 | SendAddonMessage("IMBA_TRACKER_UPDATE","CALIBRATE","RAID"); |
||
233 | --DEFAULT_CHAT_FRAME:AddMessage("Requesting Calibration") |
||
234 | IMBA_Tracker_ValidateTime=GetTime()+60; |
||
235 | IMBA_Tracker_PrePinged=false; |
||
236 | end |
||
237 | end |
||
238 | end |
||
239 | |||
240 | |||
241 | |||
242 | if IMBA_Tracker_Calibrating and IMBA_Tracker_CountTime<GetTime() then |
||
243 | sort(IMBA_Tracker_Calibration,IMBA_Tracker_Calibration_Sort) |
||
244 | --DEFAULT_CHAT_FRAME:AddMessage("Calibration Vote Score of "..IMBA_Tracker_Calibration[1].score.." Delta= "..IMBA_Tracker_Calibration[1].x..", "..IMBA_Tracker_Calibration[1].y); |
||
245 | if IMBA_Tracker_Calibration[1].score>1.5 then |
||
246 | IMBA_Tracker_PingDelta.x=IMBA_Tracker_Calibration[1].x+IMBA_Tracker_CalibratePing.x |
||
247 | IMBA_Tracker_PingDelta.y=IMBA_Tracker_Calibration[1].y+IMBA_Tracker_CalibratePing.y |
||
248 | IMBA_Tracker_ValidatePos=false; |
||
249 | end |
||
250 | IMBA_Tracker_Calibrating=false |
||
251 | end |
||
252 | |||
253 | x=x*zoom+IMBA_Tracker_PingDelta.x; |
||
254 | y=y*zoom+IMBA_Tracker_PingDelta.y; |
||
255 | |||
256 | if IMBA_Tracker_Loaded then |
||
257 | IMBA_SavedVariables.LastPlayerPos={x=x;y=y} |
||
258 | end |
||
259 | |||
260 | if not IMBA_Tracker_ValidatePos and (IMBA_Tracker_EnabledRaid or IMBA_Tracker_EnabledGuild) and IMBA_Tracker_UpdateTime<GetTime() then |
||
261 | local ang=minimapPlayerModel:GetFacing(); |
||
262 | |||
263 | local _, effectiveArmor, _, _, _ = UnitArmor("player"); |
||
264 | local baseDefense, armorDefense = UnitDefense("player"); |
||
265 | local defense=baseDefense+armorDefense |
||
266 | local _, englishClass = UnitClass("player"); |
||
267 | |||
268 | local msg=string.format("%.3f %.3f %.3f %d %d %d %d %d %s %d %d",x,y,ang,UnitHealth("player"),UnitHealthMax("player"),UnitMana("player"),UnitManaMax("player"),UnitPowerType("player"),englishClass,effectiveArmor,defense); |
||
269 | if IMBA_Tracker_EnabledGuild then |
||
270 | SendAddonMessage("IMBA_TRACKER_DATA",msg,"GUILD"); |
||
271 | end |
||
272 | if IMBA_Tracker_EnabledRaid then |
||
273 | SendAddonMessage("IMBA_TRACKER_DATA",msg,"RAID"); |
||
274 | end |
||
275 | |||
276 | IMBA_Tracker_UpdateTime=GetTime()+IMBA_TRACKER_UPDATE_RATE; |
||
277 | |||
278 | if IMBA_Tracker_EnabledGuild and IMBA_Tracker_StopTimeGuild<GetTime() then |
||
279 | IMBA_Tracker_EnabledGuild=false; |
||
280 | end |
||
281 | |||
282 | if IMBA_Tracker_EnabledRaid and IMBA_Tracker_StopTimeRaid<GetTime() then |
||
283 | IMBA_Tracker_EnabledRaid=false; |
||
284 | end |
||
285 | end |
||
286 | |||
287 | end |