WoWInterface SVN Auditor

Compare Revisions

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

Rev 1 → Rev 2

core.lua New file
0,0 → 1,270
Auditor = LibStub("AceAddon-3.0"):NewAddon("Auditor", "AceConsole-3.0", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("Auditor")
 
 
--[[ DECLARE LOCALS ]]--
local resources = {
"loot", --[1]
"merch", --[2]
"quest", --[3]
"trade", --[4]
"mail", --[5]
"ah", --[6]
"train", --[7]
"taxi", --[8]
"repairs", --[9]
"other", --[10]
"reconciliation", --[11]
"guildbank", --[12]
}
local agent
local auditorSessionTime = time()
local prevTotal = nil
local resource = 10
local auditPeriod = 30
 
--[[ DATABASE DEFAULTS ]]--
local defaults = {
realm = {
timeOffset = 0,
useOffset = false
},
}
 
 
--[[ STARTUP ]]--
function Auditor:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("AuditorDB", defaults, "Default")
agent = UnitName("player")
 
-- Create DB for toon if it doesn't exist
self:NewToonDB()
-- Clear out last session's data
self:DataReset("session")
end
 
function Auditor:OnEnable()
-- Resource focus triggers
self:RegisterEvent('LOOT_OPENED', EventHandler, 1)
self:RegisterEvent('MERCHANT_SHOW', EventHandler, 2)
self:RegisterEvent('BANKFRAME_OPENED', EventHandler, 2)
self:RegisterEvent('QUEST_COMPLETE', EventHandler, 3)
self:RegisterEvent('TRADE_SHOW', EventHandler, 4)
self:RegisterEvent('MAIL_SHOW', EventHandler, 5)
self:RegisterEvent('AUCTION_HOUSE_SHOW', EventHandler, 6)
self:RegisterEvent('TRAINER_SHOW', EventHandler, 7)
self:RegisterEvent('CONFIRM_TALENT_WIPE', EventHandler, 7)
self:RegisterEvent('TAXIMAP_OPENED', EventHandler, 8)
self:RegisterEvent('GUILDBANKFRAME_OPENED', EventHandler, 12)
self:RegisterEvent('MERCHANT_CLOSED', EventHandler)
self:RegisterEvent('BANKFRAME_CLOSED', EventHandler)
self:RegisterEvent('GUILDBANKFRAME_CLOSED', EventHandler)
self:RegisterEvent('TRADE_CLOSE', EventHandler)
self:RegisterEvent('MAIL_CLOSED', EventHandler)
self:RegisterEvent('TRAINER_CLOSED', EventHandler)
self:RegisterEvent('AUCTION_HOUSE_CLOSED', EventHandler)
-- Events
self:RegisterEvent('CHAT_MSG_MONEY')
self:RegisterEvent('PLAYER_MONEY')
 
-- Hooks
hooksecurefunc("RepairAllItems", function() self:RepairAllItems() end)
hooksecurefunc("CursorHasItem", function() self:CursorHasItem() end)
hooksecurefunc("TakeInboxMoney", function(...) self:TakeInboxMoney(...) end)
-- Data housekeeping functions
self:UpdateTimeFrame()
self:ReconcileData()
end
 
--[[ DATA MANIPULATION FUNCTIONS]]--
 
function Auditor:DataReset(timeFrame, toon)
local toonToReset = ""
if toon ~= nil then
toonToReset = toon
else
toonToReset = auditorPlayer
end
 
for _,logmode in pairs(auditorLogMode) do
self.db.realm[toonToReset].data[logmode][timeFrame] = {incomings = 0, outgoings = 0}
end
-- Reset time for gold per hour
if timeFrame == "session" then
auditorSessionTime = time()
end
end
 
function Auditor:ReconcileData()
-- Set current cash
self.db.realm.agents[agent] = GetMoney() or 0
prevTotal = self.db.realm.agents[agent]
 
-- Add up total incomings and outgoings according to Auditor
 
-- Does Auditor's data sync with reality? If not, make it so
 
end
 
--[[ EVENT FUNCTIONS ]]--
 
function Auditor:EventHandler(trigger)
resource = trigger or 10
end
 
function Auditor:CHAT_MSG_MONEY()
self:OnShareMoney(event, arg1)
end
 
function Auditor:PLAYER_MONEY()
self.db.realm.agents[agent] = GetMoney() or 0
self:UpdateTimeFrame()
self:UpdateFigures()
end
 
function Auditor:OnShareMoney(event, arg1)
local gold, silver, copper, money, prevResource
 
-- Parse the message for money gained.
_, _, gold = string.find(arg1, "(%d+) " .. GOLD)
_, _, silver = string.find(arg1, "(%d+) " .. SILVER)
_, _, copper = string.find(arg1, "(%d+) " .. COPPER)
if gold then gold = tonumber(gold) else gold = 0 end
if silver then silver = tonumber(silver) else silver = 0 end
if copper then copper = tonumber(copper) else copper = 0 end
money = copper + silver * 100 + gold * 10000
 
prevResource = resource
 
-- This will force a money update with calculated amount.
prevTotal = prevTotal - money
resource = 1
Auditor:UpdateFigures()
resource = prevResource
 
-- This will suppress the incoming PLAYER_MONEY event.
prevTotal = prevTotal + money
end
 
 
--[[ MAIN MONEY DATA ALLOCATION FUNCTION ]]--
 
function Auditor:UpdateFigures()
local diff = (self.db.realm.agents[agent] - prevTotal) or 0
prevTotal = self.db.realm.agents[agent]
 
if diff > 0 then
-- Prevention of incomings on outgoing-only resources
if (resource == 7 or resource == 8 or resource == 9) then
resource = 10
end
-- Update day's data
self.db.realm[agent][resource][1] = self.db.realm[agent][resource][1] + diff
-- Update total data, maybe? Or put that in updatetimeframe?
 
elseif diff < 0 then
-- Prevention of outgoings on incoming-only resources
if (resource == 1) then
resource = 10
end
diff = diff * -1;
self.db.realm[agent][resource][2] = self.db.realm[agent][resource][2] + diff
else
return
end
 
-- Repairs --> Merchant
if resource == 9 then
self:Print(L.RepairSuccessful..Auditor:FormatMoneyFull(diff, true, coloured))
resource = 2
end
end
 
function Auditor:UpdateTimeFrame()
-- Check if Auditor should reset
local dateTable = date("*t")
local diff = time{year = dateTable.year, day = dateTable.day, month = dateTable.month, hour = dateTable.hour, min = dateTable.min, sec = dateTable.sec} - self.db.realm[auditorPlayer].timeDate.timeDate
local dayDiff = math.floor(diff / 86400)
-- Keep date current
self.db.realm[auditorPlayer].timeDate.niceDate = date("%d %b '%y")
 
if dayDiff ~= 0 and dayDiff <30 then
repeat
table.remove (self.db.realm[agent])
until #self.db.realm[agent] == auditPeriod - dayDiff
local periodDB = Auditor:GetPeriodDB()
repeat
table.insert (self.db.realm[agent], 1, periodDB)
until #self.db.realm[agent] == 30
else
self.db.realm[agent] = nil
Auditor:NewAgentDB()
end
-- Lastly, if the date has changed, obviously we need to clear out the day's data.
self:DataReset("day")
 
-- Time offset crap. Amfg, I hate this stuff. It's retarded.
self.db.realm[auditorPlayer].timeDate.timeDate = time{year = dateTable.year, day = dateTable.day, month = dateTable.month, hour = 0} + (self.db.realm.timeOffset * 3600)
 
end
 
--[[ DATABASE MANIPULATION ]]--
 
function Auditor:NewAgentDB()
local periodDB = Auditor:GetPeriodDB()
local auditDB = {}
for i = 1, auditPeriod do
table.insert (auditDB, periodDB)
end
-- Assign newly created DB to audit agent
self.db.realm[agent] = auditDB
-- Scrap the tables
auditDB, periodDB = nil
-- Assign agent wealth
self.db.realm.agents[agent] = GetMoney() or 0
end
 
function Auditor:GetPeriodDB()
local periodDB = {}
for i = 1, #resources do
table.insert (periodDB, { 0, 0 })
end
return periodDB
end
 
function Auditor:NewRealmDB()
if not self.db.realm.agents then
self.db.realm.agents = {}
end
end
 
--[[ HOOKING FUNCTIONS ]]--
 
function Auditor:RepairAllItems()
resource = 9
end
 
function Auditor:CursorHasItem()
if InRepairMode() then
resource = 9
end
end
 
function Auditor:TakeInboxMoney(mailIndex)
local _, _, sender, _, _, _, _, _, _, _, _, _= GetInboxHeaderInfo(mailIndex)
if sender ~= nil then
if strfind(sender, L.AuctionHouse) then
resource = 6
else
resource = 5
end
else
resource = 5
end
end
 
--[[ UTILITY FUNCTIONS ]]--
 
function Auditor:PrintResetTime()
self:Print(date("Auditor will reset at %H:%M (24hr clock), on %A, %d %b '%y (local time).", self.db.realm[auditorPlayer].timeDate.timeDate + 86400))
end
\ No newline at end of file