Mobile step 6: client-side auto hunt with AUTO button

Engine-free AutoHunt state machine (search/engage/loot/return/paused) driven
from the game loop through the existing manual paths: move target, target
packet, normal attack, quickslot skills, item pick-up and belt potions.
player.SetAutoHunt/GetAutoHuntState/SetAutoHuntOption with autohunt.cfg;
AUTO button on the combat wheel (tap toggles, long press opens settings).
Tests: ava2.auto_hunt, extended ava2.touch_game; 54/54.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 22:05:15 +09:00
co-authored by Claude Opus 5.5
parent ed2c185135
commit 64d25e3571
13 changed files with 1085 additions and 2 deletions
+68
View File
@@ -8,11 +8,16 @@
#include "eter_image/GrpDevice.h"
#include "test_rundir.h"
#include "eter_net/PythonNetworkStream.h"
#include "eter_net/NetworkActorManager.h"
#include "python_system.h"
#include <Python.h>
#include <SDL3/SDL.h>
#include <array>
#include <cassert>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <iostream>
namespace {
@@ -148,6 +153,69 @@ int main(int argc, char** argv) {
"assert mm.GetGlobalPosition()[0] + mm.GetWidth() == 1024\n"
"game.OnUpdate()\n");
// Auto hunt (mobile step 6): the AUTO button sits on the combat wheel and is real UI; with a
// main actor and a mob the native driver targets, walks, stops in reach and gives up on the dead.
ava2::CPythonSystem::SetConfigDirectory(std::filesystem::temp_directory_path().string());
std::filesystem::remove(std::filesystem::temp_directory_path() / "autohunt.cfg");
runtime.execute("ab = hud.combat_wheel.auto_button\n"
"assert ab.IsShow() and not player.IsAutoHunt()\n"
"assert player.SetAutoHunt(1) == 0\n" // no main actor yet
"touch_tb = ab.GetGlobalPosition()\n"
"touch_tb = (touch_tb[0] + ab.GetWidth() / 2, touch_tb[1] + ab.GetHeight() / 2)\n"
"assert player.GetAutoHuntOption('radius') == 1500\n"
"player.SetAutoHuntOption('radius', 2000)\nplayer.SetAutoHuntOption('stones', 1)\n"
"assert player.GetAutoHuntOption('radius') == 2000 and player.GetAutoHuntOption('stones') == 1\n"
"player.SetAutoHuntOption('stones', 0)\n");
tb = PyDict_GetItemString(PyModule_GetDict(main), "touch_tb");
const float ab_x = float(PyInt_AsLong(PyTuple_GetItem(tb, 0)));
const float ab_y = float(PyInt_AsLong(PyTuple_GetItem(tb, 1)));
assert(sink.IsUiAt(ab_x, ab_y));
{
std::ifstream cfg(std::filesystem::temp_directory_path() / "autohunt.cfg");
std::string text((std::istreambuf_iterator<char>(cfg)), std::istreambuf_iterator<char>());
assert(text.find("radius 2000\n") != std::string::npos && text.find("stones 0\n") != std::string::npos);
}
auto& actors = ava2::NetworkActorManager::Instance();
ava2::SNetworkActorData me{};
me.m_dwVID = 5001; me.m_bType = 6; me.m_stName = "AutoHunter"; me.m_lCurX = 10000; me.m_lCurY = 10000;
actors.AppendActor(me);
ava2::PythonNetworkStream::Instance().SetMainActorVID(5001);
ava2::SNetworkActorData mob{};
mob.m_dwVID = 5002; mob.m_bType = 0; mob.m_dwRace = 101; mob.m_lCurX = 10800; mob.m_lCurY = 10000;
actors.AppendActor(mob);
auto hunter = actors.GetActorInstance(5001);
auto prey = actors.GetActorInstance(5002);
assert(hunter && prey);
// Tap AUTO: on (button turns green, state text shows the fight).
wm->RunMouseMove(long(ab_x), long(ab_y));
runtime.execute("ab.OnMouseLeftButtonDown()\nab.OnMouseLeftButtonUp()\n"
"assert player.IsAutoHunt() and ab.isOn\n");
ava2::ProcessAutoHunt();
runtime.execute("assert player.GetAutoHuntState() == ('engage', 5002), player.GetAutoHuntState()\n"
"assert player.GetTargetVID() == 5002\n"
"ab.OnUpdate()\nassert ab.state_text.GetText() == 'Fight'\n");
assert(hunter->HasMoveTarget());
hunter->SetPosition(10700.0f, hunter->GetY(), 10000.0f);
ava2::ProcessAutoHunt();
assert(!hunter->HasMoveTarget());
// Steering pauses it; the mob dies; turning it off from the button.
ava2::SetPlayerJoystick(true, 1.0f, 0.0f);
ava2::ProcessAutoHunt();
runtime.execute("assert player.GetAutoHuntState()[0] == 'paused'\n");
ava2::SetPlayerJoystick(false, 0.0f, 0.0f);
prey->SetHP(0);
runtime.execute("ab.OnMouseLeftButtonDown()\nab.OnMouseLeftButtonUp()\n"
"assert not player.IsAutoHunt()\nab.OnUpdate()\nassert not ab.isOn\n"
// Long press opens the settings window instead of toggling.
"ab.OnMouseLeftButtonDown()\nab.pressTime -= 1000\nab.OnUpdate()\nab.OnMouseLeftButtonUp()\n"
"import ui_mobile_autohunt\n"
"assert not player.IsAutoHunt() and ui_mobile_autohunt._settings.IsShow()\n"
"ui_mobile_autohunt._settings.Close()\n");
actors.RemoveActor(5002);
actors.RemoveActor(5001);
ava2::PythonNetworkStream::Instance().SetMainActorVID(0);
std::filesystem::remove(std::filesystem::temp_directory_path() / "autohunt.cfg");
SDL_FillSurfaceRect(surface, nullptr, 0xff10141e);
wm->Render(); SDL_RenderPresent(renderer);
// CDisc geometry: the attack disc is dark red between the icon and the rim; empty screen is not.