Skip to content

Commit

Permalink
Initial Roll Bonus support
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonomit committed Oct 31, 2022
1 parent 6bf3062 commit d57ab61
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
29 changes: 25 additions & 4 deletions Server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ function LootReserve.Server:Load()
-- 2021-08-28: Convert active session LootCategory to LootCategories
-- Date is late because the check was added late
if versionSave < "2022-05-21" then
if LootReserve.Server.CurrentSession and not LootReserve.Server.CurrentSession.Settings.LootCategories then
LootReserve.Server.CurrentSession.Settings.LootCategories = {LootReserve.Server.CurrentSession.Settings.LootCategory};
LootReserve.Server.NewSessionSettings.LootCategories = {LootReserve.Server.CurrentSession.Settings.LootCategory};
if self.CurrentSession and not self.CurrentSession.Settings.LootCategories then
self.CurrentSession.Settings.LootCategories = {self.CurrentSession.Settings.LootCategory};
self.NewSessionSettings.LootCategories = {self.CurrentSession.Settings.LootCategory};
end
end

Expand Down Expand Up @@ -628,7 +628,7 @@ function LootReserve.Server:Load()

-- 2022-09-25: Remove invalid Loot Categories
if versionSave < "2022-09-25" then
if LootReserve.Server.CurrentSession then
if self.CurrentSession then
local newLootCategories = { };
for _, category in ipairs(self.CurrentSession.Settings.LootCategories or {}) do
if LootReserve.Data.Categories[category] then
Expand All @@ -653,6 +653,20 @@ function LootReserve.Server:Load()
end
end

-- 2022-10-30: Add RollBonus field
if versionSave < "2022-10-30" then
if self.CurrentSession and self.CurrentSession.Members then
for member, memberData in pairs(self.CurrentSession.Members) do
if not memberData.RollBonuses then
memberData.RollBonuses = { };
for _, id in ipairs(memberData.ReservedItems) do
memberData.RollBonuses[id] = 0;
end
end
end
end
end

-- Create Item objects
for _, roll in ipairs(self.RollHistory) do
roll.Item = LootReserve.ItemCache:Item(roll.Item);
Expand Down Expand Up @@ -1668,6 +1682,7 @@ function LootReserve.Server:StartSession()
ReservesLeft = self.CurrentSession.Settings.MaxReservesPerPlayer,
ReservesDelta = 0,
ReservedItems = { ItemID, ItemID, ... },
RollBonuses = { [ItemID] = 0, [ItemID] = 10, ... },
Locked = nil,
OptedOut = nil,
},
Expand Down Expand Up @@ -1718,6 +1733,7 @@ function LootReserve.Server:StartSession()
ReservesLeft = self.CurrentSession.Settings.MaxReservesPerPlayer,
ReservesDelta = 0,
ReservedItems = { },
RollBonuses = { },
Locked = nil,
OptedOut = nil,
};
Expand All @@ -1733,9 +1749,11 @@ function LootReserve.Server:StartSession()
ReservesLeft = self.CurrentSession.Settings.MaxReservesPerPlayer,
ReservesDelta = 0,
ReservedItems = { },
RollBonuses = { },
Locked = nil,
OptedOut = nil,
};
member.RollBonuses = importedMember.RollBonuses;
self.CurrentSession.Members[player] = member;
for _, itemID in ipairs(importedMember.ReservedItems) do
itemID = LootReserve.Data:GetToken(itemID) or itemID;
Expand Down Expand Up @@ -3065,6 +3083,9 @@ function LootReserve.Server:PrepareRequestRoll()
if oldRoll == LootReserve.Constants.RollType.NotRolled then
if not rollSubmitted then
self.RequestedRoll.Players[player][i] = tonumber(roll);
if not self.RequestedRoll.Custom and self.CurrentSession and self.CurrentSession.Members and self.CurrentSession.Members[player] then
self.RequestedRoll.Players[player][i] = self.RequestedRoll.Players[player][i] + self.CurrentSession.Members[player].RollBonuses[self.RequestedRoll.Item:GetID()];
end
rollSubmitted = true;
else
extraRolls = true;
Expand Down
5 changes: 2 additions & 3 deletions Windows/ServerExportWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ function LootReserve.Server.Export:UpdateReservesExportText()
if members and next(members) then
local maxItems = 0
for player, member in LootReserve:Ordered(members, function(aMember, bMember, aPlayer, bPlayer) return aPlayer < bPlayer; end) do
text = text .. format("\n%s,%s,%d", player, member.Class and select(2, LootReserve:GetClassInfo(member.Class)) or "", member.ReservesDelta);
for i, itemID in ipairs(member.ReservedItems) do
text = text .. format(",%d", itemID);
text = text .. format("\n%s,%s,%d,%d", player, member.Class and select(2, LootReserve:GetClassInfo(member.Class)) or "", member.ReservesDelta, itemID);
maxItems = i > maxItems and i or maxItems;
end
end
text = format("Player,Class,Delta%s", string.rep(",Item", maxItems)) .. text;
text = format("Player,Class,Delta%s", string.rep(",Item", maxItems and 1)) .. text;
end
self:SetText(text);
end
Expand Down
22 changes: 18 additions & 4 deletions Windows/ServerImportWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local function ParseMultireserveCount(value)
end
end

local function ParseDelta(value)
local function ParseNumber(value)
if type(value) == "string" then
value = tonumber(value:match("([%+%-]?%d+)"));
end
Expand Down Expand Up @@ -210,7 +210,7 @@ function LootReserve.Server.Import:InputOptionsUpdated()
-- Try to guess if there's a headers row
if self.UseHeaders == nil then
if #self.Rows > 1 then
for _, header in ipairs({"name", "player", "member", "character"}) do
for _, header in ipairs({"name", "player", "member", "character", "delta", "bonus"}) do
for _, cell in ipairs(self.Rows[1]) do
if tostring(cell):lower():match(header) then
self.UseHeaders = true;
Expand Down Expand Up @@ -248,10 +248,12 @@ function LootReserve.Server.Import:InputOptionsUpdated()
break;
end
end
elseif header:find("delta") then
elseif header:find("delta") or header:find("reservebonus") then
self.Columns[i] = "Delta"
elseif header:find("class") then
self.Columns[i] = "Class";
elseif header:find("rollbonus") then
self.Columns[i] = "RollBonus";
end
end
end
Expand Down Expand Up @@ -324,6 +326,7 @@ function LootReserve.Server.Import:SessionSettingsUpdated()
row.Count = nil;
row.Delta = nil;
row.Class = nil;
row.Bonus = nil;
for i, column in ipairs(self.Columns) do
if column == "Count" and row[i] then
if not row.Count then
Expand All @@ -334,7 +337,7 @@ function LootReserve.Server.Import:SessionSettingsUpdated()
end
if column == "Delta" and row[i] then
if not row.Delta then
row.Delta = ParseDelta(row[i]);
row.Delta = ParseNumber(row[i]);
else
return "Only one column can be marked as \"Delta\"";
end
Expand All @@ -346,6 +349,13 @@ function LootReserve.Server.Import:SessionSettingsUpdated()
return "Only one column can be marked as \"Class\"";
end
end
if column == "RollBonus" and row[i] then
if not row.Bonus then
row.Bonus = ParseNumber(row[i]);
else
return "Only one column can be marked as \"RollBonus\"";
end
end
end
end

Expand Down Expand Up @@ -416,6 +426,7 @@ function LootReserve.Server.Import:SessionSettingsUpdated()
{
NameMatchResult = nameMatchResult,
ReservedItems = { },
RollBonuses = { },
InvalidReasons = { },
ReservesDelta = nil,
Class = nil,
Expand All @@ -427,6 +438,7 @@ function LootReserve.Server.Import:SessionSettingsUpdated()
end
for i = 1, (row.Count or 1) * itemCount * playerCount do
table.insert(member.ReservedItems, itemID);
member.RollBonuses[itemID] = row.Bonus or 0;
itemReserveCount[itemID] = (itemReserveCount[itemID] or 0) + 1;
itemReserveCountByPlayer[player] = itemReserveCountByPlayer[player] or { };
itemReserveCountByPlayer[player][itemID] = (itemReserveCountByPlayer[player][itemID] or 0) + 1;
Expand Down Expand Up @@ -568,6 +580,7 @@ function LootReserve.Server.Import:Import()
ReservesLeft = nil,
ReservesDelta = 0,
ReservedItems = { },
RollBonuses = member.RollBonuses,
Locked = nil,
OptedOut = nil,
};
Expand All @@ -580,6 +593,7 @@ function LootReserve.Server.Import:Import()
ReservesLeft = nil,
ReservesDelta = 0,
ReservedItems = { },
RollBonuses = member.RollBonuses,
Locked = nil,
OptedOut = nil,
};
Expand Down
2 changes: 1 addition & 1 deletion Windows/ServerImportWindow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<Frame name="LootReserveServerImportOptionColumnTemplate" virtual="true" inherits="LootReserveServerImportOptionTemplate" parentArray="Columns">
<KeyValues>
<KeyValue key="field" type="string" value="Columns" />
<KeyValue key="values" type="string" value="|cFF808080Unused|r=Unused$Player$Item$Count$Delta$Class" />
<KeyValue key="values" type="string" value="|cFF808080Unused|r=Unused$Player$Item$Count$Delta$Class$Bonus" />
<KeyValue key="width" type="number" value="65" />
<KeyValue key="justify" type="string" value="LEFT" />
</KeyValues>
Expand Down

0 comments on commit d57ab61

Please sign in to comment.