Skip to content

Commit 31e2212

Browse files
committed
Fixed potion shop & added debugs.
1 parent fe1ff6b commit 31e2212

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

src/001-constants.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,6 @@ local DEBUG_ACCOUNTS = {
25392539
'fatality',
25402540
'rydan',
25412541
'shadowart',
2542-
'aini',
2542+
'jontor',
25432543
'draadloos'
25442544
}

src/005-container.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Container = (function()
88
local setInterval = Core.setInterval
99
local when = Core.when
1010
local formatList = Core.formatList
11+
local debug = Core.debug
1112
local log = Console.log
1213
local info = Console.info
1314
local prompt = Console.prompt
@@ -156,6 +157,7 @@ Container = (function()
156157

157158
-- Registers the error watcher
158159
watchContainerFullError = function()
160+
debug('containerMoveItems: container full event')
159161
return when(EVENT_ERROR, ERROR_CONTAINER_FULL, onContainerFull)
160162
end
161163

@@ -166,6 +168,7 @@ Container = (function()
166168

167169
-- Moving is paused, stop recurse
168170
if isMovingPaused then
171+
debug('containerMoveItems: moving paused')
169172
return
170173
end
171174

@@ -184,6 +187,7 @@ Container = (function()
184187
end
185188
-- Reset depths and finish
186189
resetContainerDepths(fromContainer, toContainer, sourceDepth, destDepth, function()
190+
debug('containerMoveItems: resetContainerDepths -> callback')
187191
callback(true, moveHits)
188192
end)
189193
return
@@ -202,9 +206,11 @@ Container = (function()
202206
sourceDepth = sourceDepth + 1
203207
spotOffset = 0
204208
xeno.containerUseItem(fromContainer, itemCount-1, true, true)
209+
debug('containerMoveItems: cascade [last slot]')
205210
else
206211
spotOffset = spotOffset + 1
207212
-- Skip to next item immediately
213+
debug('containerMoveItems: moveItem() [last slot]')
208214
moveItem(self)
209215
end
210216
return
@@ -214,6 +220,7 @@ Container = (function()
214220
if blackList and blackList[item.id] then
215221
spotOffset = spotOffset + 1
216222
-- Skip to next item immediately
223+
debug('containerMoveItems: moveItem() [blacklist]')
217224
moveItem(self)
218225
return
219226
end
@@ -222,6 +229,7 @@ Container = (function()
222229
if whiteList and not whiteList[item.id] then
223230
spotOffset = spotOffset + 1
224231
-- Skip to next item immediately
232+
debug('containerMoveItems: moveItem() [filter]')
225233
moveItem(self)
226234
return
227235
end
@@ -230,6 +238,7 @@ Container = (function()
230238
if itemFilter and not itemFilter(item) then
231239
spotOffset = spotOffset + 1
232240
-- Skip to next item immediately
241+
debug('containerMoveItems: moveItem() [filter func]')
233242
moveItem(self)
234243
return
235244
end
@@ -245,6 +254,7 @@ Container = (function()
245254
if moveCounts[item.id] <= 0 then
246255
spotOffset = spotOffset + 1
247256
-- Skip to next item immediately
257+
debug('containerMoveItems: moveItem() [no need]')
248258
moveItem(self)
249259
return
250260
end
@@ -266,6 +276,7 @@ Container = (function()
266276
lastMove.count = moveStackCount
267277

268278
-- Move item to destination
279+
debug(('containerMoveItems: move item %d, %d => %d, %d x%d'):format(fromContainer, spotOffset, toContainer, toSlot, moveStackCount))
269280
xeno.containerMoveItemToContainer(fromContainer, spotOffset, toContainer, toSlot, moveStackCount)
270281
end
271282

@@ -295,17 +306,21 @@ Container = (function()
295306
clearTimeout(moveInterval)
296307
end
297308
-- Reset depths and finish
309+
debug('containerMoveItems: reset depths [no bp, no cascade]')
298310
resetContainerDepths(fromContainer, toContainer, sourceDepth, destDepth, function()
311+
debug('containerMoveItems: callback() [no bp, no cascade]')
299312
callback(false, moveHits)
300313
end)
301314
return
302315
end
303316
-- Open destination container
317+
debug('containerMoveItems: open destination')
304318
xeno.containerUseItem(toContainer, toSlot, not openWindow, true)
305319
setTimeout(function()
306320
-- Update toContainer index if we opened in a new window
307321
if openWindow then
308322
toContainer = getLastContainer()
323+
debug('containerMoveItems: new window = ' .. toContainer)
309324
-- Reset destination depth, since we're in a new destination
310325
destDepth = 0
311326
end
@@ -324,11 +339,14 @@ Container = (function()
324339

325340
-- Register full event again
326341
fullEvent = watchContainerFullError()
342+
debug('containerMoveItems: cascade depth = ' .. destDepth)
327343
return
328344
end
329345
-- No cascade backpack, stop entirely
330346
-- Reset depths and finish
347+
debug('containerMoveItems: reset depths [cascaded]')
331348
resetContainerDepths(fromContainer, toContainer, sourceDepth, destDepth, function()
349+
debug('containerMoveItems: callback() [cascaded]')
332350
callback(false, moveHits)
333351
-- Kill move event
334352
if moveInterval then

src/008-npc.lua

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Npc = (function()
66
local talk = Core.talk
77
local checkSoftBoots = Core.checkSoftBoots
88
local getXenoVersion = Core.getXenoVersion
9+
local debug = Core.debug
910
local error = Console.error
1011
local getTotalItemCount = Container.getTotalItemCount
1112
local containerMoveItems = Container.containerMoveItems
@@ -15,11 +16,13 @@ Npc = (function()
1516
local function moveTransactionGoldChange(container, callback)
1617
-- Move loose gold change from container to gold backpack
1718
-- uses main bp if gold backpack isn't assigned.
19+
debug('moveTransactionGoldChange: ' .. container .. ', ' .. _backpacks['Gold'])
1820
containerMoveItems({
1921
src = container,
20-
dest = _backpacks['Gold'] or _backpacks['Main'],
22+
dest = _backpacks['Gold'],
2123
items = {
22-
[3031] = true
24+
[3031] = true,
25+
[3035] = true
2326
},
2427
disableSourceCascade = true,
2528
openwindow = false
@@ -115,6 +118,7 @@ Npc = (function()
115118

116119
-- No more to sell
117120
if amount <= 0 then
121+
debug('shopSellItem: sellItem -> callback()')
118122
callback()
119123
return
120124
end
@@ -130,14 +134,17 @@ Npc = (function()
130134
setTimeout(function()
131135
-- Remaining count to sell, recurse
132136
if remaining > 0 then
137+
debug('shopSellItem: sellItem()')
133138
sellItem()
134139
-- Sold all items, callback
135140
else
141+
debug('shopSellItem: callback()')
136142
callback()
137143
end
138144
end, pingDelay(DELAY.TRADE_TRANSACTION))
139145
-- Failed to sell, retrying
140146
elseif tries > 0 then
147+
debug('shopSellItem: retry('.. tries-1 ..')')
141148
shopSellItem(itemid, callback, neededCount, tries-1)
142149
-- Out of tries. Failed to sell stack.
143150
else
@@ -146,6 +153,7 @@ Npc = (function()
146153
return
147154
end
148155
-- Start recursive selling
156+
debug('shopSellItem: sellItem() [start]')
149157
sellItem()
150158
end
151159

@@ -156,43 +164,52 @@ Npc = (function()
156164
itemlist[#itemlist+1] = itemid
157165
end
158166
local itemcount = #itemlist
167+
debug('shopSellLoot: itemcount = '.. itemcount ..'')
159168

160169
function sell(index)
161170
local itemid = itemlist[index]
162171

163172
-- No more items, finish
164173
if not itemid then
165174
-- Move change to gold
175+
debug('shopSellLoot: moveTransactionGoldChange()')
166176
moveTransactionGoldChange(0, function()
177+
debug('shopSellLoot: callback()')
167178
callback()
168179
end)
169180
return
170181
end
171182

172183
local amount = shopSellableCount(itemid)
184+
debug('shopSellLoot: shopSellableCount('.. itemid ..') = ' .. amount)
173185

174186
if amount > 0 then
175187
shopSellItem(itemid, function()
188+
debug('shopSellLoot: shopSellItem('.. itemid ..')')
176189
-- Recurse to next item in list
177190
setTimeout(function()
178191
sell(index + 1)
192+
debug('shopSellLoot: sell('.. index + 1 ..')')
179193
end, pingDelay(DELAY.TRADE_TRANSACTION))
180194
end)
181195
else
182196
-- If we don't have the item, recurse without a wait.
183197
sell(index + 1)
198+
debug('shopSellLoot: sell('.. index + 1 ..') [no item]')
184199
end
185200
end
186201

187202
if nodialog then
188203
sell(1)
204+
debug('shopSellLoot: sell(1)')
189205
return
190206
end
191207

192208
talk({'hi', 'trade'}, function()
193209
-- Todo: use NPC proxy to verify trade window
194210
setTimeout(function()
195211
sell(1)
212+
debug('shopSellLoot: sell(1) [greet]')
196213
end, pingDelay(DELAY.RANGE_TALK))
197214
end)
198215
end
@@ -202,6 +219,7 @@ Npc = (function()
202219
callback()
203220
return
204221
end
222+
debug('shopSellFlasks: shopSellLoot()')
205223
shopSellLoot(ITEM_LIST_FLASKS, callback, true)
206224
end
207225

@@ -245,6 +263,7 @@ Npc = (function()
245263

246264
-- Price not found
247265
if price <= 0 then
266+
debug('shopBuyItemUpToCount: callback')
248267
callback()
249268
return
250269
end
@@ -258,20 +277,24 @@ Npc = (function()
258277
-- Remaining count to buy, continue
259278
if remaining > 0 then
260279
buyItem()
280+
debug('shopBuyItemUpToCount -> buyAgain: buyItem()')
261281
-- Bought all items, destination is not main, callback
262282
elseif destination > 0 then
263283
-- Final cleanup
284+
debug('shopBuyItemUpToCount -> buyAgain: containerMoveItems()')
264285
containerMoveItems({
265286
src = mainbp,
266287
dest = destination,
267288
items = {[itemid] = true},
268289
disableSourceCascade = true,
269290
openwindow = false
270291
}, function(success)
292+
debug('shopBuyItemUpToCount -> buyAgain: callback() [move]')
271293
callback()
272294
end)
273295
-- Bought all items, destination is main
274296
else
297+
debug('shopBuyItemUpToCount -> buyAgain: callback()')
275298
callback()
276299
end
277300
end
@@ -282,6 +305,7 @@ Npc = (function()
282305
-- and we have less than 3 free slots
283306
local freeSlots = xeno.getContainerItemCapacity(mainbp) - xeno.getContainerItemCount(mainbp)
284307
if destination > 0 and freeSlots < 4 then
308+
debug('shopBuyItemUpToCount: containerMoveItems()')
285309
-- Move to destination after buying stack
286310
containerMoveItems({
287311
src = mainbp,
@@ -291,14 +315,17 @@ Npc = (function()
291315
openwindow = false
292316
}, function(success)
293317
buyAgain()
318+
debug('shopBuyItemUpToCount: buyAgain() [retry]')
294319
end)
295320
else
296321
buyAgain()
322+
debug('shopBuyItemUpToCount: buyAgain()')
297323
end
298324
end, pingDelay(DELAY.TRADE_TRANSACTION))
299325
-- Failed to buy, retrying
300326
elseif tries > 0 then
301327
shopBuyItemUpToCount(itemid, neededCount, destination, callback, tries-1)
328+
debug('shopBuyItemUpToCount: retry(' .. tries - 1 .. ')')
302329
-- Out of tries. Failed to buy stack.
303330
else
304331
error('Failed to buy ' .. xeno.getItemNameByID(itemid) .. ' (' .. neededStackCount .. 'x). ' .. 'Make sure you have enough capacity and gold.')
@@ -314,7 +341,9 @@ Npc = (function()
314341
local backpack = _backpacks[group] and _backpacks[group] or nil
315342
local function buyListItem(index)
316343
-- Reached end of list, callback
344+
317345
if index > #items then
346+
debug('shopBuySupplies: callback')
318347
callback()
319348
return
320349
end
@@ -324,12 +353,14 @@ Npc = (function()
324353

325354
-- Item doesn't exist or not needed
326355
if not item or not item.needed or item.needed < 1 then
356+
debug('shopBuySupplies: buyListItem(' .. index + 1 .. ') [skip]')
327357
buyListItem(index + 1)
328358
return
329359
end
330360

331361
-- Buy item
332362
shopBuyItemUpToCount(item.id, item.needed, backpack, function()
363+
debug('shopBuySupplies: buyListItem(' .. index + 1 .. ')')
333364
buyListItem(index + 1)
334365
end)
335366
end
@@ -358,11 +389,13 @@ Npc = (function()
358389
if group == 'Potions' then
359390
talk({'trade'}, function()
360391
shopSellFlasks(function()
392+
debug('shopBuySupplies: buyListItem(1) [greet, potions]')
361393
buyListItem(1)
362394
end)
363395
end)
364396
else
365397
talk({'trade'}, function()
398+
debug('shopBuySupplies: buyListItem(' .. index + 1 .. ') [greet]')
366399
buyListItem(1)
367400
end)
368401
end
@@ -371,9 +404,11 @@ Npc = (function()
371404
-- Try to sell flasks if we may be at the magic shop
372405
if group == 'Potions' then
373406
shopSellFlasks(function()
407+
debug('shopBuySupplies: buyListItem(1) [potions]')
374408
buyListItem(1)
375409
end)
376410
else
411+
debug('shopBuySupplies: buyListItem(1)')
377412
buyListItem(1)
378413
end
379414
end

0 commit comments

Comments
 (0)