Add profile-driven AdventureBot character generation
clang PCH / build (push) Waiting to run
GCC PCH / build (push) Canceled after 0s

This commit is contained in:
Nico committed 2026-10-28 11:30:47 +01:00
1 parent e333f2f9fc
commit 04aa87fcfc
33 files changed
+3465 -2

No files matched your search

@@ -0,0 +1,39 @@
"""Execute production equipment proc affinity, including mana-trinket rejection."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
s=(root/'src/server/game/World/AdventureGeneratorMgr.cpp').read_text()
a=s.index(' bool UsefulSpell(');b=s.index('{',a);e=b+1;depth=1
while depth:depth+=(s[e]=='{')-(s[e]=='}');e+=1
code=r'''
#include "AdventureGeneratorPolicy.h"
#include <cassert>
#include <unordered_map>
#include <vector>
using uint32=unsigned;using Archetype=AdventureGeneratorPolicy::Archetype;
enum {ITEM_MOD_INTELLECT=5,POWER_MANA=0,SPELL_AURA_PERIODIC_ENERGIZE=1,SPELL_AURA_MOD_POWER_REGEN,SPELL_AURA_MOD_POWER_REGEN_PERCENT,SPELL_AURA_MOD_INCREASE_ENERGY,SPELL_AURA_MOD_INCREASE_ENERGY_PERCENT,SPELL_EFFECT_ENERGIZE,SPELL_EFFECT_ENERGIZE_PCT,SPELL_AURA_MOD_STAT,SPELL_AURA_MOD_SPELL_HIT_CHANCE,SPELL_AURA_MOD_SPELL_CRIT_CHANCE,SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL,SPELL_AURA_MOD_HEALING_DONE,SPELL_AURA_MOD_DAMAGE_DONE,SPELL_AURA_MOD_ATTACK_POWER,SPELL_AURA_MOD_RANGED_ATTACK_POWER};
enum class StatType{Strength=0,Agility=1,Intellect=3};
struct Effect{int ApplyAuraName=0,MiscValue=0,Effect=0;unsigned TriggerSpell=0;};
struct Info{std::vector<Effect>Effects;};
struct Spells{std::unordered_map<unsigned,Info> data;Info*GetSpellInfo(unsigned id){auto i=data.find(id);return i==data.end()?nullptr:&i->second;}}spells;auto sSpellMgr=&spells;
'''+s[a:e]+r'''
int main(){
auto warrior=AdventureGeneratorPolicy::Archetypes()[0],mage=AdventureGeneratorPolicy::Archetypes()[7];
spells.data[1].Effects={{SPELL_AURA_PERIODIC_ENERGIZE,POWER_MANA,0,0}};
assert(!UsefulSpell(1,warrior));assert(UsefulSpell(1,mage));
spells.data[2].Effects={{0,POWER_MANA,SPELL_EFFECT_ENERGIZE,0}};assert(!UsefulSpell(2,warrior));
spells.data[3].Effects={{0,0,0,1}};assert(!UsefulSpell(3,warrior));assert(UsefulSpell(3,mage));
spells.data[4].Effects={{SPELL_AURA_MOD_STAT,int(StatType::Intellect),0,0}};assert(!UsefulSpell(4,warrior));assert(UsefulSpell(4,mage));
spells.data[5].Effects={{SPELL_AURA_MOD_STAT,int(StatType::Strength),0,0}};assert(UsefulSpell(5,warrior));assert(!UsefulSpell(5,mage));
spells.data[6].Effects={{0,0,0,6}};assert(UsefulSpell(6,warrior)); // bounded cyclic trigger metadata
spells.data[7].Effects={{SPELL_AURA_MOD_SPELL_HIT_CHANCE,0,0,0}};assert(!UsefulSpell(7,warrior));assert(UsefulSpell(7,mage));
spells.data[8].Effects={{SPELL_AURA_MOD_DAMAGE_DONE,2,0,0}};assert(!UsefulSpell(8,warrior));assert(UsefulSpell(8,mage));
spells.data[9].Effects={{SPELL_AURA_MOD_DAMAGE_DONE,1,0,0}};assert(UsefulSpell(9,warrior));assert(!UsefulSpell(9,mage));
assert(UsefulSpell(999,warrior)); // missing metadata never grants a spell
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['g++','-std=c++17','-I',str(root/'src/server/game/World'),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Production equipment affinity: mana-only/direct/triggered procs, caster/physical stat effects and bounded cycles passed')
@@ -0,0 +1,64 @@
"""Exercise production generator command gates for ownership/retirement."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
s=(root/'src/server/game/World/AdventureGeneratorMgr.cpp').read_text()
a=s.index('bool AdventureGeneratorMgr::Command(');b=s.index('{',a);e=b+1;depth=1
while depth:depth+=(s[e]=='{')-(s[e]=='}');e+=1
code=r'''
#include <cassert>
#include "AdventureGeneratorPolicy.h"
#include <cstdint>
#include <memory>
#include <sstream>
#include <string>
using uint32=uint32_t;using uint8=uint8_t;
struct Field{unsigned number=0;std::string str="ready";unsigned GetUInt32(){return number;}unsigned GetUInt8(){return number;}std::string GetString(){return str;}};
struct Row{Field f[6];Field*Fetch(){return f;}bool NextRow(){return false;}};
struct Transaction{template<class...A>void PAppend(char const*,A...){}};
struct Future{bool get(){return true;}};struct Commit{Future m_future;};
struct DB{bool owned=true,persistent=false,online=false;int retired=0;std::string state="ready";
template<class...A>std::shared_ptr<Row>PQuery(char const*,A...){if(!owned)return nullptr;auto row=std::make_shared<Row>();row->f[0].number=6;row->f[1].str=state;row->f[2].number=persistent;row->f[3].number=online;row->f[4].str="warrior";row->f[5].number=42;return row;}
std::shared_ptr<Row>Query(char const*){return nullptr;}auto BeginTransaction(){return std::make_shared<Transaction>();}Commit AsyncCommitTransaction(std::shared_ptr<Transaction>){++retired;return {};}
}CharacterDatabase;
struct ChatHandler{void SendSysMessage(char const*){}template<class...A>void PSendSysMessage(char const*,A...){} };
bool schema=true;bool Schema(){return schema;}
namespace GameTime{unsigned GetGameTime(){return 100;}}
enum class ClientlessPlayerState{Offline,Online,Removing};
constexpr int UNIT_STATE_CASTING=1,POWER_MANA=0;
struct Player{bool combat=false,casting=false;int saves=0;bool IsInWorld(){return true;}bool IsAlive(){return true;}bool IsInCombat(){return combat;}bool IsBeingTeleported(){return false;}bool GetTransport(){return false;}bool IsInFlight(){return false;}bool HasUnitState(int){return casting;}unsigned getClass(){return 1;}void UpdateMaxHealth(){}void SetFullHealth(){}void SetFullPower(int){}void SaveToDB(std::shared_ptr<Transaction>){++saves;}};
struct Session{Player player;Player*GetPlayer(){return &player;}};
int equipped=0;bool Equip(Player*,AdventureGeneratorPolicy::Archetype const&,std::mt19937&,std::string&){++equipped;return true;}
struct Behavior{void InterruptForInteraction(Player*){}}behavior;auto sAdventureBehaviorMgr=&behavior;
#define TC_LOG_INFO(...) ((void)0)
struct World{Session session;bool available=false;Session*FindClientlessSession(unsigned){return available?&session:nullptr;}ClientlessPlayerState state=ClientlessPlayerState::Offline;auto GetClientlessPlayerState(unsigned){return state;}}world;auto sWorld=&world;
struct Core{int starts=0,stops=0;bool StartPlayer(unsigned,unsigned,int){++starts;return true;}bool StopPlayer(unsigned){++stops;return true;}}core;auto sClientlessPlayerMgr=&core;int CreateClientlessAdventureLuaController(){return 0;}
struct AdventureGeneratorMgr{
int creates=0;bool Command(ChatHandler*,char const*);
bool Create(ChatHandler*,uint32,uint32,uint8,unsigned,std::string const&,bool){++creates;return true;}
bool Profile(unsigned,std::string&lua){lua="return {}";return true;}
};
'''+s[a:e]+r'''
int main(){
AdventureGeneratorMgr mgr;ChatHandler handler;auto run=[&](char const*args){return mgr.Command(&handler,args);};
schema=false;assert(!run("create 6 1"));schema=true;
assert(run("create 6 1"));assert(mgr.creates==1);assert(run("create 6 1 "));assert(mgr.creates==2);
assert(!run("create 6 0"));assert(!run("create 6 11"));assert(!run("create 6 1 256 any any temporary 1"));assert(mgr.creates==2);
assert(run("create 6 2 60 horde warrior temporary 42"));assert(mgr.creates==4);
CharacterDatabase.owned=false;assert(!run("retire 26"));assert(!run("logout 26"));assert(!run("login 26"));assert(!run("equip 26"));assert(!core.stops && !core.starts && !CharacterDatabase.retired);
CharacterDatabase.owned=true;CharacterDatabase.persistent=true;assert(!run("retire 30"));CharacterDatabase.persistent=false;
CharacterDatabase.online=true;assert(!run("retire 30"));CharacterDatabase.online=false;
world.state=ClientlessPlayerState::Removing;assert(!run("retire 30"));world.state=ClientlessPlayerState::Offline;
assert(run("retire 30"));assert(CharacterDatabase.retired==1);
CharacterDatabase.state="retired";assert(!run("login 30"));assert(!core.starts);CharacterDatabase.state="ready";
assert(run("login 30"));assert(core.starts==1);assert(run("logout 30"));assert(core.stops==1);
assert(!run("equip 30"));world.available=true;world.session.player.combat=true;assert(!run("equip 30"));world.session.player.combat=false;
world.session.player.casting=true;assert(!run("equip 30"));world.session.player.casting=false;
assert(run("equip 30"));assert(equipped==1 && world.session.player.saves==1);
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['g++','-std=c++17','-I',str(root/'src/server/game/World'),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Production generator commands: batch bounds, dedicated ownership, persistent/online/removing retirement protection and retired login refusal passed')
@@ -0,0 +1,50 @@
"""Execute the actual cultural naming/profile generator with real Lua."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
code=r'''
#include "AdventureGeneratorPolicy.h"
#include <lua.hpp>
#include <cassert>
#include <cctype>
#include <set>
int main(){
using namespace AdventureGeneratorPolicy;
std::set<std::string> global;
lua_State* L=luaL_newstate();
for(unsigned race:{1,2,3,4,5,6,7,8,9,10,11,22})for(unsigned gender:{0,1}){
std::set<std::string> cultural;
for(unsigned seed=0;seed<256;++seed){
std::mt19937 r(seed),again(seed);auto name=Name(race,gender,r);assert(name==Name(race,gender,again));
assert(name.size()>=3 && name.size()<=12 && std::isupper(name[0]));for(unsigned i=1;i<name.size();++i)assert(std::islower(name[i]));
cultural.insert(name);global.insert(name);
for(auto const&a:Archetypes()){
auto profile=Profile(name,a,race,"local_tavern","home_region",r);
assert(luaL_loadbuffer(L,profile.data(),profile.size(),"generated-profile")==LUA_OK);assert(lua_pcall(L,0,1,0)==LUA_OK);
lua_getfield(L,-1,"identity");lua_getfield(L,-1,"name");assert(name==lua_tostring(L,-1));lua_pop(L,1);
lua_getfield(L,-1,"background");assert(std::string(lua_tostring(L,-1)).find(Origin(race))!=std::string::npos);lua_pop(L,2);
lua_getfield(L,-1,"professions");lua_getfield(L,-1,"primary");assert(lua_rawlen(L,-1)==2);
lua_rawgeti(L,-1,1);assert(std::string(lua_tostring(L,-1))==AdventureProfessionPolicy::PrimaryForSkill(a.Skills[0]));lua_pop(L,3);
lua_getfield(L,-1,"personality");for(auto key:{"sociability","adventurousness","wanderlust","group_loyalty"}){lua_getfield(L,-1,key);auto value=lua_tonumber(L,-1);assert(value>=.25 && value<=.9);lua_pop(L,1);}lua_pop(L,1);
lua_getfield(L,-1,"behavior");lua_getfield(L,-1,"initial_location");assert(std::string(lua_tostring(L,-1))=="local_tavern");lua_settop(L,0);
}
}
assert(cultural.size()>=50);
}
assert(global.size()>900);
std::string raw="A quote \" slash \\ newline\nreturn os.execute('no')";auto escaped=LuaString(raw);
assert(luaL_dostring(L,("return "+escaped).c_str())==LUA_OK);assert(raw==lua_tostring(L,-1));lua_settop(L,0);
auto warrior=Archetypes()[0];assert(Armor(warrior,39)==3 && Armor(warrior,40)==4);
auto hunter=Archetypes()[2];assert(Armor(hunter,39)==2 && Armor(hunter,40)==3);
assert(EligibleItem(60,58,3,85,false,false));assert(!EligibleItem(60,61,3,85,false,false));
assert(!EligibleItem(60,58,5,85,false,false));assert(!EligibleItem(60,58,3,85,true,false));assert(!EligibleItem(60,58,3,85,false,true));
assert(!EligibleItem(60,1,3,85,false,false));
lua_close(L);
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
flags=subprocess.check_output(['pkg-config','--cflags','--libs','lua5.4'],text=True).split()
subprocess.run(['g++','-std=c++17','-I',str(root/'src/server/game/World'),str(p/'test.cpp'),'-o',str(p/'test'),*flags],check=True)
subprocess.run([str(p/'test')],check=True)
print('Production generator: 6144 cultural names and 61440 real Lua profiles, profession coherence, personality ranges, escaping and equipment/armor gates passed')
@@ -56,6 +56,7 @@ struct Player{
unsigned level=60;bool combat=false,casting=false;History history;int requests=0;std::unordered_map<unsigned,unsigned>skills,caps,steps;std::unordered_set<unsigned>known;
std::unordered_map<unsigned,std::unique_ptr<Item>>inventory;
Guid GetGUID(){return {};}unsigned getLevel(){return level;}unsigned getRace(){return 1;}unsigned getClass(){return 1;}
bool IsInWorld(){return true;}
bool IsSpellFitByClassAndRace(unsigned){return true;}bool HasSpell(unsigned id){return known.count(id);}
unsigned GetPureSkillValue(unsigned skill){return skills[skill];}unsigned GetPureMaxSkillValue(unsigned skill){return caps[skill];}unsigned GetSkillStep(unsigned skill){return steps[skill];}
void LearnSpell(unsigned id,bool){known.insert(id);auto rank=spellMgr.GetSpellLearnSkill(id);if(rank){caps[rank->skill]=rank->maximum;steps[rank->skill]=rank->step;}
@@ -75,6 +76,7 @@ struct Player{
void Add(ItemTemplate*p,unsigned count=20){inventory[p->id]=std::make_unique<Item>(Item{p,count});}
};
struct Spell{Player*p;SpellInfo*info;Item*m_CastItem=nullptr;Spell(Player*q,SpellInfo*i,int):p(q),info(i){}bool CanAutoCast(Player*q){assert(q==p && m_CastItem);return info->autoCast;}};
struct ClientlessCharacterFactory{static bool PrepareSkillRank(Player*,unsigned,unsigned){assert(false);return false;}};
'''+header+'\n'+function(' bool RoleMatches(')+'\n'+function('ItemTemplate const* AdventureSupplyMgr::Select(')+'\n'+function('AdventureSupplyMgr::UseResult AdventureSupplyMgr::TryUse(')+'\n'+function('void AdventureSupplyMgr::LearnSecondaries(')+r'''
int main(){
using U=AdventureSupplyPolicy::Use;AdventureSupplyMgr mgr;Player p;auto&r=mgr._records[26];
@@ -0,0 +1,90 @@
"""Execute the production native factory with transactional/publishing adapters."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
source=(root/'src/server/game/World/ClientlessCharacterFactory.cpp').read_text()
source=source[:source.index('bool ClientlessCharacterFactory::PrepareSkillRank(')]
source='\n'.join(line for line in source.splitlines() if not line.startswith('#include'))
header=(root/'src/server/game/World/ClientlessCharacterFactory.h').read_text()
header='\n'.join(line for line in header.splitlines() if not line.startswith('#include'))
code=r'''
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <memory>
#include <random>
#include <string>
using uint8=uint8_t;using uint32=uint32_t;
#define TC_GAME_API
constexpr int SEC_PLAYER=0,GENDER_FEMALE=1,CLASS_DEATH_KNIGHT=6,CONFIG_MAX_PLAYER_LEVEL=0,CONFIG_CHARACTERS_PER_REALM=1,LOCALE_enUS=0,CHAR_NAME_SUCCESS=0,TOTAL_LOCALES=4,POWER_MANA=0,LOGIN_REP_REALM_CHARACTERS=0;
using LocaleConstant=int;
struct ObjectGuid{unsigned id;unsigned GetCounter()const{return id;}};enum class HighGuid{Player};
struct Field {uint32 value=0;std::string text="BOT";uint8 GetUInt8(){return value;}uint32 GetUInt32(){return value;}std::string GetString(){return text;}};
struct Row{Field fields[3];Field*Fetch(){return fields;}};using QueryResult=std::shared_ptr<Row>;
struct Transaction{int characterRows=0,profileRows=0;};using CharacterDatabaseTransaction=std::shared_ptr<Transaction>;
struct Future{bool success=true;bool get(){return success;}};struct Commit{Future m_future;};
struct Statement{void setUInt32(int,uint32){}};
struct Database {
bool account=true,duplicate=false,success=true;uint32 count=1;int commits=0,savedCharacters=0,savedProfiles=0,realmWrites=0;Statement stmt;
template<class...A>QueryResult PQuery(char const*sql,A...){
std::string query(sql);if(query.find("SELECT 1")!=std::string::npos)return duplicate?std::make_shared<Row>():nullptr;
if(query.find("COUNT(*)")!=std::string::npos){auto row=std::make_shared<Row>();row->fields[0].value=count;return row;}
if(!account)return nullptr;auto row=std::make_shared<Row>();row->fields[1].value=3;return row;
}
void EscapeString(std::string&){}CharacterDatabaseTransaction BeginTransaction(){return std::make_shared<Transaction>();}
Commit AsyncCommitTransaction(CharacterDatabaseTransaction tx){++commits;if(success){savedCharacters+=tx->characterRows;savedProfiles+=tx->profileRows;}return {{success}};}
Statement*GetPreparedStatement(int){return &stmt;}void Execute(Statement*){++realmWrites;}
}CharacterDatabase,LoginDatabase;
struct CharacterCreateInfo {protected:std::string Name;uint8 Race=0,Class=0,Gender=0,Skin=0,Face=0,HairStyle=0,HairColor=0,FacialHair=0;};
struct Motion {void Initialize(){}};
struct WorldSession {enum class WorldSessionMode{Clientless};template<class...T>WorldSession(T...){} };
struct Player {
static inline bool createSuccess=true;static inline int cleaned=0;unsigned level=1;ObjectGuid guid{0};Motion motion;
explicit Player(WorldSession*){}void CleanupsBeforeDelete(){++cleaned;}static bool ValidateAppearance(uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8,bool){return true;}
Motion*GetMotionMaster(){return &motion;}bool Create(unsigned id,CharacterCreateInfo*){guid={id};return createSuccess;}void setCinematic(int){}unsigned getLevel(){return level;}void SetLevel(unsigned l){level=l;}void InitStatsForLevel(bool){}void InitTalentForLevel(){}void InitTaxiNodesForLevel(){}void InitGlyphsForLevel(){}void SetCanModifyStats(bool){}void UpdateMaxHealth(){}void UpdateMaxPower(int){}void SetMoney(int){}void LearnDefaultSkills(){}void UpdateSkillsForLevel(){}void SetFullHealth(){}void SetFullPower(int){}
void SaveToDB(CharacterDatabaseTransaction tx,bool creating){assert(creating);++tx->characterRows;}ObjectGuid GetGUID(){return guid;}
};
struct World {bool connected=false;bool FindSession(uint32){return connected;}unsigned getIntConfig(int c){return c==CONFIG_MAX_PLAYER_LEVEL?85:10;}}world;auto sWorld=&world;
namespace AccountMgr {int security=0;int GetSecurity(uint32,int){return security;}}
struct Realm {struct{int Realm=1;}Id;}realm;
bool normalizePlayerName(std::string&s){return !s.empty();}
struct Info{unsigned Race_related=0,Required_expansion=0;};struct Store {Info info;Info*LookupEntry(unsigned){return &info;}}sChrRacesStore,sChrClassesStore;
struct ObjectMgr {
bool valid=true,reserved=false;unsigned nextGuid=30;Info info;
Info*GetPlayerInfo(unsigned,unsigned){return valid?&info:nullptr;}bool IsReservedName(std::string const&){return reserved;}
static int CheckPlayerName(std::string const&,int,bool){return CHAR_NAME_SUCCESS;}
struct Generator{unsigned Generate(){return 30;}}generator;template<HighGuid G>Generator&GetGenerator(){return generator;}
}objects;auto sObjectMgr=&objects;
struct Cache {bool duplicate=false;int published=0;bool GetCharacterCacheByName(std::string const&){return duplicate;}template<class...T>void AddCharacterCacheEntry(T...){++published;}}cache;auto sCharacterCache=&cache;
struct ScriptMgr {int creates=0;void OnPlayerCreate(Player*){++creates;}}scripts;auto sScriptMgr=&scripts;
'''+header+'\n'+source+r'''
int main(){
using Factory=ClientlessCharacterFactory;Factory::Definition d{"Aldren",1,1,0,60,42};int prepared=0,appended=0;
auto prepare=[&](Player*p,std::string&){++prepared;assert(p->getLevel()==60);return true;};
auto append=[&](CharacterDatabaseTransaction const&tx,Player*){++appended;++tx->profileRows;};
auto run=[&](){return Factory::Create(6,d,prepare,append);};
auto ok=run();assert(ok.Guid==30 && ok.Error.empty());assert(cache.published==1 && scripts.creates==1 && appended==1 && prepared==1);
assert(CharacterDatabase.savedCharacters==1 && CharacterDatabase.savedProfiles==1 && Player::cleaned==1 && LoginDatabase.realmWrites==1);
// Preparation failure never invokes save, appends profile, publishes cache or hooks.
auto commits=CharacterDatabase.commits;auto failed=Factory::Create(6,d,[](Player*,std::string&e){e="gear unavailable";return false;},append);
assert(!failed.Guid && failed.Error=="gear unavailable" && CharacterDatabase.commits==commits && appended==1 && cache.published==1);
// DB rollback cannot publish either half of the generated identity.
CharacterDatabase.success=false;auto rollback=run();assert(!rollback.Guid && cache.published==1 && scripts.creates==1);
assert(CharacterDatabase.savedCharacters==1 && CharacterDatabase.savedProfiles==1 && LoginDatabase.realmWrites==1);CharacterDatabase.success=true;
// Ordinary active players, privileged accounts and exhausted accounts are protected.
auto previous=prepared;world.connected=true;assert(!run().Guid);world.connected=false;
AccountMgr::security=3;assert(!run().Guid);AccountMgr::security=0;
CharacterDatabase.count=10;assert(!run().Guid);CharacterDatabase.count=1;
objects.valid=false;assert(!run().Guid);objects.valid=true;objects.reserved=true;assert(!run().Guid);objects.reserved=false;
cache.duplicate=true;assert(!run().Guid);cache.duplicate=false;CharacterDatabase.duplicate=true;assert(!run().Guid);CharacterDatabase.duplicate=false;
LoginDatabase.account=false;assert(!run().Guid);LoginDatabase.account=true;
d.Level=86;assert(!run().Guid);d.Level=54;d.Class=CLASS_DEATH_KNIGHT;assert(!run().Guid);d.Level=60;d.Class=1;
assert(prepared==previous);assert(cache.published==1 && scripts.creates==1);
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['g++','-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Production native factory: character/profile atomicity, failed preparation/commit, cache publication order, account/security/name/cap gates passed')
@@ -0,0 +1,40 @@
"""Execute native tier-based skill preparation before world insertion."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
s=(root/'src/server/game/World/ClientlessCharacterFactory.cpp').read_text()
a=s.index('bool ClientlessCharacterFactory::PrepareSkillRank(')
code=r'''
#include <cassert>
#include <unordered_map>
using uint32=unsigned;constexpr unsigned MAX_SKILL_STEP=16;
struct RC{unsigned MinLevel=5,SkillTierID=1;}rc;
struct DBC {bool available=true;RC*GetSkillRaceClassInfo(unsigned,unsigned,unsigned){return available?&rc:nullptr;}}sDBCManager;
struct Tier{unsigned Value[16]={75,150,225,300,375,450,525};}tier;
struct Store{bool available=true;Tier*LookupEntry(unsigned){return available?&tier:nullptr;}}sSkillTiersStore;
struct Player{
bool inWorld=false;unsigned level=60,step=0,value=0,cap=0;int writes=0;
bool IsInWorld(){return inWorld;}unsigned getRace(){return 1;}unsigned getClass(){return 1;}unsigned getLevel(){return level;}
unsigned GetSkillStep(unsigned){return step;}unsigned GetPureSkillValue(unsigned){return value;}unsigned GetPureMaxSkillValue(unsigned){return cap;}
void SetSkill(unsigned,unsigned s,unsigned v,unsigned c){++writes;step=s;value=v;cap=c;}
};
struct ClientlessCharacterFactory{static bool PrepareSkillRank(Player*,unsigned,unsigned);};
'''+s[a:]+r'''
int main(){
Player p;using F=ClientlessCharacterFactory;
assert(F::PrepareSkillRank(&p,186,1));assert(p.step==1 && p.value==75 && p.cap==75);
assert(F::PrepareSkillRank(&p,186,5));assert(p.step==5 && p.value==375 && p.cap==375);
auto previous=p.writes;assert(F::PrepareSkillRank(&p,186,1));assert(p.step==5 && p.writes==previous);
assert(!F::PrepareSkillRank(&p,186,0));assert(!F::PrepareSkillRank(&p,186,17));assert(!F::PrepareSkillRank(&p,186,8));
p.inWorld=true;assert(!F::PrepareSkillRank(&p,186,6));p.inWorld=false;
p.level=4;assert(!F::PrepareSkillRank(&p,186,6));p.level=60;
sDBCManager.available=false;assert(!F::PrepareSkillRank(&p,186,6));sDBCManager.available=true;
sSkillTiersStore.available=false;assert(!F::PrepareSkillRank(&p,186,6));
assert(p.writes==previous);assert(!F::PrepareSkillRank(nullptr,186,1));
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['g++','-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Production offline skill preparation: native tier caps, no downgrading, rank/level/race/tier gates and no modification of online players passed')