/mt_switchbot 1 attrs|start|stop|status runs one bot per character that calls the original UseItem path every 250 ms, so checks, probabilities, ItemLog CHANGE_ATTRIBUTE and scroll use are the manual path's. Up to two alternatives of 1-5 targets; stops on matched/limit/no_scroll/item_gone/ rejected/busy/stopped, erased on logout or warp. Per-roll INFO lines are held back via a quiet flag on ChatPacket. MTF1 cap mask advertises 64. Verified live on 203 with an extra channel-5 core (port 13040) running the isolated build: limit, matched, already-matched, move during run, stop and logout during run; 72 ItemLog rows for 72 rolls. No attribute lock yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
6.2 KiB
Markdown
79 lines
6.2 KiB
Markdown
# PORT switchbot (automatic attribute change), v1
|
|
|
|
AVA2-style automatic rerolling (reference: AVA2 `new_switchbot.cpp` / `uiswitchbot.py`), rebuilt so that the server stays authoritative and the existing reroll path is unchanged. Source: `src/server/game/src/port_switchbot.h`, command `mt_switchbot` (cmd.cpp), quiet-INFO hook in `CHARACTER::ChatPacket` (char.cpp), fields in char.h. No attribute lock, no DB schema, no packet header, no P2P transfer.
|
|
|
|
## Rules
|
|
|
|
- Each roll calls the original `CHARACTER::UseItem(scroll cell, target cell)`. All checks, probabilities, the addon handling, `ItemLog CHANGE_ATTRIBUTE` and scroll consumption are the manual path's. That includes the 71151/76023 restriction (weapon/body, level limit <= 40) and the GM quest flag. A roll counts only when exactly one scroll of the chosen vnum was consumed. Otherwise the bot stops with `rejected` and resends the original INFO line once.
|
|
- The per-roll INFO lines (`属性已变更`) are held back while the bot calls UseItem (`m_portQuietInfo`); all other chat types pass through.
|
|
- Only `ITEM_USE / USE_CHANGE_ATTRIBUTE` scrolls are accepted. `USE_CHANGE_ATTRIBUTE2` has no handler in this server's UseItemEx.
|
|
- Target item: inventory cell, not costume, attribute set != -1, at least one attribute, not equipped or in an exchange. It is bound by item ID.
|
|
- One bot per character. One roll every 250 ms (`PASSES_PER_SEC(1)/4`). Limit 1..1000 rolls.
|
|
- Targets: up to 2 alternatives, each 1..5 distinct (apply, minimum). An alternative matches when every target is found among the 5 normal attribute slots with value >= minimum. Any matching alternative stops the bot (AVA2 CheckItem semantics). The bot also checks before it starts, so an item that already matches consumes nothing.
|
|
- Allowed targets are the applies the attribute table can roll for this item's set, excluding the item's base proto applies. The maximum is `lValues[min(maxLevelBySet,5)-1]`. Items with an addon type also allow skill damage 30 / normal hit 65, the item_addon bounds.
|
|
- Every tick re-checks the state and stops with a reason. This replaces AVA2's hooks into every move/trade path.
|
|
- Character gone, VID changed (logout or warp) or descriptor lost: the bot is erased silently.
|
|
- `busy`: dead, warping, `!CanHandleItem()`, exchange, own shop, shop, safebox or cube open.
|
|
- `item_gone`: the item is missing, has another owner, has left the inventory window or is equipped.
|
|
- `no_scroll`, `limit`, `matched`, `rejected`, `stopped`.
|
|
- No offline rolling. Rolls stop when the player leaves, and every completed roll has already been saved and logged by the original path.
|
|
|
|
## Protocol (CHAT_TYPE_COMMAND, version 1)
|
|
|
|
Requests (250 ms per-character throttle; tokens <= 10 chars, <= 30 tokens):
|
|
|
|
```
|
|
/mt_switchbot 1 attrs CELL
|
|
/mt_switchbot 1 start CELL SCROLL_VNUM LIMIT N1 (APPLY MIN)*N1 [N2 (APPLY MIN)*N2]
|
|
/mt_switchbot 1 stop
|
|
/mt_switchbot 1 status
|
|
```
|
|
|
|
Replies:
|
|
|
|
```
|
|
MTSB1 attrs CELL VNUM COUNT
|
|
MTSB1 attr INDEX APPLY MAX (COUNT rows, INDEX 0..COUNT-1)
|
|
MTSB1 attrs_end CELL COUNT
|
|
MTSB1 state ACTIVE CELL VNUM ROLLS LIMIT SCROLL SCROLLS REASON
|
|
MTSB1 error VERB CODE
|
|
```
|
|
|
|
`REASON` is one of `running matched limit no_scroll item_gone rejected busy stopped idle`. Error codes:
|
|
|
|
| Code | Meaning |
|
|
| --- | --- |
|
|
| `rate` | throttled |
|
|
| `invalid` | malformed |
|
|
| `item` | no item in that cell |
|
|
| `equipped` | equipped or in an exchange |
|
|
| `no_attr` | the item cannot be rerolled |
|
|
| `scroll` | the scroll is missing or the wrong type |
|
|
| `target` | the apply is not allowed, above the maximum or a duplicate |
|
|
| `running` | this character already has a bot |
|
|
| `busy` | see the busy states above |
|
|
|
|
A state line is pushed after every roll and when the bot stops. When the reason is `item_gone`, CELL and VNUM are 0.
|
|
|
|
Capability: the MTF1 cap mask advertises bit 64 (63 -> 127). Clients that don't know it ignore it, and the client also times out to "unsupported" against old servers.
|
|
|
|
## Verification
|
|
|
|
- `tests/features/test_switchbot.py` compiles the production header against stubs of the UseItem/ChatPacket contract. It covers the allowed list (proto exclusion, set filter, level cap, addon), validation, two alternatives, the already-matched start, quiet INFO, limit, `no_scroll`, `rejected` (INFO resent once), `item_gone`, `busy`, stop/status/idle and silent erase on a VID change.
|
|
- `tests/features/test_queries.py` was updated for cap mask 127.
|
|
- FreeBSD build of the whole game target on 203 in `/root/metin2-features-dev` (BINDIR=GAMEDIR=`/root/metin2-features-dev/bin`), log `/root/metin2-features-dev/switchbot-build.log`, with no warnings from the new code. The live `/usr/metin2` binary was not replaced and no service was restarted.
|
|
- Live test on 2026-10-15. 203 ran an extra core (`/usr/metin2/server/channel5/first`: CHANNEL 5, PORT 13040, P2P 14040, MAP_ALLOW 1 21 41) with its `game` symlinked to the isolated binary. The macOS native client (`--live-server 192.168.21.203:11000:13040`) drove [SA]Admin, sword 279, scroll 71084:
|
|
- `attrs` returned 14 rows for the sword (18 for armor 12019), received complete.
|
|
- limit 10 → `limit` after 10 rolls. State lines arrived about every 0.24 s (about 4 rolls/s); the scroll count fell 200 → 190.
|
|
- Two alternatives with minimum 1 → `matched` after 18 rolls.
|
|
- Start on an item that already matches → `matched` with 0 rolls and no scroll used.
|
|
- Moving the item 33 → 90 mid-run → the run continued, the state line reported cell 90, and `stop` → `stopped`.
|
|
- Client exit mid-run (8 rolls) → `log.log` stopped at the exit second. The CHANGE_ATTRIBUTE row count (72 = 10+18+12+12+12+8) stayed the same 20 s later.
|
|
- Every roll wrote one `CHANGE_ATTRIBUTE` row. The core's syserr shows no new errors; the `new_quest_lv52` LUA_ERROR also appears on the live cores.
|
|
- Not done yet: `busy` and `no_scroll` on the real server (unit tests only), and Android device validation.
|
|
|
|
## Open items
|
|
|
|
- Attribute lock: AVA2 stores it at attribute index 7, which the current 7-slot layout cannot hold. It needs its own storage design (see the client migration plan, phase 6).
|
|
- In 203 `player.item_proto`, 71084, 71151, 76014, 76023 and 39028 are USE/USE_CHANGE_ATTRIBUTE (subtype 18); 71302 (the AVA2 talisman scroll) does not exist. The bot accepts any `USE_CHANGE_ATTRIBUTE` scroll and leaves item rules to the original path.
|