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:
co-authored by
Claude Opus 5.5
parent
ed2c185135
commit
64d25e3571
@@ -0,0 +1,145 @@
|
||||
// Mobile step 6 auto hunt state machine (src/game/auto_hunt.h), without the engine.
|
||||
#include "auto_hunt.h"
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace ava2;
|
||||
|
||||
namespace {
|
||||
AutoHuntInput At(uint32_t now, float x, float z) {
|
||||
AutoHuntInput in;
|
||||
in.now = now;
|
||||
in.x = x;
|
||||
in.z = z;
|
||||
return in;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
// Off does nothing.
|
||||
{
|
||||
AutoHunt hunt;
|
||||
auto in = At(1000, 0, 0);
|
||||
in.mobs.push_back({7, 300, 0, 50, false});
|
||||
const auto out = hunt.Update(in);
|
||||
assert(out.move == AutoHuntOutput::Move::None && !out.attack && !out.target);
|
||||
}
|
||||
// Search -> engage: target packet + walk; in range: stop + attack; skill when ready.
|
||||
{
|
||||
AutoHunt hunt;
|
||||
hunt.Start(0, 0);
|
||||
auto in = At(1000, 0, 0);
|
||||
in.mobs.push_back({7, 600, 0, 50, false});
|
||||
in.mobs.push_back({8, 900, 0, 50, false});
|
||||
auto out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Engage && hunt.GetTarget() == 7);
|
||||
assert(out.target == 7 && out.move == AutoHuntOutput::Move::Go && out.moveX == 600.0f);
|
||||
in = At(2000, 450, 0);
|
||||
in.mobs.push_back({7, 600, 0, 50, false});
|
||||
in.readySkillSlots = {3};
|
||||
out = hunt.Update(in);
|
||||
assert(out.move == AutoHuntOutput::Move::Stop && out.attack == 7 && out.skillSlot == 3);
|
||||
// Skill gap: next frame only attacks.
|
||||
in.now = 2100;
|
||||
out = hunt.Update(in);
|
||||
assert(out.attack == 7 && out.skillSlot == -1 && out.move == AutoHuntOutput::Move::None);
|
||||
// Busy (attack motion) blocks skills even after the gap.
|
||||
in.now = 4000;
|
||||
in.busy = true;
|
||||
out = hunt.Update(in);
|
||||
assert(out.attack == 7 && out.skillSlot == -1);
|
||||
// Target died, own drop nearby -> loot before the next mob.
|
||||
in = At(4100, 450, 0);
|
||||
in.mobs.push_back({8, 900, 0, 50, false});
|
||||
in.items.push_back({100, 500, 300});
|
||||
out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Loot && hunt.GetTarget() == 100);
|
||||
assert(out.move == AutoHuntOutput::Move::Go && out.moveX == 500.0f && out.moveZ == 300.0f);
|
||||
in = At(4500, 500, 250);
|
||||
in.mobs.push_back({8, 900, 0, 50, false});
|
||||
in.items.push_back({100, 500, 300});
|
||||
out = hunt.Update(in);
|
||||
assert(out.pick == 100 && out.move == AutoHuntOutput::Move::Stop);
|
||||
// Picked up -> next mob.
|
||||
in = At(4800, 500, 250);
|
||||
in.mobs.push_back({8, 900, 0, 50, false});
|
||||
out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Engage && out.target == 8);
|
||||
}
|
||||
// Area: mobs outside the radius and stones (unless enabled) are skipped; return to the anchor.
|
||||
{
|
||||
AutoHunt hunt;
|
||||
hunt.options.radius = 1000;
|
||||
hunt.Start(0, 0);
|
||||
auto in = At(1000, 800, 0);
|
||||
in.mobs.push_back({1, 2500, 0, 50, false});
|
||||
in.mobs.push_back({2, 700, 0, 80, true});
|
||||
auto out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Return && out.move == AutoHuntOutput::Move::Go && out.moveX == 0.0f);
|
||||
hunt.options.attackStones = true;
|
||||
out = hunt.Update(At(1100, 700, 0));
|
||||
in.now = 1200;
|
||||
out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Engage && hunt.GetTarget() == 2 && out.attack == 2);
|
||||
}
|
||||
// Chase watchdog: no progress for kChaseTimeout -> target ignored for kIgnoreTime.
|
||||
{
|
||||
AutoHunt hunt;
|
||||
hunt.Start(0, 0);
|
||||
auto in = At(1000, 0, 0);
|
||||
in.mobs.push_back({5, 800, 0, 50, false});
|
||||
hunt.Update(in);
|
||||
in.now = 1000 + AutoHunt::kChaseTimeout + 10;
|
||||
auto out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Search && out.move == AutoHuntOutput::Move::Stop);
|
||||
in.now += 100;
|
||||
out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Search && !out.target);
|
||||
in.now += AutoHunt::kIgnoreTime;
|
||||
out = hunt.Update(in);
|
||||
assert(out.target == 5);
|
||||
}
|
||||
// Manual input pauses, resumes after kResumeDelay and re-anchors where the player stopped.
|
||||
{
|
||||
AutoHunt hunt;
|
||||
hunt.options.radius = 500;
|
||||
hunt.Start(0, 0);
|
||||
auto in = At(1000, 0, 0);
|
||||
in.manual = true;
|
||||
auto out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Paused && out.move == AutoHuntOutput::Move::None);
|
||||
in = At(2000, 3000, 0);
|
||||
in.mobs.push_back({9, 3200, 0, 50, false});
|
||||
out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Paused && !out.target);
|
||||
in.now = 1000 + AutoHunt::kResumeDelay;
|
||||
out = hunt.Update(in);
|
||||
assert(hunt.GetState() == AutoHuntState::Engage && out.target == 9);
|
||||
assert(hunt.GetAnchorX() == 3000.0f);
|
||||
}
|
||||
// Potions run in every state with their own gap; HP first. Death turns it off.
|
||||
{
|
||||
AutoHunt hunt;
|
||||
hunt.Start(0, 0);
|
||||
auto in = At(1000, 0, 0);
|
||||
in.hpPercent = 30;
|
||||
in.spPercent = 10;
|
||||
in.hpSlotUsable = in.spSlotUsable = true;
|
||||
auto out = hunt.Update(in);
|
||||
assert(out.useQuickSlot == 24);
|
||||
in.now = 1500;
|
||||
assert(hunt.Update(in).useQuickSlot == -1);
|
||||
in.now = 2100;
|
||||
in.hpPercent = 80;
|
||||
assert(hunt.Update(in).useQuickSlot == 25);
|
||||
in.now = 3200;
|
||||
in.spSlotUsable = false;
|
||||
assert(hunt.Update(in).useQuickSlot == -1);
|
||||
in.dead = true;
|
||||
out = hunt.Update(in);
|
||||
assert(out.stopped && !hunt.IsOn());
|
||||
}
|
||||
std::cout << "Auto hunt state machine passed" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user