From 73f59a2218629ca97fb2dc64dea9d13a439b984d Mon Sep 17 00:00:00 2001 From: EsreverWoW <49285632+EsreverWoW@users.noreply.github.com> Date: Wed, 18 Jan 2023 16:22:01 -0600 Subject: [PATCH] [Quests] AutoAccept for Wrath Classic --- .../Modules/Quests/AutoAccept_Vanilla.lua | 54 +--- ShestakUI/Modules/Quests/AutoAccept_Wrath.lua | 299 ++++++++++++++++++ 2 files changed, 304 insertions(+), 49 deletions(-) create mode 100644 ShestakUI/Modules/Quests/AutoAccept_Wrath.lua diff --git a/ShestakUI/Modules/Quests/AutoAccept_Vanilla.lua b/ShestakUI/Modules/Quests/AutoAccept_Vanilla.lua index 0ea405cbc..936248c52 100644 --- a/ShestakUI/Modules/Quests/AutoAccept_Vanilla.lua +++ b/ShestakUI/Modules/Quests/AutoAccept_Vanilla.lua @@ -10,14 +10,11 @@ QuickQuest:SetScript("OnEvent", function(self, event, ...) self[event](...) end) local QuickQuestDB = { toggle = true, items = true, - faireport = true, gossip = true, gossipraid = 1, modifier = "SHIFT", reverse = false, share = false, - withered = true, - nomi = true, } local QuickQuestBlacklistDB = { @@ -80,19 +77,10 @@ QuickQuest:Register("QUEST_GREETING", function() local active = GetNumActiveQuests() if(active > 0) then - local logQuests = GetQuestLogQuests(true) for index = 1, active do - local name, complete = GetActiveTitle(index) + local _, complete = GetActiveTitle(index) if(complete) then - local questID = logQuests[name] - if(not questID) then - SelectActiveQuest(index) - else - local _, _, worldQuest = GetQuestTagInfo(questID) - if(not worldQuest) then - SelectActiveQuest(index) - end - end + SelectActiveQuest(index) end end end @@ -100,13 +88,8 @@ QuickQuest:Register("QUEST_GREETING", function() local available = GetNumAvailableQuests() if(available > 0) then for index = 1, available do - local isTrivial, isIgnored - if T.Classic then - isTrivial = IsActiveQuestTrivial(index) - else - isTrivial, _, _, _, isIgnored = GetAvailableQuestInfo(index) - end - if(not isTrivial and not isIgnored) then + local isTrivial = IsActiveQuestTrivial(index) + if(not isTrivial) then SelectAvailableQuest(index) end end @@ -156,28 +139,13 @@ QuickQuest:Register("GOSSIP_SHOW", function() local _, _, trivial, ignored = GetAvailableGossipQuestInfo(index) if(not trivial and not ignored) then SelectGossipAvailableQuest(index) - elseif(trivial and npcID == 64337 and QuickQuestDB.nomi) then - SelectGossipAvailableQuest(index) end end end if(available == 0 and active == 0 and GetNumGossipOptions() == 1) then - if(string.match((GetGossipOptions()), TRACKER_HEADER_PROVINGGROUNDS)) then - -- ignore proving grounds queue - return - end - - if(QuickQuestDB.faireport) then - if(npcID == 57850) then - return SelectGossipOption(1) - end - end - if(QuickQuestDB.gossip) then - local _, instance, _, _, _, _, _, mapID = GetInstanceInfo() - if(QuickQuestDB.withered and instance == "scenario" and mapID == 1626) then return end - + local _, instance = GetInstanceInfo() if(instance == "raid" and QuickQuestDB.gossipraid > 0) then if(GetNumGroupMembers() > 1 and QuickQuestDB.gossipraid < 2) then return @@ -191,18 +159,6 @@ QuickQuest:Register("GOSSIP_SHOW", function() end end) -local darkmoonNPC = {} - -QuickQuest:Register("GOSSIP_CONFIRM", function(index) - if(not QuickQuestDB.faireport) then return end - - local npcID = GetNPCID() - if(npcID and darkmoonNPC[npcID]) then - SelectGossipOption(index, "", true) - StaticPopup_Hide("GOSSIP_CONFIRM") - end -end) - QuestFrame:UnregisterEvent("QUEST_DETAIL") QuickQuest:Register("QUEST_DETAIL", function(...) if(not QuickQuestBlacklistDB[GetQuestID()]) then diff --git a/ShestakUI/Modules/Quests/AutoAccept_Wrath.lua b/ShestakUI/Modules/Quests/AutoAccept_Wrath.lua new file mode 100644 index 000000000..04e77ce83 --- /dev/null +++ b/ShestakUI/Modules/Quests/AutoAccept_Wrath.lua @@ -0,0 +1,299 @@ +local T, C, L, _ = unpack(select(2, ...)) +if C.automation.accept_quest ~= true then return end + +---------------------------------------------------------------------------------------- +-- Quest automation(QuickQuest by p3lim) +---------------------------------------------------------------------------------------- +local _, ns = ... +local QuickQuestDB = { + general = { + share = false, + skipgossip = true, + skipgossipwhen = 1, + pausekey = 'SHIFT', + pausekeyreverse = false, + }, + blocklist = { + items = {}, + npcs = {}, + quests = {}, + }, +} + +local EventHandler = CreateFrame('Frame') +EventHandler.events = {} +EventHandler:SetScript('OnEvent', function(self, event, ...) + self:Trigger(event, ...) +end) + +function EventHandler:Register(event, func) + local registered = not not self.events[event] + if not registered then + self.events[event] = {} + end + + for _, f in next, self.events[event] do + if f == func then + -- avoid the same function being registered multiple times for the same event + return + end + end + + table.insert(self.events[event], func) + + if not registered then + self:RegisterEvent(event) + end +end + +function EventHandler:Unregister(event, func) + local funcs = self.events[event] + if funcs then + for i, f in next, funcs do + if f == func then + funcs[i] = nil + break + end + end + end + + if funcs and #funcs == 0 then + self:UnregisterEvent(event) + end +end + +function EventHandler:Trigger(event, ...) + local funcs = self.events[event] + if funcs then + for _, func in next, funcs do + if type(func) == 'string' then + self:Trigger(func, ...) + else + if func(...) then + self:Unregister(event, func) + end + end + end + end +end + +ns.EventHandler = EventHandler + +local NPC_ID_PATTERN = '%w+%-.-%-.-%-.-%-.-%-(.-)%-' +function ns.GetNPCID(unit) + local npcGUID = UnitGUID(unit or 'npc') + if npcGUID then + return tonumber(npcGUID:match(NPC_ID_PATTERN)) + end +end + +function ns.ShouldAcceptTrivialQuests() + for index = 1, C_Minimap.GetNumTrackingTypes() do + local name, _, isActive = C_Minimap.GetTrackingInfo(index) + if name == MINIMAP_TRACKING_TRIVIAL_QUESTS then + return isActive + end + end +end + +function ns.tLength(t) + local count = 0 + for _ in next, t do + count = count + 1 + end + return count +end + +local EventHandler = ns.EventHandler +local paused + +local ignoredQuests = {} +local cashRewards = { + [45724] = 1e5, -- Champion's Purse, 10 gold +} +local function IsQuestIgnored(questID) + if ignoredQuests[questID] then + return true + end + + local questTitle = tonumber(questID) and C_QuestLog.GetQuestInfo(questID) or '' + for key in next, QuickQuestDB.blocklist.quests do + if key == questID or questTitle:lower():find(tostring(key):lower()) then + return true + end + end + + return false +end + +EventHandler:Register('GOSSIP_SHOW', function() + -- triggered when the player interacts with an NPC that presents dialogue + if paused then + return + end + + if QuickQuestDB.blocklist.npcs[ns.GetNPCID()] then + return + end + + -- turn in all completed quests + for index, info in next, C_GossipInfo.GetActiveQuests() do + if not IsQuestIgnored(info.questID) then + if info.isComplete then + C_GossipInfo.SelectActiveQuest(index) + end + end + end + + -- accept all available quests + for index, info in next, C_GossipInfo.GetAvailableQuests() do + if not IsQuestIgnored(info.questID) then + if not info.isTrivial or ns.ShouldAcceptTrivialQuests() then + C_GossipInfo.SelectAvailableQuest(info.questID) + end + end + end +end) +EventHandler:Register('QUEST_GREETING', 'GOSSIP_SHOW') + +EventHandler:Register('QUEST_DETAIL', function(questItemID) + -- triggered when the information about an available quest is available + if paused then + return + end + + AcceptQuest() +end) + +EventHandler:Register('QUEST_PROGRESS', function() + -- triggered when an active quest is selected during turn-in + if paused then + return + end + + if QuickQuestDB.blocklist.npcs[ns.GetNPCID()] then + return + end + + if not IsQuestCompletable() then + return + end + + -- iterate through the items part of the quest + for index = 1, GetNumQuestItems() do + local itemLink = GetQuestItemLink('required', index) + if itemLink then + -- check to see if the item is blocked + local questItemID = GetItemInfoFromHyperlink(itemLink) + for itemID in next, QuickQuestDB.blocklist.items do + if itemID == questItemID then + -- item is blocked, prevent this quest from opening again and close it + ignoredQuests[GetQuestID()] = true + CloseQuest() + return + end + end + else + -- item is not cached yet, trigger the item and wait for the cache to populate + EventHandler:Register('QUEST_ITEM_UPDATE', 'QUEST_PROGRESS') + GetQuestItemInfo('required', index) + return + end + end + + CompleteQuest() + EventHandler:Unregister('QUEST_ITEM_UPDATE', 'QUEST_PROGRESS') +end) + +EventHandler:Register('QUEST_COMPLETE', function() + -- triggered when an active quest is ready to be completed + if paused then + return + end + + if GetNumQuestChoices() <= 1 then + -- complete the quest by accepting the first item + GetQuestReward(1) + end +end) + +EventHandler:Register('QUEST_COMPLETE', function() + -- triggered when an active quest is ready to be completed + local numItemRewards = GetNumQuestChoices() + if numItemRewards <= 1 then + -- no point iterating over a single item or none at all + return + end + + local highestItemValue, highestItemValueIndex = 0 + + -- iterate through the item rewards and automatically select the one worth the most + for index = 1, numItemRewards do + local itemLink = GetQuestItemLink('choice', index) + if itemLink then + -- check the value on the item and compare it to the others + local _, _, _, _, _, _, _, _, _, _, itemValue = GetItemInfo(itemLink) + local itemID = GetItemInfoFromHyperlink(itemLink) + + -- some items are containers that contains currencies of worth + itemValue = cashRewards[itemID] or itemValue + + -- compare the values + if itemValue > highestItemValue then + highestItemValue = itemValue + highestItemValueIndex = index + end + else + -- item is not cached yet, trigger the item and wait for the cache to populate + EventHandler:Register('QUEST_ITEM_UPDATE', 'QUEST_COMPLETE') + GetQuestItemInfo('choice', index) + return + end + end + + if highestItemValueIndex then + -- this is considered an intrusive action, as we're modifying the UI + QuestInfoItem_OnClick(QuestInfoRewardsFrame.RewardButtons[highestItemValueIndex]) + end + + EventHandler:Unregister('QUEST_ITEM_UPDATE', 'QUEST_COMPLETE') +end) + +EventHandler:Register('QUEST_ACCEPT_CONFIRM', function() + -- triggered when a quest is shared in the party, but requires confirmation (like escorts) + if paused then + return + end + + AcceptQuest() +end) + +EventHandler:Register('QUEST_ACCEPTED', function(questID) + -- triggered when a quest has been accepted by the player + if QuickQuestDB.general.share then + local questLogIndex = C_QuestLog.GetLogIndexForQuestID(questID) + if questLogIndex then + QuestLogPushQuest(questLogIndex) + end + end +end) + +EventHandler:Register('MODIFIER_STATE_CHANGED', function(key, state) + -- triggered when the player clicks any modifier keys on the keyboard + if string.sub(key, 2) == QuickQuestDB.general.pausekey then + -- change the paused state + if QuickQuestDB.general.pausekeyreverse then + paused = state ~= 1 + else + paused = state == 1 + end + end +end) + +EventHandler:Register('PLAYER_LOGIN', function() + -- triggered when the game has completed the login process + if QuickQuestDB.general.pausekeyreverse then + -- default to a paused state + paused = true + end +end) \ No newline at end of file