fix: align spirit stone insertion and stack consumption with AVA2

This commit is contained in:
shen
2026-10-17 23:32:59 -07:00
parent d7d0de3ae9
commit ac4a05a0c3
3 changed files with 79 additions and 11 deletions
+14
View File
@@ -0,0 +1,14 @@
# AVA2 spirit stones (staged on sbtest)
The stone catalogue and portable generator are in the sibling metin2-client repository:
`tools/server/ava2-stones/README.md`. That directory includes the complete source audit, generated patch interface, read-only owned-item impact audit and test results.
The 138 source ITEM_METIN rows include 20 ordinary +0..+5 chains, special stones and the broken-stone marker. Unsupported wolfman stones and original empty-attribute placeholders are explicitly disabled in the staged data, rather than silently converted to sword resistance or usable zero-effect stones. Existing custom +6 rows remain compatible until a separately backed-up inventory/socket migration.
This server change aligns the actual ITEM_METIN branch with AVA2's default (ENABLE_ADDSTONE_FAILURE is disabled): insertion always succeeds, and exactly one stone is consumed. Existing destination, wear-flag, duplicate-family and socket checks remain. The selected 40250-compatible three-socket packet format remains unchanged.
`python3 tests/features/test_stone_socket.py` compiles and executes the actual branch with lightweight dependencies. It verifies success, one-per-stack and last-item removal, duplicate family, equipped/exchange refusal, target type and socket eligibility. Full FreeBSD compilation also succeeded. The staged binary hash is 4b335083a26116771e18c97b3a41b039e1ff28efe93e957494fc62b6c5dfe94d.
Ordinary QA1017, isolated player_sb/account_sb, confirmed insertion and stack decrement, actual casting-speed +35 and max-HP +1200 deltas, and all three new exclusive-family pairs. The original test equipment was re-equipped after the probes. No production binary, owned item or socket was changed.
For isolated gmake builds, override both BINDIR and GAMEDIR: the old Makefile automatically moves its output into GAMEDIR after linking. The sbtest proto backups and test fixture backups are under /root/deploy-features/20261017-ava2-stones/.
+8 -11
View File
@@ -5149,19 +5149,16 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
if (item2->GetSocket(i) >= 1 && item2->GetSocket(i) <= 2 && item2->GetSocket(i) >= item->GetValue(2))
{
// 석 확률
if (number(1, 100) <= 30)
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("메틴석 부착에 성공하였습니다."));
item2->SetSocket(i, item->GetVnum());
}
else
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("메틴석 부착에 실패하였습니다."));
item2->SetSocket(i, ITEM_BROKEN_METIN_VNUM);
}
// PORT: AVA2 ENABLE_ADDSTONE_FAILURE is disabled: insertion always succeeds.
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("메틴석 부착에 성공하였습니다."));
item2->SetSocket(i, item->GetVnum());
LogManager::instance().ItemLog(this, item2, "SOCKET", item->GetName());
ITEM_MANAGER::instance().RemoveItem(item, "REMOVE (METIN)");
// PORT: AVA2 consumes one stone, including stackable +0..+5 stones.
if (item->GetCount() == 1)
ITEM_MANAGER::instance().RemoveItem(item, "REMOVE (METIN)");
else
item->SetCount(item->GetCount() - 1);
break;
}
+57
View File
@@ -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=&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')