-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.lua
237 lines (200 loc) · 6.97 KB
/
core.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
local A = FonzAppraiser
local L = A.locale
A.module 'fa'
local util = A.requires(
'util.table',
'util.money',
'util.item',
'util.group'
)
local palette = A.require 'fa.palette'
local pricing = A.require 'fa.value.pricing'
local filter = A.require 'fa.filter'
local session = A.require 'fa.session'
local misc = A.require 'fa.misc'
local gui_main = A.require 'fa.gui.main'
local gui_config = A.require 'fa.gui.config'
local gui_minimap = A.require 'fa.gui.minimap'
-- Events --
--[[
Notes:
- GlobalStrings.lua is Blizzard's own code for Lua string constants
--]]
do
local find = string.find
local isInGroup = util.isInGroup
local extendedStringToMoney = util.extendedStringToMoney
--GlobalStrings.lua: YOU_LOOT_MONEY = "You loot %s"
-- e.g. "You loot 1 Silver, 10 Copper"
local PATTERN_MONEY_LOOT_YOU = "^You loot (.+)"
--GlobalStrings.lua: LOOT_MONEY_SPLIT = "Your share of the loot is %s."
-- e.g. "Your share of the loot is 2 Silver, 21 Copper."
local PATTERN_MONEY_LOOT_SPLIT = "^Your share of the loot is (.+)%.$"
function A:CHAT_MSG_MONEY(msg)
--Money loot while solo obtained reliably from LOOT_OPENED/LOOT_SLOT_CLEARED
--events.
--These chat messages are checked only in groups.
if not isInGroup() then return end
local money_string
--Shift-click money loot in a group.
_, _, money_string = find(msg, PATTERN_MONEY_LOOT_YOU)
if not money_string then
--Shared money loot in a group.
_, _, money_string = find(msg, PATTERN_MONEY_LOOT_SPLIT)
if not money_string then return end
end
local value = extendedStringToMoney(money_string)
if value and value > 0 then
session.lootMoney(value, L["shared"])
A:guiUpdate()
else
A.warn("Money loot message but no value found. Original message: %s",
msg)
end
end
end
do
local GetTime = GetTime
local find = string.find
local makeStoreToken = util.makeStoreToken
local parseItemLink = util.parseItemLink
--GlobalStrings.lua: LOOT_ITEM_SELF = "You receive loot: %s."
-- e.g. "You receive loot: [Heavy Leather]."
--GlobalStrings.lua: LOOT_ITEM_SELF_MULTIPLE = "You receive loot: %sx%d."
-- e.g. "You receive loot: [Heavy Leather]x3."
local PATTERN_ITEM_LOOT_SELF = "^You receive loot: (.+)%.$"
local PATTERN_ITEM_LOOT_SELF_COUNT = "x(%d+)$"
--GlobalStrings.lua: LOOT_ROLL_WON = "%s won: %s|Hitem:%d:%d:%d:%d|h[%s]|h%s"
-- e.g. "You won: [Heavy Leather]"
local PATTERN_ITEM_LOOT_WON = "^You won: (.+)"
local LOOT_TYPE_SELF = 0
local LOOT_TYPE_WON = 1
local loot_type
local last_loot_time, last_won_code, last_self_code
local function seenTooSoon(loot_time)
return (GetTime() - loot_time) < 1
end
function A:CHAT_MSG_LOOT(msg)
local loot_string
_, _, loot_string = find(msg, PATTERN_ITEM_LOOT_SELF)
if loot_string then
loot_type = LOOT_TYPE_SELF
else
_, _, loot_string = find(msg, PATTERN_ITEM_LOOT_WON)
if not loot_string then return end
loot_type = LOOT_TYPE_WON
end
local item_link, _, id, code = parseItemLink(loot_string)
if code then
-- Check for immediate duplicate item loot messages across loot types
if last_loot_time then
if loot_type == LOOT_TYPE_SELF
and last_won_code and code == last_won_code
and seenTooSoon(last_loot_time) then
return
elseif loot_type == LOOT_TYPE_WON
and last_self_code and code == last_self_code
and seenTooSoon(last_loot_time) then
return
end
end
-- Record last sucessful loot
last_loot_time = GetTime()
if loot_type == LOOT_TYPE_SELF then
last_self_code = code
elseif loot_type == LOOT_TYPE_WON then
last_won_code = code
end
local token = makeStoreToken(code)
local _, _, count = find(loot_string, PATTERN_ITEM_LOOT_SELF_COUNT)
count = count and tonumber(count) or 1
if A:isEnabled() and filter.itemMatchQuality(id) then
local value = pricing.value(token)
if value and value > 0 then
A:print(format("%dx %s = %s", count, item_link,
util.formatMoneyFull(count * value)))
else
A:print(format("%dx %s", count, item_link))
end
end
session.lootItem(token, count, id)
A:guiUpdate()
else
A.warn("Item loot message but no item code found. Original message: %s",
msg)
end
end
end
do
local LootSlotIsCoin = LootSlotIsCoin
local isInGroup = util.isInGroup
local extendedStringToMoney = util.extendedStringToMoney
local money_loot_slot, money_loot_amount
function A:LOOT_OPENED()
--These events are checked only while solo.
if isInGroup() then return end
local count = GetNumLootItems()
if count < 1 then return end
for slot=1,count do
local _, name, quantity = GetLootSlotInfo(slot)
if LootSlotIsCoin(slot) then
local value = extendedStringToMoney(name)
if value and value > 0 then
money_loot_slot = slot
money_loot_amount = value
--Leave because there should only be a single coin slot
return
end
end
end
end
function A:LOOT_SLOT_CLEARED(slot)
if not money_loot_slot then return end
if not slot or slot ~= money_loot_slot then return end
if money_loot_amount then
session.lootMoney(money_loot_amount, L["solo"])
money_loot_slot = nil
money_loot_amount = nil
A:guiUpdate()
end
end
function A:LOOT_CLOSED()
money_loot_slot = nil
money_loot_amount = nil
end
end
function A:guiUpdate()
gui_main.update()
gui_config.update()
gui_minimap.update()
end
-- Loading --
local frame = CreateFrame("Frame")
A.eventframe = frame
-- Fires when an addon and its saved variables are loaded
frame:RegisterEvent("ADDON_LOADED")
-- Fires when receiving notice that the player or a member of the player’s
-- group has looted an item.
frame:RegisterEvent("CHAT_MSG_LOOT")
-- Fires when the player receives money as loot
frame:RegisterEvent("CHAT_MSG_MONEY")
-- Fires when the player begins interaction with a lootable corpse or object
frame:RegisterEvent("LOOT_OPENED")
-- Fires when the contents of a loot slot are removed
frame:RegisterEvent("LOOT_SLOT_CLEARED")
-- Fires when the player ends interaction with a lootable corpse or object
frame:RegisterEvent("LOOT_CLOSED")
frame:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == A.name then
A.is_loaded = true
A.loaded_name = A.name
A.setCharConfigDefaults()
filter.populateItemType()
gui_minimap.update()
else
local event_method = A[event]
if event_method then
event_method(A, arg1, arg2, arg3, arg4, arg5)
end
end
end)