AVA2 cross-platform client parity baseline
This commit is contained in:
@@ -0,0 +1,976 @@
|
||||
#include "item_proto.h"
|
||||
#include <cmath>
|
||||
#include "skill_description.h"
|
||||
#include "python_runtime.h"
|
||||
#include "nonplayer_data.h"
|
||||
#include "python_app.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_native_modules.h"
|
||||
#include "python_net.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_net/PythonSafeBox.h"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3) return 2;
|
||||
try {
|
||||
ava2::SkillDescriptions fixture;
|
||||
if(!fixture.load("900\tWARRIOR\tBase\t\t\tDescription\tFirst\t\tThird\tIgnored fourth\tTOGGLE|STANDING_SKILL|USE_HP\t\ticon\r\n")) throw std::runtime_error("fixture load failed");
|
||||
auto* desc=fixture.find(900);
|
||||
if(!desc || desc->type!=1 || desc->gradeNames[2]!="Base" || desc->conditions.size()!=2 || desc->attributes!=((1u<<1)|(1u<<4)|(1u<<6))) throw std::runtime_error("skill field mismatch");
|
||||
if(!fixture.load("900\tsupport\tUpdated\tMaster\t\tNew description\t\t\t\t\tPASSIVE|toggle\t\ticon\n")) throw std::runtime_error("duplicate load failed");
|
||||
desc=fixture.find(900);
|
||||
if(desc->type!=2 || desc->name!="Updated" || !desc->conditions.empty() || desc->attributes!=((1u<<1)|(1u<<4)|(1u<<6)|(1u<<17))) throw std::runtime_error("duplicate semantics mismatch");
|
||||
if(!fixture.load("901\twolfman\tExcluded\t\t\t\t\t\t\t\tTOGGLE\t\ticon\n")) throw std::runtime_error("disabled type load failed");
|
||||
if(!fixture.find(901) || !fixture.find(901)->name.empty() || fixture.find(901)->attributes) throw std::runtime_error("disabled wolfman type accepted");
|
||||
std::vector<std::string> columns(28);
|
||||
columns[0]="902";columns[1]="WARRIOR";columns[2]="Motion";columns[11]="SWORD|TWO_HANDED|ARROW|EMPTY_HAND";
|
||||
columns[13]="65530";columns[14]="4";columns[15]="k+1";columns[16]="2";
|
||||
columns[17]="Damage";columns[18]="minatk";columns[19]="maxatk";columns[26]="300";
|
||||
std::string row;for(size_t i=0;i<columns.size();++i){if(i)row+='\t';row+=columns[i];}row+='\t';
|
||||
if(!fixture.load(row))throw std::runtime_error("motion fixture failed");
|
||||
auto* motion=fixture.find(902);
|
||||
if(motion->needWeapon!=(1u|8u|(1u<<11)) || motion->gradeMotions[1]!=19 || motion->gradeMotions[3]!=69 || motion->levelLimit!=44 || motion->maxLevel!=44 || motion->affects.size()!=1 || motion->affects[0].maxFormula!="maxatk")throw std::runtime_error("motion/limits/weapons mismatch");
|
||||
if(!fixture.load(row) || fixture.find(902)->affects.size()!=2)throw std::runtime_error("original affect append semantics lost");
|
||||
std::vector<std::string> table(27);table[0]="902";table[4]="300";table[5]="0";table[7]="atk+mwep+number(1,2)";table[8]="40+100*k";table[9]="60";table[10]="2";table[11]="12";table[25]="-1";table[26]="0";
|
||||
std::string tableRow;for(size_t i=0;i<table.size();++i){if(i)tableRow+='\t';tableRow+=table[i];}
|
||||
if(!fixture.loadTable(tableRow))throw std::runtime_error("skill table rejected");
|
||||
auto* merged=fixture.find(902);
|
||||
if(merged->maxLevel!=44 || merged->levelLimit!=0 || merged->needSPFormula!="40+100*k" || merged->cooldownFormula!="12" || merged->targetRange!=uint32_t(-1) || merged->affects[0].minFormula!="minatk+minmwep+min(1,2)" || merged->affects[0].maxFormula!="maxatk+maxmwep+max(1,2)")throw std::runtime_error("skill table merge mismatch");
|
||||
fixture.records[34]=*merged;
|
||||
tableRow.replace(0,3,"34");
|
||||
auto oldFormula=fixture.find(34)->affects[0].minFormula;
|
||||
if(!fixture.loadTable(tableRow) || fixture.find(34)->affects[0].minFormula!=oldFormula)throw std::runtime_error("excluded formula overwritten");
|
||||
fixture.records[1]=*merged;
|
||||
table[0]="1";tableRow.clear();for(size_t i=0;i<table.size();++i){if(i)tableRow+='\t';tableRow+=table[i];}
|
||||
if(!fixture.loadTable(tableRow) || fixture.find(1)->affects[0].minFormula!="minatk+minmwep+min(1,2)* 3")throw std::runtime_error("three-way multiplier lost");
|
||||
auto before=fixture.find(1)->affects[0].minFormula;
|
||||
table[7]="k+1";table[8].clear();table[9].clear();table[5]="99";
|
||||
tableRow.clear();for(size_t i=0;i<table.size();++i){if(i)tableRow+='\t';tableRow+=table[i];}
|
||||
if(!fixture.loadTable(tableRow,true) || fixture.find(1)->affects[0].minFormula!=before || fixture.find(1)->needSPFormula!="40+100*k" || !fixture.find(1)->durationFormula.empty() || fixture.find(1)->levelLimit!=0)throw std::runtime_error("locale/empty field semantics mismatch");
|
||||
if(!fixture.loadTable(tableRow) || fixture.find(1)->affects[0].minFormula!="k+1" || !fixture.find(1)->affects[0].maxFormula.empty())throw std::runtime_error("scalar formula overwrite mismatch");
|
||||
ava2::PythonRuntime python(argv[1],argv[2]);
|
||||
ava2::ItemProto items;
|
||||
ava2::ItemProto rangeFixture;
|
||||
rangeFixture.records[2000].vnum=2000;rangeFixture.records[2000].range=10;
|
||||
rangeFixture.records[1998].vnum=1998;rangeFixture.records[1998].range=20;
|
||||
rangeFixture.ranges={2000,1998};
|
||||
if(rangeFixture.find(2001)->vnum!=2000 || rangeFixture.find(1998)->vnum!=1998 || rangeFixture.find(2010)->vnum!=1998 || rangeFixture.find(2018))throw std::runtime_error("item range ordering/bounds mismatch");
|
||||
if(!items.load(ava2::ReadPackedText("locale/en/item_proto")))throw std::runtime_error("original item proto rejected");
|
||||
auto sword=items.records.find(10);
|
||||
if(sword==items.records.end()||sword->second.name!="Sword+0"||sword->second.type!=1||sword->second.size!=2)throw std::runtime_error("original item proto fields mismatch");
|
||||
python.execute("import item, app\nitem.LoadItemTable('locale/en/item_proto')\n");
|
||||
python.execute("import shop\nassert shop.IsOpen()==0\nassert shop.GetTabCount()==1\nshop.Open()\nassert shop.IsOpen()==1\nshop.Close()\nassert shop.IsOpen()==0\nshop.Open()\nshop.Clear()\nassert shop.IsOpen()==0\nassert shop.GetTabCount()==1\n");
|
||||
if(!ava2::SetShopTabCount(3)||ava2::SetShopTabCount(4))throw std::runtime_error("shop tab capacity validation failed");
|
||||
ava2::SetShopTab(0,"Weapons",0);ava2::SetShopTab(2,"Special",257);
|
||||
python.execute("assert shop.GetTabCount()==3\nassert shop.GetTabName(2)=='Special'\nassert shop.GetTabCoinType(258)==1\nassert shop.GetTabName(3) is None\nassert shop.GetTabCoinType(-1)==255\nshop.Clear()\nassert shop.GetTabCount()==1\nassert shop.GetTabName(0)=='Weapons'\nassert shop.GetTabName(2) is None\n");
|
||||
ava2::ResetShopState();
|
||||
ava2::ShopItemRecord shopItem{};shopItem.vnum=0x80000001;shopItem.count=0xffffffff;shopItem.price=-1234567890123LL;shopItem.buyVnum=10;shopItem.buyCount=3;
|
||||
ava2::SetShopItem(119,shopItem);
|
||||
shopItem.sockets[7]=-123;shopItem.attributes[14]={255,-32768};shopItem.gloveAttributes[6]={254,-2};ava2::SetShopItem(119,shopItem);
|
||||
python.execute("assert shop.GetItemMetinSocket(119,7)==-123\nassert shop.GetItemAttribute(119,14)==(255,-32768)\nassert shop.GetItemRandomAttribute(119,6)==(254,-2)\nassert shop.GetItemAttribute(119,15)==(0,0)\nassert shop.GetItemRandomAttribute(120,0)==(0,0)\nassert shop.GetItemMetinSocket(119,8)==0\n");
|
||||
python.execute("assert shop.GetItemID(119)==-2147483647\nassert shop.GetItemCount(119)==-1\nassert shop.GetItemPrice(119)==-1234567890123\nassert shop.GetVnumBuy(119)==10\nassert shop.GetCountBuy(119)==3\nassert shop.GetItemID(120)==0\nshop.Clear()\nassert shop.GetItemID(119)==0\n");
|
||||
std::map<std::pair<unsigned,unsigned>,uint32_t> classifications;
|
||||
for(const auto& [id,record]:items.records)classifications[{record.type,record.subtype}]=id;
|
||||
for(const auto& [kind,id]:classifications) {
|
||||
const auto type=kind.first,subtype=kind.second;
|
||||
const auto arg=std::to_string(id);
|
||||
const std::map<unsigned,std::string> useNames={{2,"USE_TUNING"},{14,"USE_DETACHMENT"},{17,"USE_CLEAN_SOCKET"},{18,"USE_CHANGE_ATTRIBUTE"},{19,"USE_ADD_ATTRIBUTE"},{20,"USE_ADD_ACCESSORY_SOCKET"},{21,"USE_PUT_INTO_ACCESSORY_SOCKET"},{22,"USE_ADD_ATTRIBUTE2"},{24,"USE_CHANGE_ATTRIBUTE2"},{29,"USE_PUT_INTO_BELT_SOCKET"},{30,"USE_PUT_INTO_RING_SOCKET"},{31,"USE_CHANGE_COSTUME_ATTR"},{32,"USE_RESET_COSTUME_ATTR"}};
|
||||
const auto use=type!=3?"NOT_USE_TYPE":useNames.contains(subtype)?useNames.at(subtype):"USE_UNKNOWN_TYPE";
|
||||
python.execute("assert item.GetUseType("+arg+")== '"+use+"'\n");
|
||||
python.execute("assert item.IsEquipmentVID("+arg+")=="+std::to_string(type==1||type==2)+"\n"
|
||||
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(id).refined)+"\n");
|
||||
python.execute("assert item.IsRefineScroll("+arg+")=="+std::to_string(type==3&&subtype==2)+"\n"
|
||||
"assert item.IsDetachScroll("+arg+")=="+std::to_string(type==3&&subtype==14)+"\n"
|
||||
"assert item.IsKey("+arg+")=="+std::to_string(type==21)+"\n"
|
||||
"assert item.IsMetin("+arg+")=="+std::to_string(type==10)+"\n"
|
||||
"assert item.CanAddToQuickSlotItem("+arg+")=="+std::to_string(type==3||type==18)+"\n"
|
||||
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(id).refined)+"\n");
|
||||
}
|
||||
python.execute("assert item.GetUseType(10)=='NOT_USE_TYPE'\nassert item.GetUseType(27001)=='USE_UNKNOWN_TYPE'\nassert item.GetUseType(25040)=='USE_TUNING'\nassert item.IsRefineScroll(25040)==1\nassert item.GetItemName()==item.GetNames()\nitem.SelectItem(10)\n");
|
||||
python.execute("import player\n");
|
||||
ava2::TItemData metadata{};metadata.vnum=10;metadata.flags=0x800000aa;metadata.anti_flags=0x800000bb;
|
||||
ava2::SetPlayerItemData(1,12,metadata);
|
||||
python.execute("assert player.IsSameItemVnum(10,12)==1\nassert player.IsSameItemVnum(19,12)==0\nassert player.IsSameItemVnum(10,257,65548)==1\nassert player.IsSameItemVnum(0,3,12)==1\n");
|
||||
ava2::TItemData renamed{};renamed.vnum=10;std::strcpy(renamed.name,"Custom Sword");
|
||||
ava2::SetPlayerItemData(6,14,renamed);
|
||||
python.execute("assert player.GetItemNewName(6,14)=='Custom Sword'\nassert player.GetItemNewName(262)=='^'\nassert player.GetItemNewName()=='^'\nassert player.GetItemNewName(262,65550)=='Custom Sword'\n");
|
||||
python.execute("import player\n");
|
||||
ava2::TItemData counted{};counted.vnum=0x80001234u;counted.count=0xffffffffu;
|
||||
ava2::SetPlayerItemData(1,250,counted);
|
||||
counted.count=3;ava2::SetPlayerItemData(1,251,counted);
|
||||
counted.count=99;ava2::SetPlayerItemData(1,262,counted);
|
||||
counted.count=7;ava2::SetPlayerItemData(6,170,counted);
|
||||
counted.count=99;ava2::SetPlayerItemData(6,180,counted);
|
||||
counted.count=42;ava2::SetPlayerItemData(7,170,counted);
|
||||
python.execute("assert player.GetItemCountByVnum(-2147478988)==2\nassert player.GetItemCountByTT(-2147478988)==7\n");
|
||||
python.execute("for cell in range(-1,300):\n assert player.IsEquipmentSlot(cell)==int(180<=cell<=228)\n assert player.IsCostumeSlot(cell)==int(199<=cell<=203)\n assert player.IsBeltInventorySlot(cell)==int(246<=cell<262)\n assert player.IsDSEquipmentSlot(1,cell)==int(216<=cell<=228)\n assert player.IsDSEquipmentSlot(2,cell)==0\nassert player.IsDSEquipmentSlot(257,228)==1\nassert player.IsBeltInventorySlot(65782)==1\nassert player.IsEquipmentSlot(65716)==0\n");
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if((record.flags&8u) && !record.sellPrice)continue;
|
||||
ava2::TItemData priced{};priced.vnum=id;priced.count=0xffffffffu;
|
||||
ava2::SetPlayerItemData(6,15,priced);
|
||||
const uint32_t expected=(record.flags&8u)?priced.count/record.sellPrice:priced.count*record.sellPrice;
|
||||
python.execute("assert player.GetISellItemPrice(6,15)=="+std::to_string(std::bit_cast<int32_t>(expected))+"\n");
|
||||
}
|
||||
python.execute("assert player.GetISellItemPrice(3,12)==0\nassert player.GetISellItemPrice(262)==0\n");
|
||||
uint32_t cheap=0,expensive=0;
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if(record.sellPrice<=5000)cheap=id;
|
||||
if(record.sellPrice>5000)expensive=id;
|
||||
}
|
||||
if(!cheap||!expensive)throw std::runtime_error("valuable item price fixtures missing");
|
||||
ava2::TItemData valued{};valued.vnum=cheap;valued.count=0xffffffffu;
|
||||
ava2::SetPlayerItemData(6,16,valued);
|
||||
python.execute("assert player.IsValuableItem(6,16)==0\nassert item.GetRefinedVnum()=="+std::to_string(items.records.at(cheap).refined)+"\n");
|
||||
for(size_t socket=0;socket<8;++socket) {
|
||||
std::fill(std::begin(valued.alSockets),std::end(valued.alSockets),0);valued.alSockets[socket]=-1;
|
||||
ava2::SetPlayerItemData(6,16,valued);
|
||||
python.execute("assert player.IsValuableItem(6,16)=="+std::to_string(socket<6)+"\n");
|
||||
}
|
||||
std::fill(std::begin(valued.alSockets),std::end(valued.alSockets),0);valued.vnum=expensive;valued.count=1;
|
||||
ava2::SetPlayerItemData(1,16,valued);
|
||||
python.execute("assert player.IsValuableItem(16)==1\nassert player.IsValuableItem(1,16)==1\nitem.SelectItem(10)\n");
|
||||
ava2::SetPlayerItemData(3,12,metadata);
|
||||
ava2::SetPlayerItemData(1,262,metadata);
|
||||
python.execute("import player\nassert player.GetItemFlags(12)==-2147483478\nassert player.GetItemFlags(1,12)==-2147483478\nassert player.GetItemFlags(6,12)==0\nassert player.IsAntiFlagBySlot(12,0x20)==1\nassert player.IsAntiFlagBySlot(1,12,0x40)==0\nassert player.IsAntiFlagBySlot(12,-1)==1\nassert player.GetItemTypeBySlot(12)==1\nassert player.GetItemSubTypeBySlot(1,12)==0\nassert player.GetItemTypeBySlot(6,12)==0\nassert player.GetItemFlags(257,65548)==-2147483478\n");
|
||||
python.execute("assert player.GetItemFlags(3,12)==0\nassert player.GetItemFlags(262)==0\nassert player.GetItemTypeBySlot(262)==0\n");
|
||||
const std::map<unsigned,unsigned> capacities={{1,262},{2,228},{5,1152},{6,180},{7,180},{8,180},{9,180},{10,180},{11,6},{12,102}};
|
||||
for(const auto& [window,capacity]:capacities) {
|
||||
ava2::TItemData edge{};edge.vnum=0x80000001u;edge.count=0xffffffffu;
|
||||
edge.alSockets[7]=-123;edge.aAttr[14].bType=255;edge.aAttr[14].sValue=-32768;
|
||||
ava2::SetPlayerItemData(window,capacity-1,edge);
|
||||
ava2::SetPlayerItemData(window,capacity,edge);
|
||||
const auto w=std::to_string(window),last=std::to_string(capacity-1),end=std::to_string(capacity);
|
||||
python.execute("assert player.GetItemIndex("+w+","+last+")==-2147483647\n"
|
||||
"assert player.GetItemCount("+w+","+last+")==-1\n"
|
||||
"assert player.GetItemIndex("+w+","+end+")==0\n"
|
||||
"assert player.GetItemCount("+w+","+end+")==0\n"
|
||||
"assert player.GetItemMetinSocket("+w+","+last+",7)==-123\n"
|
||||
"assert player.GetItemAttribute("+w+","+last+",14)==(255,-32768)\n"
|
||||
"assert player.GetItemMetinSocket("+w+","+end+",7)==0\n"
|
||||
"assert player.GetItemAttribute("+w+","+end+",14)==(0,0)\n"
|
||||
"assert player.GetItemMetinSocket("+w+","+last+",8)==0\n"
|
||||
"assert player.GetItemAttribute("+w+","+last+",15)==(0,0)\n");
|
||||
}
|
||||
python.execute("assert player.GetItemIndex(3,12)==0\nassert player.GetItemCount(3,12)==0\nassert player.GetItemIndex(257,65548)==10\n");
|
||||
python.execute("assert player.GetItemMetinSocket(257,65797,7)==-123\nassert player.GetItemAttribute(257,65797,14)==(255,-32768)\nassert player.GetItemMetinSocket(261,-1)==0\nassert player.GetItemAttribute(261,-1)==(0,0)\nassert player.GetItemMetinSocket(261,7)==-123\nassert player.GetItemAttribute(261,14)==(255,-32768)\n");
|
||||
uint32_t tuning=0,rod=0;
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if(record.type==3&&record.subtype==2)tuning=id;
|
||||
if(record.type==13)rod=id;
|
||||
}
|
||||
if(!tuning||!rod)throw std::runtime_error("refine fixture prototypes missing");
|
||||
python.execute("item.SelectItem(10)\nfor args in [(),(12,),(1,12),(1,12,0),('bad',),(None,12)]:\n assert player.IsRefineGradeScroll(*args) is None\n assert item.GetItemName()=='Sword+0'\n");
|
||||
uint32_t unlockKey=0,unlockBox=0;
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if(record.type==21)unlockKey=id;
|
||||
if(record.type==20)unlockBox=id;
|
||||
}
|
||||
if(!unlockKey||!unlockBox)throw std::runtime_error("unlock fixture prototypes missing");
|
||||
ava2::TItemData locked{};locked.vnum=unlockBox;ava2::SetPlayerItemData(6,19,locked);
|
||||
python.execute("assert player.CanUnlock(10,6,19)==0\nassert player.CanUnlock("+std::to_string(unlockKey)+",6,19)==1\n"
|
||||
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(unlockBox).refined)+"\n"
|
||||
"assert player.CanUnlock("+std::to_string(unlockKey)+",12)==0\n");
|
||||
uint32_t detach=0;
|
||||
uint32_t sashCleaner=0,sashItem=0;
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if(record.type==3&&record.subtype==14&&record.values[0]==7)sashCleaner=id;
|
||||
if(record.type==28&&record.subtype==3)sashItem=id;
|
||||
}
|
||||
if(!sashCleaner||!sashItem)throw std::runtime_error("sash cleaning fixture prototypes missing");
|
||||
ava2::TItemData sashTarget{};sashTarget.vnum=sashItem;
|
||||
for(const int32_t absorbed:{-1,0,1,2147483647}) {
|
||||
sashTarget.alSockets[1]=absorbed;
|
||||
ava2::SetPlayerItemData(6,20,sashTarget);
|
||||
python.execute("assert player.CanDetach("+std::to_string(sashCleaner)+",6,20)=="+std::to_string(absorbed>0)+"\n"
|
||||
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(sashItem).refined)+"\n");
|
||||
}
|
||||
sashTarget.vnum=10;ava2::SetPlayerItemData(6,20,sashTarget);
|
||||
python.execute("assert player.CanDetach("+std::to_string(sashCleaner)+",6,20)==0\n");
|
||||
for(const auto& [id,record]:items.records)if(record.type==3&&record.subtype==14&&record.values[0]!=7)detach=id;
|
||||
if(!detach||(sword->second.flags&1u)==0)throw std::runtime_error("detach fixture prototypes missing");
|
||||
ava2::TItemData detachable{};detachable.vnum=10;
|
||||
ava2::SetPlayerItemData(1,18,detachable);
|
||||
python.execute("assert player.CanDetach(10,18)==0\nassert player.CanDetach("+std::to_string(detach)+",18)==0\n");
|
||||
for(size_t socket=0;socket<8;++socket) {
|
||||
std::fill(std::begin(detachable.alSockets),std::end(detachable.alSockets),0);detachable.alSockets[socket]=-1;
|
||||
ava2::SetPlayerItemData(1,18,detachable);
|
||||
python.execute("assert player.CanDetach("+std::to_string(detach)+",18)=="+std::to_string(socket<6)+"\n");
|
||||
}
|
||||
uint32_t normalStone=0,goldStone=0;
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if(record.type!=10||!(record.wearFlags&sword->second.wearFlags))continue;
|
||||
if(record.subtype==0)normalStone=id;
|
||||
if(record.subtype==1)goldStone=id;
|
||||
}
|
||||
if(!normalStone&&!goldStone)throw std::runtime_error("metin fixture prototypes missing");
|
||||
// The distributed table may contain only gold stones. Do not invent
|
||||
// a normal stone by interpreting an unrelated prototype as METIN.
|
||||
const auto testStone=normalStone?normalStone:goldStone;
|
||||
ava2::TItemData socketTarget{};socketTarget.vnum=10;
|
||||
ava2::SetPlayerItemData(6,17,socketTarget);
|
||||
python.execute("assert player.CanAttachMetin("+std::to_string(testStone)+",6,17)==3\nassert player.CanAttachMetin(0,180)==5\n");
|
||||
socketTarget.alSockets[7]=1;ava2::SetPlayerItemData(6,17,socketTarget);
|
||||
python.execute("assert player.CanAttachMetin("+std::to_string(testStone)+",6,17)=="+std::to_string(normalStone?1:4)+"\n");
|
||||
socketTarget.alSockets[7]=2;ava2::SetPlayerItemData(6,17,socketTarget);
|
||||
python.execute("assert player.CanAttachMetin("+std::to_string(testStone)+",6,17)==1\n");
|
||||
metadata.vnum=19;ava2::SetPlayerItemData(6,12,metadata);
|
||||
metadata.vnum=rod;ava2::SetPlayerItemData(6,13,metadata);
|
||||
python.execute("assert player.GetItemGrade(6,12)==9\nassert item.GetItemName().endswith('+9')\n"
|
||||
"assert player.GetItemGrade(12)==0\nassert item.GetItemName()=='Sword+0'\n"
|
||||
"assert player.CanRefine(10,12)==0\n"
|
||||
"assert player.CanRefine("+std::to_string(tuning)+",12)==1\n"
|
||||
"assert player.CanRefine("+std::to_string(tuning)+",6,12)==5\n"
|
||||
"assert player.CanRefine("+std::to_string(tuning)+",6,13)==7\n"
|
||||
"assert player.CanRefine(10,180)==6\nitem.SelectItem(10)\n");
|
||||
python.execute("assert item.SelectItemWiki(10) == 1\n"
|
||||
"assert item.GetRefinedVnum() == "+std::to_string(sword->second.refined)+"\n"
|
||||
"assert item.GetRefineSet() == "+std::to_string(sword->second.refineSet)+"\n"
|
||||
"assert item.SelectItemWiki(-1) == 0\n"
|
||||
"assert item.GetItemName() == 'Sword+0'\n");
|
||||
python.execute("assert item.GetIBuyItemPrice() == "+std::to_string(sword->second.buyPrice)+"\n"
|
||||
"assert item.GetISellItemPrice() == "+std::to_string(sword->second.sellPrice)+"\n"
|
||||
"assert item.IsAntiFlag(-1) == "+std::to_string(sword->second.antiFlags!=0)+"\n"
|
||||
"assert item.IsFlag(-1) == "+std::to_string(sword->second.flags!=0)+"\n"
|
||||
"assert item.IsWearableFlag(-1) == "+std::to_string(sword->second.wearFlags!=0)+"\n"
|
||||
"assert item.Is1GoldItem() == "+std::to_string((sword->second.flags&8)!=0)+"\n"
|
||||
"assert item.IsFlag(0) == 0\n");
|
||||
for(int i=0;i<8;++i)python.execute("assert item.GetSocket("+std::to_string(i)+") == "+std::to_string(sword->second.sockets[i])+"\n");
|
||||
python.execute("assert item.GetSocket(8) == -1\nassert item.GetSocket(-1) == -1\nassert item.GetSocket(256) == item.GetSocket(0)\n");
|
||||
for(int bit=0;bit<31;++bit) {
|
||||
uint32_t mask=1u<<bit;
|
||||
python.execute("assert item.IsAntiFlag("+std::to_string(mask)+") == "+std::to_string((sword->second.antiFlags&mask)!=0)+"\n"
|
||||
"assert item.IsFlag("+std::to_string(mask)+") == "+std::to_string((sword->second.flags&mask)!=0)+"\n"
|
||||
"assert item.IsWearableFlag("+std::to_string(mask)+") == "+std::to_string((sword->second.wearFlags&mask)!=0)+"\n");
|
||||
}
|
||||
auto finalSword=items.records.find(19);
|
||||
if(finalSword==items.records.end())throw std::runtime_error("missing final sword fixture");
|
||||
python.execute("item.SelectItem(19)\nassert item.GetRefinedVnum() == "+std::to_string(finalSword->second.refined)+"\n");
|
||||
for(int i=0;i<2;++i) {auto pair=sword->second.limits[i];python.execute("item.SelectItem(10)\nassert item.GetLimit("+std::to_string(i)+") == ("+std::to_string(pair.first)+","+std::to_string(pair.second)+")\n");}
|
||||
for(int i=0;i<3;++i) {auto pair=sword->second.applies[i];python.execute("assert item.GetAffect("+std::to_string(i)+") == ("+std::to_string(pair.first)+","+std::to_string(pair.second)+")\n");}
|
||||
python.execute("assert item.GetLimit(256) == item.GetLimit(0)\n"
|
||||
"for getter, index in ((item.GetLimit,2),(item.GetAffect,3),(item.GetAffect,-1)):\n"
|
||||
" try:\n getter(index)\n raise AssertionError('invalid table index accepted')\n"
|
||||
" except RuntimeError:\n pass\n");
|
||||
auto countBefore=items.records.size();
|
||||
bool checkedTwoHanded=false;
|
||||
for(const auto& [id,record]:items.records) {
|
||||
if(record.type!=1 || record.subtype!=3)continue;
|
||||
for(int i=0;i<3;++i) {
|
||||
if(record.applies[i].first!=7)continue;
|
||||
python.execute("item.SelectItem("+std::to_string(id)+")\n"
|
||||
"app.SetTwoHandedWeaponAttSpeedDecreaseValue(9)\n"
|
||||
"assert item.GetAffect("+std::to_string(i)+") == (7,"+std::to_string(record.applies[i].second-9)+")\n"
|
||||
"app.SetTwoHandedWeaponAttSpeedDecreaseValue(0)\n");
|
||||
checkedTwoHanded=true;break;
|
||||
}
|
||||
if(checkedTwoHanded)break;
|
||||
}
|
||||
if(!checkedTwoHanded)throw std::runtime_error("no two-handed attack-speed fixture");
|
||||
python.execute("item.SelectItem(60001)\nfallbackName=item.GetItemName()\n"
|
||||
"item.SelectItem(0)\nassert item.GetItemName() == fallbackName\n");
|
||||
if(items.load("MIPX")||items.records.size()!=countBefore)throw std::runtime_error("truncated item proto damaged records");
|
||||
auto originalWorkingDir=std::filesystem::current_path();
|
||||
std::filesystem::current_path(std::filesystem::temp_directory_path());
|
||||
python.execute("import item\nitem.SelectItem(10)\nassert item.GetItemName() == 'Sword+0'\nassert item.GetIconImageFileName() == 'icon/item/00010.tga'\nitem.LoadItemTable('locale/en/item_proto')\nassert item.GetItemName() == 'Sword+0'\nassert item.GetItemType() == 1\n");
|
||||
std::filesystem::current_path(originalWorkingDir);
|
||||
if(!ava2::LoadSkillDescriptions("locale/en/SkillDesc.txt")) throw std::runtime_error("skill description load failed");
|
||||
if(!ava2::LoadSkillTable("locale/en/SkillTable.txt")) throw std::runtime_error("skill table file load failed");
|
||||
ava2::SetPlayerStatusPoint(12,20);ava2::SetPlayerStatusPoint(204,80);
|
||||
if(std::fabs(ava2::EvaluateSkillFormula("str+ar*100+k",0.5f)-100.5f)>0.0001f || ava2::EvaluateSkillFormula("JeungJiFoo+k",0.5f)!=0.5f || ava2::EvaluateSkillFormula("UnknownState+k",0.5f)!=0)throw std::runtime_error("formula status binding mismatch " + std::to_string(ava2::EvaluateSkillFormula("str+ar*100+k",0.5f))+" / "+std::to_string(ava2::EvaluateSkillFormula("JeungJiFoo+k",0.5f))+" / "+std::to_string(ava2::EvaluateSkillFormula("1+",0.5f)));
|
||||
ava2::SetPlayerStatusPoint(12,0);ava2::SetPlayerStatusPoint(204,0);
|
||||
python.execute("import sys, struct, pack, colorInfo, musicInfo\n"
|
||||
"assert sys.version_info[:2] == (2, 7)\n"
|
||||
"assert colorInfo.CHAT_RGB_TALK == (255,255,255)\n"
|
||||
"assert musicInfo.loginMusic == 'login_window.mp3'\n"
|
||||
"assert pack.Exist('COLORINFO.PY') == 1\n"
|
||||
"assert pack.Exist('../README.md') == 0\n"
|
||||
"assert pack.Get('colorInfo.py').startswith('SUCCESS')\n"
|
||||
"try:\n pack.Get('../README.md')\n raise AssertionError('traversal accepted')\n"
|
||||
"except IOError:\n pass\n"
|
||||
"exec 'print 21 / 2'\n"
|
||||
"assert 21 / 2 == 10\n"
|
||||
"import item, player, chrmgr, chr, chat, snd, background, effect, fly, nonplayer\n"
|
||||
"import skill\n"
|
||||
"assert skill.GetSkillName(1) == 'Three-Way Cut'\n"
|
||||
"assert skill.GetSkillName(1,1) == 'Triple Cut'\n"
|
||||
"assert skill.GetSkillName(1,2) == 'Triple Slash'\n"
|
||||
"assert skill.GetSkillName(121,2) == 'Leadership'\n"
|
||||
"assert skill.GetSkillName(1,3) == 'Three-Way Cut'\n"
|
||||
"assert skill.GetSkillType(121) == skill.SKILL_TYPE_SUPPORT\n"
|
||||
"assert skill.GetSkillDescription(1) == 'Cut the enemy with lightning speed.'\n"
|
||||
"assert skill.GetSkillConditionDescriptionCount(1) == 2\n"
|
||||
"assert skill.GetSkillConditionDescription(1,0) == 'Frontal Slash Attack 3 times'\n"
|
||||
"assert skill.GetSkillConditionDescription(1,2) is None\n"
|
||||
"assert skill.GetSkillConditionDescription(1,-1) is None\n"
|
||||
"assert skill.IsToggleSkill(122) == 1\n"
|
||||
"assert skill.IsToggleSkill(1) == 0\n"
|
||||
"assert skill.GetSkillMaxLevel(1) == 20\n"
|
||||
"assert skill.GetSkillCoolTime(1,0.5) == 12\n"
|
||||
"assert skill.GetSkillNeedSP(1,0.5) == 90\n"
|
||||
"assert skill.GetSkillNeedSP(1,0.125) == 52\n"
|
||||
"assert skill.GetSkillContinuationSP(1,0.5) == 0\n"
|
||||
"assert skill.GetDuration(1,0.5) == 0\n"
|
||||
"assert skill.GetSkillLevelUpPoint(1) == 1\n"
|
||||
"assert skill.GetSkillLevelLimit(1) == 0\n"
|
||||
"assert skill.GetSkillAffectDescriptionCount(1) == 1\n"
|
||||
"assert skill.GetNewAffectDataCount(1) == 0\n"
|
||||
"for sid, index in ((1,0),(1,-1),(999999,0)):\n"
|
||||
" try:\n skill.GetNewAffectData(sid,index,0.5)\n raise AssertionError('invalid affect accepted')\n"
|
||||
" except RuntimeError:\n pass\n"
|
||||
"for invalid_point in (-1,255,99999):\n"
|
||||
" player.SetStatus(invalid_point,123)\n"
|
||||
" assert player.GetStatus(invalid_point) == 0\n"
|
||||
|
||||
"player.SetStatus(29,100)\n"
|
||||
"player.SetStatus(30,200)\n"
|
||||
"player.SetStatus(12,20)\n"
|
||||
"assert skill.GetSkillAffectDescription(1,0,0.5) == 'Total Attack Power 450-855'\n"
|
||||
"assert skill.GetSkillAffectDescription(1,-1,0.5) is None\n"
|
||||
"assert skill.GetSkillAffectDescription(1,1,0.5) is None\n"
|
||||
"player.SetStatus(29,0)\n"
|
||||
"player.SetStatus(30,0)\n"
|
||||
"player.SetStatus(12,0)\n"
|
||||
|
||||
"assert skill.IsToggleSkill(19) == 0\n"
|
||||
"assert skill.IsStandingSkill(19) == 1\n"
|
||||
"assert skill.IsUseHPSkill(19) == 0\n"
|
||||
"assert skill.GetSkillName(999999) == 'NoneSkill'\n"
|
||||
"try:\n skill.IsToggleSkill(999999)\n raise AssertionError('missing skill accepted')\n"
|
||||
"except RuntimeError:\n pass\n"
|
||||
|
||||
"assert skill.SKILL_TYPE_NONE == 0\n"
|
||||
"assert skill.SKILL_TYPE_ACTIVE == 1\n"
|
||||
"assert skill.SKILL_TYPE_SUPPORT == 2\n"
|
||||
"assert skill.SKILL_TYPE_GUILD == 3\n"
|
||||
"assert skill.SKILL_TYPE_HORSE == 4\n"
|
||||
"assert skill.SKILL_TYPE_MAX_NUM == 5\n"
|
||||
"assert skill.SKILL_GRADE_COUNT == 3\n"
|
||||
"assert skill.SKILL_GRADE_STEP_COUNT == 20\n"
|
||||
"assert skill.SKILL_GRADEGAP == 25\n"
|
||||
"assert skill.SKILL_EFFECT_COUNT == 4\n"
|
||||
"assert nonplayer.GetMonsterName(101) == ''\n"
|
||||
"nonplayer.LoadNonPlayerData('locale/en/mob_proto')\n"
|
||||
"assert nonplayer.GetMonsterName(101) == 'Wild Dog'\n"
|
||||
"assert nonplayer.GetMonsterMaxHP(101) == 126\n"
|
||||
"assert nonplayer.GetMonsterDamage(101) == (20,24)\n"
|
||||
"assert nonplayer.GetMonsterLevel(101) == 1\n"
|
||||
"matches = nonplayer.GetMobsByName('wild dog')\n"
|
||||
"assert 101 in matches and matches == sorted(matches)\n"
|
||||
"assert all(nonplayer.GetMonsterName(v).lower().startswith('wild dog') for v in matches)\n"
|
||||
"assert nonplayer.GetMobsByName('Wild Dog') == []\n"
|
||||
"assert nonplayer.GetMonsterPrice(101) == (0,0), repr(nonplayer.GetMonsterPrice(101))\n"
|
||||
"assert nonplayer.GetGradeByVID(999999) == -1\n"
|
||||
"assert nonplayer.GetLevelByVID(999999) == -1\n"
|
||||
"assert nonplayer.ON_CLICK_EVENT_TALK == 3\n"
|
||||
"assert nonplayer.MOB_RESIST_POISON == 10\n"
|
||||
"assert background.GlobalPositionToLocalPosition(123,456) == (123,456)\n"
|
||||
"assert background.GlobalPositionToMapInfo(409600,896000) == ('metin2_map_a1',409600,896000)\n"
|
||||
"assert background.GlobalPositionToMapInfo(-1,-1) == ('',0,0)\n"
|
||||
"assert effect.INDEX_FLY_TYPE_NORMAL == 0\n"
|
||||
"assert effect.INDEX_FLY_TYPE_FIRE_CRACKER == 1\n"
|
||||
"assert effect.FLY_HP_BIG == 3\n"
|
||||
"effect.RegisterEffect('ymir work/pc/warrior/effect/palbang_2_spin.mse')\n"
|
||||
"eid = effect.CreateEffect('ymir work/pc/warrior/effect/palbang_2_spin.mse', 0.0, 100.0, 0.0)\n"
|
||||
"assert eid > 0\n"
|
||||
"effect.SetPosition(eid, 10.0, 20.0, 30.0)\n"
|
||||
"effect.Update()\n"
|
||||
"effect.Render()\n"
|
||||
"effect.DeleteEffect(eid)\n"
|
||||
"fly.Update()\n"
|
||||
"fly.Render()\n"
|
||||
"assert item.ITEM_TYPE_NONE == 0\n"
|
||||
"assert item.ITEM_TYPE_WEAPON == 1\n"
|
||||
"assert item.ITEM_TYPE_ARMOR == 2\n"
|
||||
"assert item.APPLY_BLEEDING_PCT == 93\n"
|
||||
"assert item.APPLY_ATTBONUS_WOLFMAN == 94\n"
|
||||
"assert item.ANTIFLAG_WOLFMAN == (1 << 18)\n"
|
||||
"assert player.LEVEL == 1\n"
|
||||
"assert player.CONQUEROR_LEVEL == 205\n"
|
||||
"assert player.ATT_ELEMENTS == 180\n"
|
||||
"assert player.GetName() == ''\n"
|
||||
"assert player.GetStatus(player.HP) == 0\n"
|
||||
"player.SetStatus(player.LEVEL, 99)\n"
|
||||
"assert player.GetStatus(player.LEVEL) == 99\n"
|
||||
"assert player.GetMainCharacterPosition() == (0.0, 0.0, 0.0)\n"
|
||||
"assert chr.AFFECT_BLEEDING == 42\n"
|
||||
"assert chr.MOTION_MODE_CLAW == 17\n"
|
||||
"assert chrmgr.NAMECOLOR_TOURNAMENT_TEAM_A == 32\n"
|
||||
"assert chrmgr.EFFECT_ELEMENTS_WEAPON == 280\n"
|
||||
"import privateShopSearch\n"
|
||||
"assert privateShopSearch.GetItemCount() == 0\n"
|
||||
"privateShopSearch.ClearSearchItems()\n"
|
||||
"import combat_zone\n"
|
||||
"assert combat_zone.COMBAT_ZONE_MAX_ROWS_RANKING == 11\n"
|
||||
"assert combat_zone.IsRunning() == False\n"
|
||||
"import exchange\n"
|
||||
"assert exchange.EXCHANGE_ITEM_MAX_NUM == 12\n"
|
||||
"assert exchange.GetItemElementGradeFromTarget(0) == 0\n"
|
||||
"import safebox\n"
|
||||
"assert safebox.GetItemBind(0) == 0\n"
|
||||
"assert safebox.GetElements(0) == (0, 0, 0, 0)\n"
|
||||
"import shop\n"
|
||||
"assert shop.SHOP_SLOT_COUNT == 40\n"
|
||||
"assert shop.OFFLINE_SHOP_SLOT_COUNT == 80\n"
|
||||
"assert shop.GetItemElements(0) == (0, 0, 0, 0)\n"
|
||||
"import constInfo, localeInfo\n"
|
||||
"assert constInfo.IN_GAME_SHOP_ENABLE == 1\n"
|
||||
"import networkModule\n"
|
||||
"import uiInventory, ui, wndMgr\n"
|
||||
"print 'Testing LoadDialog steps...'\n"
|
||||
"boardsizex = 330 - 130\n"
|
||||
"board = ui.Board()\n"
|
||||
"board.SetPosition(wndMgr.GetScreenWidth()-boardsizex, wndMgr.GetScreenHeight()-100+30)\n"
|
||||
"board.SetSize(boardsizex, 50)\n"
|
||||
"print 'board width:', board.GetWidth()\n"
|
||||
"slot0 = ui.ImageBox()\n"
|
||||
"slot0.SetParent(board)\n"
|
||||
"slot0.LoadImage('d:/ymir work/ui/public/Parameter_Slot_02.sub')\n"
|
||||
"print 'slot0 width:', slot0.GetWidth()\n"
|
||||
"diff = board.GetWidth() - slot0.GetWidth()\n"
|
||||
"print 'diff:', diff\n"
|
||||
"import prototype\n"
|
||||
"import game\n"
|
||||
"chr.CreateInstance(101)\n"
|
||||
"assert chr.HasInstance(101) == 1\n"
|
||||
"chr.SelectInstance(101)\n"
|
||||
"chr.SetRace(0)\n"
|
||||
"assert chr.GetRace() == 0\n"
|
||||
"chr.SetWeapon(11299)\n"
|
||||
"chr.SetHair(1)\n"
|
||||
"chr.SetRotation(45.0)\n"
|
||||
"chr.SetPixelPosition(100, 200, 30)\n"
|
||||
"chr.Update()\n"
|
||||
"chr.Deform()\n"
|
||||
"print 'Testing CreateCharacterWindow lifecycle...'\n"
|
||||
"stream = networkModule.MainStream()\n"
|
||||
"stream.Create()\n"
|
||||
"stream.SetCharacterSlot(1)\n"
|
||||
"stream.SetCreateCharacterPhase()\n"
|
||||
"assert stream.curPhaseWindow.__class__.__name__ == 'CreateCharacterWindow'\n"
|
||||
"stream.curPhaseWindow._CreateCharacterWindow__SelectSlot(1)\n"
|
||||
"stream.curPhaseWindow._CreateCharacterWindow__SelectShape(1)\n"
|
||||
"stream.curPhaseWindow.editCharacterName.SetText('TestHero')\n"
|
||||
"assert stream.curPhaseWindow.editCharacterName.GetText() == 'TestHero'\n"
|
||||
"stream.curPhaseWindow.OnCreateSuccess()\n"
|
||||
"assert stream.curPhaseWindow.__class__.__name__ == 'SelectCharacterWindow'\n"
|
||||
"print 'Testing monster/NPC instantiation and network movement...'\n"
|
||||
"chr.CreateInstance(201)\n"
|
||||
"chr.SelectInstance(201)\n"
|
||||
"chr.SetRace(101)\n"
|
||||
"chr.SetPixelPosition(500, 600, 20)\n"
|
||||
"chr.CreateInstance(301)\n"
|
||||
"chr.SelectInstance(301)\n"
|
||||
"chr.SetRace(8001)\n"
|
||||
"chr.SetPixelPosition(800, 900, 10)\n"
|
||||
"import net\n"
|
||||
"assert net.COMBAT_ZONE_ACTION_LEAVE == 4\n"
|
||||
"net.SendCombatZoneRequestActionPacket(net.COMBAT_ZONE_ACTION_LEAVE, net.COMBAT_ZONE_EMPTY_DATA)\n"
|
||||
"net.SendCharacterMovePacket(1, 0, 90.0, 12345, 67890)\n"
|
||||
"net.SendCharacterPositionPacket(2)\n"
|
||||
"sw = ui.SlotWindow()\n"
|
||||
"sw.AppendSlot(0, 0, 0, 32, 32)\n"
|
||||
"wndMgr.ActivateSlot(sw.hWnd, 0)\n"
|
||||
"wndMgr.LockSlot(sw.hWnd, 0)\n"
|
||||
"wndMgr.SetSlotCountNew(sw.hWnd, 0, 1, 10)\n"
|
||||
"import textTail\n"
|
||||
"textTail.Clear()\n"
|
||||
"textTail.RegisterCharacterTextTail(1, 201)\n"
|
||||
"textTail.AttachTitle(201, 'Noble', 1.0, 0.8, 0.0)\n"
|
||||
"textTail.AttachLevel(201, '[Lv. 75]', 0.6, 1.0, 0.2)\n"
|
||||
"textTail.RegisterChatTail(201, 'Hello World!')\n"
|
||||
"assert textTail.IsChat(201) == 1\n"
|
||||
"chr.SelectInstance(201)\n"
|
||||
"chr.SetNameString('DogMaster')\n"
|
||||
"assert chr.GetName() == 'DogMaster'\n"
|
||||
"assert chr.GetNameByVID(201) == 'DogMaster'\n"
|
||||
"pos = chr.GetPixelPosition()\n"
|
||||
"assert pos[0] == 500.0 and pos[1] == 600.0\n"
|
||||
"textTail.RegisterItemTextTail(555, 'Full Moon Sword +9', 120, 'TestHero')\n"
|
||||
"textTail.ShowAllTextTail()\n"
|
||||
"textTail.ArrangeTextTail()\n"
|
||||
"textTail.SelectItemName(555)\n"
|
||||
"textTail.Render()\n"
|
||||
"textTail.HideAllTextTail()\n"
|
||||
"textTail.Clear()\n"
|
||||
"assert background.ATTR_BLOCK == 1\n"
|
||||
"assert background.ATTR_WATER == 2\n"
|
||||
"assert background.ATTR_BANPK == 4\n"
|
||||
"background.Initialize()\n"
|
||||
"assert background.LoadMap('ava2_nonexistent_map_fixture',0.0,0.0,0.0) == 0\n"
|
||||
"assert background.GetCurrentMapName() == ''\n"
|
||||
"map_loaded = background.LoadMap('metin2_map_a1',25600.0,76800.0,0.0)\n"
|
||||
"assert background.GetCurrentMapName() == ('metin2_map_a1' if map_loaded else '')\n"
|
||||
"bg_h = background.GetHeight(0.0, 0.0)\n"
|
||||
"bg_block = background.isAttrOn(0.0, 0.0, background.ATTR_BLOCK)\n"
|
||||
"print 'Python background verified: h =', bg_h, ', blocked =', bg_block\n"
|
||||
"snd.SetMusicVolume(0.8)\n"
|
||||
"snd.SetMusicVolumef(0.8)\n"
|
||||
"snd.SetSoundVolume(4)\n"
|
||||
"snd.SetSoundVolumef(0.7)\n"
|
||||
"snd.SetSoundScale(250.0)\n"
|
||||
"snd.SetAmbienceSoundScale(1200.0)\n"
|
||||
"snd.PlaySound('sound/ui/click.wav')\n"
|
||||
"snd.PlaySound3D(100.0, 50.0, 200.0, 'sound/common/swing/w_1h_c_1.wav')\n"
|
||||
"snd.FadeInMusic('bgm/login_window.mp3', 0.05)\n"
|
||||
"snd.FadeLimitOutMusic('bgm/login_window.mp3', 0.2, 0.05)\n"
|
||||
"snd.FadeOutMusic('bgm/login_window.mp3', 0.05)\n"
|
||||
"snd.FadeOutAllMusic()\n"
|
||||
"snd.StopAllSound()\n"
|
||||
"print 'Python snd module verified successfully'\n"
|
||||
"print 'Testing Python net PhaseGame integration...'\n"
|
||||
"class StartFixture:\n def __init__(self):\n self.calls=0\n def SetGamePhase(self):\n self.calls+=1\nstart_fixture=StartFixture()\nnet.SetHandler(start_fixture)\nnet.StartGame()\n"
|
||||
"net.SendEnterGamePacket()\n"
|
||||
"net.SendChatPacket('Hello Metin2 World!')\n"
|
||||
"net.SendWhisperPacket('TesterGM', 'Whisper test')\n"
|
||||
"net.SendItemPickUpPacket(777)\n"
|
||||
"net.SendItemDropPacketNew(1, 0, 5)\n"
|
||||
"net.SendOnClickPacket(201)\n"
|
||||
"net.Warp()\n"
|
||||
"print 'Testing Equipment Refine System (uirefine)...'\n"
|
||||
"item.SelectItem(10)\nassert item.GetRefinedVnum() == 11\n"
|
||||
"item.SelectItem(19)\nassert item.GetRefinedVnum() == 0\n"
|
||||
"assert player.GetItemGrade(0) >= 0\n"
|
||||
"assert player.IsRefineGradeScroll(0) is None\n"
|
||||
"assert player.GetItemCountByTT(10) == 0\n"
|
||||
"assert not hasattr(player,'GetItemRefineInformation')\n"
|
||||
"import uirefine\n"
|
||||
"refineDlg = uirefine.RefineDialog()\n"
|
||||
"pct = refineDlg.GetRefineSuccessPercentage(0, 0)\n"
|
||||
"assert pct >= 0\n"
|
||||
"refineDlg.Open(0, 0)\n"
|
||||
"refineDlg.Accept()\n"
|
||||
"net.SendRefinePacket(0, 0)\n"
|
||||
"net.SendGiveItemPacket(1001, 0, 1)\n"
|
||||
"print 'Testing Quest Dialog System (uiquest & event)...'\n"
|
||||
"import event\n"
|
||||
"assert event.BUTTON_TYPE_CANCEL == 0\n"
|
||||
"assert event.BUTTON_TYPE_DONE == 1\n"
|
||||
"assert event.BUTTON_TYPE_NEXT == 2\n"
|
||||
"event.RegisterEventSet(1)\n"
|
||||
"event.InsertText(1, 'Welcome Adventurer!')\n"
|
||||
"event.InsertTextInline(1, ' Accept quest:')\n"
|
||||
"assert event.GetLineCount(1) >= 1\n"
|
||||
"assert event.GetLineHeight(1) >= 10\n"
|
||||
"assert event.GetEventSetLocalYPosition(1) >= 10\n"
|
||||
"event.SelectAnswer(1, 254)\n"
|
||||
"event.ClearEventSet(1)\n"
|
||||
"import uiquest\n"
|
||||
"event.RegisterEventSet(2)\n"
|
||||
"event.InsertText(2, 'Quest: Clear Wild Boars')\n"
|
||||
"questDlg = uiquest.QuestDialog(1, 2)\n"
|
||||
"questDlg.MakeNextButton(event.BUTTON_TYPE_NEXT)\n"
|
||||
"questDlg.MakeQuestion(3)\n"
|
||||
"questDlg.OnUpdate()\n"
|
||||
"questDlg.CloseSelf()\n"
|
||||
"net.SendScriptAnswerPacket(1)\n"
|
||||
"net.SendScriptButtonPacket(2)\n"
|
||||
"print 'Equipment Refine & Quest System verified successfully'\n"
|
||||
"print 'Python net module PhaseGame commands verified successfully'\n");
|
||||
auto draws = ava2::GetAllActiveChrDraws();
|
||||
std::cout << "Python-driven 3D Character draws count: " << draws.size() << std::endl;
|
||||
if (draws.empty()) {
|
||||
throw std::runtime_error("GetAllActiveChrDraws returned empty despite Python chr instance creation!");
|
||||
}
|
||||
const auto& last_move = ava2::get_last_character_move();
|
||||
if (!last_move.valid || last_move.x != 12345 || last_move.y != 67890 || last_move.rot != 18 || last_move.arg != 2) {
|
||||
throw std::runtime_error("Network character move state mismatch!");
|
||||
}
|
||||
std::cout << "Character move packet verified: x=" << last_move.x << ", y=" << last_move.y << ", rot=" << int(last_move.rot) << "\n";
|
||||
// Verify PhaseGame network stream state and outgoing packets
|
||||
auto& netStream = ava2::PythonNetworkStream::Instance();
|
||||
if(netStream.IsGamePhase()) throw std::runtime_error("StartGame incorrectly changed wire phase");
|
||||
netStream.ProcessRecvData();
|
||||
python.execute("assert start_fixture.calls==1\n");
|
||||
const auto& sendQueue = netStream.GetSendQueue();
|
||||
if (sendQueue.empty()) {
|
||||
throw std::runtime_error("PythonNetworkStream send queue is unexpectedly empty after net sends!");
|
||||
}
|
||||
std::cout << "PythonNetworkStream send queue byte count: " << sendQueue.size() << std::endl;
|
||||
|
||||
std::string mobName;
|
||||
if(!ava2::GetNonPlayerName(101,mobName) || mobName!="Wild Dog")
|
||||
throw std::runtime_error("native actor name did not use decrypted mob proto");
|
||||
if(ava2::UseNonPlayerName(30000) || ava2::UseNonPlayerName(34041) || !ava2::UseNonPlayerName(20001))
|
||||
throw std::runtime_error("Windows NPC name policy mismatch");
|
||||
if(ava2::NonPlayerData::Instance().load("MMPT"))
|
||||
throw std::runtime_error("truncated mob proto accepted");
|
||||
|
||||
// Test C++ receiving packet dispatching (TPacketGCMainCharacter2Empire, TPacketGCChat)
|
||||
ava2::TPacketGCMainCharacter2Empire mainCharPkt{};
|
||||
mainCharPkt.header = ava2::HEADER_GC_MAIN_CHARACTER2_EMPIRE;
|
||||
mainCharPkt.dwVID = 54321;
|
||||
mainCharPkt.wRaceNum = 0;
|
||||
std::strncpy(mainCharPkt.szName, "HeroPlayer", ava2::CHARACTER_NAME_MAX_LEN);
|
||||
mainCharPkt.byEmpire = 2;
|
||||
mainCharPkt.bySkillGroup = 1;
|
||||
mainCharPkt.lX = 435200;
|
||||
mainCharPkt.lY = 972800;
|
||||
mainCharPkt.lZ = 50;
|
||||
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&mainCharPkt), sizeof(mainCharPkt));
|
||||
netStream.ProcessRecvData();
|
||||
|
||||
if (netStream.GetMainActorVID() != 54321) {
|
||||
throw std::runtime_error("MainActorVID mismatch after receiving TPacketGCMainCharacter2Empire!");
|
||||
}
|
||||
if (netStream.GetMainActorRace() != 0 || netStream.GetMainActorEmpire() != 2 || netStream.GetMainActorSkillGroup() != 1) {
|
||||
throw std::runtime_error("MainActor attributes mismatch after TPacketGCMainCharacter2Empire!");
|
||||
}
|
||||
|
||||
netStream.ClearSendQueue();
|
||||
python.execute("player.RequestAddLocalQuickSlot(0,2,6)\nassert player.GetLocalQuickSlot(0)==(0,0)\n");
|
||||
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("quick request without main actor sent");
|
||||
ava2::SNetworkActorData quickActor{};quickActor.m_dwVID=54321;quickActor.m_dwRace=0;quickActor.m_stName="HeroPlayer";
|
||||
ava2::NetworkActorManager::Instance().AppendActor(quickActor);
|
||||
python.execute("class QuickCallbacks:\n def __init__(self):\n self.refreshes=0\n self.emotions=[]\n def RefreshInventory(self):\n self.refreshes+=1\n def BINARY_ActEmotion(self,pos):\n self.emotions.append(pos)\nquick_callbacks=QuickCallbacks()\nplayer.SetGameWindow(quick_callbacks)\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,quick_callbacks)\nplayer.SetQuickPage(1)\nassert player.LocalQuickSlotIndexToGlobalQuickSlotIndex(2)==10\nplayer.RequestAddLocalQuickSlot(2,2,6)\nassert player.GetLocalQuickSlot(2)==(0,0)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{16,10,2,6}) throw std::runtime_error("quick add wire/page mismatch");
|
||||
const uint8_t quickStart[]={28,10,2};netStream.PushRecvData(quickStart,sizeof(quickStart));netStream.ProcessRecvData();
|
||||
python.execute("assert player.GetLocalQuickSlot(2)==(0,0)\n");
|
||||
const uint8_t quickEnd[]={6,28,11,1,7,30,10,11,29,11};netStream.PushRecvData(quickEnd,sizeof(quickEnd));netStream.ProcessRecvData();
|
||||
python.execute("assert quick_callbacks.refreshes==2\nassert player.GetLocalQuickSlot(2)==(1,7)\nassert player.GetGlobalQuickSlot(11)==(0,0)\nplayer.RequestDeleteGlobalQuickSlot(10)\nassert player.GetLocalQuickSlot(2)==(1,7)\nplayer.RequestMoveGlobalQuickSlotToLocalQuickSlot(10,4)\nplayer.RequestAddToEmptyLocalQuickSlot(3,9)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{17,10,18,10,12,16,8,3,9}) throw std::runtime_error("quick delete/move/empty request mismatch");
|
||||
const uint8_t extraQuick[]={28,35,1,7};netStream.PushRecvData(extraQuick,sizeof(extraQuick));netStream.ProcessRecvData();
|
||||
python.execute("player.RemoveQuickSlotByValue(1,7)\nassert player.GetGlobalQuickSlot(35)==(1,7)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{17,10,17,35}) throw std::runtime_error("remove by value missed hidden server quickslot");
|
||||
python.execute("player.RequestUseLocalQuickSlot(2)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{11,1,7,0}) throw std::runtime_error("inventory quickslot use mismatch");
|
||||
python.execute("net.SendItemDropPacket(7)\nnet.SendItemDropPacketNew(1,7,70000)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{224,1,7,0,0,0,0,0,20,1,7,0,0,0,0,0,0x70,0x11,1,0})
|
||||
throw std::runtime_error("AVA2 old/new drop wire or DWORD count mismatch");
|
||||
python.execute("net.SendElkDropPacket(123456)\nnet.SendGoldDropPacketNew(123456)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{224,0,0,0,0x40,0xe2,1,0,20,0,0,0,0x40,0xe2,1,0,0,0,0,0})
|
||||
throw std::runtime_error("gold drop reserved window or count mismatch");
|
||||
ava2::TPacketGCCharacterUpdate stunUpdate{};stunUpdate.header=19;stunUpdate.dwVID=54321;stunUpdate.dwAffectFlag[0]=1u<<5;
|
||||
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&stunUpdate),sizeof(stunUpdate));netStream.ProcessRecvData();
|
||||
python.execute("player.RequestDeleteGlobalQuickSlot(10)\n");
|
||||
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("affect stun allowed quickslot request");
|
||||
netStream.SendAttackPacket(0,123);netStream.SendItemUsePacket(1,7);netStream.SendItemMovePacket(1,7,1,8,1);
|
||||
netStream.SendItemPickUpPacket(123);netStream.SendItemDropPacket(1,7,0);netStream.SendItemDropPacketNew(1,7,0,1);
|
||||
netStream.SendItemUseToItemPacket(7,8);
|
||||
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("controlled actor sent inventory/attack action");
|
||||
python.execute("net.SendShopEndPacket()\nnet.SendShopBuyPacket(7)\nnet.SendShopSellPacket(7)\nnet.SendShopSellPacketNew(6,7,1)\n");
|
||||
if(!netStream.PopSendBytes().empty())throw std::runtime_error("controlled actor sent shop transaction");
|
||||
python.execute("net.SendOfflineShopEndPacket()\nnet.SendOfflineShopBuyPacket(-1,511)\n");
|
||||
if(!netStream.PopSendBytes().empty())throw std::runtime_error("controlled actor sent offline transaction");
|
||||
for(const auto operation:{5,6,11}) {
|
||||
python.execute(operation==5?"net.SendRemoveOfflineShopItem(511)\n":operation==6?"net.SendDestroyOfflineShop()\n":"net.SendOfflineShopRemoveLogs()\n");
|
||||
std::vector<uint8_t> expected(58,0);expected[0]=57;expected[1]=operation;
|
||||
if(operation==5)expected.push_back(255);
|
||||
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("offline management layout/action gate mismatch");
|
||||
}
|
||||
for(const auto operation:{13,14,15}) {
|
||||
python.execute(operation==13?"net.SendOpenShopSlot(-1)\n":operation==14?"net.SendGetBackItems()\n":"net.SendAddTime()\n");
|
||||
std::vector<uint8_t> expected(58,0);expected[0]=57;expected[1]=operation;
|
||||
if(operation==13)expected.push_back(255);
|
||||
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("offline slot/return/time layout mismatch");
|
||||
}
|
||||
python.execute("net.SendOpenWithVID(-1)\n");
|
||||
std::vector<uint8_t> openVidExpected(58,0);openVidExpected[0]=57;openVidExpected[1]=16;openVidExpected.insert(openVidExpected.end(),{255,255,255,255});
|
||||
if(netStream.PopSendBytes()!=openVidExpected)throw std::runtime_error("offline open VID layout mismatch");
|
||||
|
||||
stunUpdate.dwAffectFlag[0]=0;
|
||||
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&stunUpdate),sizeof(stunUpdate));netStream.ProcessRecvData();
|
||||
python.execute("player.RequestDeleteGlobalQuickSlot(10)\n");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{17,10}) throw std::runtime_error("cleared affect did not restore action");
|
||||
auto quickActorInstance=ava2::NetworkActorManager::Instance().GetActorInstance(54321);
|
||||
netStream.PopSendBytes();
|
||||
for(uint8_t operation=0;operation<4;++operation) {
|
||||
netStream.SendShopPacket(operation,6,255,0x12345678);
|
||||
std::vector<uint8_t> expected(58,0);expected[0]=50;expected[1]=operation;
|
||||
if(operation==1) { expected.push_back(1);expected.push_back(255); }
|
||||
if(operation==2)expected.push_back(255);
|
||||
if(operation==3)expected.insert(expected.end(),{6,255,0x78,0x56,0x34,0x12});
|
||||
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("AVA2 shop send layout mismatch");
|
||||
}
|
||||
const std::array<std::string,4> shopCalls={"net.SendShopEndPacket()","net.SendShopBuyPacket(511)","net.SendShopSellPacket(-1)","net.SendShopSellPacketNew(262,511,-1)"};
|
||||
python.execute("net.SendOfflineShopEndPacket()\n");
|
||||
std::vector<uint8_t> offlineExpected(58,0);offlineExpected[0]=57;
|
||||
if(netStream.PopSendBytes()!=offlineExpected)throw std::runtime_error("offline end layout mismatch");
|
||||
python.execute("net.SendOfflineShopBuyPacket(-1,511)\n");
|
||||
offlineExpected[1]=1;for(unsigned i=53;i<58;++i)offlineExpected[i]=255;
|
||||
if(netStream.PopSendBytes()!=offlineExpected)throw std::runtime_error("offline purchase layout mismatch");
|
||||
python.execute("class ShopCallbacks:\n def __init__(self):\n self.errors=[]\n self.ends=0\n self.price=0\n def OnShopError(self,error):\n self.errors.append(error)\n def EndShop(self):\n self.ends+=1\n def SetShopSellingPrice(self,price):\n self.price=price\nshop_callbacks=ShopCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,shop_callbacks)\n");
|
||||
const uint8_t fragmented[]={38,4,0,5};
|
||||
std::vector<uint8_t> shopUpdate(128,0);shopUpdate[0]=38;shopUpdate[1]=128;shopUpdate[3]=2;shopUpdate[4]=39;
|
||||
shopUpdate[5]=10;shopUpdate[9]=0x78;shopUpdate[10]=0x56;shopUpdate[11]=0x34;shopUpdate[12]=0x12;shopUpdate[17]=3;shopUpdate[22]=20;shopUpdate[26]=5;
|
||||
shopUpdate[58]=0xff;shopUpdate[59]=0xff;shopUpdate[60]=0xff;shopUpdate[61]=0xff;
|
||||
shopUpdate[104]=7;shopUpdate[105]=0xfe;shopUpdate[106]=0xff;
|
||||
shopUpdate[125]=8;shopUpdate[126]=0xfd;shopUpdate[127]=0xff;
|
||||
python.execute("ShopCallbacks.RefreshShop=lambda self: None\n");
|
||||
netStream.PushRecvData(shopUpdate);netStream.ProcessRecvData();
|
||||
python.execute("assert shop.GetItemID(39)==10\nassert shop.GetItemPrice(39)==0x12345678\nassert shop.GetItemCount(39)==3\nassert shop.GetVnumBuy(39)==20\nassert shop.GetCountBuy(39)==5\n");
|
||||
python.execute("assert shop.GetItemMetinSocket(39,7)==-1\nassert shop.GetItemAttribute(39,14)==(7,-2)\nassert shop.GetItemRandomAttribute(39,6)==(8,-3)\n");
|
||||
python.execute("ShopCallbacks.StartShop=lambda self,owner: setattr(self,'owner',owner)\n");
|
||||
std::vector<uint8_t> shopStart(4928,0);shopStart[0]=38;shopStart[1]=64;shopStart[2]=19;shopStart[4]=123;
|
||||
std::copy(shopUpdate.begin()+5,shopUpdate.end(),shopStart.begin()+8+39*123);
|
||||
netStream.PushRecvData(shopStart.data(),shopStart.size()-1);
|
||||
if(netStream.ProcessRecvData())throw std::runtime_error("partial shop start consumed");
|
||||
netStream.PushRecvData(shopStart.data()+shopStart.size()-1,1);netStream.ProcessRecvData();
|
||||
python.execute("assert shop_callbacks.owner==123\nassert shop.GetTabCount()==1\nassert shop.GetItemID(39)==10\nassert shop.GetItemID(79)==0\n");
|
||||
std::vector<uint8_t> shopTabs(9915,0);shopTabs[0]=38;shopTabs[1]=187;shopTabs[2]=38;shopTabs[3]=10;shopTabs[4]=124;shopTabs[8]=2;
|
||||
std::memcpy(shopTabs.data()+9,"Gold",4);std::memcpy(shopTabs.data()+4962,"Tokens",6);shopTabs[4994]=1;
|
||||
std::copy(shopUpdate.begin()+5,shopUpdate.end(),shopTabs.begin()+4995+39*123);
|
||||
netStream.PushRecvData(shopTabs);netStream.ProcessRecvData();
|
||||
python.execute("assert shop_callbacks.owner==124\nassert shop.GetTabCount()==2\nassert shop.GetTabName(0)=='Gold'\nassert shop.GetTabName(1)=='Tokens'\nassert shop.GetTabCoinType(1)==1\nassert shop.GetItemID(79)==10\nassert shop.GetItemID(39)==0\n");
|
||||
const std::vector<std::vector<uint8_t>> badShopFrames={
|
||||
{38,3,0,1},{38,4,0,0},{38,4,0,2},{38,4,0,3},
|
||||
{38,9,0,10,0,0,0,0,4},{38,9,0,10,0,0,0,0,2}};
|
||||
for(const auto& frame:badShopFrames) {
|
||||
ava2::PythonNetworkStream malformed;
|
||||
malformed.PushRecvData(frame);
|
||||
bool rejected=false;
|
||||
try { malformed.ProcessRecvData(); }catch(const std::runtime_error&) { rejected=true; }
|
||||
if(!rejected)throw std::runtime_error("malformed shop frame accepted");
|
||||
python.execute("assert shop.GetTabCount()==2\nassert shop.GetTabName(1)=='Tokens'\nassert shop.GetItemID(79)==10\n");
|
||||
}
|
||||
netStream.PushRecvData(fragmented,3);
|
||||
if(netStream.ProcessRecvData())throw std::runtime_error("partial shop frame consumed");
|
||||
netStream.PushRecvData(fragmented+3,1);netStream.ProcessRecvData();
|
||||
const uint8_t shopEvents[]={38,4,0,1,38,12,0,3,255,255,255,255,255,255,255,255};
|
||||
netStream.PushRecvData(shopEvents,sizeof(shopEvents));netStream.ProcessRecvData();
|
||||
python.execute("assert shop_callbacks.errors==['NOT_ENOUGH_MONEY']\nassert shop_callbacks.ends==1\nassert shop_callbacks.price==-1\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,quick_callbacks)\n");
|
||||
for(uint8_t operation=0;operation<4;++operation) {
|
||||
python.execute(shopCalls[operation]+"\n");
|
||||
std::vector<uint8_t> expected(58,0);expected[0]=50;expected[1]=operation;
|
||||
if(operation==1)expected.insert(expected.end(),{1,255});
|
||||
if(operation==2)expected.push_back(255);
|
||||
if(operation==3)expected.insert(expected.end(),{6,255,255,255,255,255});
|
||||
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("Python shop argument conversion mismatch");
|
||||
}
|
||||
netStream.SetMainActorVID(999);
|
||||
const uint8_t remoteStun[]={13,0x31,0xd4,0,0};
|
||||
netStream.PushRecvData(remoteStun,sizeof(remoteStun));netStream.ProcessRecvData();
|
||||
if(!quickActorInstance->IsStun() || quickActorInstance->IsDead()) throw std::runtime_error("remote stun incorrectly entered death");
|
||||
netStream.SetMainActorVID(54321);
|
||||
const uint8_t mainStun[]={13,0x31,0xd4,0,0}; // VID54321, main actor enters death as Windows does.
|
||||
netStream.PushRecvData(mainStun,sizeof(mainStun));netStream.ProcessRecvData();
|
||||
if(!quickActorInstance->IsDead()) throw std::runtime_error("Windows main-actor stun did not enter death");
|
||||
python.execute("player.RequestDeleteGlobalQuickSlot(10)\nplayer.RequestAddLocalQuickSlot(0,2,6)\n");
|
||||
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("dead actor sent quickslot request");
|
||||
ava2::AddPlayerQuickSlot(8,3,9);
|
||||
python.execute("player.RequestUseLocalQuickSlot(0)\nassert quick_callbacks.emotions==[9]\nplayer.SetQuickPage(-1)\nassert player.GetQuickPage()==3\nplayer.SetQuickPage(4)\nassert player.GetQuickPage()==0\nplayer.SetGameWindow(None)\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,quick_callbacks)\n");
|
||||
ava2::NetworkActorManager::Instance().RemoveActor(54321);
|
||||
ava2::NetworkActorManager::Instance().AppendActor(quickActor);
|
||||
|
||||
python.execute("assert player.GetMainCharacterPosition() == (25600.0,76800.0,50.0)\n"
|
||||
"assert background.GlobalPositionToLocalPosition(410600,898000) == (1000,2000)\n");
|
||||
netStream.ClearSendQueue();
|
||||
netStream.SendCharacterMovePacket(1,0,0,1000,2000,123);
|
||||
auto globalMove=netStream.PopSendBytes();
|
||||
auto wire32=[&](size_t offset) { return uint32_t(globalMove[offset]) | (uint32_t(globalMove[offset+1])<<8) | (uint32_t(globalMove[offset+2])<<16) | (uint32_t(globalMove[offset+3])<<24); };
|
||||
if(globalMove.size()!=16 || wire32(4)!=410600 || wire32(8)!=898000)
|
||||
throw std::runtime_error("local movement not converted to Windows global coordinates");
|
||||
netStream.ClearSendQueue();
|
||||
netStream.SendGiveItemPacket(0x12345678,1,0x1234,70000);
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{83,0x78,0x56,0x34,0x12,1,0x34,0x12,0x70,0x11,1,0})
|
||||
throw std::runtime_error("AVA2 DWORD give-item count/layout mismatch");
|
||||
netStream.SendRefinePacket(7,2,3,-1);
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{96,7,2,3,255})
|
||||
throw std::runtime_error("AVA2 BYTE refine index mismatch");
|
||||
netStream.SendItemUseToItemPacket(0x1234,0x5678);
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{60,1,0x34,0x12,1,0x78,0x56})
|
||||
throw std::runtime_error("AVA2 default INVENTORY position mismatch");
|
||||
netStream.SendScriptButtonPacket(0x12345678);
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{66,0x78,0x56,0x34,0x12})
|
||||
throw std::runtime_error("AVA2 script button layout mismatch");
|
||||
|
||||
python.execute("import app\nassert app.IsEnableTestServerFlag()==0\napp.EnableTestServerFlag()\nassert app.IsEnableTestServerFlag()==1\n");
|
||||
python.execute("import eventMgr\neventMgr.Update(1.5,2.5,-3.5)\n");
|
||||
if(ava2::GetGameEventCenter()!=std::array<float,3>{1.5f,-2.5f,-3.5f}) throw std::runtime_error("AVA2 event center Y sign mismatch");
|
||||
// Independent AVA2 non-GAIDEN wire fixture, including the last of 8 sockets/15 attrs/7 glove attrs.
|
||||
auto itemPacket=[](uint8_t header,uint8_t window) {
|
||||
std::vector<uint8_t> bytes(header==20?135:144,0);
|
||||
bytes[0]=header;bytes[1]=window;bytes[2]=7;
|
||||
bytes[4]=0x34;bytes[5]=0x12;bytes[8]=3;
|
||||
const size_t sockets=header==20?12:21;
|
||||
bytes[sockets+28]=0x78;bytes[sockets+29]=0x56;bytes[sockets+30]=0x34;bytes[sockets+31]=0x12;
|
||||
bytes[sockets+32+42]=9;bytes[sockets+32+43]=0xfe;bytes[sockets+32+44]=0xff;
|
||||
bytes[sockets+32+45+18]=10;bytes[sockets+32+45+19]=42;
|
||||
if(header==21) { bytes[12]=0xaa;bytes[16]=0xbb;bytes[20]=1; }
|
||||
return bytes;
|
||||
};
|
||||
python.execute("class ItemCallbacks:\n def __init__(self):\n self.refreshes=0\n self.highlights=[]\n def RefreshInventory(self):\n self.refreshes+=1\n def BINARY_Highlight_Item(self,window,cell):\n self.highlights.append((window,cell))\nitem_callbacks=ItemCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,item_callbacks)\n");
|
||||
auto basic=itemPacket(20,1);
|
||||
netStream.PushRecvData(basic.data(),basic.size()-1);
|
||||
if(netStream.ProcessRecvData()) throw std::runtime_error("incomplete AVA2 item packet consumed");
|
||||
netStream.PushRecvData(basic.data()+basic.size()-1,1);netStream.ProcessRecvData();
|
||||
auto extended=itemPacket(21,6);netStream.PushRecvData(extended);netStream.ProcessRecvData();
|
||||
python.execute("assert player.GetItemIndex(1,7)==0x1234\nassert player.GetItemCount(6,7)==3\nassert player.GetItemMetinSocket(6,7,7)==0x12345678\nassert player.GetItemAttribute(6,7,14)==(9,-2)\nassert item_callbacks.refreshes==2\nassert item_callbacks.highlights==[(6,7)]\n");
|
||||
auto data=ava2::GetPlayerItemData(6,7);
|
||||
python.execute("assert player.GetItemFlags(6,7)==0xaa\nassert player.IsAntiFlagBySlot(6,7,0x20)==1\nassert player.IsAntiFlagBySlot(6,7,0x40)==0\n");
|
||||
if(data.flags!=0xaa || data.anti_flags!=0xbb || data.randomAttr[6].bType!=10 || data.randomAttr[6].sValue!=42)
|
||||
throw std::runtime_error("AVA2 extended item data lost");
|
||||
std::vector<uint8_t> update(131,0);update[0]=25;update[1]=6;update[2]=7;update[4]=2;
|
||||
netStream.PushRecvData(update);netStream.ProcessRecvData();
|
||||
python.execute("assert player.GetItemCount(6,7)==2\nassert player.GetItemIndex(6,7)==0x1234\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,item_callbacks)\n");
|
||||
auto stored=itemPacket(85,1); // Storage/mall use extended packet format, despite different header.
|
||||
stored=extended;stored[0]=85;stored[1]=3;
|
||||
ava2::CPythonSafeBox::Instance().OpenSafeBox(45);
|
||||
netStream.PushRecvData(stored);netStream.ProcessRecvData();
|
||||
const ava2::TItemData* storedData=nullptr;
|
||||
if(!ava2::CPythonSafeBox::Instance().GetItemDataPtr(7,&storedData) || storedData->alSockets[7]!=0x12345678 || storedData->aAttr[14].sValue!=-2)
|
||||
throw std::runtime_error("AVA2 storage extended packet mismatch");
|
||||
const uint8_t phase[]={253,5};netStream.PushRecvData(phase,2);netStream.ProcessRecvData();
|
||||
if(!netStream.IsGamePhase()) throw std::runtime_error("AVA2 wire phase 5 is not Game");
|
||||
netStream.ClearSendQueue();netStream.SetPhase(ava2::PHASE_SELECT);
|
||||
if(netStream.SendChatPacket("outside game",0) || !netStream.GetSendQueue().empty()) throw std::runtime_error("AVA2 chat phase guard missing");
|
||||
if(netStream.SendSafeBoxMoneyPacket(0,100) || !netStream.GetSendQueue().empty()) throw std::runtime_error("disabled AVA2 storage money emitted party packet");
|
||||
netStream.SetPhase(ava2::PHASE_GAME);
|
||||
|
||||
// Test Chat packet reception
|
||||
bool chatCallbackFired = false;
|
||||
netStream.SetChatCallback([&](uint8_t type, const std::string& text, uint32_t vid) {
|
||||
(void)type;
|
||||
(void)vid;
|
||||
chatCallbackFired = true;
|
||||
if (text != "Server: Welcome to AVA2!") {
|
||||
throw std::runtime_error("Chat text content mismatch: " + text);
|
||||
}
|
||||
});
|
||||
std::string chatMsg = "Server: Welcome to AVA2!";
|
||||
std::vector<uint8_t> chatBuf(sizeof(ava2::TPacketGCChat) + chatMsg.size());
|
||||
auto* chatPkt = reinterpret_cast<ava2::TPacketGCChat*>(chatBuf.data());
|
||||
chatPkt->header = ava2::HEADER_GC_CHAT;
|
||||
chatPkt->size = static_cast<uint16_t>(chatBuf.size());
|
||||
chatPkt->type = ava2::CHAT_TYPE_NOTICE;
|
||||
chatPkt->dwVID = 0;
|
||||
chatPkt->bEmpire = 1;
|
||||
std::memcpy(chatBuf.data() + sizeof(ava2::TPacketGCChat), chatMsg.data(), chatMsg.size());
|
||||
netStream.PushRecvData(chatBuf.data(), chatBuf.size());
|
||||
netStream.ProcessRecvData();
|
||||
if (!chatCallbackFired) {
|
||||
throw std::runtime_error("Chat callback did not fire upon receiving TPacketGCChat!");
|
||||
}
|
||||
std::cout << "PhaseGame wire packet receive & dispatch verified successfully!\n";
|
||||
|
||||
netStream.ResetConnection();
|
||||
python.execute("class SkillCallbacks:\n def __init__(self):\n self.skills=0\n self.status=0\n def RefreshSkill(self):\n self.skills+=1\n def RefreshStatus(self):\n self.status+=1\nskill_callbacks=SkillCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,skill_callbacks)\nplayer.SetSkill(1,1)\nplayer.SetSkill(2,2)\nplayer.SetSkill(3,3)\nplayer.SetSkill(4,4)\nassert player.GetSkillLevel(1)==0\nassert player.GetSkillSlotIndex(3)==3\n");
|
||||
std::vector<uint8_t> skillsWire(1531,0);skillsWire[0]=76;
|
||||
auto setSkill=[&](int index,uint8_t grade,uint8_t level) { skillsWire[1+index*6]=grade;skillsWire[2+index*6]=level; };
|
||||
setSkill(1,0,19);setSkill(2,1,20);setSkill(3,2,30);setSkill(4,3,40);
|
||||
setSkill(114,0,10);setSkill(221,1,20);setSkill(228,2,31);setSkill(229,1,20);setSkill(243,3,40);
|
||||
netStream.PushRecvData(skillsWire.data(),1530);netStream.ProcessRecvData();
|
||||
python.execute("assert skill_callbacks.skills==0\n");
|
||||
netStream.PushRecvData(skillsWire.data()+1530,1);netStream.ProcessRecvData();
|
||||
python.execute("assert skill_callbacks.skills==1 and skill_callbacks.status==1\n"
|
||||
"assert player.GetSkillLevel(1)==19 and player.GetSkillGrade(1)==0\n"
|
||||
"assert player.GetSkillLevel(2)==1 and player.GetSkillGrade(2)==1\n"
|
||||
"assert player.GetSkillLevel(3)==1 and player.GetSkillGrade(3)==2\n"
|
||||
"assert player.GetSkillLevel(4)==1 and player.GetSkillGrade(4)==3\n"
|
||||
"assert abs(player.GetSkillCurrentEfficientPercentage(3)-0.82)<0.00001\n"
|
||||
"assert abs(player.GetSkillNextEfficientPercentage(3)-0.85)<0.00001\n"
|
||||
"assert player.GetSkillCurrentEfficientPercentage(4)==1.25\n"
|
||||
"assert player.GetSkillIndex(7)==228 and player.GetSkillLevel(7)==2\n"
|
||||
"assert player.GetSkillIndex(8)==243\n");
|
||||
std::vector<uint8_t> oldSkills(256,0);oldSkills[0]=72;oldSkills[3]=17;
|
||||
netStream.PushRecvData(oldSkills);netStream.ProcessRecvData();
|
||||
python.execute("assert player.GetSkillLevel(2)==17 and player.GetSkillGrade(2)==-1\n"
|
||||
"assert skill_callbacks.skills==2 and skill_callbacks.status==2\n"
|
||||
"net.ClearPhaseWindow(net.PHASE_WINDOW_GAME,skill_callbacks)\n");
|
||||
|
||||
python.execute("player.SetSkill(6,101)\nassert player.GetSkillLevel(6)==0\n");
|
||||
ava2::SetSkillCoolTime(101,10);
|
||||
python.execute("assert player.IsSkillCoolTime(6)==1\n"
|
||||
"assert player.GetSkillCoolTime(6)[0]==10.0\n"
|
||||
"assert player.GetSkillCoolTime(101)[0]==0.0\n"
|
||||
"assert player.ToggleCoolTime()==0\nassert player.IsSkillCoolTime(6)==0\n"
|
||||
"assert player.ToggleCoolTime()==1\nassert player.IsSkillCoolTime(6)==1\n");
|
||||
ava2::SetSkillCoolTimeAt(101,10,float(SDL_GetTicks())/1000.0f-12);
|
||||
python.execute("assert player.IsSkillCoolTime(6)==0\n"
|
||||
"total,elapsed=player.GetSkillCoolTime(6)\nassert total==10.0 and elapsed>=12.0\n"
|
||||
"assert player.GetSkillCoolTime(255)==(0.0,0.0)\n");
|
||||
netStream.ResetConnection();
|
||||
python.execute("assert player.GetSkillCoolTime(6)[0]==0.0\nassert player.IsSkillCoolTime(6)==0\n");
|
||||
|
||||
python.execute("class AffectCallbacks:\n def __init__(self):\n self.adds=[]\n self.removes=[]\n self.refreshes=0\n def BINARY_NEW_AddAffect(self,*args):\n self.adds.append(args)\n def BINARY_NEW_RemoveAffect(self,*args):\n self.removes.append(args)\n def RefreshStatus(self):\n self.refreshes+=1\naffect_callbacks=AffectCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,affect_callbacks)\nassert player.AffectIndexToSkillIndex(14)==3\nassert player.AffectIndexToSkillIndex(33)==19\nassert player.AffectIndexToSkillIndex(46)==182\nassert player.AffectIndexToSkillIndex(19)==63\nassert player.AffectIndexToSkillIndex(25)==79\nassert player.AffectIndexToSkillIndex(26)==78\nassert player.AffectIndexToSkillIndex(999)==0\n");
|
||||
ava2::SetServerTime(1700000000);
|
||||
const uint8_t affectWire[]={126,0xf4,1,0,0,128,0xfb,0xff,0xff,0xff,0,0,0,0,60,0,0,0,0,0,0,0};
|
||||
netStream.PushRecvData(affectWire,21);netStream.ProcessRecvData();
|
||||
python.execute("assert affect_callbacks.adds==[]\n");
|
||||
netStream.PushRecvData(affectWire+21,1);netStream.ProcessRecvData();
|
||||
const uint8_t removeWire[]={127,0xf4,1,0,0,128};netStream.PushRecvData(removeWire,sizeof(removeWire));netStream.ProcessRecvData();
|
||||
python.execute("assert affect_callbacks.adds==[(500,128,-5,60)]\n"
|
||||
"assert affect_callbacks.removes==[(500,128)]\n"
|
||||
"assert affect_callbacks.refreshes==1\n"
|
||||
"assert 1700000060<=player.GetStatus(129)<=1700000062\n"
|
||||
"net.ClearPhaseWindow(net.PHASE_WINDOW_GAME,affect_callbacks)\n");
|
||||
|
||||
// Literal Windows wire lengths, independent of the port's sizeof values.
|
||||
// An unmatched additional-info packet is ignored, not used to spawn an actor.
|
||||
netStream.ResetConnection();
|
||||
std::vector<uint8_t> actorInfo(75,0);
|
||||
actorInfo[0]=ava2::HEADER_GC_CHAR_ADDITIONAL_INFO;
|
||||
actorInfo[1]=0x7f;
|
||||
netStream.PushRecvData(actorInfo.data(),74);
|
||||
netStream.ProcessRecvData();
|
||||
if(ava2::NetworkActorManager::Instance().GetActorData(127))
|
||||
throw std::runtime_error("fragmented actor info spawned an actor");
|
||||
std::vector<uint8_t> actorTail(1+56+1,0);
|
||||
actorTail[1]=ava2::HEADER_GC_CHARACTER_UPDATE;
|
||||
actorTail[2]=0x7f;
|
||||
actorTail.back()=44;
|
||||
netStream.PushRecvData(actorTail);
|
||||
netStream.ProcessRecvData();
|
||||
if(ava2::NetworkActorManager::Instance().GetActorData(127))
|
||||
throw std::runtime_error("unmatched actor info spawned an actor");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{ava2::HEADER_CG_PONG})
|
||||
throw std::runtime_error("Windows actor packet length corrupted next packet");
|
||||
|
||||
netStream.ResetConnection();
|
||||
std::vector<uint8_t> petAdd(36,0);
|
||||
petAdd[0]=1; petAdd[1]=126; petAdd[21]=10;
|
||||
netStream.PushRecvData(petAdd); netStream.ProcessRecvData();
|
||||
if(ava2::NetworkActorManager::Instance().GetActorData(126))
|
||||
throw std::runtime_error("pet created before Windows additional-info packet");
|
||||
netStream.ResetConnection();
|
||||
// Add2 is 85 bytes; invisible race 20025 must never instantiate a model.
|
||||
std::vector<uint8_t> actor2(85,0);
|
||||
actor2[0]=120; actor2[1]=0x7f; actor2[47]=0x39; actor2[48]=0x4e;
|
||||
netStream.PushRecvData(actor2.data(),84); netStream.ProcessRecvData();
|
||||
std::vector<uint8_t> actor2Tail(1+52+1,0);
|
||||
actor2Tail[1]=117; actor2Tail[2]=0x7f; actor2Tail.back()=44;
|
||||
netStream.PushRecvData(actor2Tail); netStream.ProcessRecvData();
|
||||
if(ava2::NetworkActorManager::Instance().GetActorData(127))
|
||||
throw std::runtime_error("Windows invisible race instantiated");
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{ava2::HEADER_CG_PONG})
|
||||
throw std::runtime_error("Windows add2/update2 packet framing mismatch");
|
||||
const uint8_t deadFirst[]={14,0x7f,0,0,0,5,10};
|
||||
netStream.PushRecvData(deadFirst,sizeof(deadFirst));
|
||||
netStream.ProcessRecvData();
|
||||
const uint8_t deadTail[]={30,44};
|
||||
netStream.PushRecvData(deadTail,sizeof(deadTail));
|
||||
netStream.ProcessRecvData();
|
||||
if(netStream.PopSendBytes()!=std::vector<uint8_t>{ava2::HEADER_CG_PONG})
|
||||
throw std::runtime_error("renewal death packet corrupted following packet");
|
||||
ava2::ActorInstance actionActor;
|
||||
if(!actionActor.CanAct()) throw std::runtime_error("fresh actor cannot act");
|
||||
actionActor.SetParalysis(true);if(actionActor.CanAct()) throw std::runtime_error("paralysis allowed action");
|
||||
actionActor.SetParalysis(false);actionActor.SetFaint(true);if(actionActor.CanAct()) throw std::runtime_error("faint allowed action");
|
||||
actionActor.SetFaint(false);actionActor.SetSleep(true);if(actionActor.CanAct()) throw std::runtime_error("sleep allowed action");
|
||||
actionActor.SetSleep(false);if(!actionActor.CanAct()) throw std::runtime_error("cleared flags did not restore action");
|
||||
actionActor.Stun();if(actionActor.CanAct()) throw std::runtime_error("stun allowed action");
|
||||
ava2::ActorInstance deathActor;
|
||||
deathActor.SetMaxHP(200000);
|
||||
deathActor.Die();
|
||||
if(!deathActor.IsDead()) throw std::runtime_error("server death depended on fabricated damage amount");
|
||||
|
||||
netStream.ResetConnection();
|
||||
ava2::TPacketGCChat malformed{};malformed.header=ava2::HEADER_GC_CHAT;malformed.size=1;
|
||||
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&malformed),sizeof(malformed));
|
||||
bool invalidRejected=false;
|
||||
try { netStream.ProcessRecvData(); } catch(const std::runtime_error&) { invalidRejected=true; }
|
||||
if(!invalidRejected) throw std::runtime_error("undersized dynamic AVA2 packet accepted");
|
||||
netStream.ResetConnection();
|
||||
bool overflowRejected=false;
|
||||
try { netStream.PushRecvData(std::vector<uint8_t>(128*1024+1)); } catch(const std::runtime_error&) { overflowRejected=true; }
|
||||
if(!overflowRejected) throw std::runtime_error("unbounded AVA2 game receive queue");
|
||||
|
||||
ava2::ResetSkillDescriptions();
|
||||
python.execute("assert skill.GetSkillName(1) == 'NoneSkill'\n"
|
||||
"try:\n skill.GetSkillType(1)\n raise AssertionError('skill state survived reset')\n"
|
||||
"except RuntimeError:\n pass\n");
|
||||
std::cout<<"Embedded Python 2 original AVA2 modules, gameplay constants, networkModule, ui, prototype & chr 3D passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
Reference in New Issue
Block a user