vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Support for the Extravaganza
2 --
3 -- Map support liberally borrowed from GuildMap, by Bru on Blackhand
4  
5 FishingBuddy.Extravaganza = {};
6  
7 local NUMMINIPOIS = 10;
8 local ICONPATH = "Interface\\AddOns\\FishingBuddy\\Icons\\";
9 local CLOSEENOUGH = 10.0;
10  
11 -- the actual names don't matter, except to help make sure I've got 'em all
12 local ExtravaganzaFish = {};
13 ExtravaganzaFish[19807] = "Speckled Tastyfish";
14 ExtravaganzaFish[19806] = "Dezian Queenfish";
15 ExtravaganzaFish[19805] = "Keefer's Angelfish";
16 -- makes you wonder what item 19804 is, doesn't it...
17 ExtravaganzaFish[19803] = "Brownell's Blue Striped Racer";
18  
19 local UPDATETIME_SCHOOLS = 0.1;
20 local UPDATETIME_COUNTER = 60.0;
21 local STVUpdateTimer = 0;
22 local numCaught = 0;
23 local tastyfish_id = 19807;
24 local tastyfish;
25  
26 -- convert zone coords into minimap coords
27 local STVInfo = { scale = 0.18128603034401,
28 xoffset = 0.39145470225916, yoffset = 0.79412224886668 };
29  
30 local ZoomScale = {};
31 ZoomScale[0] = { xscale = 10448.3, yscale = 7072.7 };
32 ZoomScale[1] = { xscale = 12160.5, yscale = 8197.8 };
33 ZoomScale[2] = { xscale = 14703.1, yscale = 9825.0 };
34 ZoomScale[3] = { xscale = 18568.7, yscale = 12472.2 };
35 ZoomScale[4] = { xscale = 24390.3, yscale = 15628.5 };
36 ZoomScale[5] = { xscale = 37012.2, yscale = 25130.6 };
37  
38 local function GetSTVPosition()
39 local x, y = GetPlayerMapPosition("player");
40 x = (x * STVInfo.scale) + STVInfo.xoffset;
41 y = (y * STVInfo.scale) + STVInfo.yoffset;
42 return x, y;
43 end
44  
45 -- stolen directly from GuildMap
46 local function GetAngleIcon(x, y)
47 local angle = asin(x / 57);
48 if (x <= 0 and y <= 0) then
49 angle = 180 - angle;
50 elseif (x <= 0 and y > 0) then
51 angle = 360 + angle;
52 elseif (x > 0 and y >= 0) then
53 angle = angle;
54 else
55 angle = 180 - angle;
56 end
57 local fileNumber = math.floor((angle / 10) + 0.5) * 10;
58 if (fileNumber == 360) then
59 fileNumber = 0;
60 end
61 return ICONPATH.."MiniMapArrow"..fileNumber;
62 end
63  
64 local function PlotPOI(index, x, y)
65 local poi = getglobal("FishingExtravaganzaMini"..index);
66 if ( poi ) then
67 if ( x and y ) then
68 local tex = getglobal("FishingExtravaganzaMini"..index.."Texture");
69 local zoom = ZoomScale[Minimap:GetZoom()];
70 x = x * zoom.xscale;
71 y = y * zoom.yscale;
72 local dist = math.sqrt(x*x + y*y);
73 if ( dist > 56.5 ) then
74 x = x * 57 / dist;
75 y = y * 57 / dist;
76 tex:SetTexture(GetAngleIcon(x, y));
77 tex:SetTexCoord(0.0, 1.0, 0.0, 1.0);
78 else
79 tex:SetTexture("Interface\\Minimap\\ObjectIcons");
80 tex:SetTexCoord(0.0, 0.25, 0.25, 0.5);
81 end
82 poi:SetPoint("CENTER", "MinimapCluster", "TOPLEFT", 107 + x, y - 92);
83 poi:Show();
84 return true;
85 else
86 poi:Hide();
87 end
88 end
89 return false;
90 end
91  
92 local function CloseEnough(x1, y1, x2, y2)
93 local zoom = Minimap:GetZoom();
94 local x = (x1 - x2) * ZoomScale[zoom].xscale;
95 local y = (y1 - y2) * ZoomScale[zoom].yscale;
96 if (sqrt( (x * x) + (y * y) ) > 56.5) then
97 return; -- false
98 end
99 return true;
100 end
101  
102 local function GetMinimapDistance(x1, y1, x2, y2)
103 local zoom = ZoomScale[Minimap:GetZoom()];
104 local dx = (x1 - x2) * zoom.xscale;
105 local dy = (y1 - y2) * zoom.yscale;
106 return math.sqrt(dx*dx+dy*dy);
107 end
108  
109 local function FindClosest(row, x, y)
110 local dist;
111 local didx;
112 for idx=1,table.getn(row) do
113 local t = row[idx];
114 local dx = (t.x - x);
115 local dy = (t.y - y);
116 local d = dx*dx + dy*dy;
117 if ( not dist ) then
118 dist = d;
119 didx = idx;
120 elseif ( d < dist ) then
121 dist = d;
122 didx = idx;
123 end
124 end
125 if ( dist and didx ) then
126 local t = row[didx];
127 dist = GetMinimapDistance(t.x, t.y, x, y);
128 end
129 return didx, dist;
130 end
131  
132 local function GetNearestTen(x, y, dir)
133 local r = math.floor(y * 100);
134 local found = 1;
135 local limit = 10;
136 local locations = {};
137 if ( FishingBuddy_Info["Schools"] ) then
138 while ( r >=0 and r <100 ) do
139 local iy = string.format("%d", r);
140 local dist;
141 local row = FishingBuddy_Info["Schools"][iy];
142 if ( row ) then
143 local rowsize = table.getn(row);
144 if ( rowsize > 5 and limit < 11 ) then
145 limit = limit + rowsize - 5;
146 end
147 for idx=1,rowsize do
148 local t = row[idx];
149 local dist = GetMinimapDistance(t.x, t.y, x, y);
150 tinsert(locations, { dist = dist, x = t.x, y = t.y });
151 found = found + 1;
152 if ( found >= limit ) then
153 return locations;
154 end
155 end
156 end
157 r = r + dir;
158 end
159 end
160 return locations;
161 end
162  
163 -- save a school location
164 local function MarkSchool()
165 if ( not FishingBuddy_Info["Schools"] ) then
166 FishingBuddy_Info["Schools"] = {};
167 end
168 local x, y = GetSTVPosition();
169 local iy = string.format("%d", y * 100);
170 if ( not FishingBuddy_Info["Schools"][iy] ) then
171 FishingBuddy_Info["Schools"][iy] = { { x = x, y = y } };
172 else
173 local idx, dist = FindClosest(FishingBuddy_Info["Schools"][iy], x, y);
174 if ( dist > CLOSEENOUGH ) then
175 tinsert(FishingBuddy_Info["Schools"][iy], { x = x, y = y });
176 STVUpdateTimer = 0;
177 else
178 -- average something? that will cascade, which might be okay
179 -- or do we store them all during the contest and average later?
180 -- i.e. store 'close ones' in a separate place and then clean up
181 -- later
182 end
183 end
184 end
185  
186 -- let an external entity forcibly mark a school
187 FishingBuddy.Extravaganza.MarkSchool = function()
188 local zone, subzone = FishingBuddy.GetZoneInfo();
189 if ( zone == FishingBuddy.STVZONENAME ) then
190 MarkSchool();
191 end
192 end
193  
194 -- Sunday, 2pm
195 local STVDay = "0";
196 local STVStartHour = 14;
197  
198 -- Should we display the extravaganza message?
199 local function IsTime(activate)
200 local showit = false;
201 if ( FishingBuddy.IsLoaded() ) then
202 if ( FishingBuddy.GetSetting("STVTimer") == 1 ) then
203 local mhour = date("%H");
204 local hour,minute = GetGameTime();
205 local day = date("%w");
206 -- Is it Sunday?
207 if ( day == STVDay and
208 (hour >= (STVStartHour-2) and hour <(STVStartHour+2))) then
209 showit = true;
210 end
211 end
212 end
213 if ( showit ) then
214 if ( activate ) then
215 FishingExtravaganzaFrame:Show();
216 end
217 elseif ( FishingExtravaganzaFrame:IsVisible() or
218 FishingExtravaganzaMini1:IsVisible() ) then
219 FishingExtravaganzaFrame:Hide();
220 for idx=1,NUMMINIPOIS do
221 PlotPOI(idx);
222 end
223 end
224 return showit;
225 end
226 FishingBuddy.Extravaganza.IsTime = IsTime;
227  
228 local function UpdatePOI()
229 local x, y = GetSTVPosition();
230 local loc1 = GetNearestTen(x, y, -1);
231 local loc2 = GetNearestTen(x, y+0.01, 1);
232 local func = function(a, b) return a.dist < b.dist; end;
233 for idx=1,table.getn(loc2) do
234 tinsert(loc1, loc2[idx]);
235 end
236 table.sort(loc1, func);
237 for idx=1,NUMMINIPOIS do
238 local t = loc1[idx];
239 if ( t ) then
240 PlotPOI(idx, t.x - x, y - t.y);
241 else
242 PlotPOI(idx);
243 end
244 end
245 end
246  
247 -- Check for mouse down event for dragging frame.
248 FishingBuddy.Extravaganza.OnDragStart = function(arg1)
249 if (arg1 == "LeftButton") then
250 FishingExtravaganzaFrame:StartMoving();
251 FishingExtravaganzaFrame.isMoving = true;
252 end
253 end
254  
255 -- Check for drag stop event to stop dragging.
256 FishingBuddy.Extravaganza.OnDragStop = function(arg1)
257 if (arg1 == "LeftButton") then
258 FishingExtravaganzaFrame:StopMovingOrSizing();
259 FishingExtravaganzaFrame.isMoving = false;
260 end
261 end
262  
263 -- Handle watching the loot
264 FishingBuddy.Extravaganza.OnLoad = function()
265 this:RegisterEvent("PLAYER_LOGIN");
266 this:RegisterEvent("ZONE_CHANGED_NEW_AREA");
267 this:RegisterEvent("VARIABLES_LOADED");
268  
269 this:RegisterForDrag("LeftButton");
270 this:Hide();
271 end
272  
273 FishingBuddy.Extravaganza.OnEvent = function()
274 local zone, subzone = FishingBuddy.GetZoneInfo();
275 if ( event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_LOGIN" ) then
276 if ( zone == FishingBuddy.STVZONENAME and IsTime() ) then
277 this:RegisterEvent("LOOT_OPENED");
278 this:RegisterEvent("MINIMAP_UPDATE_ZOOM");
279 else
280 this:UnregisterEvent("LOOT_OPENED");
281 this:UnregisterEvent("MINIMAP_UPDATE_ZOOM");
282 end
283 elseif ( event == "LOOT_OPENED" ) then
284 if ( IsFishingLoot()) then
285 for index = 1, GetNumLootItems(), 1 do
286 if (LootSlotIsItem(index)) then
287 local fishlink = GetLootSlotLink(index);
288 local _, id, _ = FishingBuddy.SplitFishLink(fishlink);
289 if ( ExtravaganzaFish[id] ) then
290 MarkSchool();
291 STVUpdateTimer = 0;
292 if ( id == tastyfish_id ) then
293 numCaught = numCaught + 1;
294 end
295 end
296 end
297 end
298 end
299 elseif ( event == "MINIMAP_UPDATE_ZOOM" ) then
300 if ( zone == FishingBuddy.STVZONENAME ) then
301 if ( FishingBuddy.GetSetting("STVTimer") == 1 ) then
302 UpdatePOI();
303 end
304 end
305 elseif ( event == "VARIABLES_LOADED" ) then
306 local _,_,_,_,_,n = FishingBuddy.GetFishie(tastyfish_id);
307 if ( n ) then
308 tastyfish = n;
309 else
310 tastyfish = FISH;
311 end
312 IsTime(true);
313 this:UnregisterEvent("VARIABLES_LOADED");
314 end
315 end
316  
317 FishingBuddy.Extravaganza.OnUpdate = function(elapsed)
318 if ( IsTime() ) then
319 if ( not FishingExtravaganzaFrame:IsVisible() ) then
320 FishingExtravaganzaFrame:Show();
321 end
322 STVUpdateTimer = STVUpdateTimer - elapsed;
323 if ( STVUpdateTimer < 0 ) then
324 local hour,minute = GetGameTime();
325 local minleft;
326 local checkhour = STVStartHour;
327 local line;
328 if ( hour >= STVStartHour ) then
329 line = FishingBuddy.TIMELEFT;
330 checkhour = checkhour + 2;
331 else
332 line = FishingBuddy.TIMETOGO;
333 end
334 minleft = (checkhour - hour)*60 - minute;
335 if ( minleft > 0 ) then
336 FishingExtravaganzaFrameButtonText:SetTextColor(0.1, 1.0, 0.1);
337 if ( minleft < 10 ) then
338 FishingExtravaganzaFrameButtonText:SetTextColor(1.0, 0.1, 0.1);
339 end
340 line = string.format(line, minleft/60, math.mod(minleft, 60),
341 numCaught, tastyfish);
342 FishingExtravaganzaFrameButtonText:SetText(line);
343 local width = FishingExtravaganzaFrameButtonText:GetWidth();
344 FishingExtravaganzaFrame:SetWidth(width + 16);
345 UpdatePOI();
346 if ( FishingBuddy_Info["Schools"] ) then
347 STVUpdateTimer = UPDATETIME_SCHOOLS;
348 else
349 STVUpdateTimer = UPDATETIME_COUNTER;
350 end
351 end
352 end
353 else
354 FishingExtravaganzaFrame:Hide();
355 end
356 end
357  
358 local function GetObjectCoords(poi, index, numcolumns, texturewidth)
359 local width = poi:GetWidth();
360 local xCoord1, xCoord2, yCoord1, yCoord2;
361 local coordIncrement = width / texturewidth;
362 xCoord1 = mod(index , numcolumns) * coordIncrement;
363 xCoord2 = xCoord1 + coordIncrement;
364 yCoord1 = floor(index / numcolumns) * coordIncrement;
365 yCoord2 = yCoord1 + coordIncrement;
366 return xCoord1, xCoord2, yCoord1, yCoord2;
367 end
368  
369 local start = 0;
370 -- debugging routines
371 FishingBuddy.Extravaganza.Debug = function(day, hour, zone)
372 STVDay = day;
373 STVStartHour = hour;
374 if ( zone ) then
375 FishingBuddy.STVZONENAME = zone;
376 end
377 IsTime(true);
378 end
379  
380 FishingBuddy.Extravaganza.Dump = function()
381 local x, y = GetSTVPosition();
382 local iy = string.format("%d", y * 100);
383  
384 FishingBuddy.Print("Current location: %d - %f, %f", iy, x, y);
385  
386 if ( FishingBuddy_Info["Schools"][iy] ) then
387 for idx=1,table.getn(FishingBuddy_Info["Schools"][iy]) do
388 local t = FishingBuddy_Info["Schools"][iy][idx];
389 local dist = GetMinimapDistance(t.x, t.y, x, y);
390 FishingBuddy.Print("Distance: %f", dist);
391 end
392 end
393 end
394  
395 -- eventually, display what fish you caught here
396 FishingBuddy.Extravaganza.MiniMap_OnEnter = function()
397 end
398