diff --git a/Localization/Localization.en.lua b/Localization/Localization.en.lua index fb1386f8..dfe7a6e2 100644 --- a/Localization/Localization.en.lua +++ b/Localization/Localization.en.lua @@ -811,6 +811,8 @@ core.L = { CONFIRMMIGRATE = "Are you certain you wish to be the officer conducting the migration? This is a non-reversable process.", AUTOOPEN = "Auto Open Bid Window", AUTOOPENTTDESC = "When checked, bidding window will automatically open when a new item is being auctioned. If unchecked, you will be required to open it manually when needed with \"/dkp bid\".", + AUTOAWARDLOOT = "Auto Award Loot", + AUTOAWARDLOOTDESC = "When checked loot will be automatically awarded to the winner. If looting they will be master looted to the winner. If awarding from your bags they will be inserted into the next trade window with the winner.", DECREASEDISENCHANT = "Decrease Disenchant Value", DECREASEDISENCHANTTTDESC = "Decrease Disenchant Value after 3 disenchants by half every disenchant afterwards until a minimum of 5 DKP", DELETETABLES = "Delete Tables", diff --git a/Modules/Award.lua b/Modules/Award.lua index 2c68c18d..5a9de569 100644 --- a/Modules/Award.lua +++ b/Modules/Award.lua @@ -234,6 +234,42 @@ local function AwardItem(player, cost, boss, zone, loot, reassign) SendChatMessage(L["CONGRATS"].." "..winner.." "..L["ON"].." "..loot.." @ "..-cost.." "..L["DKP"], "GUILD") end + if core.DB.defaults.AutoAwardLoot then + local numLootItems = GetNumLootItems() + if numLootItems > 0 then + local lootIndex = nil + for i = 1, numLootItems do + local lootLink = GetLootSlotLink(i) + if lootIndex == nil and lootLink ~= nil and lootLink == loot then + lootIndex = i + end + end + + local candidateIndex = nil + local maxGroupMembers = MAX_RAID_MEMBERS + if not IsInRaid() then maxGroupMembers = MAX_PARTY_MEMBERS end + for i = 1, maxGroupMembers do + local candidate = GetMasterLootCandidate(lootIndex, i) + if candidateIndex == nil and candidate ~= nil and candidate == winner then + candidateIndex = i + end + end + + if lootIndex ~= nil and candidateIndex ~= nil then + GiveMasterLoot(lootIndex, candidateIndex) + end + else + if core.DB.pendingLoot == nil then + core.DB.pendingLoot = {} + end + if core.DB.pendingLoot[winner] == nil then + core.DB.pendingLoot[winner] = {} + end + tinsert(core.DB.pendingLoot[winner], loot) + InitiateTrade(winner) + end + end + end end diff --git a/Modules/Options.lua b/Modules/Options.lua index 3913917e..acbbf179 100644 --- a/Modules/Options.lua +++ b/Modules/Options.lua @@ -1182,6 +1182,29 @@ function CommDKP:Options() end) if core.IsOfficer == true then + CommDKP.ConfigTab4.AutoAwardLootCheckbox = CreateFrame("CheckButton", nil, CommDKP.ConfigTab4, "UICheckButtonTemplate"); + CommDKP.ConfigTab4.AutoAwardLootCheckbox:SetChecked(core.DB.defaults.AutoAwardLoot) + CommDKP.ConfigTab4.AutoAwardLootCheckbox:SetScale(0.8); + CommDKP.ConfigTab4.AutoAwardLootCheckbox.text:SetText("|cff5151de"..L["AUTOAWARDLOOT"].."|r"); + CommDKP.ConfigTab4.AutoAwardLootCheckbox.text:SetScale(1); + CommDKP.ConfigTab4.AutoAwardLootCheckbox.text:SetFontObject("CommDKPSmallLeft") + CommDKP.ConfigTab4.AutoAwardLootCheckbox:SetPoint("TOP", CommDKP.ConfigTab4.AutoOpenCheckbox, "BOTTOM", 0, 0); + CommDKP.ConfigTab4.AutoAwardLootCheckbox:SetScript("OnClick", function(self) + core.DB.defaults.AutoAwardLoot = self:GetChecked() + if core.DB.defaults.AutoAwardLoot == false then + core.DB.pendingLoot = {} + end + end) + CommDKP.ConfigTab4.AutoAwardLootCheckbox:SetScript("OnEnter", function(self) + GameTooltip:SetOwner(self, "ANCHOR_LEFT"); + GameTooltip:SetText(L["AUTOAWARDLOOT"], 0.25, 0.75, 0.90, 1, true); + GameTooltip:AddLine(L["AUTOAWARDLOOTDESC"], 1.0, 1.0, 1.0, true); + GameTooltip:Show(); + end) + CommDKP.ConfigTab4.AutoAwardLootCheckbox:SetScript("OnLeave", function(self) + GameTooltip:Hide() + end) + -- Suppress Broadcast Notifications checkbox CommDKP.ConfigTab4.SuppressTells = CreateFrame("CheckButton", nil, CommDKP.ConfigTab4, "UICheckButtonTemplate"); CommDKP.ConfigTab4.SuppressTells:SetPoint("LEFT", CommDKP.ConfigTab4.SuppressNotifications, "RIGHT", 200, 0) diff --git a/init.lua b/init.lua index 990293d0..4819990c 100644 --- a/init.lua +++ b/init.lua @@ -615,6 +615,71 @@ function CommDKP_OnEvent(self, event, arg1, ...) CommDKP:LootTable_Set(lootList) end end + elseif core.DB.defaults.AutoAwardLoot and event == "TRADE_SHOW" then + local traderName = UnitName("npc") + if traderName == nil or core.DB.pendingLoot == nil or core.DB.pendingLoot[traderName] == nil then + return + end + core.DB.pendingTradePlayer = traderName + core.DB.pendingTrade = {} + local pendingLoot = core.DB.pendingLoot[traderName] + for i, lootLink in pairs(pendingLoot) do + local awarded = false + for containerSlot = 0, NUM_BAG_FRAMES do + for bagSlot = 1, GetContainerNumSlots(containerSlot) do + local containerLink = GetContainerItemLink(containerSlot, bagSlot) + if not awarded and containerLink ~= nil and containerLink == lootLink then + ClearCursor() + PickupContainerItem(containerSlot, bagSlot) + local tradeSlot = TradeFrame_GetAvailableSlot() + if tradeSlot ~= nil and tradeSlot <= 6 then + ClickTradeButton(tradeSlot) + pendingLoot[i] = nil + tinsert(core.DB.pendingTrade, lootLink) + awarded = true + end + end + end + end + end + elseif core.DB.defaults.AutoAwardLoot and event == "TRADE_ACCEPT_UPDATE" then + local arg2 = ... + local traderName = UnitName("npc") + if traderName == nil or core.DB.pendingLoot == nil or core.DB.pendingLoot[traderName] == nil then + return + end + if arg1 ~= nil and arg1 == 1 then + local pendingLoot = core.DB.pendingLoot[traderName] + if core.DB.pendingTrade == nil then + core.DB.pendingTrade = {} + end + for tradeSlot = 1, 6 do + local tradeLink = GetTradePlayerItemLink(tradeSlot) + for i, lootLink in pairs(pendingLoot) do + if tradeLink ~= nil and tradeLink == lootLink then + tinsert(core.DB.pendingTrade, tradeLink) + end + end + end + end + elseif core.DB.defaults.AutoAwardLoot and event == "TRADE_CLOSED" then + local traderName = UnitName("npc") + if traderName == nil or core.DB.pendingTrade == nil or core.DB.pendingLoot == nil or core.DB.pendingLoot[traderName] == nil then + return + end + local pendingLoot = core.DB.pendingLoot[traderName] + for _, tradeLink in pairs(core.DB.pendingTrade) do + for i, lootLink in pairs(pendingLoot) do + if tradeLink == lootLink then + pendingLoot[i] = nil + end + end + end + if #pendingLoot <= 0 then + core.DB.pendingLoot[traderName] = nil + end + core.DB.pendingTrade = {} + core.DB.pendingTradePlayer = nil end end @@ -752,6 +817,7 @@ function CommDKP:OnInitialize(event, name) -- This is the FIRST function to run if #CommDKP:GetTable(CommDKP_DKPHistory, true) > core.DB.defaults.DKPHistoryLimit then CommDKP:PurgeDKPHistory() -- purges DKP History entries that exceed the "DKPHistoryLimit" option variable (oldest entries) and populates CommDKP_Archive with deleted values end + core.DB.pendingLoot = {} end end @@ -1256,4 +1322,7 @@ events:RegisterEvent("GUILD_ROSTER_UPDATE") events:RegisterEvent("PLAYER_ENTERING_WORLD") events:RegisterEvent("ZONE_CHANGED_NEW_AREA") events:RegisterEvent("BOSS_KILL") +events:RegisterEvent("TRADE_SHOW") +events:RegisterEvent("TRADE_ACCEPT_UPDATE") +events:RegisterEvent("TRADE_CLOSED") events:SetScript("OnEvent", CommDKP_OnEvent); -- calls the above CommDKP_OnEvent function to determine what to do with the event