Files
metin2-server/docs/FEATURE-SWITCHBOT.md
T
shenleiandClaude Opus 5.5 a28393b16b Port the AVA2 switchbot (自动洗练) 1:1
AVA2 new_switchbot ported as port_switchbot.{h,cpp}: SWITCHBOT item window (7),
CG/GC 171 and GG 31 with AVA2 subheaders and field order, pack(1) structs pinned
by static_assert, 0.1 s roll, P2P hand-over on warp, boot ALTER of
player.item.window. Switchers come from the inventory; current checks and
ItemLog are kept. Clients sending "mt20261016" or newer as the version
timestamp get the switchbot; older clients are left alone.

The v1 /mt_switchbot chat command, its lock verb and query capability bit 64
are removed (cap mask 1023 -> 959).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 20:26:06 +09:00

64 lines
5.1 KiB
Markdown

# PORT switchbot (自动洗练), AVA2 port
AVA2 `ENABLE_SWITCHBOT` ported 1:1 (reference: AVA2 `game/src/new_switchbot.{h,cpp}`, client `PythonSwitchbot.cpp` and `root/uiswitchbot.py`). Classes, API, packets, the window and the 0.1 s roll speed are AVA2's. It replaces the v1 `/mt_switchbot` chat protocol (`MTSB1`, query capability bit 64). That command and its lock verb are gone.
Source:
- `src/server/game/src/port_switchbot.{h,cpp}`: `SwitchbotHelper`, `CSwitchbot`, `CSwitchbotManager`, `PortSwitchbotBoot`.
- `common/length.h`: `SWITCHBOT = 7` in `EWindows` (GROUND is now 8), `SWITCHBOT_SLOT_COUNT 6 / _REAL 5 / ALTERNATIVE_COUNT 2 / NORM_ATTR_NUM 5`, `TItemPos::IsSwitchbotPosition`.
- `common/tables.h`: the switchbot tables.
## Window and items
- Items placed in the `SWITCHBOT` window (cells 0..4) are kept in `m_pointsInstant.pSwitchbotItems` and saved with `window = 'SWITCHBOT'`. The db loads, saves and deletes that window with SAFEBOX and DRAGON_SOUL_INVENTORY (three queries in `ClientManagerPlayer.cpp`).
- At boot (game cores only), `PortSwitchbotBoot` adds `'SWITCHBOT'` to the `player.item.window` enum if it is missing. The deploy SQL carries the same ALTER.
- `MoveItem` only accepts `SwitchbotHelper::IsValidItem` items into the window. That is AVA2's list: weapons, rings, and armour (body, head, shield, wrist, shoes, necklace, earrings, talisman). Cell 5 is rejected. The move hooks send:
- `switchbot_error active` when the item is moved out of a running slot;
- `switchbot_error invalid` when the item is not valid for the switchbot.
- Drop, give, exchange and safebox refuse switchbot cells: the item has to go back to the inventory first. Shops sell only from the inventory.
## Rolling
- `CSwitchbot::SwitchItems` runs every 0.1 s (`c_fSpeed`). Each active slot takes one switcher per pass.
- A slot finishes when one configured alternative fully matches within the first 5 attributes (AVA2 `CheckItem`). An alternative that isn't configured counts as a match.
- Deviations from AVA2 (also listed at the top of `port_switchbot.cpp`):
- Cell 5 (AVA2's hidden switcher cell) is never used. Switchers come from the inventory, skipping stacks that are being exchanged, locked or sold in the player's shop.
- Which switcher is used follows the manual path:
- a talisman takes only 71302;
- a weapon or body armour with no level limit above 40 takes 71151 / 76023 first;
- everything else takes 71084, then 39028.
- A slot whose item has no attributes stops instead of rolling.
- Every roll is written to ItemLog as `SWITCHBOT`, with the item id as the hint.
- End and stop messages are server commands, which the client turns into localized text:
- `switchbot_end <slot>`
- `switchbot_stop noattr <slot>`
- `switchbot_stop nochanger <slot>`
The slot is 0-based. AVA2 sent the locale ids `864` / `865` with slot+1.
- Leaving the core deletes the table once it has been sent on. A logout that unregisters the last active slot also stops the event.
- The attribute list has two pseudo sets after `ATTRIBUTE_SET_MAX_NUM`: 8 = rings (`port_rings.cpp`) and 9 = talismans (`port_pendant.cpp`).
- Warp: `CHARACTER::WarpSet` sends the table over P2P (`HEADER_GG_SWITCHBOT 31`, `TPacketGGSwitchbot`) before `GC_WARP`. The target core keeps it, and `EnterGame` re-registers the slots whose item is still there and restarts the event.
## Protocol
Header numbers, subheaders and field order are AVA2's. The structs are `pack(1)`, and their sizes are pinned with `static_assert` in `port_switchbot.cpp` and in the client (`Packet.h`, `PythonSwitchbot.h`).
| Packet | Header | Layout |
| --- | --- | --- |
| CG | 171, dynamic | `BYTE header, int size, BYTE subheader, BYTE slot` (7) + `START`: `TSwitchbotAttributeAlternativeTable[2]` (15 each) / `STOP` |
| GC | 171, dynamic | same 7-byte head + `UPDATE`: `TSwitchbotTable` (220) / `UPDATE_ITEM`: `TSwitchbotUpdateItem` (40: slot, vnum, count, 3 sockets, 7 attributes) / `SEND_ATTRIBUTE_INFORMATION`: `TSwitchbottAttributeTable[n]` (9) |
| GG | 31 | `TPacketGGSwitchbot` (223) |
CG is registered in `packet_info.cpp` with `Set(..., true)` and GG with `Set(..., false)`. The 40250 base packets are unchanged.
**Version gate.** The new client sends `mt20261016` as the `CG_CLIENT_VERSION` timestamp, in place of `__TIMESTAMP__`. Before `EnterGame` sends anything, it checks `SwitchbotHelper::IsClientSupported`, which requires `mt<date>` with date >= `PORT_SWITCHBOT_CLIENT_VERSION`. An older client gets no GC_SWITCHBOT packet. It can't fill the window either. The EU-branch client timestamp (`1215955205`) doesn't pass the gate.
## Verification
- `tests/features/test_switchbot.py` checks:
- the window enum, headers, subheaders, struct fields and sizes, on both the server and the client;
- the window hooks, the P2P hand-over, the boot ALTER and the switcher choice;
- the version gate;
- that `/mt_switchbot` is gone.
- Client: `metin2-client/tests/wiki/test_switchbot.py` checks that the window script is AVA2 `uiswitchbot.py` verbatim, plus its glue.
- Not yet compiled on 203 and not deployed. The live 203 still runs v1, so the server and client must be deployed together.