diff --git a/Constants.lua b/Constants.lua index 875da68..b4b4a8a 100644 --- a/Constants.lua +++ b/Constants.lua @@ -25,6 +25,8 @@ LootReserve.Constants.ReserveResult = { FailedLimit = 15, FailedLimitPartial = 16, FailedUsable = 17, + FailedGuild = 18, + FailedGuildRank = 19, }; LootReserve.Constants.CancelReserveResult = { OK = 0, @@ -389,6 +391,8 @@ LootReserve.Constants.ReserveResultText = [result.FailedLimit] = "That item has reached the limit of reserves", [result.FailedLimitPartial] = "Not all of your reserves were accepted because the item reached the limit of reserves", [result.FailedUsable] = "You may not reserve unusable items", + [result.FailedGuild] = "That item is not reservable if you're not member of the hosts guild", + [result.FailedGuildRank] = "This item is not reservable on your guildrank", }; local result = LootReserve.Constants.CancelReserveResult; diff --git a/ItemConditions.lua b/ItemConditions.lua index d0ec879..d2d84d3 100644 --- a/ItemConditions.lua +++ b/ItemConditions.lua @@ -8,6 +8,9 @@ local DefaultConditions = Faction = nil, ClassMask = nil, Limit = nil, + OnlyGuild = nil, + Guild = nil, + MinimumGuildRank = nil }; function LootReserve.ItemConditions:Get(itemID, server) @@ -61,6 +64,14 @@ function LootReserve.ItemConditions:Save(itemID, server) if conditions.Limit and conditions.Limit <= 0 then conditions.Limit = nil; end + if conditions.OnlyGuild == false then + conditions.OnlyGuild = nil; + conditions.Guild = nil; + conditions.MinimumGuildRank = nil; + end + if conditions.MinimumGuildRank and conditions.MinimumGuildRank >= 11 then + conditions.MinimumGuildRank = nil; + end end -- If conditions are no different from the default - delete the table @@ -299,6 +310,20 @@ function LootReserve.ItemConditions:TestFaction(faction) return faction and UnitFactionGroup("player") == faction; end +function LootReserve.ItemConditions:TestGuild(onlyGuild, server, player) + -- if server then check if player variable same as guild otherwise check if server is in my guild + if server then + return onlyGuild and UnitIsInMyGuild(player) + end + return onlyGuild and UnitIsInMyGuild(LootReserve.Client.SessionServer); +end + +function LootReserve.ItemConditions:TestGuildRank(minimumGuildRank, player) + -- C_GuildInfo.GetGuildRankOrder(UnitGUID(player)) usable on infinite range + local guildRankTesterino = C_GuildInfo.GetGuildRankOrder(UnitGUID(player)); + return minimumGuildRank and tonumber(guildRankTesterino) <= tonumber(minimumGuildRank); +end + function LootReserve.ItemConditions:TestLimit(limit, itemID, player, server) if limit <= 0 then -- Has no limiton the number of reserves @@ -355,6 +380,15 @@ function LootReserve.ItemConditions:TestPlayer(player, itemID, server) if conditions and conditions.Limit and not self:TestLimit(conditions.Limit, itemID, player, server) then return false, LootReserve.Constants.ReserveResult.FailedLimit; end + if conditions and conditions.OnlyGuild then + if self:TestGuild(conditions.OnlyGuild, server, player) then + if conditions.MinimumGuildRank and not self:TestGuildRank(conditions.MinimumGuildRank, player) then + return false, LootReserve.Constants.ReserveResult.FailedGuildRank; + end + else + return false, LootReserve.Constants.ReserveResult.FailedGuild; + end + end return true; end @@ -408,6 +442,12 @@ function LootReserve.ItemConditions:Pack(conditions) if conditions.Limit and conditions.Limit ~= 0 then text = text .. "L" .. conditions.Limit; end + if conditions.OnlyGuild == true then + text = text .. "G"; + if conditions.MinimumGuildRank and conditions.MinimumGuildRank < 11 then + text = text.. "R" .. conditions.MinimumGuildRank; + end + end return text; end @@ -442,6 +482,18 @@ function LootReserve.ItemConditions:Unpack(text) break; end end + elseif char == "G" then + conditions.OnlyGuild = true; + if text:sub(i+1, i+1) == "R" then + for len = 1, 10 do + local rank = text:sub(i + 2, i + 1 + len); + if tonumber(rank) then + conditions.MinimumGuildRank = rank; + else + break; + end + end + end end end return conditions; diff --git a/LootReserve.lua b/LootReserve.lua index f2e295f..c73eb70 100644 --- a/LootReserve.lua +++ b/LootReserve.lua @@ -1,4 +1,4 @@ -local addon, ns = ...; +local addon, ns = ...; LootReserve = LibStub("AceAddon-3.0"):NewAddon("LootReserve", "AceComm-3.0"); LootReserve.Version = GetAddOnMetadata(addon, "Version"); @@ -348,6 +348,10 @@ function LootReserve:GetNumClasses() return 11; end +function LootReserve:GetNumGuildRanks() + return GuildControlGetNumRanks() +end + function LootReserve:GetClassInfo(classID) local info = C_CreatureInfo.GetClassInfo(classID); if info then diff --git a/Windows/ServerLootEditWindow.lua b/Windows/ServerLootEditWindow.lua index d7ce11c..3e0a328 100644 --- a/Windows/ServerLootEditWindow.lua +++ b/Windows/ServerLootEditWindow.lua @@ -83,6 +83,7 @@ function LootReserve.Server.LootEdit:UpdateLootList() frame.ConditionsFrame.ClassMask:Update(); frame.ConditionsFrame.State:Update(); frame.ConditionsFrame.Limit:Update(); + frame.ConditionsFrame.OnlyGuild:Update(); frame.ConditionsFrame.LimitNoHover:Update(); frame.hovered = nil; end diff --git a/Windows/ServerLootEditWindow.xml b/Windows/ServerLootEditWindow.xml index 8d27571..6446ca4 100644 --- a/Windows/ServerLootEditWindow.xml +++ b/Windows/ServerLootEditWindow.xml @@ -6,14 +6,14 @@ - + - + @@ -21,7 +21,7 @@ + + + + + + @@ -339,6 +421,7 @@ local hovered = self:IsMouseOver() and self:GetParent():GetParent():IsMouseOver() and not UIDROPDOWNMENU_OPEN_MENU and not LootReserve.Server.LootEdit.FocusedEditBox or UIDROPDOWNMENU_OPEN_MENU == self.ConditionsFrame.ClassMaskMenu + or UIDROPDOWNMENU_OPEN_MENU == self.ConditionsFrame.GuildRankMenu or self.ConditionsFrame.Limit.EditBox:HasFocus(); if self.hovered ~= hovered then self.hovered = hovered; @@ -349,6 +432,8 @@ self.ConditionsFrame.State:SetEnabled(hovered and not self.ConditionsFrame.State.disabled); self.ConditionsFrame.State:SetShown(hovered or self.ConditionsFrame.State.shown); self.ConditionsFrame.Limit:SetShown(hovered and self.ConditionsFrame.Limit.shown and not self.ConditionsFrame.State.disabled); + self.ConditionsFrame.OnlyGuild:SetEnabled(hovered); + self.ConditionsFrame.OnlyGuild:SetShown(hovered or not self.ConditionsFrame.OnlyGuild.any); self.ConditionsFrame.LimitNoHover:SetShown(not hovered and self.ConditionsFrame.LimitNoHover.shown and not self.ConditionsFrame.State.disabled); self.ConditionsFrame:Update(); for _, part in ipairs(self.ConditionBackgrounds) do @@ -741,4 +826,4 @@ - \ No newline at end of file +