WoWInterface SVN idQuestAutomation

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 5 to Rev 6
    Reverse comparison

Rev 5 → Rev 6

trunk/Addon.lua
1,157 → 1,124
--[[----------------------------------------------------------------------------
Copyright (c) 2008, Tom Wieland
All rights reserved.
local addon = CreateFrame('Frame')
addon.completed_quests = {}
addon.uncompleted_quests = {}
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
function addon:canAutomate ()
if IsShiftKeyDown() then
return false
else
return true
end
end
 
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of idQuestAutomation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
function addon:strip_text (text)
if not text then return end
text = text:gsub('%[.*%]%s*','')
text = text:gsub('|c%x%x%x%x%x%x%x%x(.+)|r','%1')
text = text:gsub('(.+) %(.+%)', '%1')
text = text:trim()
return text
end
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------]]
function addon:QUEST_PROGRESS ()
if not self:canAutomate() then return end
if IsQuestCompletable() then
CompleteQuest()
end
end
 
local _G = _G
local addon = {}
function addon:QUEST_LOG_UPDATE ()
if not self:canAutomate() then return end
local start_entry = GetQuestLogSelection()
local num_entries = GetNumQuestLogEntries()
local title
local is_complete
local no_objectives
 
addon.quests = {}
addon.eventframe = CreateFrame('Frame')
self.completed_quests = {}
self.uncompleted_quests = {}
 
function addon:stripText (t) -- thx Shadowed
if not t then return end
t = t:gsub('%[.*%]%s*','')
t = t:gsub('|c%x%x%x%x%x%x%x%x(.+)|r','%1')
t = t:gsub('(.+) %(.+%)', '%1')
t = t:trim()
return t
if num_entries > 0 then
for i = 1, num_entries do
SelectQuestLogEntry(i)
title, _, _, _, _, _, is_complete = GetQuestLogTitle(i)
no_objectives = GetNumQuestLeaderBoards(i) == 0
if title and (is_complete or no_objectives) then
self.completed_quests[title] = true
else
self.uncompleted_quests[title] = true
end
end
end
 
SelectQuestLogEntry(start_entry)
end
 
function addon:GOSSIP_SHOW (event)
if IsShiftKeyDown() then return end
function addon:GOSSIP_SHOW ()
if not self:canAutomate() then return end
 
local button
local text
 
if GossipFrame.buttonIndex then
for i = 1, GossipFrame.buttonIndex do
button = _G['GossipTitleButton'..i]
text = self:stripText(button:GetText())
 
if button:IsVisible() then
if button.type == 'Available' then
for i = 1, 32 do
button = _G['GossipTitleButton' .. i]
if button:IsVisible() then
text = self:strip_text(button:GetText())
if button.type == 'Available' then
button:Click()
elseif button.type == 'Active' then
if self.completed_quests[text] then
button:Click()
elseif button.type == 'Active' then
if self.quests[text] then
self.quests[text] = nil
button:Click()
end
end
end
end
end
end
 
function addon:QUEST_GREETING (event)
if IsShiftKeyDown() then return end
function addon:QUEST_GREETING (...)
if not self:canAutomate() then return end
 
local button
local text
 
for i = 1, 38 do
button = _G['QuestTitleButton'..i]
 
if button then
text = self:stripText(button:GetText())
 
if button:IsVisible() then
if button.isActive == 1 then
if self.quests[text] then
self.quests[text] = nil
button:Click()
end
else
button:Click()
end
for i = 1, 32 do
button = _G['QuestTitleButton' .. i]
if button:IsVisible() then
text = self:strip_text(button:GetText())
if self.completed_quests[text] then
button:Click()
elseif not self.uncompleted_quests[text] then
button:Click()
end
end
end
end
 
function addon:QUEST_DETAIL (event)
if IsShiftKeyDown() then return end
function addon:QUEST_DETAIL ()
if not self:canAutomate() then return end
AcceptQuest()
end
 
function addon:QUEST_PROGRESS (event)
if IsShiftKeyDown() then return end
if IsQuestCompletable() then
CompleteQuest()
end
end
 
function addon:QUEST_COMPLETE (event)
if IsShiftKeyDown() then return end
if not self:canAutomate() then return end
if GetNumQuestChoices() <= 1 then
GetQuestReward(QuestFrameRewardPanel.itemChoice)
end
end
 
function addon:QUEST_LOG_UPDATE (event)
local startingQuestLogSelection = GetQuestLogSelection()
local numEntries, numQuests = GetNumQuestLogEntries()
local q
 
if numEntries > 0 then
for i = 1, numEntries do
SelectQuestLogEntry(i)
q = {GetQuestLogTitle(i)}
if q and q[7] then
self.quests[q[1]] = true
end
end
function addon.onevent (self, event, ...)
if self[event] then
self[event](self, ...)
end
 
SelectQuestLogEntry(startingQuestLogSelection)
end
 
function addon.OnEvent (frame, event, ...)
if event == 'GOSSIP_SHOW' then
addon:GOSSIP_SHOW(...)
elseif event == 'QUEST_GREETING' then
addon:QUEST_GREETING(...)
elseif event == 'QUEST_DETAIL' then
addon:QUEST_DETAIL(...)
elseif event == 'QUEST_PROGRESS' then
addon:QUEST_PROGRESS(...)
elseif event == 'QUEST_COMPLETE' then
addon:QUEST_COMPLETE(...)
elseif event == 'QUEST_LOG_UPDATE' then
addon:QUEST_LOG_UPDATE(...)
end
end
addon:SetScript('OnEvent', addon.onevent)
addon:RegisterEvent('GOSSIP_SHOW')
addon:RegisterEvent('QUEST_COMPLETE')
addon:RegisterEvent('QUEST_DETAIL')
addon:RegisterEvent('QUEST_FINISHED')
addon:RegisterEvent('QUEST_GREETING')
addon:RegisterEvent('QUEST_LOG_UPDATE')
addon:RegisterEvent('QUEST_PROGRESS')
 
addon.eventframe:SetScript('OnEvent', addon.OnEvent)
addon.eventframe:RegisterEvent('GOSSIP_SHOW')
addon.eventframe:RegisterEvent('QUEST_GREETING')
addon.eventframe:RegisterEvent('QUEST_DETAIL')
addon.eventframe:RegisterEvent('QUEST_PROGRESS')
addon.eventframe:RegisterEvent('QUEST_COMPLETE')
addon.eventframe:RegisterEvent('QUEST_LOG_UPDATE')
 
_G.idQuestAutomation = addon