Thread Tools Display Modes
05-21-24, 09:04 AM   #1
Sharpedge
A Theradrim Guardian
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 68
Need some insight on Battleground Blitz Honor tracking

I know that you get honor whenever you do a Blitz, it goes towards the weekly Vault. 5000 honor will give you 3 selections, 2500 will give you 2 and 1250 will give you one. What I am trying to go is to track the progress of the amount of honor a player has from the Battleground Blitz. The code below is my entire pvp stats, etc. I have tried to use
Code:
C_PvP.GetBrawlRewards honor, experience, itemRewards, currencyRewards, hasWon = C_PvP.GetBrawlRewards(brawlType)
but it only shows (my toon) as having 300 honor in Blitz when he actually has over 5000 because I have unlocked a 3 slots for the Vault. I've tried all I can think of, so I am hoping a new set of eyes will see what I am missing.

Code:
local pvpStatsFrame = CreateFrame("Frame", "PVPStatsFrame", UIParent, "BasicFrameTemplateWithInset")
pvpStatsFrame:SetSize(750, 400)  -- Increased size to accommodate scrolling
pvpStatsFrame:SetPoint("CENTER")
pvpStatsFrame:SetMovable(true)
pvpStatsFrame:EnableMouse(true)
pvpStatsFrame:RegisterForDrag("LeftButton")
pvpStatsFrame:SetScript("OnDragStart", pvpStatsFrame.StartMoving)
pvpStatsFrame:SetScript("OnDragStop", pvpStatsFrame.StopMovingOrSizing)
pvpStatsFrame:Hide()

pvpStatsFrame.title = pvpStatsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
pvpStatsFrame.title:SetPoint("TOP", pvpStatsFrame, "TOP", 0, -3)
pvpStatsFrame.title:SetText("PvP Statistics")


local TOP_MARGIN = -25

local function createStatLabelAndValueHorizontal(parent, labelText, xOffset, yOffset, labelTextColor)
    local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    label:SetPoint("TOPLEFT", parent, "TOPLEFT", xOffset, yOffset)
    label:SetText(labelText)
    label:SetTextColor(unpack(labelTextColor))
    
    local value = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    value:SetPoint("TOPLEFT", label, "BOTTOMLEFT", 0, -2)
    value:SetTextColor(1, 0.84, 0) -- Default color for the value text
    return label, value
end

-- Create a table to store the tabs and their corresponding frames
local tabs = {}

-- Function to hide all tab frames
local function HideAllTabs()
    for _, tabFrame in pairs(tabs) do
        tabFrame:Hide()
    end
end

-- Create a function to create tabs
local function CreateTabButton(parent, text, id)
    local tab = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
    tab:SetText(text)
    tab:SetID(id)
    tab:SetSize(120, 25)
    tab:SetScript("OnClick", function(self)
        HideAllTabs()
        tabs[self:GetID()]:Show()
    end)
    return tab
end

-- Create the tab frame
local tabFrame = CreateFrame("Frame", nil, pvpStatsFrame)
tabFrame:SetPoint("TOP", pvpStatsFrame, "TOP", 0, -30)
tabFrame:SetSize(700, 25)

-- Create the tabs
local generalTab = CreateTabButton(tabFrame, "General", 1)
generalTab:SetPoint("LEFT", tabFrame, "LEFT", 10, 0)
local otherTab = CreateTabButton(tabFrame, "BG's", 2)
otherTab:SetPoint("LEFT", generalTab, "RIGHT", 5, 0)

-- Create tab frames
tabs[1] = CreateFrame("Frame", nil, pvpStatsFrame)
tabs[1]:SetSize(700, 300)  -- Adjust size to fit within the main frame
tabs[1]:SetPoint("TOP", tabFrame, "BOTTOM", 0, -10)
tabs[1]:Show()

tabs[2] = CreateFrame("Frame", nil, pvpStatsFrame)
tabs[2]:SetSize(700, 300)
tabs[2]:SetPoint("TOP", tabFrame, "BOTTOM", 0, -10)
tabs[2]:Hide()

-- Show the first tab by default
HideAllTabs()
tabs[1]:Show()


local SOLO_SHUFFLE_INDEX = 7

-- Add PvP Stats to the General Tab
local generalStats = {
    {"Player Name:", "playerNameValue", {0, 1, 0}}, -- Green label text
    {"Conquest Points:", "conquestValue", {1, 0, 0}}, -- Red label text
    {"Honor Points:", "honorValue", {0, 0.75, 1}}, -- Blue label text
    {"Honor Level:", "honorLevelValue", {0.58, 0, 0.82}}, -- Purple label text
    {"Conquest Cap:", "conquestCapValue", {1, 0.5, 0}}, -- Orange label text
    {"Solo Shuffle Rating:", "soloShuffleRatingValue", {0, 0.75, 1}}, -- Blue label text
}

for i, stat in ipairs(generalStats) do
    local label, value = createStatLabelAndValueHorizontal(tabs[1], stat[1], 10, -10 - (i - 1) * 40, stat[3])
    tabs[1][stat[2]] = value
end


-- Add BG Stats to the BG Tab
local bgStats = {
    {"BGs Played:", "bgPlayedValue"},
    {"BGs Won:", "bgWonValue"},
    {"BGs Lost:", "bgLostValue"},
    {"Total Honorable Kills:", "totalHonorableKillsValue"},
    {"Battleground Honorable Kills:", "battlegroundHonorableKillsValue"},
    {"Blitz Honor Gained:", "blitzHonorValue"}, -- New entry for Battleground Blitz Honor
}

for i, stat in ipairs(bgStats) do
    local label, value = createStatLabelAndValueHorizontal(tabs[2], stat[1], 10, -10 - (i - 1) * 40, {1, 1, 1})
    tabs[2][stat[2]] = value
end

-- Function to fetch BG stats
local function FetchBGStats()
    local bgPlayed = GetStatistic(839) or "N/A" -- Total Battlegrounds Played
    local bgWon = GetStatistic(840) or "N/A" -- Total Battlegrounds Won
    local bgLost = tonumber(bgPlayed) - tonumber(bgWon) -- Calculate BGs Lost
    local totalHonorableKills = GetStatistic(588) or "N/A" -- Total Honorable Kills
    local battlegroundHonorableKills = GetStatistic(382) or "N/A" -- Battleground Honorable Kills

    return bgPlayed, bgWon, bgLost, totalHonorableKills, battlegroundHonorableKills
end

local isInBGBlitz = false

local function CheckIfBGBlitz()
    local instanceType, _, _, _, _, _, _, instanceID = GetInstanceInfo()
    if instanceType == "pvp" and instanceID == 1452 then
        isInBGBlitz = true
    else
        isInBGBlitz = false
    end
end

local function FetchBlitzHonor()
    local brawlType = 1 -- Assuming 1 for Battleground
    local honor, experience, itemRewards, currencyRewards, hasWon = C_PvP.GetBrawlRewards(brawlType)
    return honor or 0
end

local function UpdateBGStatsFrame()
    if not dropdown then return end  -- Ensure dropdown is initialized

    local selectedCharacter = UIDropDownMenu_GetText(dropdown)
    if not selectedCharacter or not IncCalloutDB[selectedCharacter] then return end

    local stats = IncCalloutDB[selectedCharacter]

    tabs[2].bgPlayedValue:SetText(stats.bgPlayed or "N/A")
    tabs[2].bgWonValue:SetText(stats.bgWon or "N/A")
    tabs[2].bgLostValue:SetText(stats.bgLost or "N/A")
    tabs[2].totalHonorableKillsValue:SetText(stats.totalHonorableKills or "N/A")
    tabs[2].battlegroundHonorableKillsValue:SetText(stats.battlegroundHonorableKills or "N/A")
end

local function UpdatePvPStatsFrame()
    if not IsAddOnLoaded("Blizzard_PVPUI") then
        LoadAddOn("Blizzard_PVPUI")
    end

    local conquestInfo = C_CurrencyInfo.GetCurrencyInfo(Constants.CurrencyConsts.CONQUEST_CURRENCY_ID)
    local honorInfo = C_CurrencyInfo.GetCurrencyInfo(HONOR_CURRENCY_ID)
    local honorLevel = UnitHonorLevel("player")

    -- Fetch current specialization index
    local specIndex = GetSpecialization()
    local specId = specIndex and select(1, GetSpecializationInfo(specIndex)) or nil

    -- Fetch Solo Shuffle rating using the index 7
    local index = 7
    local rating = select(2, GetPersonalRatedInfo(index)) or "N/A"

    -- Update conquest points
    local currentConquestPoints = conquestInfo.quantity
    local totalEarnedConquest = conquestInfo.totalEarned
    local weeklyEarnedConquest = conquestInfo.quantityEarnedThisWeek
    local conquestCap = conquestInfo.maxQuantity
    local displayedConquestProgress = math.min(totalEarnedConquest, conquestCap)

    -- Update PvP stats frame with fetched data
    tabs[1].playerNameValue:SetText(UnitName("player"))
    tabs[1].conquestValue:SetText(currentConquestPoints)
    tabs[1].conquestCapValue:SetText(displayedConquestProgress .. " / " .. conquestCap)
    tabs[1].honorValue:SetText(honorInfo.quantity)
    tabs[1].honorLevelValue:SetText(honorLevel)
    tabs[1].soloShuffleRatingValue:SetText(rating)

    -- Adjust PvP UI buttons based on current PvP availability
    local canUseRated = C_PvP.CanPlayerUseRatedPVPUI()
    local canUsePremade = C_LFGInfo.CanPlayerUsePremadeGroup()

    if canUseRated then
        PVPQueueFrame_SetCategoryButtonState(PVPQueueFrame.CategoryButton2, true)
        PVPQueueFrame.CategoryButton2.tooltip = nil
    end

    if canUsePremade then
        PVPQueueFrame_SetCategoryButtonState(PVPQueueFrame.CategoryButton3, true)
        PVPQueueFrame.CategoryButton3.tooltip = nil
    end
end

local function GetDefaultClassColor()
    local _, class = UnitClass("player")
    if class then
        return RAID_CLASS_COLORS[class]
    end
end

local function CreateCharacterDropdown()

    local dropdown = CreateFrame("FRAME", "SelectCharacterDropdown", pvpStatsFrame, "UIDropDownMenuTemplate")
    dropdown:SetPoint("BOTTOMLEFT", pvpStatsFrame, "BOTTOMLEFT", -15, -30)

    UIDropDownMenu_SetWidth(dropdown, 150)
    UIDropDownMenu_SetText(dropdown, "Select Character")

local function OnClick(self)
    UIDropDownMenu_SetSelectedID(dropdown, self:GetID(), true)
    PlaySound(SOUNDKIT.IG_MAINMENU_OPEN)
    local characterFullName = self:GetText()
    local characterNameOnly = string.match(characterFullName, "^[^%-]+")  -- Extracting the character name before the hyphen
    local stats = IncCalloutDB[characterFullName]

    if stats then
        local classColor = RAID_CLASS_COLORS[stats.class]
        tabs[1].playerNameValue:SetText(characterNameOnly)
        tabs[1].playerNameValue:SetTextColor(classColor.r, classColor.g, classColor.b)
        
        tabs[1].conquestValue:SetText(stats.conquestValue or "N/A")
        tabs[1].conquestCapValue:SetText(stats.conquestCapValue or "N/A")
        tabs[1].honorValue:SetText(stats.honorValue or "N/A")
        tabs[1].honorLevelValue:SetText(stats.honorLevelValue or "N/A")
        tabs[1].soloShuffleRatingValue:SetText(stats.soloShuffleRatingValue or "N/A")
        
        tabs[2].bgPlayedValue:SetText(stats.bgPlayed or "N/A")
        tabs[2].bgWonValue:SetText(stats.bgWon or "N/A")
        tabs[2].bgLostValue:SetText(stats.bgLost or "N/A")
        tabs[2].totalHonorableKillsValue:SetText(stats.totalHonorableKills or "N/A")
        tabs[2].battlegroundHonorableKillsValue:SetText(stats.battlegroundHonorableKills or "N/A")
    else
        tabs[1].playerNameValue:SetText(characterNameOnly)
        tabs[1].playerNameValue:SetTextColor(1, 1, 1)  -- Default white color

        tabs[1].conquestValue:SetText("N/A")
        tabs[1].conquestCapValue:SetText("N/A")
        tabs[1].honorValue:SetText("N/A")
        tabs[1].honorLevelValue:SetText("N/A")
        tabs[1].soloShuffleRatingValue:SetText("N/A")
        
        tabs[2].bgPlayedValue:SetText("N/A")
        tabs[2].bgWonValue:SetText("N/A")
        tabs[2].bgLostValue:SetText("N/A")
        tabs[2].totalHonorableKillsValue:SetText("N/A")
        tabs[2].battlegroundHonorableKillsValue:SetText("N/A")
    end
end

local function Initialize(self, level)
    local info = UIDropDownMenu_CreateInfo()
    local selectedCharacter = UIDropDownMenu_GetText(dropdown)  

    for k, v in pairs(IncCalloutDB) do
        if string.match(k, "^[%w]+%-[%w]+$") then
            info.text = k
            info.menuList = k
            info.func = OnClick
            info.checked = (k == selectedCharacter)  
            info.isNotRadio = true  
            UIDropDownMenu_AddButton(info, level)
        end
    end
end

    UIDropDownMenu_Initialize(dropdown, Initialize)
end

CreateCharacterDropdown()

local function SavePvPStats()
    IncCalloutDB = IncCalloutDB or {}
    local character = UnitName("player") .. "-" .. GetRealmName()
    local _, class = UnitClass("player")

    if not IncCalloutDB[character] then
        IncCalloutDB[character] = { class = class }  -- Store class info
    end

    local SavedSettings = IncCalloutDB[character]

    if IsAddOnLoaded("Blizzard_PVPUI") or LoadAddOn("Blizzard_PVPUI") then
        local conquestInfo = C_CurrencyInfo.GetCurrencyInfo(Constants.CurrencyConsts.CONQUEST_CURRENCY_ID)
        local honorInfo = C_CurrencyInfo.GetCurrencyInfo(HONOR_CURRENCY_ID)
        local honorLevel = UnitHonorLevel("player")  

        SavedSettings.conquestValue = conquestInfo.quantity
        SavedSettings.conquestCapValue = math.min(conquestInfo.totalEarned, conquestInfo.maxQuantity) .. " / " .. conquestInfo.maxQuantity
        SavedSettings.honorValue = honorInfo.quantity
        SavedSettings.honorLevelValue = honorLevel  
        SavedSettings.soloShuffleRatingValue = GetPersonalRatedInfo(SOLO_SHUFFLE_INDEX) or "N/A"
        
        -- Save BG Stats
        local bgPlayed, bgWon, bgLost, totalHonorableKills, battlegroundHonorableKills = FetchBGStats()
        SavedSettings.bgPlayed = bgPlayed
        SavedSettings.bgWon = bgWon
        SavedSettings.bgLost = bgLost
        SavedSettings.totalHonorableKills = totalHonorableKills
        SavedSettings.battlegroundHonorableKills = battlegroundHonorableKills
        SavedSettings.blitzHonorValue = FetchBlitzHonor() -- Save Blitz Honor gained
    end
end

pvpStatsFrame:SetScript("OnShow", function()
    local character = UnitName("player") .. "-" .. GetRealmName()
    local stats = IncCalloutDB[character]
    if stats then
        tabs[1].playerNameValue:SetText(UnitName("player") or "Unknown")
        local classColor = GetDefaultClassColor()
        if classColor then
            tabs[1].playerNameValue:SetTextColor(classColor.r, classColor.g, classColor.b)
        end

        tabs[1].conquestValue:SetText(stats.conquestValue or "N/A")
        tabs[1].conquestCapValue:SetText(stats.conquestCapValue or "N/A")
        tabs[1].honorValue:SetText(stats.honorValue or "N/A")
        tabs[1].honorLevelValue:SetText(stats.honorLevelValue or "N/A")
        tabs[1].soloShuffleRatingValue:SetText(stats.soloShuffleRatingValue or "N/A")
        
        tabs[2].bgPlayedValue:SetText(stats.bgPlayed or "N/A")
        tabs[2].bgWonValue:SetText(stats.bgWon or "N/A")
        tabs[2].bgLostValue:SetText(stats.bgLost or "N/A")
        tabs[2].totalHonorableKillsValue:SetText(stats.totalHonorableKills or "N/A")
        tabs[2].battlegroundHonorableKillsValue:SetText(stats.battlegroundHonorableKills or "N/A")
        tabs[2].blitzHonorValue:SetText(FetchBlitzHonor() or "0") -- Initialize Blitz Honor value
    end
    UpdatePvPStatsFrame()
    UpdateBGStatsFrame()
end)

local function EventHandler(self, event, ...)
    if event == "HONOR_XP_UPDATE" or event == "CHAT_MSG_COMBAT_HONOR_GAIN" then
        if isInBGBlitz then
            local honor = FetchBlitzHonor()
            tabs[2].blitzHonorValue:SetText(honor)
        end
    elseif event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_ENTERING_WORLD" then
        CheckIfBGBlitz()
    end
end

pvpStatsFrame:SetScript("OnEvent", EventHandler)
My full test code can be found here: https://github.com/The-Sickness/Test-Repo
  Reply With Quote
05-25-24, 10:37 AM   #2
Sharpedge
A Theradrim Guardian
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 68
I figured it out.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Need some insight on Battleground Blitz Honor tracking


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off