From 07a8de683d986c6a6a6d830cc2969dd287b1bdfb Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 00:02:09 -0700 Subject: [PATCH 1/7] Adding option to auto-loot and auto-trade items to the winner of a bid. --- Localization/Localization.en.lua | 2 + Modules/Award.lua | 36 +++++++++++++++++ Modules/Options.lua | 20 ++++++++++ init.lua | 67 ++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) 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..d16322cd 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.AutoAward 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..cbc834ce 100644 --- a/Modules/Options.lua +++ b/Modules/Options.lua @@ -1182,6 +1182,26 @@ 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() + 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..fb580c6a 100644 --- a/init.lua +++ b/init.lua @@ -615,6 +615,73 @@ 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 + print('LL: ' .. lootLink) + 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 + print(event) + 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 From 0b80175478202832b14b822f3bac8d493d4d8880 Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 01:23:06 -0700 Subject: [PATCH 2/7] Removing event print. --- init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/init.lua b/init.lua index fb580c6a..411b88a6 100644 --- a/init.lua +++ b/init.lua @@ -664,7 +664,6 @@ function CommDKP_OnEvent(self, event, arg1, ...) end end elseif core.DB.defaults.AutoAwardLoot and event == "TRADE_CLOSED" then - print(event) 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 From c97f9b5ff132115bdf1a42566327859b793a6b24 Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 01:23:36 -0700 Subject: [PATCH 3/7] Removing another print. --- init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/init.lua b/init.lua index 411b88a6..aba96a83 100644 --- a/init.lua +++ b/init.lua @@ -656,7 +656,6 @@ function CommDKP_OnEvent(self, event, arg1, ...) for tradeSlot = 1, 6 do local tradeLink = GetTradePlayerItemLink(tradeSlot) for i, lootLink in pairs(pendingLoot) do - print('LL: ' .. lootLink) if tradeLink ~= nil and tradeLink == lootLink then tinsert(core.DB.pendingTrade, tradeLink) end From 2d644932e4817f7e4d74812b7d6b7afd349b30d2 Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 06:24:46 -0700 Subject: [PATCH 4/7] Fixing variable name. --- Modules/Award.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Award.lua b/Modules/Award.lua index d16322cd..5a9de569 100644 --- a/Modules/Award.lua +++ b/Modules/Award.lua @@ -234,7 +234,7 @@ 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.AutoAward then + if core.DB.defaults.AutoAwardLoot then local numLootItems = GetNumLootItems() if numLootItems > 0 then local lootIndex = nil From 87828c4ea083e84c6aac1f2dd3d74989276dc319 Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 06:25:00 -0700 Subject: [PATCH 5/7] Registering for trade events. --- init.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/init.lua b/init.lua index aba96a83..62939083 100644 --- a/init.lua +++ b/init.lua @@ -1321,4 +1321,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 From fb414ef523d50036b45230f7620eab2c51007b7b Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 07:32:27 -0700 Subject: [PATCH 6/7] Resetting pendingLoot when the option is unchecked. --- Modules/Options.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/Options.lua b/Modules/Options.lua index cbc834ce..acbbf179 100644 --- a/Modules/Options.lua +++ b/Modules/Options.lua @@ -1191,6 +1191,9 @@ function CommDKP:Options() 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"); From 39a1417c7fb190da6f47a96d500d8e91323fedb9 Mon Sep 17 00:00:00 2001 From: Chalos Date: Sat, 29 May 2021 07:32:46 -0700 Subject: [PATCH 7/7] Resetting pendingLoot on addon load. --- init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/init.lua b/init.lua index 62939083..4819990c 100644 --- a/init.lua +++ b/init.lua @@ -817,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