forked from itsbth/MoneyMoneyMoney
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoneyMoneyMoney.lua
165 lines (165 loc) · 4.65 KB
/
MoneyMoneyMoney.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
local GetAddOnMetadata, CreateFrame, GetMoney, RepairAllItems, InRepairMode, MoneyMoneyMoneyDB, LibStub
do
local _obj_0 = _G
GetAddOnMetadata, CreateFrame, GetMoney, RepairAllItems, InRepairMode, MoneyMoneyMoneyDB, LibStub = _obj_0.GetAddOnMetadata, _obj_0.CreateFrame, _obj_0.GetMoney, _obj_0.RepairAllItems, _obj_0.InRepairMode, _obj_0.MoneyMoneyMoneyDB, _obj_0.LibStub
end
local LibDataBroker = LibStub:GetLibrary("LibDataBroker-1.1")
MoneyMoneyMoneyDB = MoneyMoneyMoneyDB or { }
local HierarchicalDB
do
local _base_0 = { }
_base_0.__index = _base_0
local _class_0 = setmetatable({
__init = function(self, levels, queriable)
self.levels, self.queriable = levels, queriable
end,
__base = _base_0,
__name = "HierarchicalDB"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
HierarchicalDB = _class_0
end
MoneyMoneyMoney = {
Name = "MoneyMoneyMoney",
Version = GetAddOnMetadata("KillTrack", "Version"),
Frame = CreateFrame("Frame"),
Broker = nil,
DB = nil,
Events = {
PLAYER_ENTERING_WORLD = function(self)
self.CurrentGold = GetMoney()
end,
PLAYER_MONEY = function(self)
local delta = GetMoney() - self.CurrentGold
self.CurrentGold = GetMoney()
return self:UpdateMoney(delta)
end
},
OnEvent = function(self, _, evt, ...)
if self.Events[evt] then
return self.Events[evt](self, ...)
else
return print("Unhandled event " .. tostring(evt) .. "!")
end
end,
UpdateMoney = function(self, delta)
if self.Expected[1] and delta == self.Expected[1].Amount then
print("MMM: Expected: " .. tostring(delta) .. " from " .. tostring(self.Expected[1].Category))
return table.remove(self.Expected, 1)
else
for category, opts in pairs(self.Categories) do
do
local flag = opts.HasFlag
if flag then
if self.Flags[flag] then
print("MMM: Flag: " .. tostring(delta) .. " from " .. tostring(source))
return
end
end
end
end
return print("MMM: Got " .. tostring(delta) .. " from unknown source.")
end
end,
Expect = function(self, source, amount)
self.Expected[#self.Expected + 1] = {
Source = source,
Amount = amount
}
return print("MMM: Expecting " .. tostring(amount) .. " from " .. tostring(source))
end,
CurrentGold = 0,
Categories = { },
Flags = { },
Expected = { },
Timers = { },
RegisterCategory = function(self, name, opts)
if opts == nil then
opts = { }
end
self.Categories[name] = opts
end,
RegisterEvent = function(self, name, actions)
self.Events[name] = function(self, ...)
do
local flag = actions.SetFlag
if flag then
self.Flags[flag] = true
end
end
do
local flag = actions.ClearFlag
if flag then
self.Flags[flag] = nil
end
end
do
local timer = actions.SetTimer
if timer then
self.Timers[timer] = GetTime()
end
end
end
end,
RegisterHook = function(self, name, fun)
return hooksecurefunc(name, function(...)
return fun(self, ...)
end)
end
}
local MMM = MoneyMoneyMoney
do
local _with_0 = LibDataBroker:NewDataObject("MoneyMoneyMoney_Broker", {
type = "data source",
label = "MoneyMoneyMoney",
tocname = "MoneyMoneyMoney"
})
_with_0.OnTooltipShow = function(self)
return self:AddLine("This is a test.")
end
_with_0.text = "MMM: 10|TInterface\\MONEYFRAME\\UI-GoldIcon:0|t"
MMM.Broker = _with_0
end
MMM:RegisterCategory('Vendor', {
HasFlag = 'UsingVendor'
})
MMM:RegisterEvent('MERCHANT_SHOW', {
SetFlag = 'UsingVendor'
})
MMM:RegisterEvent('MERCHANT_CLOSED', {
ClearFlag = 'UsingVendor'
})
MMM:RegisterHook('BuyMerchantItem', function(self, idx, qty)
local _, price, defaultQty
_, _, price, defaultQty = GetMerchantItemInfo(idx)
return self:Expect('Vendor', -price * (qty or defaultQty))
end)
MMM:RegisterCategory('Flights', {
EXPENSES = EXPENSES
})
MMM:RegisterHook('TakeTaxiNode', function(self, id)
return self:Expect('Flights', -TaxiNodeCost(id))
end)
MMM:RegisterCategory('Repair')
MMM:RegisterHook('RepairAllItems', function(self, guildBankRepair)
if not (guildBankRepair) then
return self:Expect('Repair', -GetRepairAllCost())
end
end)
for k, _ in pairs(MMM.Events) do
MMM.Frame:RegisterEvent(k)
end
return MMM.Frame:SetScript("OnEvent", (function()
local _base_0 = MMM
local _fn_0 = _base_0.OnEvent
return function(...)
return _fn_0(_base_0, ...)
end
end)())