Skip to content

Commit

Permalink
Show how many players have completed their reserves in the Reserves w…
Browse files Browse the repository at this point in the history
…indow
  • Loading branch information
Anonomit committed Jun 17, 2024
1 parent 10a084c commit 70204d6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
74 changes: 70 additions & 4 deletions Comm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local Opcodes =
OptResult = 17,
OptInfo = 18,
SendWinner = 19,
ReservesTotalMissing = 20,
};

local LAST_UNCOMPRESSED_OPCODE = Opcodes.Hello;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { };
Expand All @@ -1251,13 +1253,15 @@ function LootReserve.Server:UpdateGroupMembers()
end

for _, player in ipairs(leavers) do
changed = true;
self.CurrentSession.Members[player] = nil;
self.MembersEdit:UpdateMembersList();
end

-- 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)),
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion Windows/ClientWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70204d6

Please sign in to comment.