Add AVA2 boss scheduler, dungeon tracking and ticket shop

This commit is contained in:
shen
2026-10-18 10:41:51 -07:00
parent 0b9c2bb6b0
commit ff6163a685
24 changed files with 1601 additions and 25 deletions
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""Run the actual dungeon tracker against source and deployed legacy quest flags."""
from pathlib import Path
import subprocess, tempfile, os
source=(Path(__file__).resolve().parents[2]/'src/server/game/src/ava2_track.cpp').read_text()
source='\n'.join(line for line in source.splitlines() if not line.startswith('#include'))
code=r'''
#include <map>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstdarg>
#include <cstdio>
using WORD=unsigned short;
const int CHAT_TYPE_COMMAND=1;
int get_global_time(){return 10000;}
namespace quest {
struct PC {bool running=false; bool IsLoaded(){return true;} bool IsRunning(){return running;}};
struct CQuestManager {
PC pc;std::set<std::string> quests;std::map<std::string,int> events;
static CQuestManager& instance(){static CQuestManager m;return m;}
PC* GetPCForce(int){return &pc;}
int GetQuestIndexByName(const char* n){return quests.count(n);}
int GetEventFlag(const char* n){return events[n];}
};
}
struct Character {
std::map<std::string,int> flags;std::string packet;
bool IsPC(){return true;}int GetPlayerID(){return 1;}
int GetQuestFlag(const std::string& n){return flags[n];}
void ChatPacket(int,const char* fmt,...) {char b[1024];va_list args;va_start(args,fmt);vsnprintf(b,sizeof(b),fmt,args);va_end(args);packet+=b;}
};
using LPCHARACTER=Character*;
const int CHAT_MAX_LEN=512;
static bool settingsValid=true;
static bool PortDungeonSettings(const char*,const char*,const std::vector<const char*>&,std::vector<unsigned>& out){out={3600};return settingsValid;}
'''+source+r'''
int main(){
Character c;auto& q=quest::CQuestManager::instance();
auto check=[&](WORD id,const char* expected){c.packet.clear();Ava2TrackDungeonInfo(&c,id);assert(c.packet==expected);};
check(2598,"TrackDungeonInfo 2598|0|0#");
c.flags["devilcatacomb_zone.cooldown"]=10100;check(2598,"TrackDungeonInfo 2598|100|0#");
q.quests.insert("devilcatacomb_zone");c.flags["devilcatacomb_zone.last_exit_time"]=9900;check(2598,"TrackDungeonInfo 2598|1700|0#");
q.quests.insert("flame_dungeon");c.flags["flame_dungeon.exit_time"]=9000;check(6091,"TrackDungeonInfo 6091|800|0#");
c.flags["flame_dungeon.exit_time"]=1;check(6091,"TrackDungeonInfo 6091|0|0#");
q.quests.insert("spider_dungeon_3floor_boss");c.flags["spider_dungeon_3floor_boss.retry_limit_time"]=11000;check(2092,"TrackDungeonInfo 2092|1000|0#");
q.quests.insert("dragon_lair_access");q.events["dragon_lair_time"]=9000;check(2493,"TrackDungeonInfo 2493|2600|0#");
settingsValid=false;check(2493,"TrackDungeonInfo 2493|-1|0#");settingsValid=true;
q.pc.running=true;check(2493,"TrackDungeonInfo 2493|-1|0#");q.pc.running=false;
q.quests.insert("dragonlair");c.flags["dragonlair.time"]=10200;check(2493,"TrackDungeonInfo 2493|200|1#");
c.flags["dragonlair.cooldown"]=10100;check(2493,"TrackDungeonInfo 2493|100|0#");
c.flags["devilcatacomb_zone.last_exit_time"]=2147483647;check(2598,"TrackDungeonInfo 2598|2147475447|0#");
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run([os.environ.get('CXX','c++'),'-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('AVA2 dungeon tracker: source precedence, legacy deadlines, shared lair, unavailable settings, overflow: PASS')
+84
View File
@@ -0,0 +1,84 @@
#!/usr/bin/env python3
"""Execute the shipped ticket-shop controller with a deterministic base-shop boundary."""
import os,re,subprocess,tempfile
from pathlib import Path
src=Path(__file__).resolve().parents[2]/'src/server/game/src/ava2_ticket_shop.cpp'
body=re.sub(r'^#include[^\n]*\n','',src.read_text(),flags=re.M)
harness=r'''
#include <cassert>
#include <cstdint>
#include <cstring>
#include <map>
#include <vector>
#include <memory>
#include <string>
using DWORD=uint32_t;using BYTE=uint8_t;using WORD=uint16_t;
const int SHOP_HOST_ITEM_MAX_NUM=40,HEADER_GC_SHOP=38,CHAT_TYPE_COMMAND=1;
enum {SHOP_SUBHEADER_GC_START,SHOP_SUBHEADER_GC_END,SHOP_SUBHEADER_GC_UPDATE_ITEM,SHOP_SUBHEADER_GC_UPDATE_PRICE,SHOP_SUBHEADER_GC_OK,SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY,SHOP_SUBHEADER_GC_SOLDOUT,SHOP_SUBHEADER_GC_INVENTORY_FULL,SHOP_SUBHEADER_GC_INVALID_POS,SHOP_SUBHEADER_GC_SOLD_OUT,SHOP_SUBHEADER_GC_START_EX,SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY_EX,SHOP_SUBHEADER_GC_START_ITEM_CURRENCY,SHOP_SUBHEADER_GC_NOT_ENOUGH_ITEM};
#pragma pack(push,1)
struct WireItem { DWORD vnum,price;BYTE count,display_pos;char rest[33]; };
struct TPacketGCShopStart { DWORD owner_vid;WireItem items[40]; };
struct TPacketGCShop { BYTE header;WORD size;BYTE subheader; };
#pragma pack(pop)
static_assert(sizeof(WireItem)==43,"baseline item");
struct TShopItemTable { DWORD vnum;BYTE count; };
struct Desc { std::string frame;void BufferedPacket(const void* p,size_t n){frame.assign((const char*)p,n);}void Packet(const void* p,size_t n){frame.append((const char*)p,n);} };
class CShop;
struct Character {
CShop* shop=nullptr;Character* owner=nullptr;Desc desc;
bool dead=false,stun=false,warp=false,exchange=false,myshop=false,safebox=false,cube=false,handle=true;
int baseResult=SHOP_SUBHEADER_GC_OK,baseCalls=0,saves=0,gold=123456;
std::map<DWORD,int> items;
bool IsPC(){return true;}bool CanHandleItem(){return handle;}bool IsDead(){return dead;}bool IsStun(){return stun;}bool IsWarping(){return warp;}
bool GetExchange(){return exchange;}bool GetMyShop(){return myshop;}bool IsOpenSafebox(){return safebox;}bool IsCubeOpen(){return cube;}
DWORD GetPlayerID(){return 16;}CShop* GetShop(){return shop;}Character* GetShopOwner(){return owner;}
void SetShop(CShop* p){shop=p;}void SetShopOwner(Character* p){owner=p;}Desc* GetDesc(){return &desc;}
int CountSpecifyItem(DWORD v){return items[v];}void RemoveSpecifyItem(DWORD v,DWORD n){assert(items[v]>=int(n));items[v]-=n;}void Save(){++saves;}
};
using LPCHARACTER=Character*;
namespace quest {
struct PC {bool loaded=true,running=false;bool IsLoaded(){return loaded;}bool IsRunning(){return running;}};
struct CQuestManager {PC pc;static CQuestManager& instance(){static CQuestManager q;return q;}PC* GetPCForce(DWORD){return &pc;}};
}
struct ITEM_MANAGER {bool valid=true;static ITEM_MANAGER& instance(){static ITEM_MANAGER i;return i;}const int* GetTable(DWORD){static int proto=1;return valid?&proto:nullptr;}};
class CShop {
protected:
struct SHOP_ITEM {DWORD vnum=0;BYTE count=0;int price=0;};
using GuestMapType=std::map<Character*,bool>;
GuestMapType m_map_guest;std::vector<SHOP_ITEM> m_itemVector;
public:
bool Create(DWORD,DWORD,TShopItemTable* data){m_itemVector.resize(40);for(int i=0;i<40;++i){m_itemVector[i].vnum=data[i].vnum;m_itemVector[i].count=data[i].count;}return true;}
virtual bool AddGuest(LPCHARACTER,DWORD,bool){return false;}
virtual int Buy(LPCHARACTER ch,BYTE pos){++ch->baseCalls;if(ch->baseResult==SHOP_SUBHEADER_GC_OK)ch->items[m_itemVector[pos].vnum]+=m_itemVector[pos].count;return ch->baseResult;}
};
'''
main=r'''
int main(){
Character c;c.items[90011]=30;
assert(Ava2OpenTicketShop(&c));assert(Ava2IsTicketShop(c.GetShop()));assert(c.GetShopOwner()==&c);
assert(c.desc.frame.size()==2048);
Ava2ShopStart start;memcpy(&start,c.desc.frame.data()+sizeof(TPacketGCShop),sizeof(start));
assert(start.shop.owner_vid==0 && start.shop.items[7].vnum==25170 && start.prices[0].vnum==90011 && start.prices[7].count==30);
assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_OK);assert(c.items[25163]==1 && c.items[90011]==20 && c.gold==123456);
c.baseResult=SHOP_SUBHEADER_GC_INVENTORY_FULL;
assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_INVENTORY_FULL);assert(c.items[90011]==20 && c.items[25163]==1);
c.baseResult=SHOP_SUBHEADER_GC_OK;c.handle=false;int calls=c.baseCalls;
assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_END && c.baseCalls==calls);c.handle=true;c.dead=true;
assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_END && c.baseCalls==calls);c.dead=false;
assert(c.GetShop()->Buy(&c,8)==SHOP_SUBHEADER_GC_INVALID_POS && c.baseCalls==calls);
assert(c.GetShop()->Buy(&c,2)==SHOP_SUBHEADER_GC_NOT_ENOUGH_ITEM && c.baseCalls==calls);
assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_OK);assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_OK);
assert(c.items[90011]==0 && c.items[25163]==3 && c.gold==123456);
calls=c.baseCalls;assert(c.GetShop()->Buy(&c,0)==SHOP_SUBHEADER_GC_NOT_ENOUGH_ITEM && c.baseCalls==calls);
assert(!Ava2OpenTicketShop(&c));
Character other;auto& pc=quest::CQuestManager::instance().pc;
pc.loaded=false;assert(!Ava2OpenTicketShop(&other));pc.loaded=true;pc.running=true;assert(!Ava2OpenTicketShop(&other));pc.running=false;
other.exchange=true;assert(!Ava2OpenTicketShop(&other));other.exchange=false;
c.shop=nullptr;c.owner=nullptr;Ava2DestroyTicketShop();ITEM_MANAGER::instance().valid=false;assert(!Ava2OpenTicketShop(&other));
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(harness+body+main)
subprocess.run([os.environ.get('CXX','c++'),'-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('AVA2 shop12: source prices, native payload, item payment, no gold charge, insufficient funds, full/busy/invalid/guest/proto guards: PASS')
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Compile the shipped AVA2 calendar/state/query methods with a deterministic clock."""
from pathlib import Path
import os, subprocess, tempfile
root=Path(__file__).resolve().parents[2]/'src/server/game/src'
source=(root/'new_mob_timer.cpp').read_text(encoding='latin1')
header=(root/'new_mob_timer.h').read_text(encoding='latin1')
def function(name):
start=source.index(name);brace=source.index('{',start);depth=1;end=brace+1
while depth:
depth+=(source[end]=='{')-(source[end]=='}');end+=1
return source[start:end]
struct=header[header.index('typedef struct SNewRegen'):header.index('class CNewMobTimer')]
code=r'''
#include <algorithm>
#include <cassert>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
using BYTE=unsigned char;using WORD=unsigned short;using DWORD=unsigned int;
struct Character {
std::string packet;
void ChatPacket(int,const char* format,...) {
char b[256];va_list args;va_start(args,format);vsnprintf(b,sizeof(b),format,args);va_end(args);packet=b;
}
};
using LPCHARACTER=Character*;
const int CHAT_TYPE_COMMAND=1;
static time_t clockValue;
static time_t clockRead(time_t* out){if(out)*out=clockValue;return clockValue;}
static DWORD get_dword_time(){return 0;}
struct CMapLocation {
bool mapped=true;
static CMapLocation& instance(){static CMapLocation m;return m;}
bool Get(int,long&,WORD&){return mapped;}
};
#define time clockRead
'''+struct+r'''
class CNewMobTimer {
public:
std::vector<TNewRegen> m_vecRegenData;
void CalculateLeftTimeReal(TNewRegen*);
int CalculateLeftTime(TNewRegen*);
void GetTrackData(LPCHARACTER,WORD);
};
'''+function('void CNewMobTimer::CalculateLeftTimeReal(')+'\n'+function('int CNewMobTimer::CalculateLeftTime(')+'\n'+function('void CNewMobTimer::GetTrackData(')+r'''
#undef time
static time_t date(int year,int mon,int day,int hour,int minute,int second=0) {
tm v={};v.tm_year=year-1900;v.tm_mon=mon-1;v.tm_mday=day;v.tm_hour=hour;v.tm_min=minute;v.tm_sec=second;v.tm_isdst=-1;return mktime(&v);
}
int main(){
setenv("TZ","UTC",1);tzset();CNewMobTimer manager;TNewRegen r={};r.id=4;r.mapIndex=357;
clockValue=date(2026,10,18,5,33,40);r.minute_range=1;
manager.CalculateLeftTimeReal(&r);assert(r.leftTime==date(2026,10,18,5,34));
r.minute_range=0;r.hour=23;r.days_range=2;
clockValue=date(2026,10,17,22,59,59);manager.CalculateLeftTimeReal(&r);assert(r.leftTime==date(2026,10,17,23,0));
clockValue=date(2026,10,17,23,0,1);manager.CalculateLeftTimeReal(&r);assert(r.leftTime==date(2026,10,18,23,0)); // source is weekday modulo, not fixed 48 hours
r.days_range=0;r.hour=0;
clockValue=date(2026,2,28,23,59,59);manager.CalculateLeftTimeReal(&r);assert(r.leftTime==date(2026,3,1,0,0));
Character player;r.bossPtr=&player;assert(manager.CalculateLeftTime(&r)==65535);
r.bossPtr=nullptr;r.p2pAlive=true;r.peerAliveUntil=clockValue+30;assert(manager.CalculateLeftTime(&r)==65535);
r.peerAliveUntil=clockValue-1;assert(manager.CalculateLeftTime(&r)==1);assert(!r.p2pAlive);
manager.m_vecRegenData.push_back(r);
manager.GetTrackData(&player,999);assert(player.packet=="TrackBossInfo 999 -1 0");
manager.m_vecRegenData[0].leftTime=clockValue+65535;manager.GetTrackData(&player,4);assert(player.packet=="TrackBossInfo 4 65536 0");
CMapLocation::instance().mapped=false;manager.GetTrackData(&player,4);assert(player.packet=="TrackBossInfo 4 -1 0");
CMapLocation::instance().mapped=true;manager.m_vecRegenData[0].bossPtr=&player;manager.m_vecRegenData[0].aliveChannel=5;
manager.GetTrackData(&player,4);assert(player.packet=="TrackBossInfo 4 65535 5");
}
'''
with tempfile.TemporaryDirectory() as d:
cpp=Path(d)/'track.cpp';cpp.write_text(code);exe=Path(d)/'track'
subprocess.run([os.environ.get('CXX','c++'),'-std=c++17',str(cpp),'-o',str(exe)],check=True)
subprocess.run([str(exe)],check=True)
print('AVA2 tracker: calendar boundaries, source weekday cadence, alive state, peer expiry, channel and unknown/map guards: PASS')