feat: add quiver ammunition rules and negotiated state sync
This commit is contained in:
@@ -8,7 +8,8 @@ SRC=ROOT/'src/server/game/src'
|
||||
def text(name):return (SRC/name).read_bytes().decode('latin1')
|
||||
features=text('port_features.h');glue=text('port_boss_track.cpp');p2p=text('input_p2p.cpp');main=text('main.cpp')
|
||||
assert 'if(kind=="bosses" && args.size()==3) {PortBossQuery(ch,request);return;}' in features
|
||||
assert '"MTF1 cap %u 1 959 %lld"' in features
|
||||
# Current shared capabilities include later rank and negotiated quiver support.
|
||||
assert '"MTF1 cap %u 1 4031 %lld"' in features
|
||||
assert 'port_boss_track.cpp' in text('Makefile')
|
||||
assert 'PortBossTick();' in main.split('if (!g_bAuthServer)',1)[1].split('}',1)[0] # 1 s block, game cores only
|
||||
# Relay hook runs after the size checks and before the player lookup; old cores just miss the name.
|
||||
|
||||
@@ -59,6 +59,7 @@ static DWORD clockms=1000;unsigned get_dword_time(){return clockms;}long long ge
|
||||
struct Character {
|
||||
unsigned m_portFeatureLastQuery=0;bool pc=true;std::vector<std::string> messages;std::map<unsigned,int> points;
|
||||
bool IsPC(){return pc;}void* GetDesc(){return this;}
|
||||
void PortEnableQuiverSync(){}
|
||||
int GetPoint(unsigned point){return points[point];}
|
||||
int GetHP(){return 123;}int GetMaxHP(){return 500;}int GetSP(){return 42;}int GetMaxSP(){return 100;}int GetLevel(){return 30;}
|
||||
void ChatPacket(int,const char* format,...) {
|
||||
@@ -118,7 +119,7 @@ int main(){
|
||||
assert(rewards[0].total==100 && rewards[0].rule==WIKI_SINGLE);
|
||||
rewards=items.PortWikiChest(50012);assert(rewards[1].rule==WIKI_INDEPENDENT && rewards[1].weight==150 && rewards[1].total==100);
|
||||
assert(items.PortWikiChest(50013).empty() && items.PortWikiChest(19).empty());
|
||||
Character ch;query(ch,"1 99 travel 2493 0");assert(travelBoss==2493);query(ch,"1 1 cap");assert(ch.messages.back()=="MTF1 cap 1 1 1983 1700000000");
|
||||
Character ch;query(ch,"1 99 travel 2493 0");assert(travelBoss==2493);query(ch,"1 1 cap");assert(ch.messages.back()=="MTF1 cap 1 1 4031 1700000000");
|
||||
query(ch,"1 90 rank 0 0");assert(rankQuery==0);
|
||||
query(ch,"1 91 rank 10 0");assert(ch.messages.back()=="MTF1 error 91 invalid" && rankQuery==0);
|
||||
query(ch,"1 92 rank 6 1");assert(ch.messages.back()=="MTF1 error 92 invalid" && rankQuery==0);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
"""Compile actual ammunition functions with explicit item/character substitutes."""
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SRC = ROOT / 'src/server/game/src'
|
||||
|
||||
|
||||
class QuiverRuntimeTests(unittest.TestCase):
|
||||
def test_actual_ammunition_and_expiry_paths(self):
|
||||
text = (SRC / 'char_battle.cpp').read_bytes().decode('latin1')
|
||||
functions = text[text.index('int CHARACTER::GetArrowAndBow('):text.index('class CFuncShoot')]
|
||||
self.assertIn('m_me->UseArrow(pkArrow, iUseArrow)', text)
|
||||
self.assertIn('m_me->UseArrow(pkArrow, 1)', text)
|
||||
enum = (ROOT / 'src/server/common/item_length.h').read_text()
|
||||
self.assertIn('WEAPON_CLAW = 8', enum)
|
||||
self.assertIn('WEAPON_QUIVER = 9', enum)
|
||||
reader = (ROOT / 'src/server/db/src/ProtoReader.cpp').read_bytes()
|
||||
self.assertIn(b'"WEAPON_MOUNT_SPEAR", "WEAPON_CLAW", "WEAPON_QUIVER"', reader)
|
||||
attrs = (SRC / 'item_attribute.cpp').read_text()
|
||||
self.assertIn('GetSubType() == WEAPON_ARROW || GetSubType() == WEAPON_QUIVER', attrs)
|
||||
proto = reader.decode('latin1')
|
||||
parser = proto[proto.index('int get_Item_SubType_Value('):proto.index('int get_Item_AntiFlag_Value(')]
|
||||
trim = proto[proto.index('inline string trim_left('):proto.index('static string* StringSplit(')]
|
||||
code = r'''
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
using std::string;
|
||||
#define MIN(a,b) std::min<unsigned>((a),(b))
|
||||
#define sys_log(...) ((void)0)
|
||||
#define sys_err(...) ((void)0)
|
||||
#define _countof(a) (sizeof(a)/sizeof((a)[0]))
|
||||
using DWORD=uint32_t;
|
||||
enum {WEAR_WEAPON,WEAR_ARROW,ITEM_WEAPON=1,ITEM_LIMIT_MAX_NUM=2,LIMIT_REAL_TIME=7,
|
||||
LIMIT_REAL_TIME_START_FIRST_USE=8,LIMIT_TIMER_BASED_ON_WEAR=9};
|
||||
''' + re.search(r'enum EWeaponSubTypes\s*\{.*?\};', enum, re.S).group(0) + trim + parser + r'''
|
||||
long now=1000;long get_global_time(){return now;}
|
||||
struct Item {
|
||||
struct Proto{int bSubType=WEAPON_ARROW;} proto;
|
||||
int type=ITEM_WEAPON,count=1,limits[2]={0,0};long sockets[3]={0,0,0};
|
||||
unsigned vnum=80000;
|
||||
Proto* GetProto(){return &proto;}int GetType(){return type;}
|
||||
int GetSubType(){return proto.bSubType;}int GetCount(){return count;}
|
||||
void SetCount(int n){count=n;}unsigned GetVnum(){return vnum;}
|
||||
int GetLimitType(int i){return limits[i];}long GetSocket(int i){return sockets[i];}
|
||||
};
|
||||
using LPITEM=Item*;
|
||||
#include "port_quiver.h"
|
||||
struct CHARACTER {
|
||||
Item *bow=nullptr,*ammo=nullptr,*replacement=nullptr,*equipped=nullptr;
|
||||
LPITEM GetWear(int slot){return slot==WEAR_WEAPON?bow:ammo;}
|
||||
LPITEM FindSpecifyItem(DWORD){return replacement;}
|
||||
void EquipItem(LPITEM p){equipped=p;}
|
||||
int GetArrowAndBow(LPITEM*,LPITEM*,int=1);void UseArrow(LPITEM,DWORD);
|
||||
};
|
||||
''' + functions + r'''
|
||||
int main(){
|
||||
static_assert(WEAPON_CLAW==8 && WEAPON_QUIVER==9 && WEAPON_NUM_TYPES==10);
|
||||
assert(get_Item_SubType_Value(ITEM_WEAPON,"WEAPON_QUIVER")==WEAPON_QUIVER);
|
||||
assert(get_Item_SubType_Value(ITEM_WEAPON,"WEAPON_CLAW")==WEAPON_CLAW);
|
||||
assert(get_Item_SubType_Value(ITEM_WEAPON,"WEAPON_ARROW")==WEAPON_ARROW);
|
||||
assert(get_Item_SubType_Value(ITEM_WEAPON,"WEAPON_UNKNOWN")==-1);
|
||||
Item bow,arrow,quiver,next;bow.proto.bSubType=WEAPON_BOW;
|
||||
quiver.proto.bSubType=WEAPON_QUIVER;arrow.count=3;
|
||||
CHARACTER ch;LPITEM outBow=nullptr,outAmmo=nullptr;
|
||||
assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
ch.bow=&bow;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
ch.ammo=&arrow;
|
||||
assert(ch.GetArrowAndBow(&outBow,&outAmmo,5)==3);
|
||||
assert(outBow==&bow && outAmmo==&arrow);
|
||||
ch.UseArrow(&arrow,2);assert(arrow.count==1);
|
||||
ch.replacement=&next;ch.UseArrow(&arrow,5);
|
||||
assert(arrow.count==0 && ch.equipped==&next);
|
||||
ch.ammo=&quiver;
|
||||
assert(ch.GetArrowAndBow(&outBow,&outAmmo,300)==200);
|
||||
for(int i=0;i<1000;++i){assert(ch.GetArrowAndBow(&outBow,&outAmmo)==1);ch.UseArrow(&quiver,200);}
|
||||
assert(quiver.count==1 && outAmmo==&quiver);
|
||||
quiver.type=3;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);quiver.type=ITEM_WEAPON;
|
||||
quiver.count=0;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);quiver.count=1;
|
||||
bow.proto.bSubType=0;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);bow.proto.bSubType=WEAPON_BOW;
|
||||
quiver.limits[0]=LIMIT_REAL_TIME;quiver.sockets[0]=now-1;
|
||||
assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
quiver.sockets[0]=now;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==1);
|
||||
++now;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
quiver.limits[0]=LIMIT_REAL_TIME_START_FIRST_USE;quiver.sockets[1]=1;
|
||||
assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
quiver.sockets[0]=now+60;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==1);
|
||||
quiver.limits[0]=LIMIT_TIMER_BASED_ON_WEAR;quiver.sockets[0]=0;
|
||||
assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
quiver.sockets[0]=1;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==1);
|
||||
ch.ammo=nullptr;assert(ch.GetArrowAndBow(&outBow,&outAmmo)==0);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory(prefix='ch5-quiver-') as folder:
|
||||
root = Path(folder)
|
||||
(root / 'probe.cpp').write_text(code)
|
||||
subprocess.run(['c++', '-std=c++17', '-fsanitize=address,undefined',
|
||||
'-fno-sanitize-recover=all', '-I'+str(SRC),
|
||||
str(root/'probe.cpp'), '-o', str(root/'probe')], check=True)
|
||||
subprocess.run([str(root/'probe')], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user