diff 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
line wrap: on
line diff
--- a/core.lua	Tue Jan 04 19:39:23 2011 -0600
+++ b/core.lua	Thu Jan 06 17:04:05 2011 -0600
@@ -127,12 +127,10 @@
 }
 
 local defaults = {
-    faction = "default",
-    safebuy = "on",
-    
     --submitting cached data not yet implemented
-    enable_cache = false,
     location_cache = {},
+    debugvars = {},
+    blacklist = {},
 }
 
 function RecipeProfit:OnInitialize()
@@ -198,9 +196,39 @@
     end
 end  
 
-function RecipeProfit:ShowOptions()
-    InterfaceOptionsFrame_OpenToCategory("GatherMate 2")
-    LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate 2", "RecipeProfit")
+--Forward Functions for command listing
+local set_var,
+    get_var,
+    show_help,
+    blacklist_add,
+    blacklist_show,
+    blacklist_query
+
+local commandList --Forward declaration of command list
+
+function RecipeProfit:ParseCommands(input, level, list)
+    args = {self:GetArgs(input, level)}
+    arg0 = args[#args - 1]
+
+    if(not list[arg0]) then
+        print("Error parsing command. Type /rp help for help with this command.")
+        return
+    end
+    
+    if(type(list[arg0]) == "table") then
+        self:ParseCommands(input, level + 1, list[arg0])
+    else
+        list[arg0](input)
+    end
+end
+
+function RecipeProfit:ShowOptions(input)
+    if (input ~= "") then
+        self:ParseCommands(input, 1, commandList)
+    else
+        InterfaceOptionsFrame_OpenToCategory("GatherMate 2")
+        LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate 2", "RecipeProfit")
+    end
 end
 
 function RecipeProfit:UpdateButtons(event, ...)
@@ -236,9 +264,23 @@
     
     GatherMate:ClearDB("RecipeProfit")
     for id, note in pairs(RECIPEPROFIT_database) do
-        if((note.a and alliance) or (note.h and not alliance)) then
-            x, y = find_good_id(note.x, note.y)
-            add_note(x, y, note)
+        local blacklisted = false;
+        
+        for _, v in pairs(RECIPEPROFIT_blacklist) do
+            if(note.stock == -1 and not note.item:find("Recipe:")) then
+                blacklisted = true;
+            end
+            
+            if(tonumber(v) == note.entry) then
+                blacklisted = true;
+            end
+        end
+        
+        if(not blacklisted) then
+            if((note.a and alliance) or (note.h and not alliance)) then
+                x, y = find_good_id(note.x, note.y)
+                add_note(x, y, note)
+            end
         end
     end
     
@@ -257,6 +299,11 @@
 function add_note(x, y, note)
     local coords = GatherMate.mapData:EncodeLoc(x/100, y/100, 0)
 	local zoneID = zidmap[note.map]
+    
+    if(note["realmap"]) then
+        zoneID = note.realmap
+    end
+    
     if(not zoneID) then
         return
     end
@@ -277,14 +324,11 @@
 end
 
 function safe_cache_vendor()
-    if(not profile.enable_cache) then
-        return
-    end
-    
     if(not profile.location_cache[UnitName("NPC")]) then
         SetMapToCurrentZone()
         local pos = {}
         pos.x, pos.y = GetPlayerMapPosition("player")
+        pos.map = GetCurrentMapAreaID();
         profile.location_cache[UnitName("NPC")] = pos
     end
 end
@@ -391,3 +435,79 @@
     
     return prefix .. text
 end
+
+
+
+
+
+
+
+
+
+--[[ Debug Commands ]]
+--[[
+    set_var,
+    get_var,
+    show_help,
+    blacklist_add,
+    blacklist_show
+--]]
+
+function set_var(input)
+    print("set_var")
+end
+
+function get_var(input)
+    print("get_var")
+end
+
+function show_help(input)
+    print("show_help")
+end
+
+function blacklist_add(input)
+    if(not profile["blacklist"]) then
+        profile["blacklist"] = {}
+    end
+    _, _, val = RecipeProfit:GetArgs(input,3)
+    table.insert(profile.blacklist, val)
+    print("Added npc id \""..val.."\"to NPC blacklist.");
+end
+
+function blacklist_show(input) 
+    if(not profile["blacklist"]) then
+        profile["blacklist"] = {}
+    end
+    
+    for k,v in ipairs(profile.blacklist) do
+        print(k..": "..v)
+    end
+end
+
+function blacklist_query(input)
+    _, _, val = RecipeProfit:GetArgs(input,3)
+    if(not val) then
+        print("oops")
+        return
+    end
+    
+    entries = {};
+    for _,note in pairs(RECIPEPROFIT_database) do
+        if(note.vendor:lower():find(val:lower()) and not entries[note.entry]) then
+            entries[note.entry] = true;
+            print(note.vendor.." (ID "..note.entry.."): "..note.x..", "..note.y)
+        end
+    end
+end
+
+commandList = {
+    set = set_var,
+    get = get_var,
+    help = show_help,
+    blacklist = {
+        query = blacklist_query,
+        add = blacklist_add,
+        show = blacklist_show
+    }
+}
+