4.7 KiB
PORT batch chest opening, v1
Date: 2026-10-15. AVA2-style batch opening of gift boxes (reference: AVA2 ENABLE_MULTI_CHEST, /chest_drop, CHARACTER::OpenChest). Source: src/server/game/src/port_chest.h (header-only, included from cmd_general.cpp), command mt_chest (cmd.cpp). It reuses the quiet-INFO hook (m_portQuietInfo / m_portLastInfo) added for the switchbot. No packet header, no DB schema, no char.h/item.h change.
AVA2 rewrote the drop loop (GiveItemFromSpecialItemGroupNew, AutoGiveItemChest, cap 1000). That rewrite is not ported. Here every box goes through the original CHARACTER::UseItem → UseItemEx ITEM_GIFTBOX path, one box at a time, so the original checks, the special_item_group roll, gold/exp, ItemLog and consumption stay exactly as they are.
Rules
- Only
ITEM_GIFTBOXitems whose special item group exists, is not empty and contains none of the give typesMOB,SLOW,DRAIN_HP,POISON,MOB_GROUP. Boxes that spawn monsters or apply debuffs stay single-use (error kind). Other item types (e.g.ITEM_USEchests with quest scripts) are not batchable. - The chosen cell is opened first while it still holds the box vnum; after that, any other bag cell with the same vnum. Most gift boxes on 203 have no stack flag, so a batch normally spans many cells. Items being exchanged are skipped.
- At most 200 boxes per command.
- Before each box the character must still have 3 free bag cells (
GetEmptyInventory(3)). This keeps room for any reward, soAutoGiveItemnever has to drop one on the ground. The loop stops with reasonfull. - Busy: dead, stunned, warping, observer,
!CanHandleItem, exchange, own shop, shop open, safebox, cube. Checked before the command and before each box. - A box counts as opened only when the bag count of its vnum went down by exactly one. Anything else (the original path refused it, e.g. the dragon soul qualification) stops the loop with reason
rejected. The last INFO line of that refusal is forwarded once. - Per-box INFO lines are held back while the batch runs.
- Throttle: one command per 500 ms per player id.
Protocol (CHAT_TYPE_COMMAND, version 1)
/mt_chest 1 open CELL COUNT CELL = bag cell, COUNT = 1..200, digits only (at most 5)
MTCH1 got VNUM COUNT one line per gained vnum (box vnum excluded), at most 40 lines
MTCH1 done VNUM ASKED OPENED REASON GOLD
MTCH1 error rate|invalid|busy|item|kind|full
- REASON:
done(all asked boxes opened),empty(no box of this vnum left),full(fewer than 3 free cells),busy,rejected. - GOLD: gold balance change over the batch.
- Gains are the difference between bag + dragon soul bag counts before and after the batch.
- A request with a version other than
1, a token longer than 10 characters or more than 5 tokens is ignored silently.
There is no MTF1 capability bit (the mask stays 511). The client marks the server unsupported when no MTCH1 reply arrives within 3 s and falls back to normal single use.
Verification
tests/features/test_chest.pycompiles the production header against stubs of theUseItemgift-box contract (consume one box, gold, stacking reward, dragon soul reward, INFO lines). It covers:- cross-cell order and the gains/gold summary with INFO held back;
- a stack, fewer asked than held, more asked than held (
empty); - the 3-free-cell stop (
full,error full); - refusal by the original path (
rejected, INFO forwarded once); - non-gift box, monster box, missing and empty group (
kind); - missing/exchanging item, busy, invalid input, silently ignored version, throttle.
- It also checks the cmd.cpp / cmd_general.cpp wiring.
- All
tests/features/test_*.pypass. - FreeBSD build of the game target in
/root/metin2-features-dev(logchest-build.log, binary sha256412977c7d7fda073493533d5bee43812a8f48dcb63399f747db6180d24803853). The live/usr/metin2binary was not replaced and no live service was restarted. - Live test on 2026-10-15 against the channel-5 test core (port 13040, isolated binary) with the macOS native client as [SA]Admin, boxes created with
/item:- 50037 (stacking, 30 held), 10 asked →
done 50037 10 10 done 0, 6 gained vnums matching the bag difference exactly; - 50070 (not stacking, 4 boxes in 4 cells), all →
done 50070 4 4 done 100000, gold balance +100000; - 71036 (group spawns a monster) →
error kind, nothing consumed; an immediate second command →error rate; - remaining 20 of 50037 →
done 50037 20 20 done 0, 11 gained vnums; - plain right click without Ctrl still uses one box the original way.
log.logonly has the original path's rows (SYSTEM,TREASURE_EXP,TREASURE_GOLD). syserr shows only the pre-existingnew_quest_lv52LUA_ERROR.
- 50037 (stacking, 30 held), 10 asked →