Expand auto-hunt pursuit ranges and show server bonus effects

This commit is contained in:
shen
2026-09-30 23:02:04 -07:00
parent 922954dd97
commit eb5833747a
22 changed files with 676 additions and 82 deletions
+64 -2
View File
@@ -1,5 +1,13 @@
// PORT extension test: real Python settings → CG_CHAT → GC_CHAT → player state.
if (server && CPythonCharacterManager::Instance().GetMainInstancePtr()) {
// Real command reply inserts distinct global/event icons without replacing character affects.
CHECK(pump_until(2, [&] { return server->Has("game2:chat 0 /server_bonuses"); }));
CHECK(py("import mt_bonuses; _bonus_bar = mt_bonuses.g_game.affectShower"));
CHECK(pump_until(2, [&] { return py_true("all(k in _bonus_bar.affectImageDict for k in (20000,20001,20002,20003,20004,20006))"); }));
CHECK(py("_bonus_image = _bonus_bar.affectImageDict[20000]; assert _bonus_image.IsShow(); assert _bonus_image.description == mt_bonuses.L(mt_bonuses.ENTRIES[0][0] % 200)"));
CHECK(py("mt_bonuses.g_game.BINARY_ServerCommand_Run('ServerBonuses 100 100 100 100 0 0 0 0'); assert not any(k >= 20000 for k in _bonus_bar.affectImageDict)"));
CHECK(py("mt_bonuses.g_game.BINARY_ServerCommand_Run('ServerBonuses 300 100 100 100 0 0 0 0'); assert _bonus_bar.affectImageDict[20000].description == mt_bonuses.L(mt_bonuses.ENTRIES[0][0] % 300)"));
CHECK(py("mt_bonuses.g_game.BINARY_ServerCommand_Run('ServerBonuses bad'); assert 20000 in _bonus_bar.affectImageDict"));
auto* main_instance = CPythonCharacterManager::Instance().GetMainInstancePtr();
CPythonPlayer& player = CPythonPlayer::Instance();
const auto savedConfig = player.AutoHunt_GetConfig();
@@ -17,17 +25,59 @@ if (server && CPythonCharacterManager::Instance().GetMainInstancePtr()) {
main_instance->NEW_Stop();
main_instance->NEW_SetPixelPosition(pullPosition);
CHECK(!main_instance->IsInSafe());
CHECK(py("player.AutoHuntSetConfig(5000, 0, 0, 0, 0, 0, 0, 3); player.AutoHuntSetEnabled(1)"));
CHECK(py("player.AutoHuntSetConfig(3500, 0, 0, 0, 0, 0, 0, 3); player.AutoHuntSetEnabled(1)"));
TPixelPosition origin = {};
main_instance->NEW_GetPixelPosition(&origin);
CHECK(pump_until(2, [&] {
return server->Has("game2:chat 0 /autohunt_pull 3 5000 0 1") &&
return server->Has("game2:chat 0 /autohunt_pull 3 3500 0 1") &&
player.AutoHunt_GetGatheredCount() == 1 && !player.AutoHunt_IsGathering();
}));
TPixelPosition current = {};
main_instance->NEW_GetPixelPosition(&current);
CHECK(std::hypot(current.x-origin.x, current.y-origin.y) < 5.0f);
TPixelPosition originalMobPosition = {};
pullMob->NEW_GetPixelPosition(&originalMobPosition);
TPixelPosition closeMobPosition = origin;
closeMobPosition.x += 100;
pullMob->NEW_Stop();
pullMob->NEW_SetPixelPosition(closeMobPosition);
main_instance->NEW_Stop();
main_instance->NEW_SetPixelPosition(origin);
// A farther stone outranks the nearer pulled monster, even with bosses disabled.
CInstanceBase::SCreateData stoneData = {};
stoneData.m_bType = CActorInstance::TYPE_STONE;
stoneData.m_dwRace = 8001;
stoneData.m_dwVID = 0x700001;
stoneData.m_dwMovSpd = 100;
stoneData.m_dwAtkSpd = 100;
stoneData.m_lPosX = LONG(origin.x + 400);
stoneData.m_lPosY = LONG(origin.y);
stoneData.m_stName = "AutoHuntStoneFixture";
auto* stone = CPythonCharacterManager::Instance().CreateInstance(stoneData);
CHECK(stone && stone->IsStone() && !stone->IsInSafe());
if (stone) {
auto cfg = player.AutoHunt_GetConfig();
cfg.bAttackStone = true;
player.AutoHunt_SetConfig(cfg);
CHECK(pump_until(2, [&] { return player.GetTargetVID() == stoneData.m_dwVID; }));
player.AutoHunt_SetEnabled(false);
cfg.iGatherCount = 0;
cfg.bAttackStone = false;
player.AutoHunt_SetConfig(cfg);
player.AutoHunt_SetEnabled(true);
CHECK(pump_until(2, [&] { return player.GetTargetVID() == FakeLoginServer::kMobVID; }));
// Changing the option while already fighting takes effect immediately.
cfg.bAttackStone = true;
player.AutoHunt_SetConfig(cfg);
CHECK(pump_until(2, [&] { return player.GetTargetVID() == stoneData.m_dwVID; }));
player.AutoHunt_SetEnabled(false);
CPythonCharacterManager::Instance().DeleteInstance(stoneData.m_dwVID);
player.AutoHunt_SetEnabled(true);
CHECK(pump_until(2, [&] { return player.GetTargetVID() == FakeLoginServer::kMobVID; }));
}
player.AutoHunt_SetEnabled(false);
pullMob->NEW_Stop();
pullMob->NEW_SetPixelPosition(originalMobPosition);
CHECK(player.AutoHunt_HandleServerCommand("AutoHuntGather 1 mob 123"));
CHECK(player.AutoHunt_GetGatheredCount() == 0);
// Old replies must not complete a new request; cooldown remains across toggles.
@@ -35,6 +85,18 @@ if (server && CPythonCharacterManager::Instance().GetMainInstancePtr()) {
CHECK(player.AutoHunt_HandleServerCommand("AutoHuntGather 1 done 20"));
CHECK(player.AutoHunt_GetGatheredCount() == 0);
player.AutoHunt_SetEnabled(false);
CHECK(py("player.AutoHuntSetConfig(10000, 0, 0, 0, 0, 0, 0, 0)"));
CHECK(player.AutoHunt_GetConfig().iRange == 10000);
CHECK(py("player.AutoHuntSetConfig(15000, 0, 0, 0, 0, 0, 0, 0)"));
CHECK(player.AutoHunt_GetConfig().iRange == 15000);
TPixelPosition farPosition = origin;
farPosition.x += 2000;
main_instance->NEW_Stop();
main_instance->NEW_SetPixelPosition(farPosition);
CHECK(py("player.AutoHuntSetConfig(15000, 0, 0, 0, 0, 0, 0, 20); player.AutoHuntSetEnabled(1)"));
CHECK(player.AutoHunt_GetConfig().iRange == 15000);
CHECK(pump_until(12, [&] { return server->Has("game2:chat 0 /autohunt_pull 20 15000 0 2"); }));
player.AutoHunt_SetEnabled(false);
player.AutoHunt_SetConfig(savedConfig);
player.SetStatus(POINT_HP, hp);
player.SetStatus(POINT_MAX_HP, maxHP);
+14 -4
View File
@@ -718,10 +718,10 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
// A ping after the burst proves that GamePhase consumed every packet above and can reply.
Blank ping = {HDR_GC_PING};
Blank pong = {};
if (!c.Send(ping) || read_packet(c, HDR_CG_PONG, &pong, sizeof(pong), &error) != 1)
return Fail(name + ": CG_PONG after the entergame burst: " + error);
Event(name + ":burst_pong");
if (!c.Send(ping)) return Fail(name + ": send burst ping");
// A slow phone can request status while still processing the initial burst.
// Real CInputMain permits chat commands before this heartbeat reply too.
bool burst_pong = false;
// Then hold the connection until the test stops us, reading what the game phase sends the way
// CInputProcessor::Process frames it (static size or TDynamicSizePacketHeader, then the sequence
@@ -785,6 +785,10 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
return Fail(name + ": SEQUENCE mismatch on CG header " + std::to_string(header));
c.sequence = (c.sequence + 1) % SEQUENCE_TABLE_SIZE;
}
if (header == HDR_CG_PONG) {
if (!burst_pong) { Event(name + ":burst_pong"); burst_pong = true; }
continue;
}
// CInputMain::ItemPickup → CHARACTER::PickupItem → CItem::RemoveFromGround → EncodeRemovePacket.
if (header == HDR_CG_ITEM_PICKUP)
{
@@ -864,11 +868,17 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
return Fail(name + ": send GC_SAFEBOX_SET");
}
}
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};
if (!c.Send(chat) || !c.Send(cmd.c_str(), cmd.size() + 1)) return Fail(name + ": server bonuses reply");
}
else if (text.rfind("/autohunt_pull ", 0) == 0) {
int groups = 0, radius = 0, bosses = 0;
unsigned request = 0;
if (sscanf(text.c_str() + 15, "%d %d %d %u", &groups, &radius, &bosses, &request) != 4)
return Fail(name + ": malformed autohunt pull");
if (!groups) continue;
for (const std::string& cmd : {"AutoHuntGather " + std::to_string(request) + " mob " + std::to_string(kMobVID),
"AutoHuntGather " + std::to_string(request) + " done 1"}) {
GCChatHead chat = {HDR_GC_CHAT, static_cast<std::uint16_t>(sizeof(GCChatHead) + cmd.size() + 1), 5, 0, 1};
+3 -3
View File
@@ -393,9 +393,9 @@ int main(int argc, char** argv)
});
CHECK(loading && !failed());
CHECK(py_true(loaded));
// The loading window already warped the map; the touch host's joystick and skill buttons wait for
// the game phase.
CHECK(!PythonBoot::InGamePhase() && !PythonBoot::CurrentMapName().empty());
// The map is available during loading. A fast server may have already switched the
// network phase to Game before the loading window closes on the next script frame.
CHECK(!PythonBoot::CurrentMapName().empty());
// 6. introLoading's update steps end in net.StartGame(); the next CPythonNetworkStream::Process calls
// networkModule's SetGamePhase, which builds game.GameWindow (interfaceModule.MakeInterface) and