51 lines
3.4 KiB
Python
51 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Execute the real lock material selection/payment paths, including stale quest and SQL failure."""
|
|
from pathlib import Path
|
|
import subprocess,tempfile
|
|
root=Path(__file__).resolve().parents[2]/'src/server/game/src'
|
|
source=(root/'port_attr_lock.cpp').read_text()
|
|
use=source[source.index('const char* PortAttrLockUse('):source.index('// Quest selection')]
|
|
select=source[source.index('bool PortAttrLockSelect('):]
|
|
code=r'''
|
|
#include <cassert>
|
|
#include <cstring>
|
|
#define INVENTORY 1
|
|
struct CHARACTER {bool dead=false,stun=false,busy=false,shop=false,trade=false,safe=false;
|
|
bool IsDead(){return dead;}bool IsStun(){return stun;}bool CanHandleItem(){return !busy;}
|
|
bool GetShop(){return shop;}bool GetExchange(){return trade;}bool IsOpenSafebox(){return safe;}
|
|
};
|
|
struct Proto {int sAddonType=0;};
|
|
struct CItem {
|
|
CHARACTER* owner=nullptr;unsigned vnum=50348,count=3,window=1,mask=0,filled=31,socket=0;bool equipped=false,exchange=false,locked=false,loaded=true,m_portAttrLockLoaded=true;Proto proto;
|
|
CHARACTER* GetOwner(){return owner;}bool IsEquipped(){return equipped;}bool IsExchanging(){return exchange;}bool isLocked(){return locked;}
|
|
unsigned GetVnum(){return vnum;}unsigned GetCount(){return count;}unsigned GetWindow(){return window;}
|
|
const Proto* GetProto(){return &proto;}void SetCount(unsigned n){count=n;}void SetSocket(int,unsigned n){socket=n;}void Save(){}
|
|
unsigned GetAttributeType(unsigned i){return filled>>i&1;}
|
|
};
|
|
#include "port_attr_lock.h"
|
|
static bool saveOk=true;
|
|
unsigned PortAttrLockGet(CItem* i){i->m_portAttrLockLoaded=i->loaded;return i->mask;}
|
|
bool PortAttrLockSet(CHARACTER*,CItem* i,unsigned mask){if(!saveOk)return false;i->mask=mask;return true;}
|
|
'''+use+select+r'''
|
|
int main(){
|
|
CHARACTER ch,other;CItem material,target;material.owner=target.owner=&ch;target.vnum=100;
|
|
assert(PortAttrLockSelect(&ch,&material,4) && material.socket==4 && material.count==3);
|
|
assert(!PortAttrLockSelect(&ch,&material,0) && !PortAttrLockSelect(&ch,&material,6));
|
|
assert(!PortAttrLockSelect(&other,&material,1));material.exchange=true;assert(!PortAttrLockSelect(&ch,&material,1));material.exchange=false;
|
|
ch.shop=true;assert(!PortAttrLockSelect(&ch,&material,1));ch.shop=false;
|
|
assert(!PortAttrLockUse(&ch,&target,3,&material) && target.mask==8 && material.count==2);
|
|
assert(!strcmp(PortAttrLockUse(&ch,&target,3,&material),"material") && material.count==2);
|
|
material.vnum=50349;assert(!PortAttrLockUse(&ch,&target,3,&material) && target.mask==0 && material.count==1);
|
|
material.vnum=50348;target.loaded=false;assert(!strcmp(PortAttrLockUse(&ch,&target,1,&material),"db") && material.count==1 && target.mask==0);
|
|
target.loaded=true;saveOk=false;assert(!strcmp(PortAttrLockUse(&ch,&target,1,&material),"db") && material.count==1 && target.mask==0);saveOk=true;
|
|
target.equipped=true;assert(!strcmp(PortAttrLockUse(&ch,&target,1,&material),"item"));target.equipped=false;
|
|
target.owner=&other;assert(!strcmp(PortAttrLockUse(&ch,&target,1,&material),"item"));target.owner=&ch;
|
|
material.locked=true;assert(!strcmp(PortAttrLockUse(&ch,&target,1,&material),"material"));
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory() as d:
|
|
p=Path(d);(p/'test.cpp').write_text(code)
|
|
subprocess.run(['c++','-std=c++17','-I'+str(root),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
|
|
subprocess.run([str(p/'test')],check=True)
|
|
print('Attr lock: selection ownership/state/index, payment, wrong material, SQL load/save failure, equipped/trade guards: PASS')
|