Mercurial > wow > recipeprofit
comparison core.lua @ 36:1e73cfb6f363
Updated for 4.0.3 and GatherMate 2
| author | "Aaron Bregger <killermonkey99@gmail.com>" |
|---|---|
| date | Tue, 04 Jan 2011 17:49:34 -0600 |
| parents | 3976960cda3d |
| children | d97f61fad5b6 |
comparison
equal
deleted
inserted
replaced
| 35:23b3fb8f7085 | 36:1e73cfb6f363 |
|---|---|
| 22 but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 GNU General Public License for more details. | 24 GNU General Public License for more details. |
| 25 | 25 |
| 26 You should have received a copy of the GNU General Public License | 26 You should have received a copy of the GNU General Public License |
| 27 along with Foobar. If not, see <http://www.gnu.org/licenses/>. | 27 along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 | 28 |
| 29 Note: | 29 Note: |
| 30 This program's source code is specifically designed to work with | 30 This program's source code is specifically designed to work with |
| 31 World of Warcraft's interpreted AddOn system. | 31 World of Warcraft's interpreted AddOn system. |
| 32 | 32 |
| 35 http://www.fsf.org/licensing/licenses/gpl-faq.html#InterpreterIncompat | 35 http://www.fsf.org/licensing/licenses/gpl-faq.html#InterpreterIncompat |
| 36 | 36 |
| 37 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--)) | 37 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--)) |
| 38 | 38 |
| 39 | 39 |
| 40 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit", "AceEvent-3.0", "AceConsole-3.0") | 40 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0") |
| 41 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") | 41 |
| 42 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate2") | |
| 43 | |
| 42 local tabletest = {} | 44 local tabletest = {} |
| 43 local db = {} | 45 local db = {} |
| 44 local safeRecipes = {} | 46 local safeRecipes = {} |
| 45 local ids = {} | 47 local ids = {} |
| 46 local nodeLookup = {} | 48 local nodeLookup = {} |
| 88 end | 90 end |
| 89 end | 91 end |
| 90 end | 92 end |
| 91 end | 93 end |
| 92 | 94 |
| 93 local defaultProfile = { | |
| 94 ["show"] = { | |
| 95 ["RecipeProfit"] = "always", | |
| 96 ["Herb Gathering"] = "never", | |
| 97 ["Extract Gas"] = "never", | |
| 98 ["Fishing"] = "never", | |
| 99 ["Mining"] = "never", | |
| 100 ["Treasure"] = "never", | |
| 101 }, | |
| 102 ["trackShow"] = "active", | |
| 103 } | |
| 104 | |
| 105 local options = { | 95 local options = { |
| 106 type = "group", | 96 type = "group", |
| 107 name = "RecipeProfit", -- addon name to import from, don't localize | 97 name = "RecipeProfit", -- addon name to import from, don't localize |
| 108 handler = {}, | 98 handler = {}, |
| 109 disabled = false, | 99 disabled = false, |
| 110 args = { | 100 args = { |
| 111 opt = { | 101 heading = { |
| 112 order = 1, | 102 order = 0, |
| 113 name = "Select Database", | 103 type = "description", |
| 114 desc = "Show a different database", | 104 name = "Thank you for using RecipeProfit for GatherMate!\n\n".. |
| 115 type = "group", | 105 "RecipeProfit was recently updated to work with patch 4.0.x and GatherMate 2. If you find any bugs you can report them on curse.com or curseforge.com by contacting the author 'Yuffles'. ".. |
| 116 guiInline = true, | 106 "You can also email the author at killermonkey99".. --[[anti-spambot]] "@".."gmail.com (please try to put \"RecipeProfit\" in the subject!)\n\n".. |
| 117 args = { | 107 "You can toggle the display of RecipeProfit nodes on the map and minimap by changing the options in the general GatherMate 2 menu.", |
| 118 faction = { | 108 width = "full", |
| 119 order = 0, | 109 }, |
| 120 name = "Faction", | |
| 121 desc = "Show a different database.", | |
| 122 type = "select", | |
| 123 values = { | |
| 124 ["Alliance"] = "Alliance", | |
| 125 ["Horde"] = "Horde", | |
| 126 ["default"] = "Default", | |
| 127 }, | |
| 128 arg = "faction", | |
| 129 }, | |
| 130 | |
| 131 safeBuy = { | |
| 132 order = 1, | |
| 133 name = "Safe Recipe Buy", | |
| 134 desc = "Warn when buying a recipe not on the RecipeProfit list.", | |
| 135 type = "select", | |
| 136 values = { | |
| 137 --["on"] = "On", | |
| 138 ["off"]= "Off", | |
| 139 }, | |
| 140 arg = "safebuy", | |
| 141 }, | |
| 142 }, | |
| 143 get = function(k) return db.profile[k.arg]; end, | |
| 144 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end, | |
| 145 }, | |
| 146 loadData = { | |
| 147 order = 8, | |
| 148 name = "Import Data", | |
| 149 desc = "Load RecipeProfit and import the data to your database.", | |
| 150 type = "execute", | |
| 151 func = function() | |
| 152 RecipeProfit:DoMerge() | |
| 153 end | |
| 154 }, | |
| 155 loadProfile = { | |
| 156 order = 9, | |
| 157 name = "Load RecipeProfit Profile", | |
| 158 desc = "Loads the RecipeProfit Profile into Gathermate for easy recipe tracking.", | |
| 159 type = "execute", | |
| 160 func = function() | |
| 161 GatherMate.db.profiles["RecipeProfit"] = GatherMate.db.profiles["RecipeProfit"] or {} | |
| 162 gmdb = GatherMate.db.profiles["RecipeProfit"] | |
| 163 for k, v in pairs(defaultProfile) do | |
| 164 gmdb[k] = v; | |
| 165 end | |
| 166 GatherMate:SendMessage("OnProfileChanged"); | |
| 167 GatherMate:GetModule("Config"):UpdateConfig() | |
| 168 GatherMate:SendMessage("GatherMateConfigChanged") | |
| 169 GatherMate.db:SetProfile("RecipeProfit") | |
| 170 end | |
| 171 }, | |
| 172 } | 110 } |
| 111 } | |
| 112 | |
| 113 --maps wowhead IDs to localization independant map ids O_O | |
| 114 local zidmap={[1]=27,[3]=17,[4]=19,[8]=38,[10]=34,[11]=40,[12]=30,[14]=4, | |
| 115 [15]=141,[16]=181,[17]=11,[28]=22,[33]=37,[38]=35,[40]=39,[41]=32,[44]=36, | |
| 116 [45]=16,[46]=29,[47]=26,[51]=28,[65]=488,[66]=496,[67]=495,[85]=20, | |
| 117 [130]=21,[139]=23,[141]=41,[148]=42,[210]=492,[215]=9,[267]=24,[331]=43, | |
| 118 [357]=121,[361]=182,[394]=490,[400]=61,[405]=101,[406]=81,[440]=161, | |
| 119 [490]=201,[493]=241,[495]=491,[616]=606,[618]=281,[1377]=261,[1497]=382, | |
| 120 [1519]=301,[1537]=341,[1637]=321,[1638]=362,[1657]=381,[3430]=462, | |
| 121 [3433]=463,[3483]=465,[3487]=480,[3518]=477,[3519]=478,[3520]=473, | |
| 122 [3521]=467,[3522]=475,[3523]=479,[3524]=464,[3525]=476,[3537]=486, | |
| 123 [3557]=471,[3703]=481,[3711]=493,[4080]=499,[4197]=501,[4395]=504, | |
| 124 [4709]=607,[4714]=545,[4720]=544,[4737]=605,[4755]=611,[4815]=610, | |
| 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 | |
| 173 } | 127 } |
| 174 | 128 |
| 175 local defaults = { | 129 local defaults = { |
| 176 faction = "default", | 130 faction = "default", |
| 177 safebuy = "on", | 131 safebuy = "on", |
| 201 | 155 |
| 202 set_node_constants() | 156 set_node_constants() |
| 203 inject_options() | 157 inject_options() |
| 204 | 158 |
| 205 GatherMate:GetModule("Config"):UpdateConfig() | 159 GatherMate:GetModule("Config"):UpdateConfig() |
| 206 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") | 160 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged") |
| 207 | 161 |
| 208 --[[ hook GetNameForNode for custom highlighting ]] | 162 --[[ hook GetNameForNode for custom highlighting ]] |
| 209 local oldFunction = GatherMate.GetNameForNode | 163 local oldFunction = GatherMate.GetNameForNode |
| 210 | 164 |
| 211 GatherMate.GetNameForNode = function(lself, type, nodeID) | 165 GatherMate.GetNameForNode = function(lself, type, nodeID) |
| 214 else | 168 else |
| 215 return oldFunction(lself, type, nodeID) | 169 return oldFunction(lself, type, nodeID) |
| 216 end | 170 end |
| 217 end | 171 end |
| 218 | 172 |
| 219 --[[ hook OnProfileChanged to fix cleanup database ]] | 173 --[[hook OnProfileChanged to fix cleanup database ]] |
| 220 local oldFunction2 = GatherMate.OnProfileChanged | 174 local oldFunction2 = GatherMate.OnProfileChanged |
| 221 | 175 |
| 222 GatherMate.OnProfileChanged = function(lself, ...) | 176 GatherMate.OnProfileChanged = function(lself, ...) |
| 223 lself.db.profile.cleanupRange["RecipeProfit"] = lself.db.profile.cleanupRange["RecipeProfit"] or 15 | 177 lself.db.profile.cleanupRange["RecipeProfit"] = lself.db.profile.cleanupRange["RecipeProfit"] or 15 |
| 178 lself.db.profile.show["RecipeProfit"] = lself.db.profile.show["RecipeProfit"] == "never" and "never" or "always"; | |
| 224 oldFunction2(lself, ...) | 179 oldFunction2(lself, ...) |
| 225 end | 180 end |
| 226 | 181 |
| 227 end | 182 end |
| 228 | 183 |
| 238 | 193 |
| 239 RecipeProfit:DoMerge() | 194 RecipeProfit:DoMerge() |
| 240 end | 195 end |
| 241 | 196 |
| 242 function RecipeProfit:ShowOptions() | 197 function RecipeProfit:ShowOptions() |
| 243 LibStub("AceConfigDialog-3.0"):Open("GatherMate") | 198 InterfaceOptionsFrame_OpenToCategory("GatherMate 2") |
| 244 LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate", "RecipeProfit") | 199 LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate 2", "RecipeProfit") |
| 245 end | 200 end |
| 246 | 201 |
| 247 function RecipeProfit:UpdateButtons(event, ...) | 202 function RecipeProfit:UpdateButtons(event, ...) |
| 248 --print("UpdateButtons", event) | 203 --print("UpdateButtons", event) |
| 249 if(WorldMapFrame:IsShown()) then | 204 if(WorldMapFrame:IsShown()) then |
| 271 end | 226 end |
| 272 end | 227 end |
| 273 | 228 |
| 274 function RecipeProfit:DoMerge() | 229 function RecipeProfit:DoMerge() |
| 275 ids = {} | 230 ids = {} |
| 276 local selectedDB = get_faction_db(); | 231 local alliance = get_faction_db(); |
| 277 | 232 |
| 278 GatherMate:ClearDB("RecipeProfit") | 233 GatherMate:ClearDB("RecipeProfit") |
| 279 for id, note in pairs(selectedDB) do | 234 for id, note in pairs(RECIPEPROFIT_database) do |
| 280 x, y = find_good_id(note.x, note.y) | 235 if((note.a and alliance) or (note.h and not alliance)) then |
| 281 add_note(x, y, note) | 236 x, y = find_good_id(note.x, note.y) |
| 237 add_note(x, y, note) | |
| 238 end | |
| 282 end | 239 end |
| 283 | 240 |
| 284 GatherMate:SendMessage("GatherMateDataImport") | 241 GatherMate:SendMessage("GatherMateDataImport") |
| 285 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") | 242 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged") |
| 286 end | 243 end |
| 287 | 244 |
| 288 function get_note_title(note, factionTag) | 245 function get_note_title(note, factionTag) |
| 289 if(not factionTag) then | 246 if(not factionTag) then |
| 290 _, factionTag = get_faction_db(); | 247 _, factionTag = get_faction_db(); |
| 292 | 249 |
| 293 return note.item.." - ("..note.vendor.." ".. factionTag ..")"; | 250 return note.item.." - ("..note.vendor.." ".. factionTag ..")"; |
| 294 end | 251 end |
| 295 | 252 |
| 296 function add_note(x, y, note) | 253 function add_note(x, y, note) |
| 297 local coords = GatherMate:getID(x / 100, y / 100) | 254 local coords = GatherMate.mapData:EncodeLoc(x/100, y/100, 0) |
| 298 local zoneID = GatherMate.zoneData[note.map][3] | 255 local zoneID = zidmap[note.map] |
| 299 local nodeID = GatherMate.nodeIDs["RecipeProfit"][get_note_title(note, factionTag)] | 256 if(not zoneID) then |
| 300 | 257 print("OMFG "..note.map) |
| 301 GatherMate:InjectNode(zoneID, coords, "RecipeProfit", nodeID); | 258 return |
| 259 end | |
| 260 | |
| 261 local nodeID = GatherMate.nodeIDs["RecipeProfit"][get_note_title(note, "")] | |
| 262 print(nodeID) | |
| 263 GatherMate:InjectNode(zoneID, coords, "RecipeProfit", nodeID) | |
| 302 end | 264 end |
| 303 | 265 |
| 304 function get_faction_db() | 266 function get_faction_db() |
| 305 local factionAlliance = db.profile.faction == "Alliance" or | 267 local factionAlliance = db.profile.faction == "Alliance" or |
| 306 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance"; | 268 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance"; |
| 269 | |
| 307 if(factionAlliance) then | 270 if(factionAlliance) then |
| 308 return RECIPEPROFIT_alliance, "A"; | 271 return true, "" |
| 309 else | 272 else |
| 310 return RECIPEPROFIT_horde, "H"; | 273 return false, "" |
| 311 end | 274 end |
| 312 end | 275 end |
| 313 | 276 |
| 314 function safe_cache_vendor() | 277 function safe_cache_vendor() |
| 315 if(not profile.enable_cache) then | 278 if(not profile.enable_cache) then |
| 372 GatherMate.nodeIDs["RecipeProfit"] = {} | 335 GatherMate.nodeIDs["RecipeProfit"] = {} |
| 373 GatherMate.nodeTextures["RecipeProfit"] = {} | 336 GatherMate.nodeTextures["RecipeProfit"] = {} |
| 374 GatherMate.nodeMinHarvest["RecipeProfit"] = {} | 337 GatherMate.nodeMinHarvest["RecipeProfit"] = {} |
| 375 | 338 |
| 376 local nodes = GatherMate.nodeIDs["RecipeProfit"] | 339 local nodes = GatherMate.nodeIDs["RecipeProfit"] |
| 377 for id, note in pairs(RECIPEPROFIT_alliance) do | 340 for id, note in pairs(RECIPEPROFIT_database) do |
| 378 safeRecipes[note.item] = true; | 341 safeRecipes[note.item] = true; |
| 379 local id = get_next_texture_id(); | 342 local id = get_next_texture_id(); |
| 380 nodes[get_note_title(note, "A")] = id; | 343 |
| 381 nodeLookup[id] = note; | 344 nodes[get_note_title(note, "")] = id; |
| 382 end | |
| 383 | |
| 384 for id, note in pairs(RECIPEPROFIT_horde) do | |
| 385 safeRecipes[note.item] = true; | |
| 386 local id = get_next_texture_id(); | |
| 387 nodes[get_note_title(note, "H")] = id; | |
| 388 nodeLookup[id] = note; | 345 nodeLookup[id] = note; |
| 389 end | 346 end |
| 390 | 347 |
| 391 for i = 1, lastNodeTextureId, 1 do | 348 for i = 1, lastNodeTextureId, 1 do |
| 392 GatherMate.nodeTextures["RecipeProfit"][i] = "Interface\\Icons\\INV_Scroll_05" | 349 GatherMate.nodeTextures["RecipeProfit"][i] = "Interface\\Icons\\INV_Scroll_05" |
| 394 | 351 |
| 395 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) | 352 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) |
| 396 end | 353 end |
| 397 | 354 |
| 398 function inject_options() | 355 function inject_options() |
| 399 GatherMate:GetModule("Config").options.args.display.args.general.args.showGroup.args["showRecipeProfit"] = { | 356 local acr = LibStub("AceConfigRegistry-3.0") |
| 400 order = 6, | 357 acr:GetOptionsTable("GatherMate 2", "dialog", "RecipeProfit-1.0").args["showRecipeProfit"] = { |
| 358 order = 7, | |
| 401 name = "Show RecipeProfit nodes.", | 359 name = "Show RecipeProfit nodes.", |
| 402 desc = "Toggle showing nodes added by RecipeProfit.", | 360 desc = "Toggle showing nodes added by RecipeProfit.", |
| 403 type = "select", | 361 type = "select", |
| 404 values = { | 362 values = { |
| 405 ["always"] = "Always show", | 363 always = "Always show", |
| 406 ["never"] = "Never show", | 364 never = "Never show", |
| 407 }, | 365 }, |
| 408 arg = "RecipeProfit", | 366 arg = "RecipeProfit", |
| 409 } | 367 } |
| 410 | 368 |
| 411 GatherMate:GetModule("Config").options.args.display.args.general.args.iconGroup.args.tracking.args["showRecipeProfit"] = { | 369 GatherMate:GetModule("Config"):SendMessage("GatherMate2ConfigChanged") |
| 412 order = 6.5, | 370 end |
| 413 name = "RecipeProfit", | 371 |
| 414 desc = "Color of the tracking circle.", | |
| 415 type = "color", | |
| 416 hasAlpha = true, | |
| 417 arg = "RecipeProfit", | |
| 418 } | |
| 419 end | |
| 420 | |
| 421 -- TODO: Fix | |
| 422 function get_colored_note_name(self, nodeID) | 372 function get_colored_note_name(self, nodeID) |
| 423 local text = self.reverseNodeIDs["RecipeProfit"][nodeID] | 373 local text = self.reverseNodeIDs["RecipeProfit"][nodeID] |
| 424 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(nodeLookup[nodeID].itementry) | 374 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(nodeLookup[nodeID].itementry) |
| 425 | 375 |
| 426 if(not sLink) then | 376 if(not sLink) then |
| 427 return text | 377 RecipeProfit:ScheduleTimer("UpdateButtons", 3) |
| 378 return "|cFF000000(??) |cFF66DD66" .. text .. "|cFFFF0000 Please Wait (Querying Server)..." | |
| 428 end | 379 end |
| 429 | 380 |
| 430 local count = GetItemCount(sLink, true) | 381 local count = GetItemCount(sLink, true) |
| 431 local prefix = "|cFF888888(" .. count .. ") |cFF66DD66" | 382 local prefix = "|cFF888888(" .. count .. ") |cFF66DD66" |
| 432 | 383 |
