Aaron@0: local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit") Aaron@0: local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") Aaron@0: local tabletest = {} Aaron@0: local db = {} Aaron@1: local safeRecipes = {} Aaron@1: safer = safeRecipes Aaron@0: RecipeProfit.db = db; Aaron@0: Aaron@1: Aaron@0: function debugprint(val, indent) Aaron@0: indent = indent or ""; Aaron@0: if not(type(val) == "table") then Aaron@0: print("Not table: " .. val) Aaron@0: return Aaron@0: end Aaron@0: Aaron@0: for k,v in pairs(val) do Aaron@0: if(type(k) == "table" and type(v) == "table") then Aaron@0: print(indent .. "table key: {") Aaron@0: debugprint(k, indent .. " ") Aaron@0: print(indent .. "} = {") Aaron@0: debugprint(v, indent .. " ") Aaron@0: print(indent .. "}") Aaron@0: elseif(type(v) == "table") then Aaron@0: print(indent .. k .. " = {") Aaron@0: debugprint(v, indent .. " ") Aaron@0: print(indent .. "}") Aaron@0: else Aaron@0: print(indent .. k .. " = " .. v) Aaron@0: end Aaron@0: end Aaron@0: end Aaron@0: Aaron@0: local options = { Aaron@0: type = "group", Aaron@0: name = "RecipeProfit", -- addon name to import from, don't localize Aaron@0: handler = {}, Aaron@0: disabled = false, Aaron@0: args = { Aaron@1: opt = { Aaron@0: order = 1, Aaron@0: name = "Select Database", Aaron@0: desc = "Show a different database", Aaron@0: type = "group", Aaron@0: guiInline = true, Aaron@0: args = { Aaron@0: faction = { Aaron@0: order = 0, Aaron@0: name = "Faction", Aaron@0: desc = "Show a different database.", Aaron@0: type = "select", Aaron@0: values = { Aaron@0: ["Alliance"] = "Alliance", Aaron@0: ["Horde"] = "Horde", Aaron@1: ["default"] = "Default", Aaron@0: }, Aaron@0: arg = "faction", Aaron@0: }, Aaron@1: Aaron@1: safeBuy = { Aaron@1: order = 1, Aaron@1: name = "Safe Recipe Buy", Aaron@1: desc = "Warn when buying a recipe not on the RecipeProfit list.", Aaron@1: type = "select", Aaron@1: values = { Aaron@1: ["on"] = "On", Aaron@1: ["off"]= "Off", Aaron@1: }, Aaron@1: arg = "safebuy", Aaron@1: }, Aaron@0: }, Aaron@1: get = function(k) return db.profile[k.arg]; end, Aaron@0: set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end, Aaron@0: }, Aaron@0: loadData = { Aaron@0: order = 8, Aaron@0: name = "Import Data", Aaron@0: desc = "Load RecipeProfit and import the data to your database.", Aaron@0: type = "execute", Aaron@0: func = function() Aaron@0: RecipeProfit:DoMerge() Aaron@0: end Aaron@0: }, Aaron@0: } Aaron@0: } Aaron@0: Aaron@0: local defaults = { Aaron@1: faction = "default", Aaron@1: safebuy = "on", Aaron@0: } Aaron@0: Aaron@0: function RecipeProfit:OnInitialize() Aaron@0: profile = profile or defaults Aaron@1: for k, v in pairs(defaults) do Aaron@1: profile[k] = profile[k] or v; Aaron@1: end Aaron@1: Aaron@0: db.profile = profile Aaron@0: db.storage = {} Aaron@0: Aaron@0: GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options) Aaron@0: GatherMate:RegisterDBType("RecipeProfit", db.storage) Aaron@0: GatherMate.db.profile.show["RecipeProfit"] = "always" Aaron@0: GatherMate.nodeIDs["RecipeProfit"] = {} Aaron@0: GatherMate.nodeTextures["RecipeProfit"] = {} Aaron@0: GatherMate.nodeMinHarvest["RecipeProfit"] = {} Aaron@0: nodes = GatherMate.nodeIDs["RecipeProfit"] Aaron@0: Aaron@0: for id, note in pairs(RECIPEPROFIT_alliance) do Aaron@1: safeRecipes[note.item] = true; Aaron@0: nodes[note.item.." - ("..note.vendor.." A)"] = id * 10 Aaron@0: GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05" Aaron@0: end Aaron@0: Aaron@0: for id, note in pairs(RECIPEPROFIT_horde) do Aaron@1: safeRecipes[note.item] = true; Aaron@0: nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1 Aaron@0: GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05" Aaron@0: end Aaron@0: Aaron@0: GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) Aaron@0: GatherMate:GetModule("Config"):UpdateConfig() Aaron@0: Aaron@0: GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") Aaron@0: end Aaron@0: Aaron@0: function RecipeProfit:OnEnable() Aaron@1: for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do Aaron@1: local buttonframe = _G["MerchantItem"..i]; Aaron@1: buttonframe:HookScript("OnUpdate", function(self) Aaron@1: local buttonName = _G[self:GetName().."Name"]; Aaron@1: local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID()); Aaron@2: if(not link) then Aaron@2: return; Aaron@2: end Aaron@2: Aaron@1: local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link) Aaron@1: Aaron@1: if(sType == "Recipe" and safeRecipes[sName]) then Aaron@1: SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0); Aaron@1: SetItemButtonSlotVertexColor(self, 0, 0, 0.5); Aaron@2: buttonName:SetText("* " .. sName) Aaron@1: if(GetItemCount(link, true) == 0) then Aaron@1: buttonName:SetTextColor(0,1,1); Aaron@1: elseif(GetItemCount(link, true) < 5) then Aaron@1: buttonName:SetTextColor(1,0,1); Aaron@1: else Aaron@1: buttonName:SetTextColor(1,0,0); Aaron@1: end Aaron@1: else Aaron@1: buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor()); Aaron@1: end Aaron@1: end) Aaron@1: Aaron@1: RecipeProfit:DoMerge() Aaron@1: end Aaron@0: end Aaron@0: Aaron@0: local ids = {} Aaron@0: function findGoodId(x, y) Aaron@0: if ids[x.." "..y] then Aaron@0: return findGoodId(x + .01, y) Aaron@0: end Aaron@0: Aaron@0: ids[x.." "..y] = true Aaron@0: return x, y Aaron@0: end Aaron@0: Aaron@0: function RecipeProfit:DoMerge() Aaron@0: ids = {} Aaron@1: selectedDB = db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or Aaron@1: db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance" and Aaron@1: RECIPEPROFIT_alliance or RECIPEPROFIT_horde Aaron@0: GatherMate:ClearDB("RecipeProfit") Aaron@1: for id, note in pairs(selectedDB) do Aaron@0: x, y = findGoodId(note.x, note.y) Aaron@0: GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", Aaron@0: note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")") Aaron@0: end Aaron@0: Aaron@0: GatherMate:SendMessage("GatherMateDataImport") Aaron@0: GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") Aaron@0: end