Add attribute lock (AVA2 ENABLE_LOCK_ATTR port)
Up to two normal attribute slots (addon pair = one group) keep their type and value through CItem::ChangeAttribute, so scroll rerolls, the switchbot and GM rerolls all respect it. The mask lives in the new player.mt_item_attr_lock table (created at boot), cached per CItem and written synchronously; CopyAttributeTo carries it to refined items. No item struct, db cache or client packet change. Toggled with /mt_switchbot 1 lock CELL SLOT; MTSB1 lock line follows attrs_end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
400e44fae4
commit
dc7159338e
@@ -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