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>
113 lines
4.6 KiB
C++
113 lines
4.6 KiB
C++
// Client-side auto hunt (mobile step 6, docs/MOBILE-ARCHITECTURE.md). Not in the AVA2 client: a
|
|
// new feature written for this port, not adapted from another client. It only drives the inputs a
|
|
// player already has — walking, the attack key, quickslot skills, item pick-up and quickslot
|
|
// potions — so the server sees the same packets as manual play.
|
|
//
|
|
// Pure logic: the host (python_gameplay_modules.cpp ProcessAutoHunt) fills AutoHuntInput from the
|
|
// actor/item/skill state every frame and carries out the returned AutoHuntOutput.
|
|
#pragma once
|
|
#include <cstdint>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace ava2 {
|
|
|
|
enum class AutoHuntState : uint8_t { Off, Search, Engage, Loot, Return, Paused };
|
|
|
|
struct AutoHuntOptions {
|
|
float radius = 1500.0f; // hunt area around the anchor (map units, 100 = 1 m)
|
|
bool useSkills = true; // skills on the current quickslot page
|
|
bool pickUp = true; // walk to and pick up own / free drops
|
|
bool attackStones = false; // metin stones (TYPE_STONE) as targets
|
|
int hpPercent = 50; // use hpSlot below this HP %, 0 = never
|
|
int spPercent = 30; // use spSlot below this SP %, 0 = never
|
|
int hpSlot = 24; // global quickslot (mobile potion belt = 24..31)
|
|
int spSlot = 25;
|
|
};
|
|
|
|
struct AutoHuntMob {
|
|
uint32_t vid = 0;
|
|
float x = 0, z = 0;
|
|
float radius = 0; // defending radius, added to the attack range
|
|
bool stone = false;
|
|
};
|
|
|
|
struct AutoHuntItem {
|
|
uint32_t vid = 0;
|
|
float x = 0, z = 0;
|
|
};
|
|
|
|
struct AutoHuntInput {
|
|
uint32_t now = 0; // ms
|
|
float x = 0, z = 0; // main actor
|
|
bool dead = false;
|
|
bool canAct = true;
|
|
bool busy = false; // attack or skill motion playing
|
|
bool manual = false; // player is steering / attacking this frame
|
|
int hpPercent = 100, spPercent = 100;
|
|
float attackRange = 160.0f; // weapon reach without the victim radius
|
|
bool hpSlotUsable = false, spSlotUsable = false;
|
|
std::vector<AutoHuntMob> mobs; // living attackable actors
|
|
std::vector<AutoHuntItem> items; // ground items this player may pick up
|
|
std::vector<int> readySkillSlots; // skill slots off cooldown and not already active
|
|
};
|
|
|
|
struct AutoHuntOutput {
|
|
enum class Move : uint8_t { None, Go, Stop } move = Move::None;
|
|
float moveX = 0, moveZ = 0;
|
|
uint32_t target = 0; // send a target packet (player.SetTarget)
|
|
uint32_t attack = 0; // face this vid and press attack this frame
|
|
int skillSlot = -1; // ClickSkillSlot
|
|
uint32_t pick = 0; // SendItemPickUpPacket
|
|
int useQuickSlot = -1; // global quickslot to use (potion)
|
|
bool stopped = false; // turned itself off (death)
|
|
};
|
|
|
|
class AutoHunt {
|
|
public:
|
|
static constexpr uint32_t kResumeDelay = 3000; // after the last manual input
|
|
static constexpr uint32_t kChaseTimeout = 8000; // no progress towards a target
|
|
static constexpr uint32_t kIgnoreTime = 30000; // a given-up target / item is skipped
|
|
static constexpr uint32_t kSkillGap = 1200;
|
|
static constexpr uint32_t kPotionGap = 1000;
|
|
static constexpr uint32_t kPickGap = 300;
|
|
static constexpr uint32_t kRepathGap = 250;
|
|
static constexpr float kPickRange = 150.0f;
|
|
|
|
AutoHuntOptions options;
|
|
|
|
void Start(float x, float z);
|
|
void Stop();
|
|
bool IsOn() const { return m_state != AutoHuntState::Off; }
|
|
AutoHuntState GetState() const { return m_state; }
|
|
uint32_t GetTarget() const { return m_target; }
|
|
float GetAnchorX() const { return m_anchorX; }
|
|
float GetAnchorZ() const { return m_anchorZ; }
|
|
AutoHuntOutput Update(const AutoHuntInput& in);
|
|
|
|
private:
|
|
void Enter(AutoHuntState state, uint32_t now);
|
|
bool Ignored(uint32_t vid, uint32_t now) const;
|
|
const AutoHuntMob* FindMob(const AutoHuntInput& in, uint32_t vid) const;
|
|
const AutoHuntMob* PickMob(const AutoHuntInput& in) const;
|
|
const AutoHuntItem* PickItem(const AutoHuntInput& in) const;
|
|
void GoTo(AutoHuntOutput& out, float x, float z, uint32_t now);
|
|
void Halt(AutoHuntOutput& out);
|
|
void Potions(const AutoHuntInput& in, AutoHuntOutput& out);
|
|
|
|
AutoHuntState m_state = AutoHuntState::Off;
|
|
float m_anchorX = 0, m_anchorZ = 0;
|
|
uint32_t m_target = 0; // mob vid (Engage) or item vid (Loot)
|
|
uint32_t m_stateSince = 0;
|
|
uint32_t m_lastManual = 0;
|
|
uint32_t m_lastProgress = 0;
|
|
float m_bestDistance = 0;
|
|
uint32_t m_lastSkill = 0, m_lastPotion = 0, m_lastPick = 0, m_lastPath = 0;
|
|
bool m_moving = false;
|
|
std::unordered_map<uint32_t, uint32_t> m_ignoreUntil;
|
|
};
|
|
|
|
const char* AutoHuntStateName(AutoHuntState state);
|
|
|
|
} // namespace ava2
|