Add files via upload

This commit is contained in:
Relationship
2026-07-13 23:24:30 +01:00
committed by GitHub
parent 147375b056
commit d03a61938f
3 changed files with 138 additions and 30 deletions
+113 -9
View File
@@ -65,20 +65,45 @@ local function NewStatBlock()
return {
wins = 0, draws = 0, losses = 0,
kills = 0, deaths = 0, hk = 0,
marks = 0, honor = 0,
marks = 0, honor = 0, spend = 0,
bestKB = 0, streak = 0, bestStreak = 0,
}
end
-- Read the player's current spendable honor from the honor UI ("H" panel).
-- Turtle / OctoWoW (1.18.1+) credits honor immediately as a currency; the
-- value shown at the top of the honor panel is the this-week honor total
-- returned by GetPVPThisWeekStats(). Fall back to session/lifetime stats
-- and finally GetHonorCurrency() for other clients.
local function GetSpendableHonor()
if type(GetPVPThisWeekStats) == "function" then
local hk, honor = GetPVPThisWeekStats()
if honor then return honor end
end
if type(GetPVPSessionStats) == "function" then
local hk, honor = GetPVPSessionStats()
if honor then return honor end
end
if type(GetHonorCurrency) == "function" then
return GetHonorCurrency() or 0
end
return nil
end
local function EnsureDB()
local db = RelationshipsPVPCharDB
db.stats = db.stats or {}
db.icon = db.icon or { point = "CENTER", x = 60, y = -60 }
if db.showIcon == nil then db.showIcon = true end
-- Snapshot of spendable honor captured on BG entry:
-- { key = <BG_KEY>, value = <spendable honor when we entered> }
-- Persisted so a disconnect/relog mid-BG still resolves to a correct delta.
db.honorSnap = db.honorSnap or nil
for i = 1, table.getn(ALL_KEYS) do
local k = ALL_KEYS[i]
local s = db.stats[k] or NewStatBlock()
if s.honor == nil then s.honor = 0 end
if s.spend == nil then s.spend = 0 end
if s.bestKB == nil then s.bestKB = 0 end
if s.streak == nil then s.streak = 0 end
if s.bestStreak == nil then s.bestStreak = 0 end
@@ -90,6 +115,51 @@ local function EnsureDB()
return db
end
-- Capture the pre-match spendable-honor value on BG entry.
local function CaptureSpendableHonor(key)
if not key then return end
local db = EnsureDB()
if db.honorSnap and db.honorSnap.key == key then return end
local v = GetSpendableHonor()
if v == nil then return end
db.honorSnap = { key = key, value = v, credited = 0 }
end
-- Add any new delta between the current spendable-honor value and the
-- snapshot into the BG's spend total. Idempotent: tracks how much has
-- already been credited so RecordEnd + the on-leave transition together
-- never double-count. `clear` = true removes the snapshot afterwards.
local function FinalizeSpendableHonor(key, clear)
if not key then return end
local db = RelationshipsPVPCharDB
if not db or not db.honorSnap or db.honorSnap.key ~= key then return end
local now = GetSpendableHonor()
if now == nil then
if clear then db.honorSnap = nil end
return
end
local base = db.honorSnap.value or 0
local prior = db.honorSnap.credited or 0
local delta = (now - base) - prior
if delta < 0 then delta = 0 end
if delta > 0 then
local s = db.stats and db.stats[key]
if s then s.spend = (s.spend or 0) + delta end
db.honorSnap.credited = prior + delta
end
if clear then db.honorSnap = nil end
end
-- Handle a currentBG transition: capture on enter, finalize on leave.
local function OnCurrentBGChanged(prevKey, newKey)
if newKey and newKey ~= prevKey then
if prevKey then FinalizeSpendableHonor(prevKey, true) end
CaptureSpendableHonor(newKey)
elseif prevKey and not newKey then
FinalizeSpendableHonor(prevKey, true)
end
end
-- Clamp a UIParent-relative CENTER offset so the button stays visible on screen.
function RelationshipsPVP_ClampScreenOffset(x, y)
x = x or 0
@@ -341,6 +411,11 @@ local function RecordEnd(key, index)
end
end
-- Roll up any spendable honor gained so far this match. Snapshot is
-- kept until the currentBG->nil transition so late-credit ticks
-- (e.g. end-of-match bonus) still count.
FinalizeSpendableHonor(key, false)
RequestBattlefieldScoreData()
local me = UnitName("player")
local rows = GetNumBattlefieldScores() or 0
@@ -814,10 +889,10 @@ end
---------------------------------------------------------------
-- UI: build row FontStrings inside the stats panel
---------------------------------------------------------------
local COL_X = { 14, 158, 208, 258, 308, 358, 408, 454, 500, 550, 604, 668 }
local COL_W = { 140, 46, 46, 46, 46, 46, 46, 46, 46, 50, 60, 58 }
local COL_J = { "LEFT", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER" }
local COL_NAMES = { "bg", "games", "win", "draw", "loss", "ratio", "kb", "hk", "dth", "kd", "honor", "mk" }
local COL_X = { 14, 158, 208, 258, 308, 358, 408, 458, 508, 558, 612, 668, 740 }
local COL_W = { 140, 46, 46, 46, 46, 46, 46, 46, 46, 50, 54, 70, 100 }
local COL_J = { "LEFT", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER" }
local COL_NAMES = { "bg", "games", "win", "draw", "loss", "ratio", "kb", "hk", "dth", "kd", "mk", "bonus", "spend" }
local ROW_HEIGHT = 22
local ROW_TOP = -34
@@ -827,7 +902,7 @@ local function MakeRow(panel, tag, yOff, striped)
if striped then
local bg = panel:CreateTexture("RPVPRowBG"..tag, "BACKGROUND")
bg:SetTexture(1, 1, 1, 0.04)
bg:SetWidth(714); bg:SetHeight(ROW_HEIGHT - 2)
bg:SetWidth(846); bg:SetHeight(ROW_HEIGHT - 2)
bg:SetPoint("TOPLEFT", panel, "TOPLEFT", 14, yOff + 2)
end
for c = 1, table.getn(COL_NAMES) do
@@ -863,7 +938,7 @@ local function BuildStatsRows()
local totalY = ROW_TOP - n * ROW_HEIGHT - 4
local div = panel:CreateTexture("RPVPTotalDivider", "ARTWORK")
div:SetTexture(1, 1, 1, 0.25)
div:SetWidth(714); div:SetHeight(1)
div:SetWidth(846); div:SetHeight(1)
div:SetPoint("TOPLEFT", panel, "TOPLEFT", 14, totalY + 2)
totalRow = MakeRow(panel, "TOTAL", totalY - 6, false)
@@ -918,8 +993,16 @@ local function FillRow(r, s)
r.hk:SetText(s.hk)
r.dth:SetText(s.deaths)
r.kd:SetText(kd)
r.honor:SetText(FormatNumber(s.honor))
r.mk:SetText(s.marks)
-- Bonus honor is the honor gained from the battlefield scoreboard
-- (GetBattlefieldScore -> honorGained). Tracked per-match, per-bracket.
r.bonus:SetText(FormatNumber(s.honor or 0))
r.bonus:SetTextColor(0.6, 0.85, 1.0)
-- Spendable honor is measured as the delta of the honor UI ("H" panel)
-- from BG entry -> BG exit. This is the honor actually credited to the
-- character wallet for this BG, tracked per-player from the client.
r.spend:SetText(FormatNumber(s.spend or 0))
r.spend:SetTextColor(1.0, 0.82, 0.0)
if games == 0 then
r.ratio:SetTextColor(0.7, 0.7, 0.7)
@@ -951,6 +1034,7 @@ function RelationshipsPVP_Refresh()
totals.hk = totals.hk + s.hk
totals.deaths = totals.deaths + s.deaths
totals.honor = totals.honor + s.honor
totals.spend = (totals.spend or 0) + (s.spend or 0)
totals.marks = totals.marks + s.marks
if s.bestStreak > totals.bestStreak then totals.bestStreak = s.bestStreak end
if s.bestKB > totals.bestKB then totals.bestKB = s.bestKB end
@@ -962,7 +1046,8 @@ function RelationshipsPVP_Refresh()
RelationshipsPVPExtrasText:SetText(
"|cffffd200Best win streak:|r " .. totals.bestStreak
.. " |cffffd200Best KBs (single match):|r " .. totals.bestKB
.. " |cffffd200Total honor:|r " .. FormatNumber(totals.honor)
.. " |cffffd200Total bonus honor:|r |cffffd100" .. FormatNumber(totals.honor or 0) .. "|r"
.. " |cffffd200Total spendable honor:|r |cffffd100" .. FormatNumber(totals.spend or 0) .. "|r"
)
end
@@ -1023,6 +1108,9 @@ function RelationshipsPVP_OnLoad()
this:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
this:RegisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE")
this:RegisterEvent("CHAT_MSG_BG_SYSTEM_HORDE")
this:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN")
this:RegisterEvent("PLAYER_PVP_KILLS_CHANGED")
this:RegisterEvent("HONOR_CURRENCY_UPDATE")
SLASH_RELATIONSHIPSPVP1 = "/rpvp"
SLASH_RELATIONSHIPSPVP2 = "/relpvp"
@@ -1081,13 +1169,17 @@ function RelationshipsPVP_OnEvent(event)
RestoreIconPos()
RestorePanelPos()
local key = DetectCurrentBG()
local prev = currentBG
currentBG = key
OnCurrentBGChanged(prev, key)
if not key then endReported = {} end
RelationshipsPVP_Refresh()
elseif event == "UPDATE_BATTLEFIELD_STATUS" then
local key = DetectCurrentBG()
local prev = currentBG
currentBG = key
OnCurrentBGChanged(prev, key)
RelationshipsPVP_Refresh()
elseif event == "UPDATE_BATTLEFIELD_SCORE" then
@@ -1104,5 +1196,17 @@ function RelationshipsPVP_OnEvent(event)
or event == "CHAT_MSG_BG_SYSTEM_ALLIANCE"
or event == "CHAT_MSG_BG_SYSTEM_HORDE" then
RequestBattlefieldScoreData()
elseif event == "CHAT_MSG_COMBAT_HONOR_GAIN"
or event == "PLAYER_PVP_KILLS_CHANGED"
or event == "HONOR_CURRENCY_UPDATE" then
-- Honor was just credited. If we're currently in a tracked BG, roll
-- the spendable-honor delta into this BG's spend total right away so
-- the value ticks live instead of only at the final scoreboard.
if currentBG then
CaptureSpendableHonor(currentBG)
FinalizeSpendableHonor(currentBG, false)
RelationshipsPVP_Refresh()
end
end
end