fix: align spirit stone insertion and stack consumption with AVA2
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile the actual ITEM_METIN branch: AVA2 success/consumption and socket eligibility."""
|
||||
from pathlib import Path
|
||||
import re,subprocess,tempfile
|
||||
root=Path(__file__).resolve().parents[2]
|
||||
s=(root/'src/server/game/src/char_item.cpp').read_bytes().decode('latin1')
|
||||
a=s.index('\t\tcase ITEM_METIN:');b=s.index('\n\t\tcase ITEM_AUTOUSE:',a)
|
||||
body=s[a:b]
|
||||
body=re.sub(r'LC_TEXT\("[^"\n]*"\)','"message"',body)
|
||||
body=re.sub(r'//[^\n]*','',body)
|
||||
code=r'''
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
using DWORD=unsigned;constexpr int ITEM_SOCKET_MAX_NUM=3;
|
||||
enum {ITEM_METIN,ITEM_PICK,ITEM_ROD,ITEM_ARMOR,ITEM_WEAPON,WEARABLE_BODY=1,WEARABLE_WEAPON=16,CHAT_TYPE_INFO=0};
|
||||
struct TItemPos{int cell;}; bool IsValidItemPosition(TItemPos p){return p.cell>=0&&p.cell<225;}
|
||||
struct TItemTable{int alValues[6]{};};
|
||||
struct Item{int type=ITEM_METIN,wear=WEARABLE_WEAPON,count=3,vnum=28532;bool exchanging=false,equipped=false;
|
||||
int sockets[3]{},values[6]{};
|
||||
int GetType(){return type;} bool IsExchanging(){return exchanging;} bool IsEquipped(){return equipped;}
|
||||
int GetSocket(int i){return sockets[i];} int GetValue(int i){return values[i];} int GetWearFlag(){return wear;}
|
||||
int GetVnum(){return vnum;} int GetCount(){return count;} const char* GetName(){return "stone";}
|
||||
void SetSocket(int i,int v){sockets[i]=v;} void SetCount(int v){count=v;}
|
||||
}; using LPITEM=Item*;
|
||||
struct ITEM_MANAGER{std::map<int,TItemTable> tables;int removed=0;
|
||||
static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}
|
||||
TItemTable* GetTable(int v){auto it=tables.find(v);return it==tables.end()?nullptr:&it->second;}
|
||||
void RemoveItem(Item* item,const char*){item->count=0;++removed;}
|
||||
};
|
||||
struct LogManager{static LogManager& instance(){static LogManager l;return l;}
|
||||
template<class...T>void ItemLog(T...){}};
|
||||
#define IS_SET(value,flag) ((value)&(flag))
|
||||
struct Character{Item* target=nullptr;Item* GetItem(TItemPos){return target;}
|
||||
template<class...T>void ChatPacket(T...){}
|
||||
bool Insert(Item* item,TItemPos DestCell){switch(item->GetType()){
|
||||
'''+body+r'''
|
||||
default:return false;}return true;}
|
||||
};
|
||||
int main(){
|
||||
Item stone,target;target.type=ITEM_WEAPON;target.sockets[0]=1;stone.values[5]=19;
|
||||
Character ch;ch.target=⌖auto& m=ITEM_MANAGER::instance();m.tables[28532].alValues[5]=19;
|
||||
assert(ch.Insert(&stone,{0}));assert(target.sockets[0]==28532);assert(stone.count==2);assert(m.removed==0);
|
||||
target.sockets[1]=1;assert(!ch.Insert(&stone,{0}));assert(stone.count==2&&target.sockets[1]==1);
|
||||
target.sockets[0]=1;target.equipped=true;assert(!ch.Insert(&stone,{0}));assert(stone.count==2);
|
||||
target.equipped=false;target.exchanging=true;assert(!ch.Insert(&stone,{0}));target.exchanging=false;
|
||||
target.type=ITEM_ARMOR;target.wear=WEARABLE_BODY;assert(!ch.Insert(&stone,{0}));
|
||||
stone.wear=WEARABLE_BODY;target.sockets[0]=target.sockets[1]=target.sockets[2]=0;
|
||||
ch.Insert(&stone,{0});assert(stone.count==2); // no open sockets
|
||||
target.sockets[0]=2;stone.values[2]=2;stone.count=1;
|
||||
assert(ch.Insert(&stone,{0}));assert(target.sockets[0]==28532);assert(stone.count==0&&m.removed==1);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory(prefix='ava2-stone-socket-') as folder:
|
||||
p=Path(folder);(p/'test.cpp').write_text(code)
|
||||
subprocess.run(['c++','-std=c++14',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
|
||||
subprocess.run([str(p/'test')],check=True)
|
||||
print('PASS: actual stone branch inserts successfully, consumes one, rejects duplicates/equipped/exchange/wrong target/full sockets')
|
||||
Reference in New Issue
Block a user