Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local addonName, addonTable = ...
- -- Debugging to tekDebug
- local debug = false
- --[===[@debug@
- debug = true
- --@end-debug@]===]
- local name, _, _, enabled = GetAddOnInfo("tekDebug")
- local player = UnitName("player")
- local enabled = GetAddOnEnableState(player, "tekDebug") == 2
- if enabled and not IsAddOnLoaded("tekDebug") then
- local succ, err = LoadAddOn(name)
- end
- local debugf = debug and tekDebug and tekDebug:GetFrame(addonName)
- local function DebugPrint(...) if debugf then debugf:AddMessage(string.join(", ", tostringall(...))) end end
- local strfind, strformat, strgsub, strlower, strmatch, tostring = string.find, string.format, string.gsub, string.lower, strmatch, tostring
- local _, date, ipairs, next, pairs, select, time, tinsert, tsort, type, wipe = _, date, ipairs, next, pairs, select, time, table.insert, table.sort, type, wipe
- -- LibDataBroker
- local ldb = LibStub:GetLibrary("LibDataBroker-1.1", true)
- local LDBIcon = ldb and LibStub("LibDBIcon-1.0",true)
- local LibQTip = LibStub('LibQTip-1.0')
- local Toast = LibStub("LibToast-1.0")
- local L = LibStub("AceLocale-3.0"):GetLocale(addonName, false)
- local BF = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0")
- BF.versionString = GetAddOnMetadata(addonName, "Version");
- if debug then
- Broker_Followers = BF
- end
- local ABILITY_MAX_NUM = 2
- local TRAIT_MAX_NUM = 3
- local TOAST_FOLLOWER_UPGRADE = "BrokerFollowerUpgrade"
- local TOAST_FOLLOWER_LEVELUP = "BrokerFollowerLevelup"
- -- Little helpers
- local mechanics = {}
- local q = C_Garrison.GetFollowerAbilityCounterMechanicInfo
- for _, aid in pairs({11, 100, 168, 148, 160, 101, 105, 157, 122}) do
- local mid, _, tex = q(aid)
- mechanics[mid], mechanics[tex:lower():gsub("%.blp$","")] = aid, aid
- end
- local function getMechanicTexture(mid, formatted)
- if mechanics[mid] then
- local tex = select(3, q(mechanics[mid]))
- return formatted and strformat(BF.formatStrings.counterIconTolltip, tex) or tex
- end
- end
- local function getMechanicName(mid)
- if mechanics[mid] then
- return select(2, C_Garrison.GetFollowerAbilityCounterMechanicInfo(mechanics[mid]))
- end
- end
- local function getFormattedName(q, n)
- return strformat(BF.formatStrings.rarityColors[q], n)
- end
- local DB_VERSION = 1
- BF.followerList = {}
- BF.collectedFollowersList = {}
- BF.formatStrings = {
- rarityColors = {},
- }
- BF.specs = {
- [2] = {
- 1, 2, 7, 8, 10, --Blood Death Knight
- },
- [3] = {
- 1, 4, 7, 8, 10, --Frost Death Knight
- },
- [4] = {
- 1, 2, 7, 8, 10, --Unholy Death Knight
- },
- [5] = {
- 6, 7, 9, 10, --Balance Druid
- },
- [7] = {
- 1, 2, 6, 10, --Feral Druid
- },
- [8] = {
- 1, 2, 6, 9, --Guardian Druid
- },
- [9] = {
- 3, 4, 7, 9, --Restoration Druid
- },
- [10] = {
- 1, 6, 7, 9, 10, --Beast Master Hunter
- },
- [12] = {
- 6, 7, 8, 9, 10, --Marksmanship Hunter
- },
- [13] = {
- 2, 6, 7, 9, 10, --Survival Hunter
- },
- [14] = {
- 6, 8, 9, 10, --Arcane Mage
- },
- [15] = {
- 6, 7, 8, 9, 10, --Fire Mage
- },
- [16] = {
- 2, 7, 8, 9, 10, --Frost Mage
- },
- [17] = {
- 1, 2, 3, 6, 9, --Brewmaster Monk
- },
- [18] = {
- 3, 4, 6, 8, --Mistweaver Monk
- },
- [19] = {
- 1, 6, 8, 9, 10, --Windwalker Monk
- },
- [20] = {
- 3, 4, 8, 9, --Holy Paladin
- },
- [21] = {
- 1, 2, 4, 8, 9, --Protection Paladin
- },
- [22] = {
- 2, 7, 8, 9, 10, --Retribution Paladin
- },
- [23] = {
- 3, 4, 6, 9, --Discipline Priest
- },
- [24] = {
- 3, 4, 6, 7, --Holy Priest
- },
- [25] = {
- 4, 6, 7, 9, 10, --Shadow Priest
- },
- [26] = {
- 2, 6, 8, 9, 10, --Assassination Rogue
- },
- [27] = {
- 6, 7, 8, 9, 10, --Combat Rogue
- },
- [28] = {
- 2, 6, 7, 8, 9, --Subtlety Rogue
- },
- [29] = {
- 3, 7, 8, 9, 10, --Elemental Shaman
- },
- [30] = {
- 3, 6, 7, 9, 10, --Enhancement Shaman
- },
- [31] = {
- 3, 4, 7, 8, --Restoration Shaman
- },
- [32] = {
- 4, 7, 8, 9, 10, --Affliction Warlock
- },
- [33] = {
- 2, 7, 8, 10, 10, --Demonology Warlock
- },
- [34] = {
- 3, 8, 9, 10, 10, --Destruction Warlock
- },
- [35] = {
- 1, 6, 7, 8, 10, --Arms Warrior
- },
- [37] = {
- 2, 6, 7, 8, 10, --Fury Warrior
- },
- [38] = {
- 1, 2, 6, 7, 8, --Protection Warrior
- },
- }
- -- specSets, each specs is a setc of [counter#] = true
- BF.specSets = {}
- for specID, specData in pairs(BF.specs) do
- BF.specSets[specID] = {}
- for _, counterID in pairs(specData) do
- BF.specSets[specID][counterID] = true
- end
- end
- local defaults = {
- profile = {
- version = 1,
- autoHideDelay = 0.5,
- availableCountersToolstip = true,
- showRerollPercent = true,
- showNewComboPercent = true,
- showMarkInactive = "X",
- showInactivesList = true,
- clickableList = true,
- iconSize = 16,
- clickToShow = 2,
- tooltipBGColor = { r=0, g=0, b=0, a=1 },
- colorMatrix = true,
- showMountScavnerRowMatrix = false,
- clickableMatrix = true,
- onlyFillTopMatrixHalf = false,
- showInactivesMatrix = true,
- showToasts = true,
- -- rerollfinder
- rerollFirstWanted = 1,
- rerollSecondWanted = 2,
- minimapIcon = {
- hide = false,
- minimapPos = 220,
- radius = 80,
- },
- },
- global = {
- version = 1,
- },
- }
- -- Options Handling
- function BF:GenerateOptions()
- if not BF.options then
- local function newCounter()
- local i = 0
- return function( inc )
- i = i + 1
- return i
- end
- end
- local count = newCounter()
- BF.options = {
- name = addonName,
- type = 'group',
- handler = BF,
- args = {
- versionsString = {
- name = BF.versionString,
- order = -1,
- type = "description"
- },
- genconfig = {
- name = L["General Settings"],
- type = 'group',
- order = 1,
- get = function(info) return BF.db.profile[info[#info]] end,
- set = function(info, value) BF.db.profile[info[#info]] = value end,
- args = {
- clickToShow = {
- type = "select",
- style = "dropdown",
- values = {
- [1] = L["Click"],
- [2] = L["Hover"],
- },
- name = L["Show tooltip on:"],
- desc = L["Either make the tooltip pop up when you hover the icon or make it a toggle by clicking the icon"],
- order = count(),
- },
- autoHideDelay = {
- type = "range",
- min = 0,
- softMax = 3,
- name = L["Auto hide delay"],
- desc = L["When 'Show tooltip' is set to 'hover' then the tooltip stay for this amount of time after the mouse was moved away"],
- order = count(),
- },
- availableCountersToolstip = {
- type = "toggle",
- name = L["Follower Hovertooltip"],
- desc = L["When hovering over the followerporait in the follower tab or while recruiting in the inn then display small tooltip with all available counters for this follower"],
- order = count(),
- },
- showToasts = {
- type = "toggle",
- name = L["Show Toasts"],
- desc = L["Show toasts to inform you of follower level ups and upgrades. Upgrade toasts will tell you what ability/trait the follower gained."],
- order = count(),
- },
- iconSize = {
- type = "range",
- min = 4,
- max = 128,
- step = 1,
- name = L["Tooltip: Icon size"],
- order = count(),
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF.formatStrings.counterIconTolltip = "|T%s:"..value..":"..value..":0:0:64:64:5:59:5:59|t"
- BF:RedrawTooltip()
- end,
- },
- tooltipBGColor = {
- name = L["Background color"],
- desc = L["Background color"],
- type = 'color',
- order = count(),
- get = function(info)
- return BF.db.profile[info[#info]].r, BF.db.profile[info[#info]].g, BF.db.profile[info[#info]].b, BF.db.profile[info[#info]].a
- end,
- set = function(info, r, g, b, a)
- BF.db.profile[info[#info]] = { r = r, g = g, b = b, a = a }
- BF:RedrawTooltip()
- end,
- hasAlpha = true,
- },
- minimapIcon = {
- type = "toggle",
- name = L["Show minimap button"],
- order = count(),
- get = function(info) return not BF.db.profile.minimapIcon.hide end,
- set = function(info, value)
- BF.db.profile.minimapIcon.hide = not value
- if value then
- LDBIcon:Show(addonName)
- else
- LDBIcon:Hide(addonName)
- end
- end,
- },
- headerListViewOption = {
- type = "header",
- name = L["List view options"],
- order = count(),
- },
- clickableList= {
- type = "toggle",
- name = L["List: Clickable cells"],
- desc = L["Clicking a followers name in the list will put it into the search box in the follower list"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- showRerollPercent = {
- type = "toggle",
- name = L["Reroll column"],
- desc = L["In the list tooltip add a column at the front showing the % chance of getting a not-yet-acquired threat counter combination for epic followers when using a reroll certificate"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- showNewComboPercent = {
- type = "toggle",
- name = L["Follower upgrade %"],
- desc = L["Use the Reroll column for non-epic followers to show the % of getting a new combination of threat counters"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- showInactivesList = {
- type = "toggle",
- name = L["Show Inactive followers"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- showMarkInactive = {
- type = "input",
- name = L["Mark inactive with"],
- desc = L["Add the following after the name of incative followers in listview"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- headerMatrixViewOption = {
- type = "header",
- name = L["Matrix view options"],
- order = count(),
- },
- showInactivesMatrix = {
- type = "toggle",
- name = L["Count Inactives"],
- desc = L["Also count inactive followers in matrix view"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- colorMatrix = {
- type = "toggle",
- name = L["Color followers"],
- desc = L["Color followers in the matrix view by itemlevel. (615+: Green, 630+: Blue, 645+: Epic)"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- showMountScavnerRowMatrix = {
- type = "toggle",
- name = L["Scavenger/Mount row"],
- desc = L["Show a special row at the top indicating if you got a follower with scavanger/epic mount countering this threat"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- onlyFillTopMatrixHalf = {
- type = "toggle",
- name = L["Matrix: Top right only"],
- desc = L["Only fill the top right half of the matrix without mirroring the values onto the bottom left part as well"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- clickableMatrix = {
- type = "toggle",
- name = L["Matrix: Clickable cells"],
- desc = L["When a cell in the matrix is clicken it will print the list of followers that correpsond to it"],
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF:RedrawTooltip()
- end,
- order = count(),
- },
- },
- },
- rerollfinder = {
- name = L["Reroll Finder Settings"],
- type = 'group',
- order = 2,
- get = function(info) return BF.db.profile[info[#info]] end,
- set = function(info, value) BF.db.profile[info[#info]] = value end,
- args = {
- generateRerollListHeader = {
- type = "description",
- name = L["Generate a list of follower who have the highest chance of getting the following counters when rerolling"],
- order = count(),
- },
- rerollFirstWanted = {
- type = "select",
- style = "dropdown",
- values = {},
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF.options.args.rerollfinder.args[info[#info]].name = L["First Counter:"]..getMechanicTexture(BF.db.profile[info[#info]], true)
- BF:GenerateRerollFinderList()
- end,
- get = function(info)
- BF.options.args.rerollfinder.args[info[#info]].name = L["First Counter:"]..getMechanicTexture(BF.db.profile[info[#info]], true)
- BF:GenerateRerollFinderList()
- return BF.db.profile[info[#info]]
- end,
- name = L["First Counter:"]..getMechanicTexture(BF.db.profile.rerollFirstWanted, true),
- desc = L["First of the two counters you want to reroll towards"],
- order = count(),
- },
- rerollSecondWanted = {
- type = "select",
- style = "dropdown",
- values = {},
- set = function(info, value)
- BF.db.profile[info[#info]] = value
- BF.options.args.rerollfinder.args[info[#info]].name = L["Second Counter:"]..getMechanicTexture(BF.db.profile[info[#info]], true)
- BF:GenerateRerollFinderList()
- end,
- get = function(info)
- BF.options.args.rerollfinder.args[info[#info]].name = L["Second Counter:"]..getMechanicTexture(BF.db.profile[info[#info]], true)
- BF:GenerateRerollFinderList()
- return BF.db.profile[info[#info]]
- end,
- name = L["Second Counter:"]..getMechanicTexture(BF.db.profile.rerollSecondWanted, true),
- desc = L["Second of the two counters you want to reroll towards"],
- order = count(),
- },
- rerollHeader1= {
- type = "header",
- name = L["Output"],
- order = count(),
- },
- rerollList = {
- type = "description",
- name = "",
- fontSize = "medium",
- width = "full",
- order = count(),
- },
- },
- },
- },
- }
- for i=1,10 do
- local name = getMechanicName(i)
- if name then
- BF.options.args.rerollfinder.args.rerollFirstWanted.values[i] = name
- BF.options.args.rerollfinder.args.rerollSecondWanted.values[i] = name
- end
- end
- BF.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(BF.db)
- BF.options.args.profile.order = 3
- end
- return BF.options
- end
- function BF:ReleaseTooltip()
- LibQTip:Release(self.tooltip)
- self.tooltip.Columns = nil
- self.tooltip.Rows = nil
- self.tooltip = nil
- end
- function BF:PrepareTooltip(anchorFrame, tableInsteadOfList)
- local tooltip = LibQTip:Acquire("Broker_Followers_Tooltip", 1, "LEFT")
- if tooltip:IsShown() then
- tableInsteadOfList = self.matrixIsUsed
- end
- self.tooltip = tooltip
- self:DrawTooltip(tooltip, tableInsteadOfList)
- tooltip:SmartAnchorTo(anchorFrame)
- tooltip:Show()
- end
- function BF:RedrawTooltip()
- -- Check if we actually view matrix tooltip
- local tooltip = LibQTip:Acquire("Broker_Followers_Tooltip", 1, "LEFT")
- -- Only redraw if the tooltip is shown
- if not tooltip:IsShown() then
- return
- end
- self.tooltip = tooltip
- self:DrawTooltip(tooltip, self.matrixIsUsed)
- end
- function BF:DrawTooltip(tooltip, tableInsteadOfList)
- self:UpdateFollowerCounters()
- self:UpdateRerollCombos()
- tooltip:Clear()
- tooltip:SetBackdropColor(self.db.profile.tooltipBGColor.r, self.db.profile.tooltipBGColor.g, self.db.profile.tooltipBGColor.b, self.db.profile.tooltipBGColor.a)
- tooltip.Rows = {}
- local function sortFollowers(f1, f2)
- local f1a, f2a = BF.collectedFollowersList[f1.followerID], BF.collectedFollowersList[f2.followerID]
- if f1.isCollected and f2.isCollected then
- for _,i in pairs({1,2,3,4,6,7,8,9,10}) do
- if f1a[i] and not f2a[i] then
- return true
- end
- if not f1a[i] and f2a[i] then
- return false
- end
- end
- return f1.name < f2.name
- else
- if not f1.isCollected and not f2.isCollected then
- return f1.name > f2.name
- else
- return f1.isCollected
- end
- end
- end
- local function sortAbilities(a1, a2)
- if not a1.isTrait and a2.isTrait then
- return true
- end
- if a1.isTrait and not a2.isTrait then
- return false
- end
- local a1c = next(a1.counters)
- local a2c = next(a2.counters)
- if a1.isTrait and a2.isTrait then
- if a1c or a2c then
- return (a1c or 0) > (a2c or 0)
- else
- return a1.name > a2.name
- end
- end
- a1c = next(a1.counters)
- a2c = next(a2.counters)
- return a1c < a2c
- end
- if not tooltip.Columns then
- tooltip.Columns = {}
- end
- if not tooltip.Rows then
- tooltip.Rows = {}
- end
- local function MyAddColumn(nameType, displayName)
- if nameType then
- if not displayName then
- BF:Debug("MyAddColumn: missing displayName for", nameType)
- displayName = nameType
- end
- if not formatFunc then
- --formatFunc = CellFormat.Default
- end
- if not tooltip.Columns[nameType] then
- local colindex = tooltip:AddColumn("CENTER")
- tooltip:SetCell(1, colindex, displayName)
- tooltip.Columns[nameType] = { col = colindex }
- else
- BF:Debug("a column already exists for", nameType)
- end
- end
- end
- local function AddSpanner(name, abbr, first, last)
- -- TODO - can we, from the size of span and maybe the character count of
- -- name make a guess as to whether we could use the name instead of Abbr?
- if first <= last then
- tooltip:SetCell(1, first, abbr, nil, nil, 1 + last - first)
- end
- end
- local function openFollowerTabSearch( tooltip_cell, searchTerm )
- local searchBox = GarrisonMissionFrameFollowers.SearchBox:IsVisible() and GarrisonMissionFrameFollowers.SearchBox or GarrisonLandingPage.FollowerList.SearchBox:IsVisible() and GarrisonLandingPage.FollowerList.SearchBox
- if searchBox then
- searchBox:SetText(searchTerm)
- searchBox.clearText = searchTerm
- end
- end
- local function displayFollowersWithCounter(tooltip_cell, counters )
- local first, second = math.min(counters[1],counters[2]), math.max(counters[1],counters[2])
- local list = tooltip.counterDualSum[first][second].list
- if #list > 0 then
- local formattedList = {}
- for _, followerID in pairs(list) do
- tinsert(formattedList, strformat("%s (%s%s)",
- C_Garrison.GetFollowerLink(followerID),
- BF:GetRerollPercentForSpec( C_Garrison.GetFollowerClassSpec( followerID )),
- C_Garrison.GetFollowerStatus(followerID) == GARRISON_FOLLOWER_INACTIVE and string.format(self.formatStrings.rarityColors.red,GARRISON_FOLLOWER_INACTIVE) or ""
- )
- )
- end
- local displayString = getMechanicTexture(first, true).."/"..
- getMechanicTexture(second, true)..": "..
- table.concat(formattedList,", ")
- BF:Print(displayString)
- end
- end
- local function openRerollFinderWith(tooltip_cell, counters )
- BF.db.profile.rerollFirstWanted = counters[1]
- BF.db.profile.rerollSecondWanted = counters[2]
- InterfaceOptionsFrame_OpenToCategory(BF.optionsFrame)
- LibStub("AceConfigDialog-3.0"):SelectGroup(addonName, "rerollfinder")
- BF:GenerateRerollFinderList()
- end
- colors = {
- green = {r=0, g=1, b=0, a=1},
- white = {r=1, g=1, b=1, a=1},
- red = {r=1, g=0, b=0, a=1},
- lightGray = {r=(108/255), g=(115/255), b=(120/255), a=1},
- green = {r=(32/255), g=(255/255), b=(32/255), a=1},
- red = {r=(255/255), g=(25/255), b=(25/255), a=1},
- yellow = {r=(255/255), g=(228/255), b=(0/255), a=1},
- --lightGray = {r=0.25, g=0.25, b=0.25, a=1},
- darkGray = {r=0.1, g=0.1, b=0.1, a=1},
- lineGrey = {r=(108/255), g=(115/255), b=(120/255), a=1},
- --lightGray = {r=(82/255), g=(91/255), b=(97/255), a=1},
- }
- local function AddSeparator(tooltip)
- tooltip:AddSeparator(1, colors.lineGrey.r, colors.lineGrey.g, colors.lineGrey.b, colors.lineGrey.a)
- end
- local globaldb = self.db.global
- local profiledb = self.db.profile
- if tableInsteadOfList then
- self.matrixIsUsed = true
- -- 9x9 table, each cell showing the number of follower who counters both
- -- threats from column and row
- if tooltip:GetLineCount() == 0 then
- tooltip.Rows["icon"] = tooltip.Rows["icon"] or tooltip:AddHeader()
- tooltip.Rows["sum"] = tooltip.Rows["sum"] or tooltip:AddHeader()
- if self.db.profile.showMountScavnerRowMatrix then
- tooltip.Rows["scav"] = tooltip.Rows["scav"] or tooltip:AddHeader()
- tooltip.Rows["epic"] = tooltip.Rows["epic"] or tooltip:AddHeader()
- tooltip.Rows["treas"] = tooltip.Rows["treas"] or tooltip:AddHeader() -- hier
- end
- end
- MyAddColumn("icon","")
- -- Setup the tooltip: Add the textures to the cells of the first row and
- -- column, "" all the other cells so we start with a clean matrix
- for k=1,10 do
- local tex = getMechanicTexture(k, true)
- if tex then
- local row = tooltip.Rows[k] or tooltip:AddHeader()
- --AddSeparator(tooltip)
- MyAddColumn(tostring(k))
- tooltip:SetCell( tooltip.Rows["icon"], tooltip.Columns[tostring(k)].col, tex)
- tooltip:SetCell( row, tooltip.Columns["icon"].col, tex)
- tooltip.Rows[k] = row
- for j=1,10 do
- if tooltip.Columns[tostring(j)]then
- tooltip:SetCell( tooltip.Rows[k], tooltip.Columns[tostring(j)].col, "")
- end
- end
- end
- end
- local counterSum = {}
- tooltip.counterDualSum = {}
- local function addDualCounter( c1, c2, iLevel, followerData)
- local first, second = math.min(c1,c2), math.max(c1,c2)
- local quality = 1
- if iLevel >= 615 then
- quality = 2
- end
- if iLevel >= 630 then
- quality = 3
- end
- if iLevel >= 645 then
- quality = 4
- end
- tooltip.counterDualSum[first] = tooltip.counterDualSum[first] or {}
- tooltip.counterDualSum[first][second] = tooltip.counterDualSum[first][second] or {}
- tooltip.counterDualSum[first][second].num = ( tooltip.counterDualSum[first][second].num or 0 ) + 1
- tooltip.counterDualSum[first][second].quality = math.max( tooltip.counterDualSum[first][second].quality or 0, quality )
- tooltip.counterDualSum[first][second].list = tooltip.counterDualSum[first][second].list or {}
- tinsert(tooltip.counterDualSum[first][second].list, followerData.followerID)
- end
- table.sort(self.followerList, sortFollowers)
- local epicMountIcon = strformat(self.formatStrings.counterIconTolltip, C_Garrison.GetFollowerAbilityIcon(221))
- local scavangerIcon = strformat(self.formatStrings.counterIconTolltip, C_Garrison.GetFollowerAbilityIcon(79))
- local treasureIcon = strformat(self.formatStrings.counterIconTolltip, C_Garrison.GetFollowerAbilityIcon(256))
- for _, followerData in pairs( self.followerList ) do
- if followerData.isCollected and ( followerData.status ~= GARRISON_FOLLOWER_INACTIVE or self.db.profile.showInactivesMatrix ) then
- local counters, index, counterID = {}, 1
- counterID = self:GetFollowerAbilityCounterAtIndex(followerData.followerID, index)
- local hasEpicMount, hasScavenger, hasTreasure = self:FollowerHasEpicMountScavenger(followerData.followerID) -- hier
- while counterID do
- tinsert(counters, counterID)
- counterSum[counterID] = ( counterSum[counterID] or 0 ) + 1
- tooltip:SetCell(tooltip.Rows["sum"], tooltip.Columns[tostring(counterID)].col, counterSum[counterID])
- if self.db.profile.clickableMatrix then
- tooltip:SetCellScript(tooltip.Rows["icon"], tooltip.Columns[tostring(counterID)].col, "OnMouseUp", openFollowerTabSearch, getMechanicName(counterID))
- end
- if self.db.profile.showMountScavnerRowMatrix then
- if hasScavenger then
- tooltip:SetCell(tooltip.Rows["scav"], tooltip.Columns[tostring(counterID)].col, scavangerIcon)
- end
- if hasEpicMount then
- tooltip:SetCell(tooltip.Rows["epic"], tooltip.Columns[tostring(counterID)].col, epicMountIcon)
- end
- if hasTreasure then
- tooltip:SetCell(tooltip.Rows["treas"], tooltip.Columns[tostring(counterID)].col, treasureIcon) -- hier
- end
- end
- index = index+1
- counterID = self:GetFollowerAbilityCounterAtIndex(followerData.followerID, index)
- end
- if #counters > 1 then
- addDualCounter( counters[1], counters[2], followerData.iLevel, followerData )
- end
- end
- end
- local r,c
- for r=1,9 do
- for c=r+1,10 do
- if tooltip.Rows[r] and tooltip.Columns[tostring(c)] then
- if tooltip.counterDualSum[r] and tooltip.counterDualSum[r][c] then
- local rData, formatedNumber = tooltip.counterDualSum[r][c]
- if self.db.profile.colorMatrix then
- formatedNumber = getFormattedName(rData.quality, rData.num)
- else
- formatedNumber = rData.num
- end
- tooltip:SetCell( tooltip.Rows[r], tooltip.Columns[tostring(c)].col, formatedNumber)
- if self.db.profile.clickableMatrix then
- tooltip:SetCellScript(tooltip.Rows[r], tooltip.Columns[tostring(c)].col, "OnMouseUp", displayFollowersWithCounter, {c, r})
- end
- if not self.db.profile.onlyFillTopMatrixHalf then
- -- Mirror the matrix
- tooltip:SetCell( tooltip.Rows[c], tooltip.Columns[tostring(r)].col, formatedNumber)
- if self.db.profile.clickableMatrix then
- tooltip:SetCellScript( tooltip.Rows[c], tooltip.Columns[tostring(r)].col, "OnMouseUp", displayFollowersWithCounter, {r, c})
- end
- end
- else
- if self.db.profile.clickableMatrix then
- tooltip:SetCell( tooltip.Rows[r], tooltip.Columns[tostring(c)].col, " ")
- tooltip:SetCell( tooltip.Rows[c], tooltip.Columns[tostring(r)].col, " ")
- tooltip:SetCellScript(tooltip.Rows[r], tooltip.Columns[tostring(c)].col, "OnMouseUp", openRerollFinderWith, {c, r})
- tooltip:SetCellScript(tooltip.Rows[c], tooltip.Columns[tostring(r)].col, "OnMouseUp", openRerollFinderWith, {r, c})
- end
- end
- end
- end
- end
- for r, cData in pairs(tooltip.counterDualSum) do
- for c, rData in pairs(cData) do
- local formatedNumber
- if self.db.profile.colorMatrix then
- formatedNumber = getFormattedName(rData.quality, rData.num)
- else
- formatedNumber = rData.num
- end
- tooltip:SetCell( tooltip.Rows[r], tooltip.Columns[tostring(c)].col, formatedNumber)
- if self.db.profile.clickableMatrix then
- tooltip:SetCellScript(tooltip.Rows[r], tooltip.Columns[tostring(c)].col, "OnMouseUp", displayFollowersWithCounter, {c, r})
- end
- if not self.db.profile.onlyFillTopMatrixHalf then
- -- Mirror the matrix
- tooltip:SetCell( tooltip.Rows[c], tooltip.Columns[tostring(r)].col, formatedNumber)
- if self.db.profile.clickableMatrix then
- tooltip:SetCellScript( tooltip.Rows[c], tooltip.Columns[tostring(r)].col, "OnMouseUp", displayFollowersWithCounter, {r, c})
- end
- end
- end
- end
- else
- self.matrixIsUsed = false
- -- Tooltip: List of followers with 5 columns for counters/traits
- tooltip:AddHeader()
- table.sort( self.followerList, sortFollowers)
- if self.db.profile.showRerollPercent then
- local rerollIcon = strformat(self.formatStrings.counterIconTolltip, GetItemIcon(118354))
- MyAddColumn("reroll")
- tooltip:SetCell(1, tooltip.Columns["reroll"].col, rerollIcon)
- end
- for i=1,ABILITY_MAX_NUM do
- MyAddColumn("counter"..i,"")
- end
- AddSpanner("Threats", "vs", tooltip.Columns["counter1"].col, tooltip.Columns["counter"..ABILITY_MAX_NUM].col)
- for i=1,TRAIT_MAX_NUM do
- MyAddColumn("trait"..i,"")
- end
- AddSpanner("Traits", "Traits", tooltip.Columns["trait1"].col, tooltip.Columns["trait"..TRAIT_MAX_NUM].col)
- for _, followerData in pairs( self.followerList ) do
- if followerData.isCollected and
- (self.db.profile.showInactivesList or followerData.status ~= GARRISON_FOLLOWER_INACTIVE) then
- local row = tooltip:AddLine("")
- local coloredName = getFormattedName(followerData.quality, followerData.name)
- tooltip:SetCell(row, 1, strformat("%s%s (%d)",
- (followerData.status == GARRISON_FOLLOWER_INACTIVE and self.db.profile.showMarkInactive or ""),
- coloredName,
- followerData.level == GARRISON_FOLLOWER_MAX_LEVEL and followerData.iLevel or followerData.level) )
- if self.db.profile.clickableList then
- tooltip:SetCellScript(row, 1, "OnMouseUp", openFollowerTabSearch, followerData.name)
- end
- local index, counters = 1, {}
- local counter = self:GetFollowerAbilityCounterAtIndex(followerData.followerID, index)
- while counter and index <= ABILITY_MAX_NUM do
- tinsert(counters, counter)
- index = index +1
- counter = self:GetFollowerAbilityCounterAtIndex(followerData.followerID, index)
- end
- table.sort(counters)
- for i=1,#counters do
- tooltip:SetCell(row, tooltip.Columns["counter"..i].col, getMechanicTexture(counters[i], true) )
- end
- if self.db.profile.showRerollPercent and
- ( ( followerData.combo and self.reRollCombos[followerData.combo] > 1 ) or
- self.db.profile.showNewComboPercent )then
- local percent
- if followerData.quality > 3 then
- percent = self:GetRerollPercentForSpec( C_Garrison.GetFollowerClassSpec( followerData.followerID ) )
- else
- percent = self:GetFollowerUpgradePercent( followerData.followerID )
- end
- tooltip:SetCell(row, tooltip.Columns["reroll"].col, percent)
- end
- index = 1
- local traitID, traits = C_Garrison.GetFollowerTraitAtIndex(followerData.followerID, index), {}
- while traitID > 0 and index <= TRAIT_MAX_NUM do
- tinsert(traits, traitID)
- index = index+1
- traitID = C_Garrison.GetFollowerTraitAtIndex(followerData.followerID, index)
- end
- table.sort(traits)
- for i=1,#traits do
- tooltip:SetCell(row, tooltip.Columns["trait"..i].col, strformat(self.formatStrings.counterIconTolltip, C_Garrison.GetFollowerAbilityIcon(traits[i])) )
- end
- end
- end
- end
- end
- --
- function BF:FollowerXPChange(event, followerID, xpAward, oldXP, oldLevel, oldQuality)
- local name, displayID, level, quality, currXP, maxXP = C_Garrison.GetFollowerMissionCompleteInfo(followerID)
- self.Debug(name, displayID, xpAward, oldXP, oldLevel, level, oldQuality, quality)
- if oldLevel ~= level then
- -- Levelup
- local replacements = {
- ["lvl"] = level,
- ["name"] = getFormattedName(quality ,name),
- }
- local levelupString = string.gsub(L["%name% is now level %lvl%"], "%%(%w+)|?([^%%]*)%%", function (s, default)
- local key = tostring(s)
- return replacements[key] or default
- end)
- Toast:Spawn( TOAST_FOLLOWER_LEVELUP, levelupString )
- self:RedrawTooltip()
- end
- if oldQuality ~= quality then
- -- Qualitiy upgrade
- local formatedToastStrings = {}
- local followerAbilitiesData = C_Garrison.GetFollowerAbilities(followerID)
- local function getAcquiredString( abilityIndex )
- local counterID, abilityName, abilityTexture = C_Garrison.GetFollowerAbilityCounterMechanicInfo(abilityIndex)
- if not counterID then
- -- It's (1)a trait and (2) one that does not actually counter stuff
- -- e.g. Mount, +XP, Scavenger, Profession X
- abilityName = C_Garrison.GetFollowerAbilityName(abilityIndex)
- abilityTexture = C_Garrison.GetFollowerAbilityIcon(abilityIndex)
- end
- local replacements, icon= {
- ["name"] = abilityName,
- ["icon"] = strformat(self.formatStrings.counterIconTolltip, abilityTexture),
- }
- local text = string.gsub(L["Acquired %name% (%icon%)"], "%%(%w+)|?([^%%]*)%%", function (s, default)
- local key = tostring(s)
- return replacements[key] or default
- end)
- return text
- end
- local formatedToastStrings = {}
- local counters = {}
- tinsert(counters, self:GetFollowerAbilityCounterAtIndex(followerID, 1))
- -- Get icon for the ability the follower had since beginning
- local replacements = {
- ["name"] = getFormattedName(quality , name),
- ["icon"] = getMechanicTexture(counters[1], true)
- }
- local firstTextLine = string.gsub("%name% (%icon%)", "%%(%w+)|?([^%%]*)%%", function (s, default)
- local key = tostring(s)
- return replacements[key] or default
- end)
- -- Name
- tinsert(formatedToastStrings, firstTextLine)
- if quality == 3 then
- -- Green -> Blue
- -- Gained C_Garrison.GetFollowerAbilities(followerID)[3]
- tinsert(formatedToastStrings, getAcquiredString(C_Garrison.GetFollowerTraitAtIndex(followerID, 2)))
- elseif quality == 4 then
- -- Blue -> Epic
- -- Determine if we got a new combination of counters
- -- self.reRollCombos
- tinsert(counters, self:GetFollowerAbilityCounterAtIndex(followerID, 2))
- table.sort(counters)
- tinsert(formatedToastStrings, getAcquiredString( C_Garrison.GetFollowerAbilityAtIndex(followerID, 2)))
- local combo = counters[1]+counters[2]/100
- BF:Debug(name, counters[1], counters[2], combo, self.reRollCombos[combo] or "nil")
- if not self.reRollCombos[combo] then
- tinsert(formatedToastStrings, strformat( L["New epic combo: %s/%s"],
- getMechanicTexture(counters[1], true) or "ERROR",
- getMechanicTexture(counters[2], true) or "ERROR"
- ))
- end
- tinsert(formatedToastStrings, getAcquiredString( C_Garrison.GetFollowerTraitAtIndex(followerID, 3)))
- end
- Toast:Spawn( TOAST_FOLLOWER_UPGRADE, table.concat(formatedToastStrings, "\n"))
- self:RedrawTooltip()
- end
- end
- local function toastFollowerUpgrade(toast, text)
- toast:SetTitle(L["Follower upgrade"])
- toast:SetText(text)
- end
- local function toastFollowerLevelup(toast, text)
- toast:SetTitle(L["Follower levelup"])
- toast:SetText(text)
- end
- function BF:OnEnable()
- self:RegisterEvent("GARRISON_FOLLOWER_XP_CHANGED", "FollowerXPChange")
- self:RegisterEvent("GARRISON_FOLLOWER_ADDED", "RedrawTooltip")
- self:RegisterEvent("GARRISON_FOLLOWER_LIST_UPDATE", "RedrawTooltip")
- self:RegisterEvent("GARRISON_FOLLOWER_REMOVED", "RedrawTooltip")
- self:RegisterEvent("GARRISON_FOLLOWER_LIST_UPDATE", "RedrawTooltip")
- self:RegisterEvent("GARRISON_UPDATE", "UpdateTheFuckingFollowers")
- self:RegisterEvent("GARRISON_MISSION_NPC_OPENED", "UpdateTheFuckingFollowers")
- end
- function BF:OnDisable()
- self:UnregisterEvent("GARRISON_FOLLOWER_XP_CHANGED" )
- self:UnregisterEvent("GARRISON_FOLLOWER_ADDED" )
- self:UnregisterEvent("GARRISON_FOLLOWER_LIST_UPDATE" )
- self:UnregisterEvent("GARRISON_FOLLOWER_REMOVED" )
- self:UnregisterEvent("GARRISON_UPDATE" )
- self:UnregisterEvent("GARRISON_MISSION_NPC_OPENED" )
- end
- ---- Parse Follower List
- function BF:UpdateTheFuckingFollowers()
- self:Debug("GARRISON_UPDATE")
- self:UpdateFollowerCounters()
- self:UpdateRerollCombos()
- end
- function BF:UpdateFollowerCounters()
- self:Debug("UpdateFollowerCounters()")
- local followerData, counterID, followerAbilitiesData
- self.followerList = C_Garrison.GetFollowers()
- self.collectedFollowersList = {}
- for _, followerData in pairs( self.followerList ) do
- if followerData.isCollected then
- self.collectedFollowersList[followerData.followerID] = {}
- local index = 1
- local counter = self:GetFollowerAbilityCounterAtIndex(followerData.followerID, index)
- while counter do
- self.collectedFollowersList[followerData.followerID][counter] = true
- index = index+1
- counter = self:GetFollowerAbilityCounterAtIndex(followerData.followerID, index)
- end
- end
- end
- end
- function BF:FollowerHasEpicMountScavenger(id)
- -- C_Garrison.GetFollowerTraitAtIndex(id, i)
- -- 79 = Scavenger, 221 = Epic Mount
- local traitIndex, hasEpicMount, hasScavenger, hasTreasure, traidID = 1, false, false, false -- hier
- traitID = C_Garrison.GetFollowerTraitAtIndex(id, traitIndex)
- while traitID > 0 do
- hasEpicMount = hasEpicMount or traitID == 221
- hasScavenger = hasScavenger or traitID == 79
- hasTreasure = hasTreasure or traitID == 256 -- hier
- traitIndex = traitIndex +1
- traitID = C_Garrison.GetFollowerTraitAtIndex(id, traitIndex)
- end
- return hasEpicMount, hasScavenger, hasTreasure, C_Garrison.GetFollowerAbilityIcon(221), C_Garrison.GetFollowerAbilityIcon(79), C_Garrison.GetFollowerAbilityIcon(256)
- end
- function BF:GetFollowerAbilityCounterAtIndex(id, index)
- local abilityID = C_Garrison.GetFollowerAbilityAtIndex(id, index)
- if abilityID > 0 then
- return ( C_Garrison.GetFollowerAbilityCounterMechanicInfo(abilityID) )
- else
- return nil
- end
- end
- function BF:UpdateRerollCombos()
- self:Debug("UpdateRerollCombos()")
- for c,_ in pairs(self.reRollCombos) do
- self.reRollCombos[c] = nil
- end
- for _, followerData in pairs( self.followerList ) do
- if followerData.isCollected then
- local counters = {}
- tinsert(counters, self:GetFollowerAbilityCounterAtIndex(followerData.followerID, 1))
- tinsert(counters, self:GetFollowerAbilityCounterAtIndex(followerData.followerID, 2))
- if #counters == 2 then
- table.sort(counters)
- local combo = counters[1]+counters[2]/100
- followerData.combo = combo
- self.reRollCombos[combo] = ( self.reRollCombos[combo] or 0 ) +1
- end
- end
- end
- end
- ---- Enhancing the Inn Recruitment
- function BF:EnhanceRecruitFrame()
- --if true then return end
- self:UpdateFollowerCounters()
- self:UpdateRerollCombos()
- local recruitFrame = GarrisonRecruitSelectFrame.FollowerSelection
- local followers = C_Garrison.GetAvailableRecruits();
- for i=1, 3 do
- recruitFrame["Recruit"..i].PortraitFrame:SetScript("OnEnter",
- function(portraitFrame)
- if not BF.db.profile.availableCountersToolstip then return end
- local tooltip = LibQTip:Acquire("Broker_Followers_EnhancementTooltip", 1, "RIGHT")
- BF.enhanceTooltip = tooltip
- BF:AdditionalAbilitesRecruitTooltip(tooltip, i)
- tooltip:SetPoint("RIGHT",portraitFrame,"LEFT")
- tooltip:Show()
- end
- )
- recruitFrame["Recruit"..i].PortraitFrame:SetScript("OnLeave",
- function()
- if not BF.db.profile.availableCountersToolstip then return end
- LibQTip:Release(BF.enhanceTooltip)
- BF.enhanceTooltip.Columns = nil
- BF.enhanceTooltip.Rows = nil
- BF.enhanceTooltip = nil
- end
- )
- end
- end
- hooksecurefunc("GarrisonRecruitSelectFrame_UpdateRecruits", function(waiting)
- if not waiting then
- BF:EnhanceRecruitFrame()
- end
- end)
- function BF:EnhanceFollowerTab( parentFrameName )
- local parentFrame = _G[parentFrameName]
- local followerTabPortrait = parentFrame.FollowerTab.PortraitFrame
- followerTabPortrait:SetScript("OnEnter",
- function(portraitFrame)
- local tooltip = LibQTip:Acquire("Broker_Followers_EnhancementTooltip", 1, "RIGHT")
- BF.enhanceTooltip = tooltip
- BF:AdditionalAbilitesTooltip(tooltip, portraitFrame:GetParent())
- tooltip:SetPoint("RIGHT",portraitFrame,"LEFT")
- tooltip:Show()
- end)
- followerTabPortrait:SetScript("OnLeave",
- function()
- LibQTip:Release(BF.enhanceTooltip)
- BF.enhanceTooltip = nil
- end )
- for i=1,9 do
- --GarrisonMissionFrameFollowersListScrollFrameButton1
- local btn = _G[parentFrameName.."FollowersListScrollFrameButton"..i] or _G[parentFrameName.."ListScrollFrameButton"..i]
- if btn then
- local pf = btn.PortraitFrame
- pf:SetScript("OnEnter",
- function(portraitFrame)
- local tooltip = LibQTip:Acquire("Broker_Followers_EnhancementTooltip", 1, "RIGHT")
- BF.enhanceTooltip = tooltip
- local btn = portraitFrame:GetParent()
- BF:AdditionalAbilitesTooltip(tooltip, btn.info)
- tooltip:SetPoint("RIGHT",portraitFrame,"LEFT")
- tooltip:Show()
- end)
- pf:SetScript("OnLeave",
- function()
- LibQTip:Release(BF.enhanceTooltip)
- BF.enhanceTooltip = nil
- end )
- end
- end
- end
- local function getSpec(followerID)
- if type(followerID) == "string" then
- return C_Garrison.GetFollowerClassSpec(followerID)
- else
- return C_Garrison.GetFollowerClassSpecByID(followerID)
- end
- end
- local function getAbilityAtIndex(followerID, index)
- if type(followerID) == "string" then
- return C_Garrison.GetFollowerAbilityAtIndex(followerID, index)
- else
- return C_Garrison.GetFollowerAbilityAtIndexByID(followerID, index)
- end
- end
- function BF:AdditionalAbilitesTooltip( tooltip, followerInfo)
- -- if not isCollected then we need to use ...ByID() functions instead
- local id = followerInfo.followerID
- local specID = getSpec(id)
- local possibleAbilities = self.specs[specID]
- -- 2 abilites? => Show the % of getting new on reroll
- -- else => Show % of getting new combo when upgrading to epic
- -- Is there a second ability?
- if getAbilityAtIndex(id,2) > 0 then
- for _, aid in pairs(possibleAbilities) do
- local tex = getMechanicTexture( aid, true )
- tooltip:AddHeader(tex)
- end
- tooltip:AddHeader(string.format(self.formatStrings.counterIconTolltip, GetItemIcon(118354)) .. self:GetRerollPercentForSpec( specID ) )
- else
- -- 1 ability => % of getting new combo is dependent on what we already got
- local pa = (C_Garrison.GetFollowerAbilityCounterMechanicInfo(getAbilityAtIndex(id,1)))
- for _, aid in pairs(possibleAbilities) do
- local tex = getMechanicTexture( aid, true )
- -- Only interested in the abilities that we can gain
- if aid ~= pa then
- local combo = math.min(aid,pa) + math.max(aid,pa)/100
- if self.reRollCombos[combo] then
- tooltip:AddHeader(string.format(self.formatStrings.rarityColors.red,self.reRollCombos[combo])..tex)
- else
- tooltip:AddHeader(string.format(self.formatStrings.rarityColors.green,"+")..tex)
- end
- end
- end
- tooltip:AddHeader(string.format(BF.formatStrings.counterIconTolltip, "Interface\\Buttons\\JumpUpArrow") .. self:GetFollowerUpgradePercent( id ) )
- end
- end
- function BF:AdditionalAbilitesRecruitTooltip( tooltip, index)
- -- Recruitment is different, followerID are not set yet, and they
- local followerData = C_Garrison.GetAvailableRecruits()[index]
- local id = followerData.followerID
- local specID = followerData.classSpec
- local possibleAbilities = self.specs[specID]
- -- Get the predetermined ability for the recruit
- local pa
- for _, ability in pairs( C_Garrison.GetRecruitAbilities( index ) ) do
- if not ability.isTrait then
- if pa then
- tooltip:AddHeader( "ERROR" )
- self:Debug("ERROR", "AdditionalAbilitesRecruitTooltip", index, pa)
- end
- pa = next( ability.counters )
- end
- end
- for _, aid in pairs(possibleAbilities) do
- local tex = getMechanicTexture( aid, true )
- -- Only interested in the abilities that we can gain
- if aid ~= pa then
- local combo = math.min(aid,pa) + math.max(aid,pa)/100
- if self.reRollCombos[combo] then
- tooltip:AddHeader(string.format(self.formatStrings.rarityColors.red,self.reRollCombos[combo])..tex)
- else
- tooltip:AddHeader(string.format(self.formatStrings.rarityColors.green,"+")..tex)
- end
- end
- end
- tooltip:AddHeader(string.format(BF.formatStrings.counterIconTolltip, "Interface\\Buttons\\JumpUpArrow") .. self:GetFollowerUpgradePercent( id, pa ) )
- end
- function BF:GetComboFromAbilities( first, second )
- if type(first) == "table" and #first == 2 then
- return math.min(first[1], first[2]) + math.max(first[1], first[2])/100
- elseif first and second then
- return math.min(first, second) + math.max(first, second)/100
- else
- -- Should error
- return 0.0
- end
- end
- function BF:GetRerollPercentForSpec( specID )
- local spec = self.specs[specID]
- local allCombos, wantedCombos = 0, 0
- if spec then
- for i=1,(#spec-1) do
- for j=i+1,#spec do
- local combo = self:GetComboFromAbilities(spec[i], spec[j])
- allCombos = allCombos +1
- if not self.reRollCombos[combo] then
- wantedCombos = wantedCombos+1
- end
- end
- end
- end
- local percentage = ( allCombos==0 ) and 0 or ( wantedCombos / allCombos * 100 )
- return math.floor(percentage).."%"
- end
- function BF:GetFollowerUpgradePercent( id, preset )
- local specID, allCombos, wantedCombos = getSpec(id), 0, 0
- local spec = self.specs[specID]
- local aid = getAbilityAtIndex(id, 1)
- local presetCounter = preset or C_Garrison.GetFollowerAbilityCounterMechanicInfo(aid)
- local secondAbility = {}
- for k,s in pairs(spec) do
- if presetCounter and presetCounter ~= s then
- table.insert(secondAbility, s)
- end
- end
- for i=1,#secondAbility do
- local combo = self:GetComboFromAbilities(presetCounter, secondAbility[i])
- allCombos = allCombos +1
- if not self.reRollCombos[combo] then
- wantedCombos = wantedCombos+1
- end
- end
- local percentage = ( allCombos==0 ) and 0 or ( wantedCombos / allCombos * 100 )
- return math.floor(percentage).."%"
- end
- local lastRerollFinderCombo
- function BF:GenerateRerollFinderList()
- local counters = {}
- tinsert(counters, self.db.profile.rerollFirstWanted )
- tinsert(counters, self.db.profile.rerollSecondWanted)
- if counters[1] == counters[2] then
- self.options.args.rerollfinder.args.rerollList.name= L["The two counters can't be of the same type"]
- LibStub("AceConfigRegistry-3.0"):NotifyChange(addonName)
- return
- end
- local ERROR_MESSAGES, dataIsWrong = {}
- -- It seems the wowhead guide has errors in it, so when going parsing all
- -- followers check if our data has a mismatches ingame stuff
- tinsert(ERROR_MESSAGES, "!!! ERROR !!!")
- tinsert(ERROR_MESSAGES, "Wrong client data?")
- local wantedCombo = self:GetComboFromAbilities(counters)
- if wantedCombo == lastRerollFinderCombo then
- return
- end
- lastRerollFinderCombo = wantedCombo
- -- Lists of followers, down from most convinient:
- -- Has it > Reroll to it > upgrade to epic (> upgrade + reroll)
- local hasCombo, rerollCombo, upgradeCombo, upgradeRerollCombo = {}, {}, {}, {}
- for _,f in pairs(self.followerList) do
- if f.isCollected then
- local c
- local aid = getAbilityAtIndex(f.followerID, 1)
- c = C_Garrison.GetFollowerAbilityCounterMechanicInfo(aid)
- if not BF.specSets[f.classSpec][c] then
- dataIsWrong = true
- tinsert(ERROR_MESSAGES, strformat("%s (%s) counters %s",
- getFormattedName(f.quality, f.name),
- f.className,
- getMechanicTexture(c, true)))
- end
- aid = getAbilityAtIndex(f.followerID, 2)
- if aid > 0 then
- c = C_Garrison.GetFollowerAbilityCounterMechanicInfo(aid)
- if not BF.specSets[f.classSpec][c] then
- dataIsWrong = true
- tinsert(ERROR_MESSAGES, strformat("%s (%s) counters %s",
- getFormattedName(f.quality, f.name),
- f.className,
- getMechanicTexture(c, true)))
- end
- end
- if self.specSets[f.classSpec][counters[1]] and
- self.specSets[f.classSpec][counters[2]] or wantedCombo == f.combo then
- -- Collected AND the spec can have the combo?
- -- We need name, quality, from how many counters we choose and the
- -- first counter for non-epic, if he can upgrade into the combo
- local dataNeeded = {}
- dataNeeded.quality = f.quality
- dataNeeded.name = f.name
- dataNeeded.status = C_Garrison.GetFollowerStatus(f.followerID)
- dataNeeded.availCounter = #self.specs[f.classSpec]
- dataNeeded.reroll = 0 -- Chance to get it on reroll
- dataNeeded.upgrade = 0 -- Chance to get it on upgrade
- dataNeeded.counters = {}
- local aid = getAbilityAtIndex(f.followerID, 1)
- tinsert(dataNeeded.counters, (C_Garrison.GetFollowerAbilityCounterMechanicInfo(aid)))
- aid = getAbilityAtIndex(f.followerID, 2)
- if aid > 0 then
- tinsert(dataNeeded.counters, (C_Garrison.GetFollowerAbilityCounterMechanicInfo(aid)))
- end
- if f.quality == 4 then
- -- Epic follower
- if f.combo == wantedCombo then
- -- Has the combo already, no need to calculate anything
- tinsert(hasCombo, dataNeeded)
- else
- -- Can be rerolled to have the combo, choosing two out of
- -- .availCounter
- -- Does not take into acount that warlocks
- dataNeeded.reroll = ( 2 / dataNeeded.availCounter) * (1 / ( dataNeeded.availCounter - 1))*100
- tinsert(rerollCombo, dataNeeded)
- end
- else
- -- Non-epic follower, but the spec can have the combo
- -- Everyone has 1 ability
- if dataNeeded.counters[1] == counters[1] or dataNeeded.counters[1] == counters[2] then
- -- And we are already half-way there, so we need to get
- -- 1 from (available-1)
- dataNeeded.upgrade = 1 / ( dataNeeded.availCounter - 1)*100
- tinsert(upgradeCombo, dataNeeded)
- else
- -- Needs to upgrade and reroll!
- dataNeeded.reroll = ( 2 / dataNeeded.availCounter) * (1 / ( dataNeeded.availCounter - 1)) *100
- tinsert(upgradeRerollCombo, dataNeeded)
- end
- end
- end -- spec or wanted
- end -- is collected
- end -- pairs
- -- Ouput generation
- local formattedOutputStrings = {} -- output = table.concat(...,"\n")
- tinsert(formattedOutputStrings, L["Followers with this combo:"])
- if #hasCombo > 0 then
- local formattedFollowers = {}
- for _,data in pairs(hasCombo) do
- tinsert(formattedFollowers, getFormattedName(data.quality, data.name)..
- ( data.status == GARRISON_FOLLOWER_INACTIVE and ("("..string.format(self.formatStrings.rarityColors.red,GARRISON_FOLLOWER_INACTIVE)..")") or ""))
- end
- tinsert(formattedOutputStrings, table.concat(formattedFollowers, "\n"))
- else
- tinsert(formattedOutputStrings, L["None"])
- end
- tinsert(formattedOutputStrings, L["Epic followers who can be rerolled to this combo:"])
- if #rerollCombo > 0 then
- table.sort(rerollCombo, function(a,b) return a.reroll > b.reroll end)
- local formattedFollowers = {}
- for _,data in pairs(rerollCombo) do
- tinsert(formattedFollowers, strformat("%s %s/%s (%.1f%%%s)", getFormattedName(data.quality, data.name),
- getMechanicTexture(data.counters[1], true),
- getMechanicTexture(data.counters[2], true),
- data.reroll,
- data.status == GARRISON_FOLLOWER_INACTIVE and string.format(self.formatStrings.rarityColors.red,GARRISON_FOLLOWER_INACTIVE) or ""))
- end
- tinsert(formattedOutputStrings, table.concat(formattedFollowers, "\n"))
- else
- tinsert(formattedOutputStrings, L["None"])
- end
- tinsert(formattedOutputStrings, L["Non-epic followers who with a chance to get the combo when turning epic:"])
- if #upgradeCombo > 0 then
- table.sort(upgradeCombo, function(a,b) return a.upgrade > b.upgrade end)
- local formattedFollowers = {}
- for _,data in pairs(upgradeCombo) do
- tinsert(formattedFollowers, strformat("%s %s (%.1f%%%s)", getFormattedName(data.quality, data.name),
- getMechanicTexture(data.counters[1], true),
- data.upgrade,
- data.status == GARRISON_FOLLOWER_INACTIVE and string.format(self.formatStrings.rarityColors.red,GARRISON_FOLLOWER_INACTIVE) or ""))
- end
- tinsert(formattedOutputStrings, table.concat(formattedFollowers, "\n"))
- else
- tinsert(formattedOutputStrings, L["None"])
- end
- tinsert(formattedOutputStrings, L["Non-epic followers who can be rerolled to have the combo after turning epic:"])
- if #upgradeRerollCombo > 0 then
- local formattedFollowers = {}
- table.sort(upgradeRerollCombo, function(a,b) return a.reroll > b.reroll end)
- for _,data in pairs(upgradeRerollCombo) do
- tinsert(formattedFollowers, strformat("%s %s (%.1f%%%s)", getFormattedName(data.quality, data.name),
- getMechanicTexture(data.counters[1], true),
- data.reroll,
- data.status == GARRISON_FOLLOWER_INACTIVE and string.format(self.formatStrings.rarityColors.red,GARRISON_FOLLOWER_INACTIVE) or ""))
- end
- tinsert(formattedOutputStrings, table.concat(formattedFollowers, "\n"))
- else
- tinsert(formattedOutputStrings, L["None"])
- end
- if dataIsWrong and debug then tinsert(formattedOutputStrings, table.concat(ERROR_MESSAGES, "\n")) end
- -- Make the options refresh with the list
- -- Here
- self.options.args.rerollfinder.args.rerollList.name = table.concat(formattedOutputStrings, "\n")
- LibStub("AceConfigRegistry-3.0"):NotifyChange(addonName)
- end
- ---- Database Maintenance
- function BF:MigrateSavedData()
- local globaldb = self.db.global
- local profiledb = self.db.profile
- -- all db sections are current we can exit immediately
- if profiledb.version == DB_VERSION and
- globaldb.version == DB_VERSION then
- return
- else
- BF:Print(L["DB_VERSION_UPGRADE_PURGE"])
- end
- -- Migrating from before addon began keeping track of database changes
- --[[
- if globaldb.version < X then
- -- Upgrade from before version X
- end
- if profiledb.version < X then
- -- Upgrade from before version X
- end
- --]]
- profiledb.version = DB_VERSION
- globaldb.version = DB_VERSION
- end
- function BF:OnInitialize() -- ADDON_LOADED, only saved variables are guaranteed to be present
- self.db = LibStub("AceDB-3.0"):New("Broker_Follower_DB", defaults, true)
- self:MigrateSavedData()
- LibStub("AceConfig-3.0"):RegisterOptionsTable(addonName, self.GenerateOptions)
- self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName)
- self.BFLDB = ldb:NewDataObject(addonName, {
- type = "data source",
- text = "",
- icon = "Interface\\Icons\\inv_misc_lockboxghostiron",
- OnClick = function(clickedframe, button)
- if button == "RightButton" then
- InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
- else
- -- 1 = click2show
- -- 2 = hover2show
- if self.db.profile.clickToShow == 2 then
- self.db.profile.showInactivesMatrix = not self.db.profile.showInactivesMatrix
- self:PrepareTooltip(clickedframe, not IsShiftKeyDown())
- else
- -- Click 2 Show handling
- local tooltip = LibQTip:Acquire("Broker_Followers_Tooltip", 1, "LEFT")
- self.tooltip = tooltip
- self.tooltip:SetAutoHideDelay( nil )
- if tooltip:IsShown() then
- -- Tooltip is shown, hide it on click
- self:ReleaseTooltip()
- else
- -- No tooltip, show it on click
- self:PrepareTooltip(clickedframe, not IsShiftKeyDown())
- end
- end
- end
- end,
- OnEnter = function(enteredFrame)
- -- 1 = click2show
- -- 2 = hover2show
- if self.db.profile.clickToShow == 1 then return end
- self:PrepareTooltip(enteredFrame, not IsShiftKeyDown())
- self.tooltip:SetAutoHideDelay( self.db.profile.autoHideDelay or 0.25, enteredFrame, function() BF:ReleaseTooltip() end )
- end,
- OnLeave = function(tt)
- -- 1 = click2show
- -- 2 = hover2show
- if self.db.profile.clickToShow == 1 or true then return end
- LibQTip:Release(self.tooltip)
- if self.tooltip then
- self.tooltip.Columns = nil
- self.tooltip.Rows = nil
- self.tooltip = nil
- end
- end,
- })
- LDBIcon:Register(addonName, self.BFLDB, self.db.profile.minimapIcon)
- self.reRollCombos = {}
- self:EnhanceFollowerTab( "GarrisonMissionFrame" )
- self:EnhanceFollowerTab( "GarrisonLandingPage" )
- Toast:Register(TOAST_FOLLOWER_UPGRADE, toastFollowerUpgrade)
- Toast:Register(TOAST_FOLLOWER_LEVELUP, toastFollowerLevelup)
- -- Update the .format strings
- self.formatStrings.counterIconTolltip = "|T%s:"..self.db.profile.iconSize..":"..self.db.profile.iconSize..":0:0:64:64:5:59:5:59|t"
- for i=0,7 do
- self.formatStrings.rarityColors[i] = "|c"..select(4,GetItemQualityColor(i)).."%s|r"
- end
- self.formatStrings.rarityColors.green = "|cFF00FF00%s|r"
- self.formatStrings.rarityColors.red = "|cFFFF0000%s|r"
- end
- function BF:Debug(...)
- DebugPrint( ... )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement