From 70204d639c27bce0034582aa41039bd2fe22cc3d Mon Sep 17 00:00:00 2001 From: Anonomit Date: Mon, 17 Jun 2024 18:47:25 -0400 Subject: [PATCH] Show how many players have completed their reserves in the Reserves window --- Comm.lua | 74 +++++++++++++++++++++++++++++++++++++--- Server.lua | 12 +++++++ Windows/ClientWindow.lua | 9 ++++- 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/Comm.lua b/Comm.lua index 643eb11..cb1c197 100644 --- a/Comm.lua +++ b/Comm.lua @@ -29,6 +29,7 @@ local Opcodes = OptResult = 17, OptInfo = 18, SendWinner = 19, + ReservesTotalMissing = 20, }; local LAST_UNCOMPRESSED_OPCODE = Opcodes.Hello; @@ -320,6 +321,17 @@ function LootReserve.Comm:SendSessionInfo(target, starting) for i, category in ipairs(session.Settings.LootCategories) do lootCategories = format("%s%s%s", lootCategories, i == 1 and "" or ";", category); end + + local missing = 0; + local total = 0; + if LootReserve.Server.CurrentSession then + for player, member in pairs(LootReserve.Server.CurrentSession.Members) do + total = total + 1; + if member.ReservesLeft > 0 and not member.OptedOut then + missing = missing + 1; + end + end + end LootReserve.Comm:Send(realTarget, Opcodes.SessionInfo, starting == true, @@ -334,9 +346,11 @@ function LootReserve.Comm:SendSessionInfo(target, starting) session.Settings.Equip, session.Settings.Blind, session.Settings.Multireserve or 1, - optInfo); + optInfo, + total, + missing); end -LootReserve.Comm.Handlers[Opcodes.SessionInfo] = function(sender, starting, startTime, acceptingReserves, membersInfo, lootCategories, duration, maxDuration, itemReserves, itemConditions, equip, blind, multireserve, optInfo) +LootReserve.Comm.Handlers[Opcodes.SessionInfo] = function(sender, starting, startTime, acceptingReserves, membersInfo, lootCategories, duration, maxDuration, itemReserves, itemConditions, equip, blind, multireserve, optInfo, total, missing) starting = tonumber(starting) == 1; startTime = tonumber(startTime); acceptingReserves = tonumber(acceptingReserves) == 1; @@ -346,6 +360,8 @@ LootReserve.Comm.Handlers[Opcodes.SessionInfo] = function(sender, starting, star blind = tonumber(blind) == 1; multireserve = tonumber(multireserve); multireserve = math.max(1, multireserve); + total = tonumber(total); + missing = tonumber(missing); if LootReserve.Client.SessionServer and LootReserve.Client.SessionServer ~= sender and LootReserve.Client.StartTime > startTime then LootReserve:ShowError("%s is attempting to broadcast their older loot reserve session, but you're already connected to %s.|n|nPlease tell %s that they need to reset their session.", LootReserve:ColoredPlayer(sender), LootReserve:ColoredPlayer(LootReserve.Client.SessionServer), LootReserve:ColoredPlayer(sender)); @@ -416,6 +432,9 @@ LootReserve.Comm.Handlers[Opcodes.SessionInfo] = function(sender, starting, star LootReserve.Client.ItemConditions[tonumber(itemID)] = LootReserve.ItemConditions:Unpack(packed); end end + + LootReserve.Client.TotalReserves = total; + LootReserve.Client.CompleteReserves = total - missing; LootReserve.Client:UpdateCategories(); LootReserve.Client:UpdateLootList(); @@ -476,6 +495,34 @@ LootReserve.Comm.Handlers[Opcodes.OptInfo] = function(sender, out) LootReserve.Client.Window:PendOpen(); end +-- ReservesTotalMissing +function LootReserve.Comm:BroadcastReservesTotalMissing() + local missing = 0; + local total = 0; + if LootReserve.Server.CurrentSession then + for player, member in pairs(LootReserve.Server.CurrentSession.Members) do + total = total + 1; + if member.ReservesLeft > 0 and not member.OptedOut then + missing = missing + 1; + end + end + end + + LootReserve.Comm:Broadcast(Opcodes.ReservesTotalMissing, + total, + missing); +end +LootReserve.Comm.Handlers[Opcodes.ReservesTotalMissing] = function(sender, total, missing) + total = tonumber(total); + missing = tonumber(missing); + + if LootReserve.Client.SessionServer == sender then + LootReserve.Client.TotalReserves = total; + LootReserve.Client.CompleteReserves = total - missing; + LootReserve.Client:UpdateCategories(); + end +end + -- Opt Out function LootReserve.Comm:SendOptOut() LootReserve.Comm:WhisperServer(Opcodes.OptOut); @@ -601,14 +648,33 @@ function LootReserve.Comm:BroadcastReserveInfo(itemID, players) LootReserve.Comm:SendReserveInfo(nil, itemID, players); end function LootReserve.Comm:SendReserveInfo(target, itemID, players) + local missing = 0; + local total = 0; + if LootReserve.Server.CurrentSession then + for player, member in pairs(LootReserve.Server.CurrentSession.Members) do + total = total + 1; + if member.ReservesLeft > 0 and not member.OptedOut then + missing = missing + 1; + end + end + end + LootReserve.Comm:Send(target, Opcodes.ReserveInfo, itemID, - strjoin(",", unpack(players))); + strjoin(",", unpack(players)), + total, + missing); end -LootReserve.Comm.Handlers[Opcodes.ReserveInfo] = function(sender, itemID, players) +LootReserve.Comm.Handlers[Opcodes.ReserveInfo] = function(sender, itemID, players, total, missing) itemID = tonumber(itemID); + total = tonumber(total); + missing = tonumber(missing); if LootReserve.Client.SessionServer == sender then + LootReserve.Client.TotalReserves = total; + LootReserve.Client.CompleteReserves = total - missing; + LootReserve.Client:UpdateCategories(); + local wasReserver = LootReserve.Client:IsItemReservedByMe(itemID, true); if #players > 0 then diff --git a/Server.lua b/Server.lua index 6b54518..845953e 100644 --- a/Server.lua +++ b/Server.lua @@ -1237,6 +1237,8 @@ function LootReserve.Server:PrepareGuildTracking() end function LootReserve.Server:UpdateGroupMembers() + local changed = false; + if self.CurrentSession then -- Remove member info for players who left with no reserves local leavers = { }; @@ -1251,6 +1253,7 @@ function LootReserve.Server:UpdateGroupMembers() end for _, player in ipairs(leavers) do + changed = true; self.CurrentSession.Members[player] = nil; self.MembersEdit:UpdateMembersList(); end @@ -1258,6 +1261,7 @@ function LootReserve.Server:UpdateGroupMembers() -- Add member info for players who joined LootReserve:ForEachRaider(function(name, _, _, _, _, _, _, _, _, _, _, _, index) if not self.CurrentSession.Members[name] then + changed = true; self.CurrentSession.Members[name] = { Class = select(3, LootReserve:UnitClass(index)), @@ -1276,6 +1280,12 @@ function LootReserve.Server:UpdateGroupMembers() end end); end + + if changed then + -- send updated info to client about how many reserves are complete + LootReserve.Comm:BroadcastReservesTotalMissing(); + end + self:UpdateReserveList(); self:UpdateRollList(); self:UpdateAddonUsers(); @@ -2330,6 +2340,7 @@ function LootReserve.Server:Reserve(player, itemID, count, chat, skipChecks) if masquerade then LootReserve.Comm:SendReserveInfo(masquerade, itemID, LootReserve:RepeatedTable(player, myReserves)); end + LootReserve.Comm:BroadcastReservesTotalMissing(); else LootReserve.Comm:BroadcastReserveInfo(itemID, reserve.Players); end @@ -2486,6 +2497,7 @@ function LootReserve.Server:CancelReserve(player, itemID, count, chat, forced, w if masquerade then LootReserve.Comm:SendReserveInfo(masquerade, itemID, LootReserve:RepeatedTable(player, myReserves)); end + LootReserve.Comm:BroadcastReservesTotalMissing(); else LootReserve.Comm:BroadcastReserveInfo(itemID, reserve.Players); end diff --git a/Windows/ClientWindow.lua b/Windows/ClientWindow.lua index d784af9..e2ae476 100644 --- a/Windows/ClientWindow.lua +++ b/Windows/ClientWindow.lua @@ -547,7 +547,14 @@ function LootReserve.Client:UpdateCategories() end frame.Text:SetText(format(categoryCollapsed and "|cFF806900%s|r" or "%s", category.Name)); else - frame.Text:SetText(category.IndentType == 1 and (" - " .. category.Name) or category.IndentType == 2 and (" + " .. category.Name) or category.Name); + local indent = category.IndentType == 1 and " - " or category.IndentType == 2 and " + " or ""; + local name = indent .. category.Name; + + if category.Reserves == "all" and self.SessionServer and self.AcceptingReserves then + name = format("%s (%d/%d)", name, self.CompleteReserves, self.TotalReserves); + end + + frame.Text:SetText(name); frame:RegisterForClicks("LeftButtonDown"); frame:SetScript("OnClick", function(frame) self:OnCategoryClick(frame); end); end