WoWInterface SVN idQuestAutomation

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

Libraries/idLibrary-1.1.lua New file
0,0 → 1,81
local lib, oldminor = LibStub:NewLibrary('idLibrary-1.1', 1)
 
if not lib then return end
 
lib.events = {}
lib.timers = {}
lib.frame = CreateFrame('Frame')
 
lib.frame:SetScript('OnEvent', function (frame, event, ...)
local event = lib.events[event]
if event then
for k,v in pairs(event) do
v(...)
end
end
end)
lib.frame:SetScript('OnUpdate', function (frame, elapsed)
local v
for i = #lib.timers, 1, -1 do
v = lib.timers[i]
if v.time >= v.interval then
v.time = v.time - v.interval
v.func()
else
v.time = v.time + elapsed
end
end
end)
 
-- print
function lib:Print (mixed)
ChatFrame1:AddMessage(tostring(mixed) or 'nil')
end
 
-- events
function lib:RegisterEvent (name, event, func)
self.events[event] = self.events[event] or {}
self.events[event][name] = func
 
self.frame:RegisterEvent(event)
end
 
function lib:UnregisterEvent (name, event)
if self.events[event] then
self.events[event][name] = nil
if #self.events[event] == 0 then
self.events[event] = nil
self.frame:UnregisterEvent(event)
end
end
end
 
-- timers
function lib:RegisterTimer (name, func, interval)
self.timers[name] = {
interval = interval or 1,
time = 0,
func = func
}
end
 
function lib:UnregisterTimer (name)
self.timers[name] = nil
end
 
-- frames
function lib:Move (f, p1, p, p2, x, y)
f:ClearAllPoints()
f:SetPoint(p1, p, p2, x, y)
end
 
function lib:Show (f)
f:SetScript('OnShow', nil)
f:Show()
end
 
function lib:Hide (f)
f:SetScript('OnShow', f.Hide)
f:Hide()
end
 
Libraries/LibStub.lua New file
0,0 → 1,30
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]
 
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR
 
function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
 
local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end
 
function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end
 
function LibStub:IterateLibraries() return pairs(self.libs) end
setmetatable(LibStub, { __call = LibStub.GetLibrary })
end
idQuestAutomation.toc New file
0,0 → 1,9
## Interface: 20300
## Title: Industrial: Quest Automation
## Credits: Industrial
## Notes: Drive by quest NPC interaction
 
Libraries\LibStub.lua
Libraries\idLibrary-1.1.lua
 
Addon.lua
Addon.lua New file
0,0 → 1,129
--[[----------------------------------------------------------------------------
Copyright (c) 2007, Tom Wieland
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 
* 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.
 
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.
------------------------------------------------------------------------------]]
 
local _G = _G
local lib = LibStub('idLibrary-1.1')
 
local quests = {}
 
local function 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
end
 
local function GOSSIP_SHOW (event)
if IsShiftKeyDown() or not GossipFrame:IsVisible() then return end
 
local button
local text
local action
 
for i = 1, GossipFrame.buttonIndex do
button = _G['GossipTitleButton'..i]
text = stripText(button:GetText())
 
if button:IsVisible() then
if button.type == 'Active' then
if quests[text] then
action = action or button
quests[text] = nil
end
elseif button.type == 'Available' then
action = action or button
end
end
end
if action then
action:Click()
end
end
 
local function QUEST_DETAIL (event)
if IsShiftKeyDown() then return end
AcceptQuest()
end
 
local function QUEST_ACCEPT_CONFIRM (event)
if IsShiftKeyDown() then return end
end
 
local function QUEST_PROGRESS (event)
if IsShiftKeyDown() then return end
if IsQuestCompletable() then
CompleteQuest()
end
end
 
local function QUEST_COMPLETE (event)
if IsShiftKeyDown() then return end
if GetNumQuestChoices() <= 1 then
GetQuestReward(QuestFrameRewardPanel.itemChoice)
end
end
 
local function 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
quests[q[1]] = true
end
end
end
 
SelectQuestLogEntry(startingQuestLogSelection)
end
 
local function enable ()
lib:RegisterEvent('idQuestAutomation', 'GOSSIP_SHOW', GOSSIP_SHOW)
lib:RegisterEvent('idQuestAutomation', 'QUEST_DETAIL', QUEST_DETAIL)
lib:RegisterEvent('idQuestAutomation', 'QUEST_PROGRESS', QUEST_PROGRESS)
lib:RegisterEvent('idQuestAutomation', 'QUEST_COMPLETE', QUEST_COMPLETE)
lib:RegisterEvent('idQuestAutomation', 'QUEST_LOG_UPDATE', QUEST_LOG_UPDATE)
end
 
local function disable ()
lib:UnregisterEvent('idQuestAutomation', 'GOSSIP_SHOW')
lib:UnregisterEvent('idQuestAutomation', 'QUEST_DETAIL')
lib:UnregisterEvent('idQuestAutomation', 'QUEST_PROGRESS')
lib:UnregisterEvent('idQuestAutomation', 'QUEST_COMPLETE')
lib:UnregisterEvent('idQuestAutomation', 'QUEST_LOG_UPDATE')
end
 
lib:RegisterEvent('idQuestAutomation-Enable', 'PLAYER_LOGIN', enable)
lib:RegisterEvent('idQuestAutomation-Disable', 'PLAYER_LOGOUT', disable)