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
+47 -3
View File
@@ -12,7 +12,7 @@
#include <cmath>
#include <cstdint>
using DWORD = uint32_t;
constexpr int ENTITY_CHARACTER=1, ATTR_BANPK=4, MOB_RANK_BOSS=4, CHAT_TYPE_COMMAND=5;
constexpr int ENTITY_CHARACTER=1, ATTR_BANPK=4, MOB_RANK_BOSS=4, CHAT_TYPE_COMMAND=5, SECTREE_SIZE=6400;
struct Character;
using LPCHARACTER=Character*;
struct Entity { virtual ~Entity() {} bool IsType(int) { return true; } };
@@ -22,6 +22,7 @@ struct Sectree {
bool safe=false;
std::vector<Entity*> entities;
DWORD GetAttribute(long,long) { return safe ? ATTR_BANPK : 0; }
template<class F> void for_each_entity(F& f) { for(auto* e:entities) f(e); }
template<class F> void ForEachAround(F& f) { for(auto* e:entities) f(e); }
};
struct Character: Entity {
@@ -44,6 +45,7 @@ struct Character: Entity {
int GetX() { return x; }
int GetY() { return y; }
int GetMapIndex() { return 1; }
DWORD GetPlayerID() { return vid; }
int GetMobRank() { return rank; }
Sectree* GetSectree() { return sec; }
Party* GetParty() { return party; }
@@ -62,6 +64,26 @@ struct CHARACTER_MANAGER {
static CHARACTER_MANAGER& instance() { static CHARACTER_MANAGER value; return value; }
Character* Find(DWORD vid) { return mobs[vid]; }
};
using LPSECTREE=Sectree*;
struct SectreeMap {
std::map<std::pair<int,int>, Sectree*> cells;
template<class F> void for_each_in_rect(int x0,int y0,int x1,int y1,F& f) {
for (const auto& cell:cells)
if (cell.first.first>=x0/SECTREE_SIZE && cell.first.first<=x1/SECTREE_SIZE &&
cell.first.second>=y0/SECTREE_SIZE && cell.first.second<=y1/SECTREE_SIZE)
cell.second->for_each_entity(f);
}
Sectree* Find(int x,int y) {
auto it=cells.find({x/SECTREE_SIZE,y/SECTREE_SIZE});
return it==cells.end() ? nullptr : it->second;
}
};
using LPSECTREE_MAP=SectreeMap*;
struct SECTREE_MANAGER {
SectreeMap map;
static SECTREE_MANAGER& instance() { static SECTREE_MANAGER m; return m; }
SectreeMap* GetMap(int) { return &map; }
};
int now=100;
int get_global_time() { return now; }
#define DISTANCE_APPROX(x,y) int(std::hypot(x,y))
@@ -71,7 +93,8 @@ int get_global_time() { return now; }
int main() {
Sectree sec;
Character owner; owner.pc=true; owner.sec=&sec;
Character owner; owner.pc=true; owner.sec=&sec; owner.vid=1;
SECTREE_MANAGER::instance().map.cells[{0,0}]=&sec;
Character other; other.pc=true;
std::vector<Party> parties(25);
std::vector<Character> mobs(50);
@@ -104,9 +127,30 @@ int main() {
assert(owner.replies.back()=="AutoHuntGather 11 done 0");
sec.safe=false; owner.replies.clear();
do_autohunt_pull(&owner,"21 5000 0 12");
do_autohunt_pull(&owner,"3 5001 0 12");
do_autohunt_pull(&owner,"3 15001 0 12");
do_autohunt_pull(&owner,"3 5000 0 12 extra");
assert(owner.replies.empty());
// Large ranges visit distant sectors and extend only the selected owner's pursuit.
Sectree distant;
Character far; far.vid=1000; far.x=14000; far.sec=&distant;
distant.entities.push_back(&far);
SECTREE_MANAGER::instance().map.cells[{2,0}]=&distant;
CHARACTER_MANAGER::instance().mobs[far.vid]=&far;
sec.entities.clear(); now+=10;
do_autohunt_pull(&owner,"20 10000 0 13");
assert(owner.replies.back()=="AutoHuntGather 13 done 0" && !far.victim);
now+=10;
do_autohunt_pull(&owner,"20 15000 0 14");
assert(owner.replies.back()=="AutoHuntGather 14 done 1" && far.victim==&owner);
assert(AutoHuntPullLeash(&far,&owner)==15001);
assert(AutoHuntPullLeash(&mobs[49],&owner)==4000);
do_autohunt_pull(&owner,"0 15000 0 15");
assert(AutoHuntPullLeash(&far,&owner)==4000);
now+=10; do_autohunt_pull(&owner,"3 15000 0 16");
assert(AutoHuntPullLeash(&far,&other)==4000);
now+=10; do_autohunt_pull(&owner,"3 15000 0 17");
now+=180;
assert(AutoHuntPullLeash(&far,&owner)==4000);
// Unequal group sizes, exact 10-group cap and nearest ordering independent of input order.
std::vector<mt_autohunt::Candidate> candidates;
for(int g=24;g>=0;--g)
+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