Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3590a06946 | ||
|
|
06b96c62d1 | ||
|
|
bc32475742 | ||
|
|
4b4f32ed58 | ||
|
|
bcd318791e | ||
|
|
dc7159338e |
@@ -0,0 +1,83 @@
|
||||
# PORT attribute lock
|
||||
|
||||
AVA2 `ENABLE_LOCK_ATTR`, rebuilt for this server's item layout. Up to two of the five normal attribute slots keep their type and value when the item is rerolled. Source: `src/server/game/src/port_attr_lock.{h,cpp}`, `CItem::ChangeAttribute` / `CopyAttributeTo` (item_attribute.cpp), the cache fields in item.h/item.cpp, the boot hook in main.cpp, and the `lock` verb of `mt_switchbot` (port_switchbot.h).
|
||||
|
||||
## Storage
|
||||
|
||||
AVA2 keeps up to two 1-based slot indices as attribute values at indices 7 and 8 of its 15-slot attribute array. This server has `ITEM_ATTRIBUTE_MAX_NUM = 7` (5 normal + 2 rare) and `ITEM_SOCKET_MAX_NUM = 3`, which metin stones use. The `item` table does have `socket3..socket5`, but `TPlayerItem` and the client packets only carry 3 sockets, so using them would change both the db↔game and client wire formats. The `item` row is also rewritten with `REPLACE INTO`, so a column written behind the db cache would be lost.
|
||||
|
||||
The lock therefore lives in its own table, which no packet or db-cache structure carries:
|
||||
|
||||
```sql
|
||||
CREATE TABLE IF NOT EXISTS mt_item_attr_lock (item_id INT UNSIGNED NOT NULL PRIMARY KEY, mask TINYINT UNSIGNED NOT NULL) ENGINE=MyISAM
|
||||
```
|
||||
|
||||
- Each game core creates it at boot (`PortAttrLockBoot`, auth cores skip it). No manual migration is needed.
|
||||
- Bit i of `mask` is normal slot i (0..4). A mask of 0 deletes the row.
|
||||
- `PortAttrLockGet` reads the mask once per `CItem` with a synchronous `DBManager::DirectQuery` by primary key and caches it on the item (`m_portAttrLock`, `m_portAttrLockLoaded`). Exchanges on the same core keep the object and its cache. A warp or relog creates a new object, which reads the row again.
|
||||
- `PortAttrLockSet` writes synchronously, so the next core always sees the new value, and writes an `ATTR_LOCK` item log (hint = new mask).
|
||||
- A failed lookup logs a syserr, returns 0 and is retried next time. A failed write leaves the cache unchanged and returns the `db` error.
|
||||
- `CopyAttributeTo` (refine, upgrade, over9 refine, quest item swaps) copies the lock to the new item ID together with the attributes.
|
||||
- Rows of destroyed items stay behind. They are harmless because item IDs are not reused.
|
||||
|
||||
## Rules
|
||||
|
||||
- Only the five normal slots can be locked; the rare slots 5/6 are not affected. The item must sit in the inventory, not be equipped or in an exchange, not be a costume, and have an attribute set. The slot must hold an attribute.
|
||||
- At most 2 lock groups, and at least one filled slot must stay unlocked. On items with an addon type (`sAddonType`, weapons whose slots 0/1 are the skill / normal hit bonus pair), slots 0 and 1 lock and unlock together and count as one group.
|
||||
- The bot's own item cannot be locked or unlocked while the bot is rolling it (`running`).
|
||||
- Locking is free. AVA2 consumes 50348/50349 per lock or unlock; those vnums do not exist in 203 `item_proto`.
|
||||
- `CItem::ChangeAttribute` (scroll rerolls, the switchbot, the GM command):
|
||||
1. take the effective mask: stored mask ∩ filled slots, with the addon pair kept whole;
|
||||
2. clear the normal slots;
|
||||
3. apply the addon only if the addon pair is not locked;
|
||||
4. put back the locked slots at their indices;
|
||||
5. reroll the remaining count with the original `PutAttribute`. It writes to the first empty slot and skips types already present, so the gaps fill in order without duplicating a locked type.
|
||||
|
||||
With no lock, the effective mask is 0 and the sequence equals the original. The attribute count is kept, and the rare slots are untouched.
|
||||
- Adding an attribute (71085) and rare-attribute scrolls do not look at the lock.
|
||||
|
||||
## Protocol (part of mt_switchbot v1)
|
||||
|
||||
```
|
||||
/mt_switchbot 1 lock CELL SLOT toggle the lock on normal slot SLOT (0..4)
|
||||
MTSB1 lock CELL VNUM MASK effective mask; also sent after every attrs_end
|
||||
MTSB1 error lock CODE item equipped no_attr busy running slot max db rate invalid
|
||||
```
|
||||
|
||||
`slot` means out of range or empty. `max` means a third group, or every filled slot locked. `db` means the write failed. Older servers never send a `lock` line, so the client shows no lock buttons there.
|
||||
|
||||
## Verification
|
||||
|
||||
- `tests/features/test_attr_lock.py` cuts the production `CItem::ChangeAttribute` body out of item_attribute.cpp and compiles it against a stub item. It checks that:
|
||||
- with no lock every slot changes;
|
||||
- locked slots 1+3 are kept in place and the gaps are refilled;
|
||||
- a locked type is not rolled again;
|
||||
- a lock on an empty slot is ignored;
|
||||
- a locked addon pair skips `ApplyAddon`, while an unlocked one is rerolled;
|
||||
- the rare slot is untouched and the count is kept;
|
||||
- there is no DB lookup when there are no attributes;
|
||||
- every toggle, effective-mask and group-count rule holds.
|
||||
- It also checks the boot hook, the Makefile, the cache initialisation and that `CopyAttributeTo` copies the lock.
|
||||
- `tests/features/test_switchbot.py` covers the `lock` verb (toggle, `slot`, `max`, `db`, `running`, `no_attr`, `item`, `invalid`, the addon pair) and the lock line after `attrs_end`.
|
||||
- FreeBSD: full rebuild of game in `/root/metin2-features-dev` (log `attrlock-build.log`; `item.h` changed, so every .cpp was touched).
|
||||
- Live on 2026-10-15, channel-5 test core (13040) with the isolated binary, macOS client, [SA]Admin, armour 11209 (item 20000178, 5 attributes), scroll 71084:
|
||||
- the first boot created the table;
|
||||
- locking slot 1 → mask 2, then slot 3 → mask 10, then slot 0 → `error lock max`;
|
||||
- 10 switchbot rolls (`limit`, scrolls 143 → 133): (23,10) in slot 1 and (39,10) in slot 3 stayed the same on every roll, slots 0/2/4 changed every roll, and there were no duplicate types;
|
||||
- the row read `20000178 10`;
|
||||
- a new client session showed `lock 19 11209 10` (reloaded from the table);
|
||||
- unlocking → 8 → 0, and the row was deleted;
|
||||
- `log` has four `ATTR_LOCK` rows (hints 2, 10, 8, 0).
|
||||
- Not done: Android device test.
|
||||
|
||||
## Production deployment
|
||||
|
||||
- 2026-10-15 16:08, approved by the user. All 203 live cores now run main `dc71593` (`game` sha256 `a8556bdc…`, the exact binary the channel-5 core was tested with, built in `/root/metin2-features-dev`). The db binary is unchanged. 0 players were online.
|
||||
- Package `/root/deploy-features/20261015-attrlock` (`deploy.sh check|go|rollback`, `SHA256SUMS`). The previous `game`/`db` (boss deploy, `400e44f`) are in `/root/backup-bin/20261015-160813`. The 8 changed files were synced into `/usr/metin2/src`, and the replaced ones are in `src-before/`. Because `item.h` changed, a later `rebuild.sh build` must touch every game .cpp. `sh deploy.sh rollback` restores both; the `mt_item_attr_lock` table can stay, since old binaries ignore it.
|
||||
- CH2–CH4 and the channel-5 core were started by hand after `start.sh 1`, giving 14 game cores plus db and auth.
|
||||
- Live acceptance on CH1 (13000), same armour 11209 (item 20000178), scroll 71084:
|
||||
- lock slot 1 → 2, slot 3 → 10, slot 0 → `error lock max`;
|
||||
- 10 switchbot rolls (scrolls 133 → 123): (23,10) and (39,10) unchanged on every roll, the other slots changed;
|
||||
- the row read `20000178 10`; a new session showed `lock 19 11209 10`;
|
||||
- unlocking → 8 → 0 deleted the row, and four new `ATTR_LOCK` log rows were written;
|
||||
- no `PortAttrLock` syserr entries.
|
||||
@@ -0,0 +1,58 @@
|
||||
# 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_GIFTBOX` items whose special item group exists, is not empty and contains none of the give types `MOB`, `SLOW`, `DRAIN_HP`, `POISON`, `MOB_GROUP`. Boxes that spawn monsters or apply debuffs stay single-use (`error kind`). Other item types (e.g. `ITEM_USE` chests 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, so `AutoGiveItem` never has to drop one on the ground. The loop stops with reason `full`.
|
||||
- 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.py` compiles the production header against stubs of the `UseItem` gift-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_*.py` pass.
|
||||
- FreeBSD build of the game target in `/root/metin2-features-dev` (log `chest-build.log`, binary sha256 `412977c7d7fda073493533d5bee43812a8f48dcb63399f747db6180d24803853`). The live `/usr/metin2` binary 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.log` only has the original path's rows (`SYSTEM`, `TREASURE_EXP`, `TREASURE_GOLD`). syserr shows only the pre-existing `new_quest_lv52` LUA_ERROR.
|
||||
|
||||
## Production deployment
|
||||
|
||||
- Deployed 2026-10-15 16:43 with the user's approval, 0 players online. Server main bc32475, game sha256 `412977c7…` (the channel-5 tested binary), db unchanged. Package `/root/deploy-features/20261015-chest`, backup `/root/backup-bin/20261015-164314`, rollback `sh /root/deploy-features/20261015-chest/deploy.sh rollback`. `/usr/metin2/src` was synced (cmd.cpp, cmd_general.cpp, port_chest.h).
|
||||
- On the first start the db core exited at boot (`QueryLocaleSet: ... errno 2013 Lost connection to MySQL server during query`, db.core kept as `db.core.164339` in the package). MySQL itself had not restarted and the db binary is unchanged. A clean stop of every core and a db-first start (db, auth, CH1–CH4, game99, then channel5) came up normally: 14 game, 1 db, 1 auth, port 15000 listening. If this repeats, check `ps` for `./db` after every deploy, not only the game count.
|
||||
- CH1 (13000) acceptance with the channel-5 scenario: 50037 ×10 → `done 50037 10 10 done 0` (8 vnums, equal to the bag difference); 50070 ×4 in 4 cells → `done 50070 4 4 done 100000`; 71036 → `error kind`, then `error rate`; remaining 20 → `done 50037 20 20 done 0`; plain use unchanged. syserr only has the pre-existing `new_quest_lv52` LUA_ERROR.
|
||||
@@ -27,6 +27,7 @@ Requests (250 ms per-character throttle; tokens <= 10 chars, <= 30 tokens):
|
||||
/mt_switchbot 1 start CELL SCROLL_VNUM LIMIT N1 (APPLY MIN)*N1 [N2 (APPLY MIN)*N2]
|
||||
/mt_switchbot 1 stop
|
||||
/mt_switchbot 1 status
|
||||
/mt_switchbot 1 lock CELL SLOT (attribute lock, see FEATURE-ATTR-LOCK.md)
|
||||
```
|
||||
|
||||
Replies:
|
||||
@@ -36,6 +37,7 @@ 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 lock CELL VNUM MASK (after every attrs_end, and as the reply to lock)
|
||||
MTSB1 error VERB CODE
|
||||
```
|
||||
|
||||
@@ -87,5 +89,5 @@ Capability: the MTF1 cap mask advertises bit 64 (63 -> 127). Clients that don't
|
||||
|
||||
## 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).
|
||||
- Attribute lock: done separately in `FEATURE-ATTR-LOCK.md` (table `mt_item_attr_lock`, applied inside `CItem::ChangeAttribute`, so every bot roll keeps the locked slots). The bot's own item cannot be locked or unlocked while it rolls.
|
||||
- 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.
|
||||
|
||||
@@ -61,7 +61,7 @@ CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp
|
||||
desc_client.cpp desc_manager.cpp desc_p2p.cpp dev_log.cpp dungeon.cpp empire_text_convert.cpp entity.cpp\
|
||||
entity_view.cpp event.cpp event_queue.cpp exchange.cpp file_loader.cpp fishing.cpp gm.cpp guild.cpp\
|
||||
guild_manager.cpp guild_war.cpp horse_rider.cpp horsename_manager.cpp input.cpp input_auth.cpp input_db.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp port_attr_lock.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
item.cpp item_addon.cpp item_attribute.cpp item_manager.cpp item_manager_idrange.cpp locale.cpp\
|
||||
locale_service.cpp log.cpp login_data.cpp lzo_manager.cpp marriage.cpp matrix_card.cpp\
|
||||
messenger_manager.cpp mining.cpp mob_manager.cpp monarch.cpp motion.cpp over9refine.cpp p2p.cpp packet_info.cpp\
|
||||
|
||||
@@ -12,6 +12,7 @@ ACMD(do_port_biolog);
|
||||
ACMD(do_port_features);
|
||||
ACMD(do_port_switchbot);
|
||||
ACMD(do_port_pickup);
|
||||
ACMD(do_port_chest);
|
||||
ACMD(do_user_horse_ride);
|
||||
ACMD(do_user_horse_back);
|
||||
ACMD(do_user_horse_feed);
|
||||
@@ -286,9 +287,6 @@ struct command_info cmd_info[] =
|
||||
{
|
||||
{ "!RESERVED!", NULL, 0, POS_DEAD, GM_IMPLEMENTOR }, /* 반드시 이 것이 처음이어야 한다. */
|
||||
{ "autohunt_pull", do_autohunt_pull, 0, POS_STANDING, GM_PLAYER },
|
||||
{ "mt_features", do_port_features, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_switchbot", do_port_switchbot, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_pickup", do_port_pickup, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "bio", do_port_biolog, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "biolog", do_port_biolog, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "server_bonuses", do_server_bonuses, 0, POS_DEAD, GM_PLAYER },
|
||||
@@ -601,6 +599,12 @@ struct command_info cmd_info[] =
|
||||
{ "ds_list", do_ds_list, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "do_clear_affect", do_clear_affect, 0, POS_DEAD, GM_LOW_WIZARD},
|
||||
|
||||
// PORT: feature commands stay at the end: commands are prefix matched in table order, so an entry placed
|
||||
// earlier would take over abbreviations of original commands (/m -> mob, /mt -> mto).
|
||||
{ "mt_features", do_port_features, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_switchbot", do_port_switchbot, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_pickup", do_port_pickup, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_chest", do_port_chest, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "\n", NULL, 0, POS_DEAD, GM_IMPLEMENTOR } /* 반드시 이 것이 마지막이어야 한다. */
|
||||
};
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "port_features.h"
|
||||
#include "port_switchbot.h"
|
||||
#include "port_pickup.h"
|
||||
#include "port_chest.h"
|
||||
|
||||
extern int g_server_id;
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ void CItem::Initialize()
|
||||
m_bExchanging = false;
|
||||
memset(&m_alSockets, 0, sizeof(m_alSockets));
|
||||
memset(&m_aAttr, 0, sizeof(m_aAttr));
|
||||
m_portAttrLock = 0;
|
||||
m_portAttrLockLoaded = false;
|
||||
|
||||
m_pkDestroyEvent = NULL;
|
||||
m_pkOwnershipEvent = NULL;
|
||||
|
||||
@@ -171,6 +171,9 @@ class CItem : public CEntity
|
||||
int GetAttributeCount();
|
||||
void ClearAttribute();
|
||||
void ChangeAttribute(const int* aiChangeProb=NULL);
|
||||
// PORT: attribute lock cache, see port_attr_lock.h.
|
||||
BYTE m_portAttrLock;
|
||||
bool m_portAttrLockLoaded;
|
||||
void AddAttribute();
|
||||
void AddAttribute(BYTE bType, short sValue);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "char.h"
|
||||
#include "desc.h"
|
||||
#include "item_manager.h"
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
const int MAX_NORM_ATTR_NUM = ITEM_MANAGER::MAX_NORM_ATTR_NUM;
|
||||
const int MAX_RARE_ATTR_NUM = ITEM_MANAGER::MAX_RARE_ATTR_NUM;
|
||||
@@ -189,24 +190,40 @@ void CItem::ChangeAttribute(const int* aiChangeProb)
|
||||
{
|
||||
int iAttributeCount = GetAttributeCount();
|
||||
|
||||
// PORT: locked slots (port_attr_lock.h) keep their type and value; the rest are rerolled into the gaps.
|
||||
TItemTable const * pProto = GetProto();
|
||||
const bool bAddon = pProto && pProto->sAddonType;
|
||||
const unsigned lock = iAttributeCount ? PortAttrLockEffective(PortAttrLockGet(this), PortAttrFilled(this), bAddon) : 0;
|
||||
TPlayerItemAttribute aLocked[MAX_NORM_ATTR_NUM];
|
||||
memcpy(aLocked, m_aAttr, sizeof(aLocked));
|
||||
|
||||
ClearAttribute();
|
||||
|
||||
if (iAttributeCount == 0)
|
||||
return;
|
||||
|
||||
TItemTable const * pProto = GetProto();
|
||||
|
||||
if (pProto && pProto->sAddonType)
|
||||
if (bAddon && !(lock & kPortAttrLockAddonPair))
|
||||
{
|
||||
ApplyAddon(pProto->sAddonType);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
|
||||
if (lock >> i & 1)
|
||||
m_aAttr[i] = aLocked[i];
|
||||
|
||||
int iFilled = 0;
|
||||
|
||||
for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
|
||||
if (m_aAttr[i].bType)
|
||||
++iFilled;
|
||||
|
||||
static const int tmpChangeProb[ITEM_ATTRIBUTE_MAX_LEVEL] =
|
||||
{
|
||||
0, 10, 40, 35, 15,
|
||||
};
|
||||
|
||||
for (int i = GetAttributeCount(); i < iAttributeCount; ++i)
|
||||
// PutAttribute fills the first empty slot, so the gaps between locked slots fill in order.
|
||||
for (int i = iFilled; i < iAttributeCount; ++i)
|
||||
{
|
||||
if (aiChangeProb == NULL)
|
||||
{
|
||||
@@ -333,6 +350,10 @@ void CItem::SetForceAttribute(int i, BYTE bType, short sValue)
|
||||
void CItem::CopyAttributeTo(LPITEM pItem)
|
||||
{
|
||||
pItem->SetAttributes(m_aAttr);
|
||||
|
||||
// PORT: the lock follows the attributes to the refined / replaced item.
|
||||
if (const unsigned lock = PortAttrLockGet(this))
|
||||
PortAttrLockSet(GetOwner(), pItem, lock);
|
||||
}
|
||||
|
||||
int CItem::GetRareAttrCount()
|
||||
|
||||
@@ -238,6 +238,7 @@ extern std::vector<TPlayerTable> g_vec_save;
|
||||
unsigned int save_idx = 0;
|
||||
|
||||
void PortBossTick();
|
||||
void PortAttrLockBoot();
|
||||
|
||||
void heartbeat(LPHEART ht, int pulse)
|
||||
{
|
||||
@@ -792,6 +793,9 @@ int start(int argc, char **argv)
|
||||
config_init(st_localeServiceName);
|
||||
// END_OF_LOCALE_SERVICE
|
||||
|
||||
if (!g_bAuthServer)
|
||||
PortAttrLockBoot();
|
||||
|
||||
#ifdef __WIN32__
|
||||
// In Windows dev mode, "verbose" option is [on] by default.
|
||||
bVerbose = true;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "stdafx.h"
|
||||
#include "utils.h"
|
||||
#include "char.h"
|
||||
#include "db.h"
|
||||
#include "item.h"
|
||||
#include "log.h"
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
void PortAttrLockBoot() {
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(
|
||||
"CREATE TABLE IF NOT EXISTS mt_item_attr_lock (item_id INT UNSIGNED NOT NULL PRIMARY KEY,"
|
||||
" mask TINYINT UNSIGNED NOT NULL) ENGINE=MyISAM"));
|
||||
if(msg->uiSQLErrno)sys_err("PortAttrLockBoot: cannot create mt_item_attr_lock (errno %u)",msg->uiSQLErrno);
|
||||
}
|
||||
|
||||
unsigned PortAttrLockGet(CItem* item) {
|
||||
if(item->m_portAttrLockLoaded)return item->m_portAttrLock;
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT mask FROM mt_item_attr_lock WHERE item_id=%u",item->GetID()));
|
||||
if(msg->uiSQLErrno){sys_err("PortAttrLockGet: item %u lookup failed",item->GetID());return 0;}
|
||||
unsigned mask=0;
|
||||
if(msg->Get()->uiNumRows) {
|
||||
MYSQL_ROW row=mysql_fetch_row(msg->Get()->pSQLResult);
|
||||
str_to_number(mask,row[0]);
|
||||
}
|
||||
item->m_portAttrLock=BYTE(mask);item->m_portAttrLockLoaded=true;
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool PortAttrLockSet(CHARACTER* ch,CItem* item,unsigned mask) {
|
||||
std::unique_ptr<SQLMsg> msg(mask?
|
||||
DBManager::instance().DirectQuery("REPLACE INTO mt_item_attr_lock (item_id,mask) VALUES(%u,%u)",item->GetID(),mask):
|
||||
DBManager::instance().DirectQuery("DELETE FROM mt_item_attr_lock WHERE item_id=%u",item->GetID()));
|
||||
if(msg->uiSQLErrno){sys_err("PortAttrLockSet: item %u mask %u failed",item->GetID(),mask);return false;}
|
||||
item->m_portAttrLock=BYTE(mask);item->m_portAttrLockLoaded=true;
|
||||
char hint[16];snprintf(hint,sizeof(hint),"%u",mask);
|
||||
if(ch)LogManager::instance().ItemLog(ch,item,"ATTR_LOCK",hint);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef METIN2_PORT_ATTR_LOCK_H
|
||||
#define METIN2_PORT_ATTR_LOCK_H
|
||||
// PORT: attribute lock (AVA2 ENABLE_LOCK_ATTR). Up to two of the five normal attribute slots keep their type and
|
||||
// value through CItem::ChangeAttribute, so manual scrolls, the switchbot and GM rerolls all respect it.
|
||||
// AVA2 keeps the lock indices in attribute slots 7/8; this server has no spare attribute or socket slot, so the
|
||||
// mask lives in player.mt_item_attr_lock keyed by item ID (port_attr_lock.cpp) and no client packet changes.
|
||||
// Bit i = normal slot i. On items with an addon type, slots 0 and 1 (skill / normal hit bonus) are one group.
|
||||
|
||||
static const unsigned kPortAttrLockSlots=5,kPortAttrLockGroups=2,kPortAttrLockAddonPair=3;
|
||||
|
||||
// Mask of the normal slots that hold an attribute.
|
||||
template<class Item> unsigned PortAttrFilled(Item* item) {
|
||||
unsigned filled=0;
|
||||
for(unsigned i=0;i<kPortAttrLockSlots;++i)if(item->GetAttributeType(i))filled|=1u<<i;
|
||||
return filled;
|
||||
}
|
||||
|
||||
inline unsigned PortAttrLockGroupCount(unsigned mask,bool addon) {
|
||||
unsigned groups=0;
|
||||
for(unsigned i=0;i<kPortAttrLockSlots;++i)if(mask>>i&1)++groups;
|
||||
if(addon && (mask&kPortAttrLockAddonPair)==kPortAttrLockAddonPair)--groups;
|
||||
return groups;
|
||||
}
|
||||
|
||||
// The stored mask as ChangeAttribute applies it: only filled slots, the addon pair kept whole.
|
||||
inline unsigned PortAttrLockEffective(unsigned mask,unsigned filled,bool addon) {
|
||||
mask&=(1u<<kPortAttrLockSlots)-1;
|
||||
if(addon && (mask&kPortAttrLockAddonPair))mask|=kPortAttrLockAddonPair;
|
||||
return mask&filled;
|
||||
}
|
||||
|
||||
// Toggle the lock on SLOT. Returns NULL and sets OUT, or an MTSB1 error code:
|
||||
// slot (out of range or empty), max (a third group, or every filled slot would be locked).
|
||||
inline const char* PortAttrLockToggle(unsigned mask,unsigned slot,unsigned filled,bool addon,unsigned& out) {
|
||||
if(slot>=kPortAttrLockSlots || !(filled>>slot&1))return "slot";
|
||||
mask=PortAttrLockEffective(mask,filled,addon);
|
||||
const unsigned bit=addon && slot<2?kPortAttrLockAddonPair&filled:1u<<slot;
|
||||
if(mask&bit){out=mask&~bit;return 0;}
|
||||
const unsigned next=mask|bit;
|
||||
if(PortAttrLockGroupCount(next,addon)>kPortAttrLockGroups || next==filled)return "max";
|
||||
out=next;return 0;
|
||||
}
|
||||
|
||||
class CItem;
|
||||
class CHARACTER;
|
||||
void PortAttrLockBoot();
|
||||
// Cached on the item after the first lookup. A failed lookup returns 0 and is retried next time.
|
||||
unsigned PortAttrLockGet(CItem* item);
|
||||
// Writes synchronously (a following warp loads the new value on the next core); false on SQL error.
|
||||
bool PortAttrLockSet(CHARACTER* ch,CItem* item,unsigned mask);
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
#ifndef METIN2_PORT_CHEST_H
|
||||
#define METIN2_PORT_CHEST_H
|
||||
// PORT: AVA2-style batch chest opening (ENABLE_MULTI_CHEST /chest_drop). AVA2 rewrote the drop loop
|
||||
// (GiveItemFromSpecialItemGroupNew); here every box goes through the original CHARACTER::UseItem gift-box path,
|
||||
// so its checks, special_item_group roll, gold/exp, ItemLog and consumption are unchanged. Boxes of one vnum are
|
||||
// opened from the chosen cell first, then from any other cell (most gift boxes do not stack). Per-box INFO lines
|
||||
// are held back and the gains are reported once as MTCH1 lines. Protocol: docs/FEATURE-CHEST.md.
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static const unsigned kPortChestMax=200, kPortChestReportVnums=40, kPortChestFreeCells=3;
|
||||
static const DWORD kPortChestGapMs=500;
|
||||
static std::map<DWORD,DWORD> g_portChestLastCommand;
|
||||
|
||||
static bool PortChestNumber(const std::string& text,unsigned& value) {
|
||||
if(text.empty() || text.size()>5)return false;
|
||||
value=0;
|
||||
for(char c:text){if(c<'0'||c>'9')return false;value=value*10+unsigned(c-'0');}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Gift boxes whose group only hands out items, gold or exp. Groups that spawn monsters, slow, poison or drain
|
||||
// HP stay single-use: opening a stack of them at once would spawn every group around the player in one tick.
|
||||
static bool PortChestBatchable(LPITEM item) {
|
||||
if(item->GetType()!=ITEM_GIFTBOX)return false;
|
||||
const CSpecialItemGroup* group=ITEM_MANAGER::instance().GetSpecialItemGroup(item->GetVnum());
|
||||
if(!group || group->IsEmpty())return false;
|
||||
const DWORD unsafe[]={CSpecialItemGroup::MOB,CSpecialItemGroup::SLOW,CSpecialItemGroup::DRAIN_HP,
|
||||
CSpecialItemGroup::POISON,CSpecialItemGroup::MOB_GROUP};
|
||||
for(DWORD kind:unsafe)if(group->Contains(kind))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool PortChestBusy(LPCHARACTER ch) {
|
||||
return ch->IsDead() || ch->IsStun() || ch->IsWarping() || ch->IsObserverMode() || !ch->CanHandleItem() ||
|
||||
ch->GetExchange() || ch->GetMyShop() || ch->GetShopOwner() || ch->IsOpenSafebox() || ch->IsCubeOpen();
|
||||
}
|
||||
|
||||
// Item counts by vnum over the bag and the dragon soul bag, where AutoGiveItem puts what a box gives.
|
||||
static std::map<DWORD,long long> PortChestSnapshot(LPCHARACTER ch) {
|
||||
std::map<DWORD,long long> counts;
|
||||
for(int i=0;i<INVENTORY_MAX_NUM;++i)if(LPITEM item=ch->GetInventoryItem(i))counts[item->GetVnum()]+=item->GetCount();
|
||||
for(int i=0;i<DRAGON_SOUL_INVENTORY_MAX_NUM;++i)
|
||||
if(LPITEM item=ch->GetItem(TItemPos(DRAGON_SOUL_INVENTORY,i)))counts[item->GetVnum()]+=item->GetCount();
|
||||
return counts;
|
||||
}
|
||||
|
||||
// The box to open next: the chosen cell while it still holds this vnum, otherwise any bag cell that does.
|
||||
static LPITEM PortChestNext(LPCHARACTER ch,unsigned cell,DWORD vnum) {
|
||||
LPITEM item=ch->GetInventoryItem(cell);
|
||||
if(item && item->GetVnum()==vnum && !item->IsExchanging())return item;
|
||||
for(int i=0;i<INVENTORY_MAX_NUM;++i) {
|
||||
item=ch->GetInventoryItem(i);
|
||||
if(item && item->GetVnum()==vnum && !item->IsExchanging())return item;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* PortChestOpen(LPCHARACTER ch,unsigned cell,unsigned asked) {
|
||||
if(cell>=unsigned(INVENTORY_MAX_NUM) || !asked || asked>kPortChestMax)return "invalid";
|
||||
if(PortChestBusy(ch))return "busy";
|
||||
LPITEM first=ch->GetInventoryItem(cell);
|
||||
if(!first || first->IsExchanging())return "item";
|
||||
if(!PortChestBatchable(first))return "kind";
|
||||
if(ch->GetEmptyInventory(kPortChestFreeCells)==-1)return "full";
|
||||
const DWORD vnum=first->GetVnum();
|
||||
const std::map<DWORD,long long> before=PortChestSnapshot(ch);
|
||||
const long long goldBefore=ch->GetGold();
|
||||
unsigned opened=0;const char* reason="done";std::string rejection;
|
||||
while(opened<asked) {
|
||||
if(PortChestBusy(ch)){reason="busy";break;}
|
||||
// Stop while a whole weapon still fits, so AutoGiveItem never has to drop a reward on the ground.
|
||||
if(ch->GetEmptyInventory(kPortChestFreeCells)==-1){reason="full";break;}
|
||||
LPITEM box=PortChestNext(ch,cell,vnum);
|
||||
if(!box){reason="empty";break;}
|
||||
const int count=ch->CountSpecifyItem(vnum);
|
||||
ch->m_portQuietInfo=true;ch->m_portLastInfo.clear();
|
||||
ch->UseItem(TItemPos(INVENTORY,box->GetCell()));
|
||||
ch->m_portQuietInfo=false;
|
||||
// Success is judged by the original path consuming exactly one box, not by its return value.
|
||||
if(ch->CountSpecifyItem(vnum)!=count-1){reason="rejected";rejection=ch->m_portLastInfo;break;}
|
||||
++opened;
|
||||
}
|
||||
if(!rejection.empty())ch->ChatPacket(CHAT_TYPE_INFO,"%s",rejection.c_str());
|
||||
const std::map<DWORD,long long> after=PortChestSnapshot(ch);
|
||||
unsigned reported=0;
|
||||
for(const auto& entry:after) {
|
||||
if(entry.first==vnum)continue;
|
||||
auto it=before.find(entry.first);
|
||||
const long long gained=entry.second-(it==before.end()?0:it->second);
|
||||
if(gained<=0)continue;
|
||||
if(++reported>kPortChestReportVnums)break;
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 got %u %lld",unsigned(entry.first),gained);
|
||||
}
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 done %u %u %u %s %lld",unsigned(vnum),asked,opened,reason,
|
||||
(long long)ch->GetGold()-goldBefore);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ACMD(do_port_chest) {
|
||||
if(!ch || !ch->IsPC() || !ch->GetDesc())return;
|
||||
std::istringstream input(argument);std::vector<std::string> args;std::string token;
|
||||
while(input>>token){if(token.size()>10 || args.size()>=5)return;args.push_back(token);}
|
||||
if(args.size()<2 || args[0]!="1")return;
|
||||
DWORD& last=g_portChestLastCommand[ch->GetPlayerID()];
|
||||
if(last && get_dword_time()-last<kPortChestGapMs){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 error rate");return;}
|
||||
last=get_dword_time();
|
||||
unsigned cell=0,count=0;const char* error="invalid";
|
||||
if(args[1]=="open" && args.size()==4 && PortChestNumber(args[2],cell) && PortChestNumber(args[3],count))
|
||||
error=PortChestOpen(ch,cell,count);
|
||||
if(error)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 error %s",error);
|
||||
}
|
||||
#endif
|
||||
@@ -3,11 +3,13 @@
|
||||
// PORT: AVA2-style automatic attribute change. Every roll goes through the original
|
||||
// CHARACTER::UseItem change-attribute path, so its checks, probabilities, log and consumption apply unchanged.
|
||||
// One bound item per character; not persisted; stops on logout, warp, busy windows or any rejected roll.
|
||||
// The lock verb toggles the attribute lock (port_attr_lock.h) that ChangeAttribute applies to every reroll.
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
static const unsigned kPortSwitchAlternatives=2, kPortSwitchTargets=5, kPortSwitchLimit=1000;
|
||||
static const unsigned kPortSwitchAddonSkillMax=30, kPortSwitchAddonNormalMax=65; // CItemAddonManager::ApplyAddonTo bounds.
|
||||
@@ -141,6 +143,29 @@ static void PortSwitchStop(LPCHARACTER ch,const char* reason) {
|
||||
g_portSwitchbots.erase(it);
|
||||
}
|
||||
|
||||
static void PortSwitchLockLine(LPCHARACTER ch,LPITEM item) {
|
||||
const bool addon=item->GetProto() && item->GetProto()->sAddonType;
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 lock %u %u %u",unsigned(item->GetCell()),unsigned(item->GetVnum()),
|
||||
PortAttrLockEffective(PortAttrLockGet(item),PortAttrFilled(item),addon));
|
||||
}
|
||||
|
||||
// lock CELL SLOT: toggle the lock on one normal slot; not while the bot rolls this item.
|
||||
static const char* PortSwitchLock(LPCHARACTER ch,unsigned cell,unsigned slot) {
|
||||
if(PortSwitchBusy(ch))return "busy";
|
||||
LPITEM item=cell<INVENTORY_MAX_NUM?ch->GetItem(TItemPos(INVENTORY,cell)):NULL;
|
||||
if(!item)return "item";
|
||||
if(item->IsEquipped() || item->IsExchanging())return "equipped";
|
||||
if(item->GetType()==ITEM_COSTUME || item->GetAttributeSetIndex()<0)return "no_attr";
|
||||
auto it=g_portSwitchbots.find(ch->GetPlayerID());
|
||||
if(it!=g_portSwitchbots.end() && it->second.item==item->GetID())return "running";
|
||||
const bool addon=item->GetProto() && item->GetProto()->sAddonType;
|
||||
unsigned mask=0;
|
||||
if(const char* error=PortAttrLockToggle(PortAttrLockGet(item),slot,PortAttrFilled(item),addon,mask))return error;
|
||||
if(!PortAttrLockSet(ch,item,mask))return "db";
|
||||
PortSwitchLockLine(ch,item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void PortSwitchAttrs(LPCHARACTER ch,unsigned cell) {
|
||||
LPITEM item=cell<INVENTORY_MAX_NUM?ch->GetItem(TItemPos(INVENTORY,cell)):NULL;
|
||||
if(!item){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 error attrs item");return;}
|
||||
@@ -150,6 +175,7 @@ static void PortSwitchAttrs(LPCHARACTER ch,unsigned cell) {
|
||||
for(unsigned i=0;i<allowed.size();++i)
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 attr %u %u %d",i,allowed[i].first,allowed[i].second);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 attrs_end %u %u",cell,unsigned(allowed.size()));
|
||||
PortSwitchLockLine(ch,item);
|
||||
}
|
||||
|
||||
// start CELL SCROLL LIMIT N1 (APPLY VALUE)*N1 [N2 (APPLY VALUE)*N2]
|
||||
@@ -199,8 +225,12 @@ ACMD(do_port_switchbot) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 error %s rate",verb.c_str());return;
|
||||
}
|
||||
ch->m_portSwitchbotLastCommand=get_dword_time();
|
||||
unsigned cell=0;
|
||||
unsigned cell=0,slot=0;
|
||||
if(verb=="attrs" && args.size()==3 && PortSwitchNumber(args[2],cell)) PortSwitchAttrs(ch,cell);
|
||||
else if(verb=="lock" && args.size()==4 && PortSwitchNumber(args[2],cell) && PortSwitchNumber(args[3],slot)) {
|
||||
const char* error=PortSwitchLock(ch,cell,slot);
|
||||
if(error)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 error lock %s",error);
|
||||
}
|
||||
else if(verb=="stop" && args.size()==2) PortSwitchStop(ch,"stopped");
|
||||
else if(verb=="status" && args.size()==2) {
|
||||
auto it=g_portSwitchbots.find(ch->GetPlayerID());
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Attribute lock: compile the production CItem::ChangeAttribute body against a stub item and check the lock rules."""
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
SRC=ROOT/'src/server/game/src'
|
||||
def text(name):return (SRC/name).read_bytes().decode('latin1')
|
||||
attribute=text('item_attribute.cpp');glue=text('port_attr_lock.cpp');main=text('main.cpp')
|
||||
body=re.search(r'void CItem::ChangeAttribute\(const int\* aiChangeProb\)\n\{.*?\n\}\n',attribute,re.S).group(0)
|
||||
copy=re.search(r'void CItem::CopyAttributeTo\(LPITEM pItem\)\n\{.*?\n\}\n',attribute,re.S).group(0)
|
||||
assert 'PortAttrLockSet(GetOwner(), pItem, lock)' in copy # refine / replacement keeps the lock
|
||||
assert 'port_attr_lock.cpp' in text('Makefile') and '#include "port_attr_lock.h"' in attribute
|
||||
assert 'if (!g_bAuthServer)\n\t\tPortAttrLockBoot();' in main.split('config_init(st_localeServiceName);',1)[1][:120]
|
||||
assert 'CREATE TABLE IF NOT EXISTS mt_item_attr_lock' in glue and 'item->m_portAttrLockLoaded=true' in glue
|
||||
assert 'm_portAttrLockLoaded = false;' in text('item.cpp')
|
||||
code=r'''
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
typedef unsigned char BYTE;
|
||||
enum {ITEM_ATTRIBUTE_MAX_LEVEL=5,ITEM_ATTRIBUTE_MAX_NUM=7,SKILL=71,NORMAL=72};
|
||||
const int MAX_NORM_ATTR_NUM=5;
|
||||
struct TPlayerItemAttribute{BYTE bType;short sValue;};
|
||||
struct TItemTable{short sAddonType;};
|
||||
class CHARACTER;
|
||||
#include "port_attr_lock.h"
|
||||
static unsigned g_lock=0;static int g_lookups=0;static BYTE g_next=10;
|
||||
class CItem {
|
||||
public:
|
||||
TPlayerItemAttribute m_aAttr[ITEM_ATTRIBUTE_MAX_NUM];TItemTable proto;
|
||||
CItem(){memset(m_aAttr,0,sizeof(m_aAttr));proto.sAddonType=0;}
|
||||
BYTE GetAttributeType(int i){return m_aAttr[i].bType;}
|
||||
int GetAttributeCount(){int i=0;while(i<MAX_NORM_ATTR_NUM && m_aAttr[i].bType)++i;return i;}
|
||||
void ClearAttribute(){for(int i=0;i<MAX_NORM_ATTR_NUM;++i)m_aAttr[i].bType=0,m_aAttr[i].sValue=0;}
|
||||
const TItemTable* GetProto(){return &proto;}
|
||||
bool HasAttr(BYTE t){for(int i=0;i<MAX_NORM_ATTR_NUM;++i)if(m_aAttr[i].bType==t)return true;return false;}
|
||||
// CItem::AddAttribute / AddAttr: write at GetAttributeCount(), the first empty slot.
|
||||
void Put(BYTE t,short v){int i=GetAttributeCount();assert(i<MAX_NORM_ATTR_NUM && !HasAttr(t));m_aAttr[i].bType=t;m_aAttr[i].sValue=v;}
|
||||
void ApplyAddon(int){Put(NORMAL,-5);Put(SKILL,3);}
|
||||
void PutAttribute(const int*){while(HasAttr(g_next))++g_next;Put(g_next,g_next*10);++g_next;}
|
||||
void ChangeAttribute(const int* aiChangeProb=NULL);
|
||||
};
|
||||
unsigned PortAttrLockGet(CItem*){++g_lookups;return g_lock;}
|
||||
@BODY@
|
||||
static CItem Item(const std::vector<BYTE>& types,bool addon){
|
||||
CItem item;item.proto.sAddonType=addon;
|
||||
for(size_t i=0;i<types.size();++i)item.m_aAttr[i].bType=types[i],item.m_aAttr[i].sValue=types[i]*10+1;
|
||||
item.m_aAttr[5].bType=90;item.m_aAttr[5].sValue=9; // rare slot untouched
|
||||
return item;
|
||||
}
|
||||
static void Check(CItem& item,unsigned keep,const CItem& before,int count){
|
||||
assert(item.GetAttributeCount()==count); // contiguous, same count
|
||||
for(int i=0;i<MAX_NORM_ATTR_NUM;++i){
|
||||
if(keep>>i&1)assert(item.m_aAttr[i].bType==before.m_aAttr[i].bType && item.m_aAttr[i].sValue==before.m_aAttr[i].sValue);
|
||||
for(int j=0;j<i;++j)assert(!item.m_aAttr[i].bType || item.m_aAttr[i].bType!=item.m_aAttr[j].bType);
|
||||
}
|
||||
assert(item.m_aAttr[5].bType==90 && item.m_aAttr[5].sValue==9);
|
||||
}
|
||||
int main(){
|
||||
// No lock: identical to the original (addon first, then rerolls), all values change.
|
||||
CItem a=Item({1,2,3,4,5},false),b=a;g_lock=0;a.ChangeAttribute();Check(a,0,b,5);
|
||||
for(int i=0;i<5;++i)assert(a.m_aAttr[i].sValue!=b.m_aAttr[i].sValue);
|
||||
// Slots 1 and 3 locked: kept in place, gaps refilled in order, no duplicate types.
|
||||
a=Item({1,2,3,4,5},false);b=a;g_lock=10;a.ChangeAttribute();Check(a,10,b,5);
|
||||
assert(a.m_aAttr[0].sValue!=b.m_aAttr[0].sValue && a.m_aAttr[4].sValue!=b.m_aAttr[4].sValue);
|
||||
// Locked type is never rolled again (PutAttribute skips existing types).
|
||||
g_next=2;a=Item({1,2,3},false);b=a;g_lock=2;a.ChangeAttribute();Check(a,2,b,3);assert(a.m_aAttr[0].bType!=2&&a.m_aAttr[2].bType!=2);
|
||||
// Lock on an empty slot is ignored; count kept.
|
||||
a=Item({1,2},false);b=a;g_lock=16;a.ChangeAttribute();Check(a,0,b,2);
|
||||
// Addon item: lock on slot 1 keeps the whole pair and skips ApplyAddon; otherwise the addon is rerolled.
|
||||
a=Item({NORMAL,SKILL,3,4},true);a.m_aAttr[0].sValue=-7;b=a;g_lock=2;a.ChangeAttribute();Check(a,3,b,4);
|
||||
a=Item({NORMAL,SKILL,3,4},true);a.m_aAttr[0].sValue=-7;b=a;g_lock=8;a.ChangeAttribute();Check(a,8,b,4);
|
||||
assert(a.m_aAttr[0].bType==NORMAL && a.m_aAttr[0].sValue==-5 && a.m_aAttr[1].bType==SKILL && a.m_aAttr[1].sValue==3);
|
||||
// No attributes: cleared, no lookup.
|
||||
g_lookups=0;a=Item({},false);a.ChangeAttribute();assert(a.GetAttributeCount()==0 && g_lookups==0);
|
||||
|
||||
// Toggle rules.
|
||||
unsigned out=0;const unsigned five=31,three=7;
|
||||
assert(!PortAttrLockToggle(0,4,five,false,out) && out==16);
|
||||
assert(!PortAttrLockToggle(16,0,five,false,out) && out==17);
|
||||
assert(!strcmp(PortAttrLockToggle(17,1,five,false,out),"max")); // third group
|
||||
assert(!PortAttrLockToggle(17,4,five,false,out) && out==1); // unlock
|
||||
assert(!strcmp(PortAttrLockToggle(0,3,three,false,out),"slot")); // empty slot
|
||||
assert(!strcmp(PortAttrLockToggle(0,5,five,false,out),"slot"));
|
||||
assert(!strcmp(PortAttrLockToggle(1,1,3,false,out),"max")); // would lock every filled slot
|
||||
assert(!PortAttrLockToggle(0,0,five,true,out) && out==3); // addon pair = one group
|
||||
assert(!PortAttrLockToggle(3,4,five,true,out) && out==19);
|
||||
assert(!strcmp(PortAttrLockToggle(19,2,five,true,out),"max"));
|
||||
assert(!PortAttrLockToggle(19,1,five,true,out) && out==16);
|
||||
assert(!strcmp(PortAttrLockToggle(0,0,3,true,out),"max")); // pair is all there is
|
||||
assert(PortAttrLockEffective(1,five,true)==3 && PortAttrLockEffective(0xff,three,false)==7 && PortAttrLockEffective(24,three,false)==0);
|
||||
assert(PortAttrLockGroupCount(31,true)==4 && PortAttrLockGroupCount(5,true)==2);
|
||||
puts("PASS: ChangeAttribute keeps locked slots (plain/addon/empty), no duplicates, rare untouched; toggle rules");
|
||||
}
|
||||
'''.replace('@BODY@',body)
|
||||
with tempfile.TemporaryDirectory(prefix='mt-attrlock-') as folder:
|
||||
path=Path(folder);(path/'test.cpp').write_text(code)
|
||||
subprocess.run(['c++','-std=c++17','-Wall','-I'+str(SRC),str(path/'test.cpp'),'-o',str(path/'test')],check=True)
|
||||
subprocess.run([str(path/'test')],check=True)
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile the production batch-chest header against stubs of the original UseItem gift-box contract."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
SRC=ROOT/'src/server/game/src'
|
||||
cmd=(SRC/'cmd.cpp').read_bytes().decode('latin1')
|
||||
assert 'ACMD(do_port_chest);' in cmd and '"mt_chest", do_port_chest, 0, POS_DEAD, GM_PLAYER' in cmd
|
||||
assert '#include "port_chest.h"' in (SRC/'cmd_general.cpp').read_bytes().decode('latin1')
|
||||
code=r'''
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using DWORD=unsigned;using BYTE=unsigned char;using WORD=unsigned short;using INT=int;
|
||||
enum {ITEM_USE=3,ITEM_GIFTBOX=23,INVENTORY=1,DRAGON_SOUL_INVENTORY=3,INVENTORY_MAX_NUM=10,DRAGON_SOUL_INVENTORY_MAX_NUM=4};
|
||||
enum {CHAT_TYPE_INFO=1,CHAT_TYPE_COMMAND=5};
|
||||
static DWORD clockms=1000;DWORD get_dword_time(){return clockms;}
|
||||
struct TItemPos{BYTE window_type;WORD cell;TItemPos(BYTE w,WORD c):window_type(w),cell(c){}};
|
||||
struct CItem{DWORD vnum;int count;BYTE type;bool exchanging=false;WORD cell=0;
|
||||
DWORD GetVnum(){return vnum;}int GetCount(){return count;}BYTE GetType(){return type;}bool IsExchanging(){return exchanging;}WORD GetCell(){return cell;}};
|
||||
using LPITEM=CItem*;
|
||||
struct CSpecialItemGroup{
|
||||
enum EGiveType{NONE,GOLD,EXP,MOB,SLOW,DRAIN_HP,POISON,MOB_GROUP};
|
||||
std::vector<DWORD> vnums;bool IsEmpty()const{return vnums.empty();}
|
||||
bool Contains(DWORD v)const{for(DWORD x:vnums)if(x==v)return true;return false;}
|
||||
};
|
||||
static std::map<DWORD,CSpecialItemGroup> groups;
|
||||
struct ITEM_MANAGER{static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}
|
||||
const CSpecialItemGroup* GetSpecialItemGroup(DWORD v){auto it=groups.find(v);return it==groups.end()?nullptr:&it->second;}};
|
||||
struct CHARACTER{
|
||||
bool m_portQuietInfo=false;std::string m_portLastInfo;
|
||||
LPITEM bag[INVENTORY_MAX_NUM]={};LPITEM ds[DRAGON_SOUL_INVENTORY_MAX_NUM]={};std::vector<CItem*> owned;
|
||||
int gold=0;bool dead=false,shop=false,refuse=false;int uses=0;std::vector<std::string> messages,info;
|
||||
bool IsPC(){return true;}void* GetDesc(){return this;}DWORD GetPlayerID(){return 7;}
|
||||
bool IsDead(){return dead;}bool IsStun()const{return false;}bool IsWarping()const{return false;}bool IsObserverMode(){return false;}
|
||||
bool CanHandleItem(){return true;}void* GetExchange(){return nullptr;}void* GetMyShop(){return shop?this:nullptr;}
|
||||
void* GetShopOwner(){return nullptr;}bool IsOpenSafebox(){return false;}bool IsCubeOpen(){return false;}
|
||||
INT GetGold()const{return gold;}
|
||||
LPITEM GetInventoryItem(WORD c)const{return c<INVENTORY_MAX_NUM?bag[c]:nullptr;}
|
||||
LPITEM GetItem(TItemPos p){return p.window_type==DRAGON_SOUL_INVENTORY?ds[p.cell]:bag[p.cell];}
|
||||
int GetEmptyInventory(BYTE size)const{int free=0;for(auto* i:bag)free+=!i;return free>=size?0:-1;}
|
||||
int CountSpecifyItem(DWORD v)const{int n=0;for(auto* i:bag)if(i&&i->vnum==v)n+=i->count;return n;}
|
||||
LPITEM Put(DWORD v,int n,BYTE t=ITEM_USE,int at=-1){
|
||||
for(int c=0;c<INVENTORY_MAX_NUM;++c)if(at<0?!bag[c]:c==at){CItem* i=new CItem{v,n,t};i->cell=c;bag[c]=i;owned.push_back(i);return i;}
|
||||
return nullptr;}
|
||||
void ChatPacket(BYTE type,const char* format,...){
|
||||
char out[513];va_list a;va_start(a,format);vsnprintf(out,sizeof(out),format,a);va_end(a);
|
||||
if(m_portQuietInfo&&type==CHAT_TYPE_INFO){m_portLastInfo=out;return;}
|
||||
(type==CHAT_TYPE_INFO?info:messages).emplace_back(out);
|
||||
}
|
||||
// Original gift-box contract: one box consumed, 100 gold + one 27001 (stacking) + a dragon soul for box 50100,
|
||||
// one INFO line per reward; the DS-quest style refusal returns false with an INFO line and consumes nothing.
|
||||
bool UseItem(TItemPos p){
|
||||
++uses;LPITEM box=GetItem(p);assert(box && p.window_type==INVENTORY && m_portQuietInfo);
|
||||
if(refuse){ChatPacket(CHAT_TYPE_INFO,"finish the dragon soul quest first");return false;}
|
||||
gold+=100;ChatPacket(CHAT_TYPE_INFO,"gold 100");
|
||||
if(--box->count==0)bag[p.cell]=nullptr;
|
||||
bool stacked=false;for(auto* i:bag)if(i&&i->vnum==27001){++i->count;stacked=true;break;}
|
||||
if(!stacked)Put(27001,1);
|
||||
if(box->vnum==50100)for(auto*& d:ds)if(!d){d=new CItem{110000,1,ITEM_USE};owned.push_back(d);break;}
|
||||
ChatPacket(CHAT_TYPE_INFO,"got potion");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
using LPCHARACTER=CHARACTER*;
|
||||
#define ACMD(name) void name(LPCHARACTER ch,const char* argument)
|
||||
#include "port_chest.h"
|
||||
static CHARACTER* ch;
|
||||
static void cmd(const char* text){clockms+=600;ch->messages.clear();ch->info.clear();ch->uses=0;do_port_chest(ch,text);}
|
||||
static const std::string& last(){return ch->messages.back();}
|
||||
static void fresh(){ch=new CHARACTER;}
|
||||
int main(){
|
||||
groups[50100].vnums={27001,1,110000};groups[50200].vnums={27001,CSpecialItemGroup::MOB};groups[50300].vnums={};
|
||||
// Non-stacking boxes spread over cells: chosen cell first, then the others; gains summed, INFO held back.
|
||||
fresh();ch->Put(50100,1,ITEM_GIFTBOX,0);ch->Put(50100,1,ITEM_GIFTBOX,4);ch->Put(50100,1,ITEM_GIFTBOX,5);
|
||||
cmd("1 open 4 3");
|
||||
assert(ch->messages.size()==3 && ch->messages[0]=="MTCH1 got 27001 3" && ch->messages[1]=="MTCH1 got 110000 3");
|
||||
assert(last()=="MTCH1 done 50100 3 3 done 300" && ch->info.empty() && !ch->m_portQuietInfo && ch->CountSpecifyItem(50100)==0);
|
||||
// Stacked box, fewer asked than held; then more asked than held -> empty.
|
||||
fresh();ch->Put(50100,5,ITEM_GIFTBOX);cmd("1 open 0 2");assert(last()=="MTCH1 done 50100 2 2 done 200" && ch->bag[0]->count==3);
|
||||
cmd("1 open 0 200");assert(last()=="MTCH1 done 50100 200 3 empty 300" && ch->uses==3);
|
||||
// Single boxes free their own cell for the reward, so free space never shrinks.
|
||||
fresh();for(int i=0;i<7;++i)ch->Put(50100,1,ITEM_GIFTBOX);
|
||||
cmd("1 open 0 7");assert(last()=="MTCH1 done 50100 7 7 done 700");
|
||||
// A stack + 6 fillers leaves exactly 3 free cells: the first reward takes one, then it stops at 2 free.
|
||||
fresh();ch->Put(50100,7,ITEM_GIFTBOX);for(int i=0;i<6;++i)ch->Put(1,1);
|
||||
cmd("1 open 0 7");assert(last()=="MTCH1 done 50100 7 1 full 100" && ch->uses==1);
|
||||
cmd("1 open 0 1");assert(last()=="MTCH1 error full" && ch->uses==0);
|
||||
// Refusal by the original path: stops, forwards its INFO once.
|
||||
fresh();ch->Put(50100,3,ITEM_GIFTBOX);ch->refuse=true;cmd("1 open 0 3");
|
||||
assert(last()=="MTCH1 done 50100 3 0 rejected 0" && ch->info.size()==1 && ch->info[0]=="finish the dragon soul quest first");
|
||||
// Kinds: not a gift box, monster group box, no/empty group.
|
||||
fresh();ch->Put(27001,5);cmd("1 open 0 1");assert(last()=="MTCH1 error kind");
|
||||
ch->Put(50200,2,ITEM_GIFTBOX);cmd("1 open 1 1");assert(last()=="MTCH1 error kind");
|
||||
ch->Put(50300,2,ITEM_GIFTBOX);cmd("1 open 2 1");assert(last()=="MTCH1 error kind");
|
||||
ch->Put(50400,2,ITEM_GIFTBOX);cmd("1 open 3 1");assert(last()=="MTCH1 error kind" && ch->uses==0);
|
||||
// Item, exchange, busy, validation, throttle.
|
||||
cmd("1 open 9 1");assert(last()=="MTCH1 error item");
|
||||
LPITEM box=ch->Put(50100,2,ITEM_GIFTBOX);box->exchanging=true;cmd("1 open 4 1");assert(last()=="MTCH1 error item");box->exchanging=false;
|
||||
ch->shop=true;cmd("1 open 4 1");assert(last()=="MTCH1 error busy");ch->shop=false;
|
||||
for(auto bad:{"1 open 4 0","1 open 4 201","1 open 10 1","1 open 4","1 open x 1","1 open 4 1 1","1 close 4 1","1 open 4 999999"}){cmd(bad);assert(last()=="MTCH1 error invalid");}
|
||||
cmd("2 open 4 1");assert(ch->messages.empty());
|
||||
cmd("1 open 4 1");assert(last()=="MTCH1 done 50100 1 1 done 100");
|
||||
do_port_chest(ch,"1 open 4 1");assert(last()=="MTCH1 error rate" && ch->CountSpecifyItem(50100)==1);
|
||||
cmd("1 open 4 1");assert(last()=="MTCH1 done 50100 1 1 done 100");
|
||||
puts("PASS: cross-cell order, stacks, gains summary, free-cell stop, refusal, kinds, item/busy/validation/throttle");
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory(prefix='mt-chest-') as folder:
|
||||
path=Path(folder);(path/'test.cpp').write_text(code)
|
||||
subprocess.run(['c++','-std=c++17','-Wall','-I'+str(SRC),str(path/'test.cpp'),'-o',str(path/'test')],check=True)
|
||||
subprocess.run([str(path/'test')],check=True)
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Port commands must not take over abbreviations of the original commands.
|
||||
|
||||
interpret_command (cmd.cpp) picks the first table entry whose name starts with the typed command
|
||||
(strncmp over the typed length; do_cmd entries need an exact match). A port command placed before an
|
||||
original one would steal its abbreviations, as mt_features once did with /m (mob) and /mt (mto).
|
||||
"""
|
||||
from pathlib import Path
|
||||
import re
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
text=(ROOT/'src/server/game/src/cmd.cpp').read_bytes().decode('latin1')
|
||||
table=text.split('struct command_info cmd_info[] =',1)[1]
|
||||
entries=re.findall(r'\{\s*"((?:[^"\\]|\\.)*)",\s*([A-Za-z_0-9]+|NULL)',table)
|
||||
assert entries[0][0]=='!RESERVED!'
|
||||
end=[i for i,(name,_) in enumerate(entries) if name=='\\n']
|
||||
assert end,'table sentinel not found'
|
||||
entries=entries[1:end[0]]
|
||||
PORT=lambda name:name.startswith('mt_')
|
||||
port=[name for name,_ in entries if PORT(name)]
|
||||
assert {'mt_features','mt_switchbot','mt_pickup','mt_chest'}<=set(port),port
|
||||
|
||||
def resolve(rows,cmd):
|
||||
for name,fn in rows:
|
||||
if fn=='do_cmd':
|
||||
if name==cmd:return name
|
||||
elif name.startswith(cmd):return name
|
||||
return None
|
||||
|
||||
original=[(name,fn) for name,fn in entries if not PORT(name)]
|
||||
for name in port:assert resolve(entries,name)==name,name
|
||||
for name,_ in original:
|
||||
for k in range(1,len(name)+1):
|
||||
typed=name[:k]
|
||||
assert resolve(entries,typed)==resolve(original,typed),'/%s now runs %s instead of %s'%(typed,resolve(entries,typed),resolve(original,typed))
|
||||
for typed in ('m','mt','mo'):assert not PORT(resolve(entries,typed) or ''),typed
|
||||
assert resolve(entries,'m')=='mob' and resolve(entries,'mt')=='mto'
|
||||
print('cmd prefix ok: %d commands, %d port'%(len(entries),len(port)))
|
||||
@@ -41,13 +41,13 @@ void event_cancel(LPEVENT* e){if(*e)(*e)->cancelled=true;*e=nullptr;}
|
||||
#define EVENTINFO(name) struct name : public event_info_data
|
||||
#define PASSES_PER_SEC(s) ((s)*4)
|
||||
static DWORD clockms=1000;DWORD get_dword_time(){return clockms;}
|
||||
struct CHARACTER;
|
||||
struct CItem {
|
||||
class CHARACTER;
|
||||
class CItem {public:
|
||||
DWORD id,vnum;BYTE type,subtype;int set=0;unsigned cell;BYTE window=INVENTORY;bool equipped=false,exchanging=false;int count=1;
|
||||
CHARACTER* owner=nullptr;TItemTable proto{};TPlayerItemAttribute attrs[7];
|
||||
DWORD GetID(){return id;}DWORD GetVnum(){return vnum;}BYTE GetType(){return type;}BYTE GetSubType(){return subtype;}
|
||||
int GetAttributeSetIndex(){return set;}const TItemTable* GetProto(){return &proto;}
|
||||
const TPlayerItemAttribute& GetAttribute(int i){return attrs[i];}
|
||||
const TPlayerItemAttribute& GetAttribute(int i){return attrs[i];}BYTE GetAttributeType(int i){return attrs[i].bType;}
|
||||
int GetAttributeCount(){int n=0;for(int i=0;i<5;++i)n+=attrs[i].bType!=0;return n;}
|
||||
CHARACTER* GetOwner(){return owner;}BYTE GetWindow(){return window;}unsigned GetCell(){return cell;}
|
||||
bool IsEquipped(){return equipped;}bool IsExchanging(){return exchanging;}
|
||||
@@ -58,7 +58,7 @@ struct ITEM_MANAGER{
|
||||
static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}
|
||||
LPITEM Find(DWORD id){for(auto* i:items)if(i->id==id)return i;return nullptr;}
|
||||
};
|
||||
struct CHARACTER {
|
||||
class CHARACTER {public:
|
||||
DWORD m_portSwitchbotLastCommand=0;bool m_portQuietInfo=false;std::string m_portLastInfo;
|
||||
DWORD pid=7;VID vid;bool desc=true,busy=false,dead=false,reject=false;int uses=0;
|
||||
std::vector<std::string> messages,info;std::vector<CItem*> inventory;
|
||||
@@ -92,6 +92,10 @@ struct CHARACTER_MANAGER{
|
||||
};
|
||||
#define ACMD(name) void name(LPCHARACTER ch,const char* argument)
|
||||
#include "port_switchbot.h"
|
||||
// Lock storage stub: the real one is a player.mt_item_attr_lock row (port_attr_lock.cpp).
|
||||
static std::map<DWORD,unsigned> locks;static bool lockFail=false;
|
||||
unsigned PortAttrLockGet(CItem* item){return locks[item->id];}
|
||||
bool PortAttrLockSet(CHARACTER*,CItem* item,unsigned mask){if(lockFail)return false;locks[item->id]=mask;return true;}
|
||||
static CHARACTER ch;
|
||||
static void cmd(const char* text){clockms+=300;ch.messages.clear();do_port_switchbot(&ch,text);}
|
||||
static long tick(){for(auto& e:events)if(!e->cancelled&&e->func){long r=e->func(e.get(),0);if(!r)e->func=nullptr;return r;}return -1;}
|
||||
@@ -110,8 +114,9 @@ int main(){
|
||||
|
||||
// Allowed list: proto applies excluded, set filter, level cap picks lValues[level-1].
|
||||
cmd("1 attrs 10");
|
||||
assert(ch.messages.size()==4 && ch.messages[0]=="MTSB1 attrs 10 11209 2");
|
||||
assert(ch.messages[1]=="MTSB1 attr 0 3 12" && ch.messages[2]=="MTSB1 attr 1 63 6" && last()=="MTSB1 attrs_end 10 2");
|
||||
assert(ch.messages.size()==5 && ch.messages[0]=="MTSB1 attrs 10 11209 2");
|
||||
assert(ch.messages[1]=="MTSB1 attr 0 3 12" && ch.messages[2]=="MTSB1 attr 1 63 6" && ch.messages[3]=="MTSB1 attrs_end 10 2");
|
||||
assert(last()=="MTSB1 lock 10 11209 0");
|
||||
armor.proto.sAddonType=1;cmd("1 attrs 10");assert(ch.messages[3]=="MTSB1 attr 2 71 30" && ch.messages[4]=="MTSB1 attr 3 72 65");armor.proto.sAddonType=0;
|
||||
cmd("1 attrs 30");assert(last()=="MTSB1 error attrs no_attr");
|
||||
cmd("1 attrs 99");assert(last()=="MTSB1 error attrs item");
|
||||
@@ -161,6 +166,30 @@ int main(){
|
||||
ch.vid.id=100;ch.messages.clear();assert(tick()==0 && ch.messages.empty() && g_portSwitchbots.empty());
|
||||
assert(ch.uses==6);
|
||||
|
||||
// Lock toggle: filled slots only, at most 2 groups and never every filled slot, not on the rolling item.
|
||||
armor.attrs[0]={APPLY_STR,2};armor.attrs[1]={APPLY_CRITICAL,1};armor.attrs[2]={APPLY_ATTBONUS_MONSTER,2};
|
||||
cmd("1 lock 10 0");assert(last()=="MTSB1 lock 10 11209 1");
|
||||
cmd("1 lock 10 2");assert(last()=="MTSB1 lock 10 11209 5");
|
||||
cmd("1 lock 10 1");assert(last()=="MTSB1 error lock max");
|
||||
cmd("1 lock 10 3");assert(last()=="MTSB1 error lock slot");
|
||||
cmd("1 lock 10 5");assert(last()=="MTSB1 error lock slot");
|
||||
cmd("1 lock 10 0");assert(last()=="MTSB1 lock 10 11209 4" && locks[1001]==4);
|
||||
cmd("1 lock 10 1");assert(last()=="MTSB1 lock 10 11209 6");
|
||||
cmd("1 attrs 10");assert(last()=="MTSB1 lock 10 11209 6");
|
||||
cmd("1 lock 30 0");assert(last()=="MTSB1 error lock no_attr");
|
||||
cmd("1 lock 99 0");assert(last()=="MTSB1 error lock item");
|
||||
cmd("1 lock 10");assert(last()=="MTSB1 error lock invalid");
|
||||
lockFail=true;cmd("1 lock 10 1");assert(last()=="MTSB1 error lock db" && locks[1001]==6);lockFail=false;
|
||||
ch.rolls={{{APPLY_STR,2}}};cmd("1 start 10 71084 5 1 3 12");cmd("1 lock 10 1");assert(last()=="MTSB1 error lock running");
|
||||
cmd("1 stop");
|
||||
// Addon weapon: slots 0 and 1 lock together and count as one group.
|
||||
armor.proto.sAddonType=1;locks[1001]=0;armor.attrs[3]={APPLY_MAX_HP,500};
|
||||
cmd("1 lock 10 1");assert(last()=="MTSB1 lock 10 11209 3");
|
||||
cmd("1 lock 10 3");assert(last()=="MTSB1 lock 10 11209 11");
|
||||
cmd("1 lock 10 2");assert(last()=="MTSB1 error lock max");
|
||||
cmd("1 lock 10 0");assert(last()=="MTSB1 lock 10 11209 8");
|
||||
armor.proto.sAddonType=0;armor.attrs[2]=armor.attrs[3]=TPlayerItemAttribute{};locks.clear();
|
||||
|
||||
// Malformed or foreign input is ignored or rejected without side effects.
|
||||
cmd("2 status");assert(ch.messages.empty());
|
||||
cmd("1 explode");assert(last()=="MTSB1 error explode invalid");
|
||||
|
||||
Reference in New Issue
Block a user