-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.lua
More file actions
executable file
·220 lines (190 loc) · 7.25 KB
/
events.lua
File metadata and controls
executable file
·220 lines (190 loc) · 7.25 KB
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
-- SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
-- Copyright (c) 2025-2026 Thomas Floeren
local MYNAME, A = ...
local db = A.db
local CLR = A.CLR
local addonprint, debugprint, debugprint_pt = A.addonprint, A.debugprint, A.debugprint_pt
local type = type
local format = format
-- Misc variables
local realm
local NEXT_BID_MULTI = 1.05 -- +5%
--[[============================================================================
Events
============================================================================]]--
-- https://www.townlong-yak.com/framexml/live/Blizzard_BlackMarketUI/Blizzard_BlackMarketUI.lua
-- https://warcraft.wiki.gg/wiki/API_C_BlackMarket.RequestItems
-- This is in the events section bc it triggers BLACK_MARKET_ITEM_UPDATE.
function A.bm_refresh()
if not A.bm_is_connected then
addonprint('This requires the BMAH to be opened!')
return
end
C_BlackMarket.RequestItems()
end
--[[
NOTES:
https://warcraft.wiki.gg/wiki/Category:API_systems/BlackMarketInfo
Blizz std messages: 'Bid accepted.', 'You have been outbid on <item name>.',
'You won an auction for <item name>'
]]
local function get_strings_for_notif(market_id, item_id)
local link, curr, min, min_next, incr_next
if db.realms[realm] and db.realms[realm].auctions and db.realms[realm].auctions[market_id] then
link = db.realms[realm].auctions[market_id].link
curr = db.realms[realm].auctions[market_id].curr_bid
min = db.realms[realm].auctions[market_id].min_bid
end
if type(curr) ~= 'number' or type(min) ~= 'number' then
debugprint(format('%sCould not get prices from DB!', CLR.WARN()))
curr, min, min_next, incr_next = '<???>', '<???>', '<???>', '<???>'
else
min_next = floor((min * NEXT_BID_MULTI) / 1e4) * 1e4
incr_next = min_next - curr
curr, min, min_next, incr_next =
GetMoneyString(curr, true), GetMoneyString(min, true), GetMoneyString(min_next, true), GetMoneyString(incr_next, true)
end
if type(link) ~= 'string' then
debugprint(format('%sCould not get link from DB! Trying GetItemInfo...', CLR.WARN()))
link = item_id and C_Item.GetItemInfo(item_id) or '<Unknown Item>'
end
local time = '[' .. A.time_format(time(), false) .. ']'
return time, link, curr, min, min_next, incr_next
end
local id_for_bid_notif
local bmah_update_wait
local function BLACK_MARKET_ITEM_UPDATE()
debugprint_pt('BLACK_MARKET_ITEM_UPDATE fired.')
if bmah_update_wait then return end
bmah_update_wait = true
C_Timer.After(db.cfg.delay_after_bm_itemupdate_event, function()
debugprint_pt('Updating now.')
A.show_records(true)
if id_for_bid_notif then
local time, link, curr, min, min_next, incr_next =
get_strings_for_notif(id_for_bid_notif)
if db.cfg.notif_chat and db.cfg.notif_chat_bid then
local str = format(
'%s placed on %s. Your next minimum bid: %s (+%s)',
curr,
link,
min_next,
incr_next
)
addonprint(str)
end
if db.cfg.notif_frame and db.cfg.notif_frame_bid then
local str = format('%s%s %s placed on %s\124r', CLR.TXT(), time, curr, link)
tinsert(db.global.notifs, 1, str)
A.show_notifs()
end
id_for_bid_notif = nil
end
bmah_update_wait = nil
end)
end
local function BLACK_MARKET_OPEN()
A.bm_is_connected = true
A.time_bm_opened = GetTime()
end
local function BLACK_MARKET_CLOSE()
A.bm_is_connected = false
A.hide_records()
end
local function BLACK_MARKET_OUTBID(market_id, item_id)
if db.cfg.notif_sound and db.cfg.notif_sound_outbid then PlaySoundFile(644193, 'Master') end -- "Aargh"
local chat = db.cfg.notif_chat and db.cfg.notif_chat_outbid
local frame = db.cfg.notif_frame and db.cfg.notif_frame_outbid
if chat or frame then
local time, link, curr, min, min_next, incr_next = get_strings_for_notif(market_id, item_id)
if chat then
local str = format('%sOutbid on %s at %s', CLR.WARN(), link, CLR.TXT(curr))
addonprint(str)
end
if frame then
local str =
format('%s%s Outbid on %s at %s\124r', CLR.WARN(), time, link, CLR.TXT(curr))
tinsert(db.global.notifs, 1, str)
A.show_notifs()
end
end
debugprint('BLACK_MARKET_OUTBID', market_id, item_id)
end
local function BLACK_MARKET_WON(market_id, item_id)
if db.cfg.notif_sound and db.cfg.notif_sound_won then PlaySoundFile(636419, 'Master') end -- "Nicely Done"
local chat = db.cfg.notif_chat and db.cfg.notif_chat_won
local frame = db.cfg.notif_frame and db.cfg.notif_frame_won
if chat or frame then
local time, link, curr, min, min_next, incr_next = get_strings_for_notif(market_id, item_id)
if chat then
local str = format('%s%s won for %s', CLR.GOOD(), link, CLR.TXT(curr))
addonprint(str)
end
if frame then
local str = format('%s%s %s won for %s\124r', CLR.GOOD(), time, link, CLR.TXT(curr))
tinsert(db.global.notifs, 1, str)
A.show_notifs()
end
end
debugprint('BLACK_MARKET_WON', market_id, item_id)
end
local function BLACK_MARKET_BID_RESULT(market_id, result_code)
if result_code == 0 then
if db.cfg.notif_sound and db.cfg.notif_sound_bid then PlaySoundFile(636627, 'Master') end -- "Yes"
-- The bid triggers a BLACK_MARKET_ITEM_UPDATE. So send the msg with that event, for up-to-date data.
if
db.cfg.notif_chat and db.cfg.notif_chat_bid
or db.cfg.notif_frame and db.cfg.notif_frame_bid
then
id_for_bid_notif = market_id
end
end
debugprint('BLACK_MARKET_BID_RESULT', market_id, result_code)
end
-- For the simulator
A.BLACK_MARKET_BID_RESULT = BLACK_MARKET_BID_RESULT
A.BLACK_MARKET_WON = BLACK_MARKET_WON
A.BLACK_MARKET_OUTBID = BLACK_MARKET_OUTBID
A.BLACK_MARKET_ITEM_UPDATE = BLACK_MARKET_ITEM_UPDATE
local function PLAYER_LOGIN()
A.user_is_author = tf6 and tf6.user_is_tflo
realm = A.get_bm_realm() -- Not available at addon load time
if type(realm) ~= 'string' then return end
A.realm = realm
db.realms[realm] = db.realms[realm] or {}
db.realms[realm].auctions = db.realms[realm].auctions or {}
db.realms[realm].records = db.realms[realm].records or {}
if A.user_is_author then A.set_test_config() end
end
local function FIRST_FRAME_RENDERED()
-- Interestingly, the OnHide script doesn't run when a frame gets dismissed per logout;
-- So, this works without any further measures.
if db.global.num_unread_notifs > 0 then A.show_notifs(false, true) end
C_Timer.After(10, function()
if A.db_updated then
addonprint(format('Database updated to v%s.', CLR.KEY(db.db_version)))
end
if not realm or not A.realm then addonprint(A.MSG_NO_REALM) end
debugprint(format('Realm: %s', tostring(realm)))
end)
end
--[[----------------------------------------------------------------------------
Event frame, handlers, and registration
----------------------------------------------------------------------------]]--
local ef = CreateFrame('Frame', MYNAME .. '_eventframe')
local event_handlers = {
['BLACK_MARKET_ITEM_UPDATE'] = BLACK_MARKET_ITEM_UPDATE,
['BLACK_MARKET_CLOSE'] = BLACK_MARKET_CLOSE,
['BLACK_MARKET_OPEN'] = BLACK_MARKET_OPEN,
['BLACK_MARKET_OUTBID'] = BLACK_MARKET_OUTBID, -- marketID, itemID
['BLACK_MARKET_WON'] = BLACK_MARKET_WON, -- marketID, itemID
['BLACK_MARKET_BID_RESULT'] = BLACK_MARKET_BID_RESULT, -- marketID, resultCode
['PLAYER_LOGIN'] = PLAYER_LOGIN,
['FIRST_FRAME_RENDERED'] = FIRST_FRAME_RENDERED,
}
for event in pairs(event_handlers) do
ef:RegisterEvent(event)
end
ef:SetScript('OnEvent', function(_, event, ...)
event_handlers[event](...) -- We do not want a nil check here.
end)