Add mobile touch UI and AVA2 biology system with server tools
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include "../../src/host/touch_layout.h"
|
||||
#include <cstdio>
|
||||
|
||||
int main() {
|
||||
int failures = 0;
|
||||
auto check = [&](bool ok, const char* message) {
|
||||
if (!ok) { std::fprintf(stderr, "FAIL: %s\n", message); ++failures; }
|
||||
};
|
||||
struct Screen { float width, height, inset, target; };
|
||||
for (const auto screen : {Screen{640, 360, 24, 48}, Screen{800, 600, 0, 48},
|
||||
Screen{1300, 600, 40, 48}, Screen{1067, 600, 32, 72},
|
||||
Screen{1366, 1024, 62, 48}}) {
|
||||
const auto layout = mt_host::make_touch_layout(screen.width, screen.height, screen.inset, screen.target);
|
||||
const auto& attack = layout.buttons[0];
|
||||
float previous_angle = -1000;
|
||||
float first_distance = 0;
|
||||
for (int i = 0; i < int(layout.buttons.size()); ++i) {
|
||||
const auto& b = layout.buttons[i];
|
||||
check(b.x - b.radius >= screen.inset && b.x + b.radius <= screen.width - screen.inset &&
|
||||
b.y - b.radius >= 0 && b.y + b.radius <= screen.height, "visible controls stay inside the safe area");
|
||||
check(2 * b.radius >= screen.target - 0.01f, "controls retain minimum touch size");
|
||||
if (i >= 1 && i <= 6) {
|
||||
check(b.y + b.radius <= screen.height - 40 * layout.scale,
|
||||
"skills leave the bottom status and menu strip clear");
|
||||
const float dx = b.x - attack.x, dy = b.y - attack.y;
|
||||
const float distance = std::hypot(dx, dy);
|
||||
if (i == 1) first_distance = distance;
|
||||
check(std::abs(distance - first_distance) < 0.01f, "all six skills occupy one ring");
|
||||
float angle = std::atan2(dy, dx);
|
||||
if (angle < 0) angle += 6.2831853f;
|
||||
check(angle > previous_angle, "skill order follows the arc without reversing");
|
||||
previous_angle = angle;
|
||||
}
|
||||
for (int j = 0; j < i; ++j) {
|
||||
const auto& other = layout.buttons[j];
|
||||
check(std::hypot(b.x - other.x, b.y - other.y) > 1.25f * (b.radius + other.radius),
|
||||
"expanded touch areas cannot activate a neighboring control");
|
||||
}
|
||||
}
|
||||
}
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// PORT: loot must yield to local combat, including actors outside the pull reply.
|
||||
if (server && CPythonPlayer::Instance().NEW_GetMainActorPtr()) {
|
||||
auto& player = CPythonPlayer::Instance();
|
||||
auto* main = player.NEW_GetMainActorPtr();
|
||||
auto& manager = CPythonCharacterManager::Instance();
|
||||
const auto saved = player.AutoHunt_GetConfig();
|
||||
TPixelPosition savedMain; main->NEW_GetPixelPosition(&savedMain);
|
||||
auto* existing = manager.GetInstancePtr(FakeLoginServer::kMobVID);
|
||||
TPixelPosition savedMob; existing->NEW_GetPixelPosition(&savedMob);
|
||||
TPixelPosition origin = savedMob; origin.x += 1000;
|
||||
main->NEW_Stop(); main->NEW_SetPixelPosition(origin);
|
||||
CHECK(!main->IsInSafe());
|
||||
TPixelPosition far = origin; far.x += 20000;
|
||||
existing->NEW_Stop(); existing->NEW_SetPixelPosition(far);
|
||||
auto config = saved; config.iGatherCount = 0; config.iPickup = CPythonPlayer::AUTO_HUNT_PICKUP_ALL;
|
||||
config.bAttackStone = false; config.vecSkillIndices.clear();
|
||||
player.AutoHunt_SetEnabled(false); player.AutoHunt_SetConfig(config);
|
||||
const DWORD itemVID = 0x710010, mobVID = 0x710011;
|
||||
CPythonItem::Instance().CreateItem(itemVID, 1, origin.x + 500, origin.y, origin.z, false);
|
||||
player.AutoHunt_SetEnabled(true);
|
||||
CHECK(pump_until(2, [&] { return player.AutoHunt_GetState() == CPythonPlayer::AUTO_HUNT_LOOT; }));
|
||||
CInstanceBase::SCreateData data = {};
|
||||
data.m_bType = CActorInstance::TYPE_ENEMY; data.m_dwRace = existing->GetRace();
|
||||
data.m_dwVID = mobVID; data.m_dwMovSpd = 100; data.m_dwAtkSpd = 100;
|
||||
TPixelPosition here; main->NEW_GetPixelPosition(&here);
|
||||
data.m_lPosX = LONG(here.x + 80); data.m_lPosY = LONG(here.y);
|
||||
data.m_stName = "LootInterruptFixture";
|
||||
auto* mob = manager.CreateInstance(data);
|
||||
CHECK(mob);
|
||||
CHECK(pump_until(2, [&] { return player.AutoHunt_GetState() == CPythonPlayer::AUTO_HUNT_ENGAGE && player.GetTargetVID() == mobVID; }));
|
||||
player.AutoHunt_SetEnabled(false);
|
||||
manager.DeleteInstance(mobVID);
|
||||
// Once the threat is gone, loot is eligible again rather than permanently abandoned.
|
||||
main->NEW_Stop(); main->NEW_SetPixelPosition(origin);
|
||||
player.AutoHunt_SetEnabled(true);
|
||||
CHECK(pump_until(2, [&] { return player.AutoHunt_GetState() == CPythonPlayer::AUTO_HUNT_LOOT; }));
|
||||
player.AutoHunt_SetEnabled(false);
|
||||
CPythonItem::Instance().DeleteItem(itemVID);
|
||||
existing->NEW_Stop(); existing->NEW_SetPixelPosition(savedMob);
|
||||
main->NEW_Stop(); main->NEW_SetPixelPosition(savedMain);
|
||||
player.AutoHunt_SetConfig(saved);
|
||||
pump_frames(30);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// PORT: isolated item-table extension. All non-biology records stay byte-identical.
|
||||
#include "GameLib/StdAfx.h"
|
||||
#include "GameLib/ItemData.h"
|
||||
#include "EterBase/lzo.h"
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
using Item=CItemData::TItemTable;
|
||||
static constexpr std::array<DWORD,4> item_key{{173217,72619434,408587239,27973291}};
|
||||
static std::vector<BYTE> read_file(const char* path){
|
||||
std::ifstream stream(path,std::ios::binary);
|
||||
if(!stream)throw std::runtime_error("cannot read proto");
|
||||
return {std::istreambuf_iterator<char>(stream),std::istreambuf_iterator<char>()};
|
||||
}
|
||||
static DWORD word(const std::vector<BYTE>& data,size_t offset){
|
||||
if(offset+4>data.size())throw std::runtime_error("truncated proto");
|
||||
DWORD value;std::memcpy(&value,data.data()+offset,4);return value;
|
||||
}
|
||||
static void put_word(std::vector<BYTE>& data,size_t offset,DWORD value){std::memcpy(data.data()+offset,&value,4);}
|
||||
static void write_file(const char* path,const std::vector<BYTE>& data){
|
||||
std::ofstream stream(path,std::ios::binary|std::ios::trunc);
|
||||
if(!stream.write(reinterpret_cast<const char*>(data.data()),data.size()))throw std::runtime_error("cannot write proto");
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=4)return 2;
|
||||
try {
|
||||
static CLZO lzo; auto key=item_key;
|
||||
auto input=read_file(argv[1]);
|
||||
if(input.size()<20 || std::memcmp(input.data(),"MIPX",4) || word(input,4)!=1 || word(input,8)!=sizeof(Item))throw std::runtime_error("item proto stride");
|
||||
CLZObject decoded;
|
||||
if(!CLZO::Instance().Decompress(decoded,input.data()+20,key.data()))throw std::runtime_error("item proto decode");
|
||||
if(decoded.GetSize()!=size_t(word(input,12))*sizeof(Item))throw std::runtime_error("proto count/size mismatch");
|
||||
std::map<DWORD,Item> rows;
|
||||
for(DWORD i=0;i<word(input,12);++i){Item r;std::memcpy(&r,decoded.GetBuffer()+i*sizeof(Item),sizeof(Item));rows[r.dwVnum]=r;}
|
||||
std::ifstream file(argv[2],std::ios::binary);std::string line;size_t changed=0;
|
||||
while(std::getline(file,line)) {
|
||||
std::istringstream stream(line); unsigned v,type,sub,size,anti,flags,buy,sell;
|
||||
if(!(stream>>v>>type>>sub>>size>>anti>>flags>>buy>>sell))throw std::runtime_error("biology item row");
|
||||
std::array<int,6> values{};for(auto& value:values)if(!(stream>>value))throw std::runtime_error("biology item values");
|
||||
std::string name;std::getline(stream,name);if(!name.empty()&&name[0]=='\t')name.erase(0,1);
|
||||
if(name.size()>24)throw std::runtime_error("biology item name too long");
|
||||
Item r{};r.dwVnum=v;r.bType=type;r.bSubType=sub;r.bSize=size;r.dwAntiFlags=anti;r.dwFlags=flags;
|
||||
r.dwIBuyItemPrice=buy;r.dwISellItemPrice=sell;
|
||||
for(int i=0;i<6;++i)r.alValues[i]=values[i];
|
||||
std::memcpy(r.szName,name.data(),name.size());std::memcpy(r.szLocaleName,name.data(),name.size());
|
||||
rows[v]=r;++changed;
|
||||
}
|
||||
std::vector<BYTE> plain;for(const auto& pair:rows){const BYTE* bytes=reinterpret_cast<const BYTE*>(&pair.second);plain.insert(plain.end(),bytes,bytes+sizeof(Item));}
|
||||
CLZObject encoded;if(!CLZO::Instance().CompressEncryptedMemory(encoded,plain.data(),plain.size(),key.data()))throw std::runtime_error("encode");
|
||||
std::vector<BYTE> result(input.begin(),input.begin()+20);put_word(result,12,rows.size());put_word(result,16,encoded.GetSize());
|
||||
result.insert(result.end(),encoded.GetBuffer(),encoded.GetBuffer()+encoded.GetSize());
|
||||
CLZObject verified;if(!CLZO::Instance().Decompress(verified,result.data()+20,key.data()) || verified.GetSize()!=plain.size() || std::memcmp(verified.GetBuffer(),plain.data(),plain.size()))throw std::runtime_error("round-trip");
|
||||
write_file(argv[3],result);std::printf("biology items=%zu total=%zu; verified round-trip\n",changed,rows.size());return 0;
|
||||
}catch(const std::exception& e){std::fprintf(stderr,"%s\n",e.what());return 1;}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// Runtime loading remains the original 40250 path and binary format.
|
||||
// An optional item limits table (vnum, limit type 0, value 0, limit type 1, value 1) mirrors the few
|
||||
// item_proto.txt limit changes made on our server (tools/server/*), so the tooltip states what the
|
||||
// server enforces; only aLimits of the listed items may change.
|
||||
// server enforces. An optional 14-row stone overlay restores extracted +6 stone data.
|
||||
#include "GameLib/StdAfx.h"
|
||||
#include "GameLib/ItemData.h"
|
||||
#include "UserInterface/StdAfx.h"
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -23,6 +24,7 @@
|
||||
namespace {
|
||||
using Item = CItemData::TItemTable;
|
||||
using Mob = CPythonNonPlayer::TMobTable;
|
||||
std::map<DWORD, std::array<long, 11>> stones;
|
||||
|
||||
constexpr std::array<DWORD, 4> item_key{{173217, 72619434, 408587239, 27973291}};
|
||||
constexpr std::array<DWORD, 4> mob_key{{4813894, 18955, 552631, 6822045}};
|
||||
@@ -99,6 +101,14 @@ void apply_limits(Record&, const std::map<DWORD, Limits>&, std::size_t&) {}
|
||||
|
||||
template <>
|
||||
void apply_limits<Item>(Item& record, const std::map<DWORD, Limits>& limits, std::size_t& changed) {
|
||||
const auto stone = stones.find(record.dwVnum);
|
||||
if (stone != stones.end()) {
|
||||
const auto& s = stone->second;
|
||||
record.bType = s[0]; record.bSubType = s[1]; record.dwWearFlags = s[2];
|
||||
std::memset(record.aApplies, 0, sizeof(record.aApplies));
|
||||
record.aApplies[0].bType = s[3]; record.aApplies[0].lValue = s[4];
|
||||
for (int i = 0; i < 6; ++i) record.alValues[i] = s[5+i];
|
||||
}
|
||||
const auto found = limits.find(record.dwVnum);
|
||||
if (found == limits.end()) return;
|
||||
std::memcpy(record.aLimits, found->second.data(), sizeof(record.aLimits));
|
||||
@@ -110,6 +120,10 @@ bool limits_field(std::size_t, DWORD, const std::map<DWORD, Limits>&) { return f
|
||||
|
||||
template <>
|
||||
bool limits_field<Item>(std::size_t offset, DWORD vnum, const std::map<DWORD, Limits>& limits) {
|
||||
if (stones.count(vnum) && (offset == offsetof(Item, bType) || offset == offsetof(Item, bSubType) ||
|
||||
(offset >= offsetof(Item, dwWearFlags) && offset < offsetof(Item, dwWearFlags)+sizeof(Item::dwWearFlags)) ||
|
||||
(offset >= offsetof(Item, aApplies) && offset < offsetof(Item, aApplies)+sizeof(Item::aApplies)) ||
|
||||
(offset >= offsetof(Item, alValues) && offset < offsetof(Item, alValues)+sizeof(Item::alValues)))) return true;
|
||||
return limits.count(vnum) && offset >= offsetof(Item, aLimits) &&
|
||||
offset < offsetof(Item, aLimits) + sizeof(Item::aLimits);
|
||||
}
|
||||
@@ -151,7 +165,7 @@ std::vector<BYTE> patch(const char* source, const char* names_path,
|
||||
std::memcpy(plain.data() + std::size_t(i) * sizeof(Record), &record, sizeof(Record));
|
||||
++translated;
|
||||
}
|
||||
// No item stats, VNUM, canonical name, or mob gameplay fields may change (but the listed item limits).
|
||||
// Only locale names, listed limits and explicit stone overlay fields may change.
|
||||
for (DWORD i = 0; i < count; ++i) {
|
||||
const std::size_t start = std::size_t(i) * sizeof(Record);
|
||||
const std::size_t name_start = start + offsetof(Record, szLocaleName);
|
||||
@@ -185,14 +199,27 @@ std::vector<BYTE> patch(const char* source, const char* names_path,
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 7 && argc != 8) {
|
||||
if (argc != 7 && argc != 8 && argc != 9) {
|
||||
std::cerr << "usage: locale_proto_patch item_proto mob_proto item_names_gbk mob_names_gbk out_item out_mob"
|
||||
" [item_limits]\n";
|
||||
" [item_limits [item_stones]]\n";
|
||||
return 2;
|
||||
}
|
||||
try {
|
||||
static CLZO lzo;
|
||||
const auto item = patch<Item>(argv[1], argv[3], item_key, "MIPX", true, read_limits(argc == 8 ? argv[7] : nullptr));
|
||||
if (argc == 9) {
|
||||
std::ifstream stream(argv[8]);
|
||||
if (!stream) throw std::runtime_error("cannot read stone overlay");
|
||||
std::string line;
|
||||
while (std::getline(stream, line)) {
|
||||
if (line.empty() || line[0] == '#') continue;
|
||||
std::istringstream row(line); DWORD vnum; std::array<long,11> values{};
|
||||
if (!(row >> vnum) || vnum < 28700 || vnum > 28713) throw std::runtime_error("bad stone vnum");
|
||||
for (auto& value : values) if (!(row >> value)) throw std::runtime_error("bad stone row");
|
||||
if (values[0] != 10 || !stones.emplace(vnum, values).second) throw std::runtime_error("bad stone type/duplicate");
|
||||
}
|
||||
if (stones.size() != 14) throw std::runtime_error("stone overlay must contain all 14 stones");
|
||||
}
|
||||
const auto item = patch<Item>(argv[1], argv[3], item_key, "MIPX", true, read_limits(argc >= 8 ? argv[7] : nullptr));
|
||||
const auto mob = patch<Mob>(argv[2], argv[4], mob_key, "MMPT", false);
|
||||
write_file(argv[5], item);
|
||||
write_file(argv[6], mob);
|
||||
|
||||
@@ -730,6 +730,20 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
bool shopping = false;
|
||||
std::int32_t gold = kStartGold;
|
||||
std::uint32_t bag0 = 0; // vnum in inventory cell 0 (the fake character starts with an empty bag)
|
||||
// Mobile gesture fixture only: a weapon can be equipped/unequipped and the purchased potion moved.
|
||||
const bool mobile_fixture = std::getenv("MT_TEST_MOBILE") != nullptr;
|
||||
bool mobile_equipped = false;
|
||||
std::uint16_t potion_cell = 0;
|
||||
auto item_set = [&](std::uint16_t cell, std::uint32_t vnum) {
|
||||
auto set = zeroed<GCItemSet>();
|
||||
set.header = HDR_GC_ITEM_SET;
|
||||
set.cell = {1, cell};
|
||||
set.vnum = vnum;
|
||||
set.count = vnum ? 1 : 0;
|
||||
return c.Send(set);
|
||||
};
|
||||
if (!item_set(3, 30006)) return Fail(name + ": biology material fixture");
|
||||
if (mobile_fixture && !item_set(2, 19)) return Fail(name + ": mobile weapon fixture");
|
||||
int quest_page = 0; // the quest dialogue's last page sent (1 question, 2 next, 3 done)
|
||||
bool safebox_open = false;
|
||||
std::uint32_t safebox0 = kSafeboxItemVnum;
|
||||
@@ -788,6 +802,27 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
if (header == HDR_CG_PONG) {
|
||||
if (!burst_pong) { Event(name + ":burst_pong"); burst_pong = true; }
|
||||
continue;
|
||||
}
|
||||
if (header == HDR_CG_ITEM_USE) {
|
||||
CGItemUse use;
|
||||
std::memcpy(&use, packet, sizeof(use));
|
||||
Event(name + ":item_use " + std::to_string(use.pos.cell));
|
||||
if (mobile_fixture && use.pos.window_type == 1 &&
|
||||
use.pos.cell == (mobile_equipped ? 229 : 2)) {
|
||||
mobile_equipped = !mobile_equipped;
|
||||
if (!item_set(use.pos.cell, 0) || !item_set(mobile_equipped ? 229 : 2, 19))
|
||||
return Fail(name + ": mobile equipment reply");
|
||||
}
|
||||
}
|
||||
if (header == HDR_CG_ITEM_MOVE) {
|
||||
CGItemMove move;
|
||||
std::memcpy(&move, packet, sizeof(move));
|
||||
Event(name + ":item_move " + std::to_string(move.pos.cell) + " " + std::to_string(move.change_pos.cell));
|
||||
if (mobile_fixture && bag0 && move.pos.cell == potion_cell && move.change_pos.cell <= 1) {
|
||||
potion_cell = move.change_pos.cell;
|
||||
if (!item_set(move.pos.cell, 0) || !item_set(potion_cell, bag0))
|
||||
return Fail(name + ": mobile move reply");
|
||||
}
|
||||
}
|
||||
// CInputMain::ItemPickup → CHARACTER::PickupItem → CItem::RemoveFromGround → EncodeRemovePacket.
|
||||
if (header == HDR_CG_ITEM_PICKUP)
|
||||
@@ -868,6 +903,14 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
return Fail(name + ": send GC_SAFEBOX_SET");
|
||||
}
|
||||
}
|
||||
else if (text == "/bio status" || text == "/bio mission 1 0") {
|
||||
const bool submitted = text == "/bio mission 1 0";
|
||||
for (const std::string& cmd : {std::string("biotime 1000"),
|
||||
submitted ? std::string("biodata 1 4 1600") : std::string("biodata 1 3 0")}) {
|
||||
GCChatHead chat = {HDR_GC_CHAT, static_cast<std::uint16_t>(sizeof(GCChatHead) + cmd.size() + 1), 5, 0, 1};
|
||||
if (!c.Send(chat) || !c.Send(cmd.c_str(), cmd.size() + 1)) return Fail(name + ": biolog reply");
|
||||
}
|
||||
}
|
||||
else if (text == "/server_bonuses") {
|
||||
const std::string cmd = "ServerBonuses 200 200 200 200 200 0 200 0";
|
||||
GCChatHead chat = {HDR_GC_CHAT, static_cast<std::uint16_t>(sizeof(GCChatHead) + cmd.size() + 1), 5, 0, 1};
|
||||
@@ -922,7 +965,7 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
CGAttack attack;
|
||||
std::memcpy(&attack, packet, sizeof(attack));
|
||||
Event(name + ":attack " + std::to_string(attack.type) + " " + std::to_string(attack.victim_vid));
|
||||
if (attack.victim_vid == kMobVID && mob_hp > 0)
|
||||
if (combatFixtureDamage && attack.victim_vid == kMobVID && mob_hp > 0)
|
||||
{
|
||||
--mob_hp;
|
||||
GCDamageInfo damage = {HDR_GC_DAMAGE_INFO, kMobVID, 1 /* DAMAGE_NORMAL */, 100};
|
||||
@@ -1026,6 +1069,7 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
else if (sub == SHOP_CG_BUY && shopping && packet[3] == 0 && bag0 == 0)
|
||||
{
|
||||
bag0 = kShopItemVnum;
|
||||
potion_cell = 0;
|
||||
GCItemSet set = zeroed<GCItemSet>();
|
||||
set.header = HDR_GC_ITEM_SET;
|
||||
set.cell = {1, 0}; // INVENTORY, cell 0
|
||||
|
||||
@@ -73,6 +73,9 @@ public:
|
||||
bool Failed() { return !Error().empty(); }
|
||||
bool Has(const std::string& event);
|
||||
|
||||
// Keep the later manual combat fixture alive during auto-hunt checks.
|
||||
std::atomic<bool> combatFixtureDamage{true};
|
||||
|
||||
struct Connection;
|
||||
|
||||
private:
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
// Exit 77 (ctest SKIP) when the client is missing, unless MT_ASSETS_STRICT=1, which fails instead.
|
||||
#include "ScriptLib/StdAfx.h"
|
||||
#include "../../src/platform/ScriptLib/PythonBoot.h"
|
||||
#define MT_NATIVE_HAS_LIVE_CLIENT 1
|
||||
#include "../../src/host/touch_controller.h"
|
||||
#include "../../src/platform/ScriptLib/PythonHost.h"
|
||||
#include "../../src/platform/UserInterface/ServerClock.h"
|
||||
#include "../../src/platform/UserInterface/UserInterface.h"
|
||||
@@ -54,6 +56,7 @@
|
||||
#include "GameLib/ItemManager.h"
|
||||
#include "UserInterface/PythonItem.h"
|
||||
#include "UserInterface/StdAfx.h"
|
||||
#include "UserInterface/PythonNetworkStream.h"
|
||||
#include "UserInterface/PythonPlayer.h"
|
||||
#include "UserInterface/PythonExchange.h"
|
||||
#include "UserInterface/PythonTextTail.h"
|
||||
@@ -260,6 +263,8 @@ int main(int argc, char** argv)
|
||||
CHECK(GetPlatformServerTime() >= 123456789 && GetPlatformServerTime() < 123457789);
|
||||
CHECK(GetPlatformServerTimeStamp() >= 123456789 && GetPlatformServerTimeStamp() <= 123456791);
|
||||
PythonBoot::SetUISize(800, 600);
|
||||
const bool mobile_test = std::getenv("MT_TEST_MOBILE") != nullptr;
|
||||
PythonBoot::SetTouchInput(mobile_test);
|
||||
const bool ran = PythonBoot::RunMainScript("", &error);
|
||||
if (!ran)
|
||||
std::fprintf(stderr, "RunMainScript: %s\n", error.c_str());
|
||||
@@ -376,7 +381,7 @@ int main(int argc, char** argv)
|
||||
// CPythonSkill read skilldesc.txt and skilltable.txt (RegisterSkillDesc/RegisterSkillTable); skill 1's
|
||||
// cool time is skilltable's constant "12".
|
||||
CHECK(py("import skill\n"
|
||||
"assert skill.GetSkillName(1, 0) == 'Three-Way Cut', skill.GetSkillName(1, 0)\n"
|
||||
"assert skill.GetSkillName(1, 0) and (__import__('os').getenv('MT_LIVE_BIOLOG') or skill.GetSkillName(1, 0) == 'Three-Way Cut'), skill.GetSkillName(1, 0)\n"
|
||||
"assert skill.GetSkillType(1) == skill.SKILL_TYPE_ACTIVE, skill.GetSkillType(1)\n"
|
||||
"assert skill.GetSkillCoolTime(1, 1.0) == 12, skill.GetSkillCoolTime(1, 1.0)"));
|
||||
}
|
||||
@@ -415,6 +420,7 @@ int main(int argc, char** argv)
|
||||
// has to read all of it: an unknown or mis-sized packet makes CheckPacket log "Unknown packet
|
||||
// header" and drop the receive buffer. Offline the fake server ends with a ping the client
|
||||
// must answer; live the stream has to stay in the game window and connected for 10 s.
|
||||
|
||||
const bool burst = pump_until(live ? 10 : 30, [&] {
|
||||
return failed() || (server && server->Has("game2:burst_pong"));
|
||||
});
|
||||
@@ -424,6 +430,121 @@ int main(int argc, char** argv)
|
||||
CHECK(live || (GetPlatformServerTime() < 120000 && GetPlatformServerTimeStamp() < 120000));
|
||||
CHECK(py_true(gaming));
|
||||
CHECK(py("import net\nassert net.IsConnect(), 'disconnected in the game phase'"));
|
||||
|
||||
// Opt-in, dedicated fixture account only: real server biolog smoke, no generic gameplay mutations.
|
||||
if (live && std::getenv("MT_LIVE_BIOLOG")) {
|
||||
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
|
||||
CHECK(py("import mt_biolog, player\nmt_biolog.Toggle()"));
|
||||
CHECK(pump_until(8, [] { return py_true("mt_biolog.g_window.hasState"); }));
|
||||
CHECK(py("_bio=mt_biolog.g_window\nimport sys\nsys.stderr.write('AVA2 bio index=%d count=%d material=%d remaining=%d\\n' % (_bio.index,_bio.count,player.GetItemCountByVnum(30006),_bio.Remaining()))"));
|
||||
const std::string mode=env("MT_LIVE_BIOLOG");
|
||||
if (mode=="resume") {
|
||||
CHECK(py_true("_bio.index==1 and player.GetItemCountByVnum(30006)==1 and _bio.Remaining()>0"));
|
||||
} else if(mode=="gift4") {
|
||||
CHECK(py_true("_bio.index==4 and _bio.Phase()=='stone' and _bio.CanAct()"));
|
||||
CHECK(py("_bio.Act()"));
|
||||
CHECK(pump_until(5, [] { return py_true("_bio.Phase()=='gift'"); }));
|
||||
CHECK(py("_bio.Gift(0)"));
|
||||
CHECK(pump_until(5, [] { return py_true("_bio.index==5 and player.GetStatus(240)==4"); }));
|
||||
CHECK(py("net.SendChatPacket('/bio gift 0')"));
|
||||
pump_until(0.4, [] { return false; });
|
||||
CHECK(py_true("_bio.index==5 and player.GetStatus(240)==4"));
|
||||
} else if(mode=="reset") {
|
||||
CHECK(py_true("_bio.index==5 and player.GetStatus(240)==4"));
|
||||
CHECK(py("_note_before=player.GetItemCountByVnum(70028)\nnet.SendItemUsePacket(1)"));
|
||||
CHECK(pump_until(5, [] { return py_true("_bio.mode=='reset' and _bio.ResetIndex()==4"); }));
|
||||
CHECK(py("assert player.GetItemCountByVnum(70028)==_note_before\n_bio.Gift(1)"));
|
||||
CHECK(pump_until(5, [] { return py_true("_bio.bonuses[3]==2 and player.GetStatus(240)==0 and player.GetStatus(241)==4"); }));
|
||||
CHECK(py_true("player.GetItemCountByVnum(70028)==_note_before-1"));
|
||||
} else if(mode=="gift13") {
|
||||
CHECK(py_true("_bio.index==13 and _bio.Phase()=='gift'"));
|
||||
CHECK(py("assert player.GetItemCountByVnum(70028)==_note_before\n_bio.Gift(1)"));
|
||||
CHECK(pump_until(5, [] { return py_true("_bio.index==14 and _bio.Phase()=='complete' and player.GetStatus(43)==10"); }));
|
||||
} else if(mode=="complete") {
|
||||
CHECK(pump_until(5, [] { return py_true("_bio.index==14 and _bio.bonuses[12]==2 and 13 in _bio.ResetEntries()"); }));
|
||||
CHECK(py_true("player.GetStatus(43)==10"));
|
||||
} else if(mode=="shop") {
|
||||
CHECK(py("_bio.Shop()\n_bio.browse=13\n_bio.Refresh()\nassert mt_biolog.SHOP[13]['vnum']==300004\nassert _bio.CanAct()\n_bio.Act()"));
|
||||
CHECK(pump_until(5, [] { return py_true("player.GetItemCountByVnum(300004)==1 and player.GetItemCountByVnum(30091)==0"); }));
|
||||
} else {
|
||||
CHECK(py_true("_bio.index==1 and _bio.count==0 and _bio.CanAct()"));
|
||||
CHECK(py("_bio.Act()"));
|
||||
CHECK(pump_until(5, [] { return py_true("player.GetItemCountByVnum(30006)==1 and _bio.Remaining()>0"); }));
|
||||
CHECK(py_true("_bio.Remaining()<=601"));
|
||||
if(mode=="aux") {
|
||||
CHECK(py_true("_bio.count==1 and player.GetItemCountByVnum(71035)==0 and _bio.CanAct()"));
|
||||
CHECK(py("_bio.Act()"));
|
||||
CHECK(pump_until(5, [] { return py_true("player.GetItemCountByVnum(30006)==0 and player.GetItemCountByVnum(30250)==0"); }));
|
||||
} else {
|
||||
CHECK(py_true("not _bio.CanAct()"));
|
||||
CHECK(py("net.SendChatPacket('/bio mission 1 1')"));
|
||||
pump_until(0.5, [] { return false; });
|
||||
CHECK(py_true("player.GetItemCountByVnum(30006)==1"));
|
||||
}
|
||||
}
|
||||
CHECK(py("import app\napp.Exit()"));
|
||||
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
|
||||
PythonBoot::Stop();
|
||||
std::printf("biolog live fixture: %s\n", g_failures ? "FAILED" : "PASS");
|
||||
return g_failures ? 1 : 0;
|
||||
}
|
||||
|
||||
if (mobile_test) {
|
||||
// Input remains blocked by the original phase curtain until its fade finishes.
|
||||
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
|
||||
CHECK(py("import mt_mobile_hud, ui, player\n"
|
||||
"_hud = mt_mobile_hud.g_hud\n"
|
||||
"_hud.taskbar.Show()\n"
|
||||
"_hud.OnUpdate()\n"
|
||||
"_hud.window.interface.wndInventory.Hide()"));
|
||||
CHECK(py_true("_hud.IsShow()"));
|
||||
CHECK(py_true("not ui.Window.IsShow(_hud.taskbar)"));
|
||||
CHECK(py_true("len(_hud.top) == 4 and len(_hud.side) == 3"));
|
||||
CHECK(py_true("all(button.GetWidth() >= 48 for button in _hud.top + _hud.side)"));
|
||||
CHECK(py_true("_hud.status.values[0] == player.GetStatus(player.HP)"));
|
||||
CHECK(py_true("_hud.experience is _hud.taskbar.expGaugeBoard and _hud.experience.IsShow()"));
|
||||
CHECK(py_true("len(_hud.taskbar.expGauge) == 4"));
|
||||
CHECK(py_true("_hud.status.gauge is _hud.taskbar.GetChild('Gauge_Board')"));
|
||||
CHECK(py_true("_hud.experience.GetGlobalPosition()[1] > 500"));
|
||||
TouchController touch;
|
||||
touch.set_enabled(true);
|
||||
touch.update_screen_size(800, 600);
|
||||
std::string menuXY;
|
||||
CHECK(PythonBoot::Evaluate("'%d %d' % _hud.top[1].GetGlobalPosition()", &menuXY, nullptr));
|
||||
int menuX = 0, menuY = 0;
|
||||
CHECK(std::sscanf(menuXY.c_str(), "'%d %d'", &menuX, &menuY) == 2 ||
|
||||
std::sscanf(menuXY.c_str(), "%d %d", &menuX, &menuY) == 2);
|
||||
const float nx = float(menuX + 24) / 800, ny = float(menuY + 24) / 600;
|
||||
CHECK(touch.on_finger_down(102, nx, ny));
|
||||
CHECK(py_true("__import__('wndMgr').IsPickedWindow(_hud.top[1].hWnd)"));
|
||||
CHECK(touch.on_finger_up(102, nx, ny));
|
||||
CHECK(py_true("_hud.window.interface.wndInventory.IsShow()"));
|
||||
CHECK(py("_hud.window.interface.wndInventory.Hide()\n"
|
||||
"_hud.taskbar.Hide()\n"
|
||||
"assert not _hud.IsShow()\n"
|
||||
"_hud.taskbar.Show()\n"
|
||||
"assert _hud.IsShow()"));
|
||||
}
|
||||
if (!live) {
|
||||
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
|
||||
CHECK(py("import mt_biolog\nassert mt_biolog.g_window and mt_biolog.g_entry\n"
|
||||
"mt_biolog.g_entry.OnUpdate()"));
|
||||
// Exercise the actual minimap entry hit target, not a direct Toggle callback.
|
||||
std::string entryXY;
|
||||
CHECK(PythonBoot::Evaluate("'%d %d' % mt_biolog.g_entry.GetGlobalPosition()", &entryXY, nullptr));
|
||||
int entryX = 0, entryY = 0;
|
||||
CHECK(std::sscanf(entryXY.c_str(), "'%d %d'", &entryX, &entryY) == 2 ||
|
||||
std::sscanf(entryXY.c_str(), "%d %d", &entryX, &entryY) == 2);
|
||||
PythonBoot::UIMouseMove(entryX + 30, entryY + 24);
|
||||
CHECK(py_true("__import__('wndMgr').IsPickedWindow(mt_biolog.g_entry.hWnd)"));
|
||||
PythonBoot::UIMouseButton(1, true, entryX + 30, entryY + 24);
|
||||
PythonBoot::UIMouseButton(1, false, entryX + 30, entryY + 24);
|
||||
CHECK(pump_until(3, [] { return py_true("mt_biolog.g_window.IsShow() and mt_biolog.g_window.hasState"); }));
|
||||
CHECK(py("_bio=mt_biolog.g_window\nimport player\n_old_level=player.GetStatus(player.LEVEL)\nplayer.SetStatus(player.LEVEL,105)\n_bio.options=[True,False,True]\n_bio.Refresh()\nassert _bio.count==3 and _bio.CanAct()\nassert not _bio.SetData('99 0 0'.split())\n_bio.Act()\nassert not _bio.CanAct()\n_bio.Act()"));
|
||||
CHECK(pump_until(3, [] { return py_true("_bio.count==4"); }));
|
||||
CHECK(py_true("not _bio.CanAct() and _bio.Remaining()>0"));
|
||||
CHECK(py("assert _bio.SetData('9 11 0'.split())\nassert _bio.Phase()=='gift'\nassert sum(button.IsShow() for button in _bio.choices)==3\nassert _bio.SetData('13 36 0'.split())\nassert sum(button.IsShow() for button in _bio.choices)==2\nplayer.SetStatus(player.LEVEL,_old_level)\n_bio.Hide()"));
|
||||
}
|
||||
CHECK(count_syserr("Unknown packet header") == 0);
|
||||
CHECK(count_syserr(kUnhandledPacket) == 0);
|
||||
CHECK(count_syserr("does not handle this header") == 0);
|
||||
@@ -745,8 +866,11 @@ int main(int argc, char** argv)
|
||||
std::printf("port_login_flow_test: %s\n", e.c_str());
|
||||
}
|
||||
}
|
||||
#include "autohunt_pull_checks.inc"
|
||||
if (server) server->combatFixtureDamage = false;
|
||||
#include "autohunt_pull_checks.inc"
|
||||
#include "autohunt_recovery_checks.inc"
|
||||
#include "autohunt_crowd_checks.inc"
|
||||
if (server) server->combatFixtureDamage = true;
|
||||
// 9. (批次 4-b) Combat: a left click on the stray dog reaches CPythonPlayer::__OnClickActor, which targets it
|
||||
// (CG_TARGET → GC_TARGET, uitarget shows the HP board) and walks into range to attack. Each attack frame's
|
||||
// hit (CPythonPlayerEventHandler::OnHit) sends CG_ATTACK; the fake server answers GC_DAMAGE_INFO + GC_TARGET,
|
||||
@@ -918,17 +1042,101 @@ int main(int argc, char** argv)
|
||||
return py_true(("__import__('player').GetItemIndex(0) == " + std::to_string(FakeLoginServer::kShopItemVnum) +
|
||||
" and __import__('player').GetElk() == " + bought_gold).c_str());
|
||||
}));
|
||||
pump_ui_refresh();
|
||||
click(1, bag0);
|
||||
CHECK(py_true("__import__('mouseModule').mouseController.isAttached()"));
|
||||
click(1, std::make_pair(shelf0.first + 32, shelf0.second));
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:shop 3 0 1"); }));
|
||||
pump_ui_refresh();
|
||||
if (mobile_test) {
|
||||
CHECK(py("import mt_mobile_inventory, mouseModule, player\n"
|
||||
"_bag = _stream.curPhaseWindow.interface.wndInventory"));
|
||||
// Existing game rules forbid taking equipment off while shopping.
|
||||
PythonBoot::UIKey(DIK_ESCAPE, true);
|
||||
PythonBoot::UIKey(DIK_ESCAPE, false);
|
||||
CHECK(pump_until(2, [] { return py_true("not shop.IsOpen()"); }));
|
||||
pump_ui_refresh(); // let the server's SHOP_END finish before reopening the bag
|
||||
CHECK(py("_bag.Show()\n_bag.SetTop()"));
|
||||
TouchController touch;
|
||||
touch.set_enabled(true);
|
||||
touch.update_screen_size(800, 600);
|
||||
auto tap_at = [&](std::pair<int, int> at) {
|
||||
CHECK(touch.on_finger_down(301, float(at.first)/800, float(at.second)/600));
|
||||
CHECK(touch.on_finger_up(301, float(at.first)/800, float(at.second)/600));
|
||||
pump_frames(1);
|
||||
};
|
||||
auto drag_to = [&](std::pair<int, int> from, std::pair<int, int> to) {
|
||||
CHECK(touch.on_finger_down(302, float(from.first)/800, float(from.second)/600));
|
||||
CHECK(touch.on_finger_motion(302, float(to.first)/800, float(to.second)/600));
|
||||
CHECK(py_true("mouseModule.mouseController.isAttached()"));
|
||||
CHECK(touch.on_finger_up(302, float(to.first)/800, float(to.second)/600));
|
||||
};
|
||||
const auto weapon = std::make_pair(bag0.first+64, bag0.second);
|
||||
tap_at(weapon);
|
||||
CHECK(py_true("_bag.tooltipItem.IsShow() and not mouseModule.mouseController.isAttached()"));
|
||||
CHECK(!server->Has("game2:item_use 2"));
|
||||
tap_at(weapon);
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:item_use 2") &&
|
||||
py_true("player.GetItemIndex(2) == 0 and player.GetItemIndex(player.EQUIPMENT_SLOT_START+4) == 19"); }));
|
||||
pump_ui_refresh();
|
||||
auto equipped = slot0("wndInventory.wndEquip");
|
||||
equipped.first += 3; equipped.second += 3; // weapon cell's original local (3,3)
|
||||
tap_at(equipped);
|
||||
tap_at(equipped);
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:item_use 229") &&
|
||||
py_true("player.GetItemIndex(2) == 19 and player.GetItemIndex(player.EQUIPMENT_SLOT_START+4) == 0"); }));
|
||||
CHECK(py("net.SendOnClickPacket(" + std::to_string(FakeLoginServer::kShopVID) + ")"));
|
||||
CHECK(pump_until(2, [] { return py_true("shop.IsOpen()"); }));
|
||||
pump_ui_refresh();
|
||||
const auto bag1 = std::make_pair(bag0.first+32, bag0.second);
|
||||
drag_to(bag0, bag1);
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:item_move 0 1") &&
|
||||
py_true("player.GetItemIndex(0) == 0 and player.GetItemIndex(1) == 27001"); }));
|
||||
pump_ui_refresh();
|
||||
drag_to(bag1, bag0);
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:item_move 1 0") &&
|
||||
py_true("player.GetItemIndex(0) == 27001 and player.GetItemIndex(1) == 0"); }));
|
||||
pump_ui_refresh();
|
||||
// A page change invalidates the first tap, even when the second touch is at the same pixels.
|
||||
tap_at(weapon);
|
||||
const auto before_stale = server->Events().size();
|
||||
CHECK(py("_bag.SetInventoryPage(1)"));
|
||||
tap_at(weapon);
|
||||
CHECK(py("_bag.SetInventoryPage(0)\nassert not mouseModule.mouseController.isAttached()"));
|
||||
pump_frames(2);
|
||||
auto recent = server->Events();
|
||||
for (size_t i = before_stale; i < recent.size(); ++i)
|
||||
CHECK(recent[i].find(":item_use ") == std::string::npos);
|
||||
pump_ui_refresh();
|
||||
auto shop_blank = slot0("dlgShop"); // title/body background, not a shelf slot
|
||||
// A stale drag must not sell whatever is now in that slot.
|
||||
CHECK(touch.on_finger_down(303, float(bag0.first)/800, float(bag0.second)/600));
|
||||
CHECK(touch.on_finger_motion(303, float(shop_blank.first)/800, float(shop_blank.second)/600));
|
||||
CHECK(py("_bag.SetInventoryPage(1)"));
|
||||
CHECK(touch.on_finger_up(303, float(shop_blank.first)/800, float(shop_blank.second)/600));
|
||||
CHECK(py("assert not mouseModule.mouseController.isAttached()\n"
|
||||
"assert not __import__('constInfo').GET_ITEM_QUESTION_DIALOG_STATUS()\n"
|
||||
"_bag.SetInventoryPage(0)"));
|
||||
pump_ui_refresh();
|
||||
drag_to(bag0, shop_blank);
|
||||
CHECK(py_true("_bag.questionDialog and _bag.questionDialog.IsShow()"));
|
||||
CHECK(!server->Has("game2:shop 3 0 1"));
|
||||
CHECK(py("_bag.OnCloseQuestionDialog()"));
|
||||
CHECK(py_true("player.GetItemIndex(0) == 27001"));
|
||||
drag_to(bag0, shop_blank);
|
||||
CHECK(py("_bag.SellItem()"));
|
||||
} else {
|
||||
click(1, bag0);
|
||||
CHECK(py_true("__import__('mouseModule').mouseController.isAttached()"));
|
||||
click(1, std::make_pair(shelf0.first + 32, shelf0.second));
|
||||
}
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:shop 3 0 1"); }));
|
||||
|
||||
const std::string sold_gold = std::to_string(FakeLoginServer::kStartGold - (int) FakeLoginServer::kShopItemPrice + FakeLoginServer::kShopSellPrice);
|
||||
CHECK(pump_until(2, [&] {
|
||||
return py_true(("__import__('player').GetItemIndex(0) == 0 and __import__('player').GetElk() == " + sold_gold).c_str());
|
||||
}));
|
||||
PythonBoot::UIKey(DIK_ESCAPE, true);
|
||||
PythonBoot::UIKey(DIK_ESCAPE, false);
|
||||
if (mobile_test) {
|
||||
CHECK(py("_stream.curPhaseWindow.interface.dlgShop.Close()"));
|
||||
} else {
|
||||
PythonBoot::UIKey(DIK_ESCAPE, true);
|
||||
PythonBoot::UIKey(DIK_ESCAPE, false);
|
||||
}
|
||||
CHECK(pump_until(2, [&] { return server->Has("game2:shop 0"); }));
|
||||
CHECK(pump_until(2, [] { return py_true("not __import__('shop').IsOpen() and not _stream.curPhaseWindow.interface.dlgShop.IsShow()"); }));
|
||||
}
|
||||
@@ -1312,7 +1520,8 @@ int main(int argc, char** argv)
|
||||
want.push_back(e);
|
||||
for (const auto& e : events)
|
||||
if (e.rfind(prefix, 0) == 0 && e.find(":move ") == std::string::npos &&
|
||||
e.find(":pickup ") == std::string::npos &&
|
||||
e.find(":pickup ") == std::string::npos && e.find(":item_use ") == std::string::npos &&
|
||||
e.find(":item_move ") == std::string::npos &&
|
||||
e.find(":exchange ") == std::string::npos && e.find(":chat ") == std::string::npos &&
|
||||
e.find(":target ") == std::string::npos && e.find(":attack ") == std::string::npos &&
|
||||
e.find(":click ") == std::string::npos && e.find(":shop ") == std::string::npos &&
|
||||
@@ -1324,6 +1533,27 @@ int main(int argc, char** argv)
|
||||
dump(*server);
|
||||
}
|
||||
|
||||
if (mobile_test) {
|
||||
TouchController touch;
|
||||
touch.set_enabled(true);
|
||||
touch.update_screen_size(800, 600);
|
||||
CHECK(!PythonBoot::IsPointInsideActiveUI(240, 270));
|
||||
CHECK(touch.on_finger_down(101, 0.3f, 0.45f));
|
||||
touch.on_finger_motion(101, 0.325f, 0.46666667f);
|
||||
touch.update_screen_size(800, 600); // renderer does this each frame
|
||||
std::vector<UIRenderCommand> overlay;
|
||||
touch.append_ui_commands(overlay);
|
||||
bool kept_origin = false;
|
||||
for (const auto& cmd : overlay)
|
||||
if (cmd.argb == 0x52997847 && cmd.kind == UIRenderCommand::Line)
|
||||
// The base circle's first segment starts at (origin.x + radius, origin.y).
|
||||
kept_origin |= std::abs(cmd.x1 - (240.0f + mt_host::make_touch_layout(800, 600, 0, 48).scale * 65.0f)) < 0.1f &&
|
||||
std::abs(cmd.y1 - 270.0f) < 0.1f;
|
||||
CHECK(kept_origin);
|
||||
touch.on_finger_up(101, 0.325f, 0.46666667f);
|
||||
|
||||
}
|
||||
|
||||
CHECK(py("import app\napp.Exit()"));
|
||||
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
|
||||
CHECK(!PythonBoot::IsAppLooping());
|
||||
|
||||
Reference in New Issue
Block a user