comparison core.lua @ 51:bc43986f7fb0

Added system of blacklisting bad vendors. Added a couple internal chat commands for debugging.
author "Aaron Bregger <killermonkey99@gmail.com>"
date Thu, 06 Jan 2011 17:04:05 -0600
parents 352fe939b884
children 993b57631e81
comparison
equal deleted inserted replaced
50:6c58e7b2b828 51:bc43986f7fb0
125 [4922]=700,[5034]=720,[5042]=640,[5095]=708,[5144]=615,[5145]=614, 125 [4922]=700,[5034]=720,[5042]=640,[5095]=708,[5144]=615,[5145]=614,
126 [5146]=613,[5287]=673,[5339]=689,[5416]=737,[5630]=737,[5695]=772 126 [5146]=613,[5287]=673,[5339]=689,[5416]=737,[5630]=737,[5695]=772
127 } 127 }
128 128
129 local defaults = { 129 local defaults = {
130 faction = "default",
131 safebuy = "on",
132
133 --submitting cached data not yet implemented 130 --submitting cached data not yet implemented
134 enable_cache = false,
135 location_cache = {}, 131 location_cache = {},
132 debugvars = {},
133 blacklist = {},
136 } 134 }
137 135
138 function RecipeProfit:OnInitialize() 136 function RecipeProfit:OnInitialize()
139 profile = RECIPEPROFIT_profile or defaults 137 profile = RECIPEPROFIT_profile or defaults
140 138
196 GatherMate.db.profile.show["RecipeProfit"] = "always" 194 GatherMate.db.profile.show["RecipeProfit"] = "always"
197 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged") 195 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged")
198 end 196 end
199 end 197 end
200 198
201 function RecipeProfit:ShowOptions() 199 --Forward Functions for command listing
202 InterfaceOptionsFrame_OpenToCategory("GatherMate 2") 200 local set_var,
203 LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate 2", "RecipeProfit") 201 get_var,
202 show_help,
203 blacklist_add,
204 blacklist_show,
205 blacklist_query
206
207 local commandList --Forward declaration of command list
208
209 function RecipeProfit:ParseCommands(input, level, list)
210 args = {self:GetArgs(input, level)}
211 arg0 = args[#args - 1]
212
213 if(not list[arg0]) then
214 print("Error parsing command. Type /rp help for help with this command.")
215 return
216 end
217
218 if(type(list[arg0]) == "table") then
219 self:ParseCommands(input, level + 1, list[arg0])
220 else
221 list[arg0](input)
222 end
223 end
224
225 function RecipeProfit:ShowOptions(input)
226 if (input ~= "") then
227 self:ParseCommands(input, 1, commandList)
228 else
229 InterfaceOptionsFrame_OpenToCategory("GatherMate 2")
230 LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate 2", "RecipeProfit")
231 end
204 end 232 end
205 233
206 function RecipeProfit:UpdateButtons(event, ...) 234 function RecipeProfit:UpdateButtons(event, ...)
207 --print("UpdateButtons", event) 235 --print("UpdateButtons", event)
208 if(WorldMapFrame:IsShown()) then 236 if(WorldMapFrame:IsShown()) then
234 ids = {} 262 ids = {}
235 local alliance = get_faction_db(); 263 local alliance = get_faction_db();
236 264
237 GatherMate:ClearDB("RecipeProfit") 265 GatherMate:ClearDB("RecipeProfit")
238 for id, note in pairs(RECIPEPROFIT_database) do 266 for id, note in pairs(RECIPEPROFIT_database) do
239 if((note.a and alliance) or (note.h and not alliance)) then 267 local blacklisted = false;
240 x, y = find_good_id(note.x, note.y) 268
241 add_note(x, y, note) 269 for _, v in pairs(RECIPEPROFIT_blacklist) do
270 if(note.stock == -1 and not note.item:find("Recipe:")) then
271 blacklisted = true;
272 end
273
274 if(tonumber(v) == note.entry) then
275 blacklisted = true;
276 end
277 end
278
279 if(not blacklisted) then
280 if((note.a and alliance) or (note.h and not alliance)) then
281 x, y = find_good_id(note.x, note.y)
282 add_note(x, y, note)
283 end
242 end 284 end
243 end 285 end
244 286
245 GatherMate:SendMessage("GatherMateDataImport") 287 GatherMate:SendMessage("GatherMateDataImport")
246 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged") 288 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged")
255 end 297 end
256 298
257 function add_note(x, y, note) 299 function add_note(x, y, note)
258 local coords = GatherMate.mapData:EncodeLoc(x/100, y/100, 0) 300 local coords = GatherMate.mapData:EncodeLoc(x/100, y/100, 0)
259 local zoneID = zidmap[note.map] 301 local zoneID = zidmap[note.map]
302
303 if(note["realmap"]) then
304 zoneID = note.realmap
305 end
306
260 if(not zoneID) then 307 if(not zoneID) then
261 return 308 return
262 end 309 end
263 310
264 local nodeID = GatherMate.nodeIDs["RecipeProfit"][get_note_title(note, "")] 311 local nodeID = GatherMate.nodeIDs["RecipeProfit"][get_note_title(note, "")]
275 return false, "" 322 return false, ""
276 end 323 end
277 end 324 end
278 325
279 function safe_cache_vendor() 326 function safe_cache_vendor()
280 if(not profile.enable_cache) then
281 return
282 end
283
284 if(not profile.location_cache[UnitName("NPC")]) then 327 if(not profile.location_cache[UnitName("NPC")]) then
285 SetMapToCurrentZone() 328 SetMapToCurrentZone()
286 local pos = {} 329 local pos = {}
287 pos.x, pos.y = GetPlayerMapPosition("player") 330 pos.x, pos.y = GetPlayerMapPosition("player")
331 pos.map = GetCurrentMapAreaID();
288 profile.location_cache[UnitName("NPC")] = pos 332 profile.location_cache[UnitName("NPC")] = pos
289 end 333 end
290 end 334 end
291 335
292 function button_update(self) 336 function button_update(self)
389 prefix = "|cFFFF0000(" .. count .. ") |cFF66DD66" 433 prefix = "|cFFFF0000(" .. count .. ") |cFF66DD66"
390 end 434 end
391 435
392 return prefix .. text 436 return prefix .. text
393 end 437 end
438
439
440
441
442
443
444
445
446
447 --[[ Debug Commands ]]
448 --[[
449 set_var,
450 get_var,
451 show_help,
452 blacklist_add,
453 blacklist_show
454 --]]
455
456 function set_var(input)
457 print("set_var")
458 end
459
460 function get_var(input)
461 print("get_var")
462 end
463
464 function show_help(input)
465 print("show_help")
466 end
467
468 function blacklist_add(input)
469 if(not profile["blacklist"]) then
470 profile["blacklist"] = {}
471 end
472 _, _, val = RecipeProfit:GetArgs(input,3)
473 table.insert(profile.blacklist, val)
474 print("Added npc id \""..val.."\"to NPC blacklist.");
475 end
476
477 function blacklist_show(input)
478 if(not profile["blacklist"]) then
479 profile["blacklist"] = {}
480 end
481
482 for k,v in ipairs(profile.blacklist) do
483 print(k..": "..v)
484 end
485 end
486
487 function blacklist_query(input)
488 _, _, val = RecipeProfit:GetArgs(input,3)
489 if(not val) then
490 print("oops")
491 return
492 end
493
494 entries = {};
495 for _,note in pairs(RECIPEPROFIT_database) do
496 if(note.vendor:lower():find(val:lower()) and not entries[note.entry]) then
497 entries[note.entry] = true;
498 print(note.vendor.." (ID "..note.entry.."): "..note.x..", "..note.y)
499 end
500 end
501 end
502
503 commandList = {
504 set = set_var,
505 get = get_var,
506 help = show_help,
507 blacklist = {
508 query = blacklist_query,
509 add = blacklist_add,
510 show = blacklist_show
511 }
512 }
513