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
@@ -2101,6 +2101,8 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
static bool wasMoving = false;
|
||||
static uint32_t lastMoveSent = 0;
|
||||
float moveYaw = 0.0f;
|
||||
// Auto hunt (mobile step 6) steers and presses attack like a player would.
|
||||
ava2::ProcessAutoHunt();
|
||||
// Attack input first (NEW_Attack ends walking); no movement while an attack plays.
|
||||
if (ava2::ProcessPlayerAttack(orbit_camera.GetYaw(), dt, wasMoving)) wasMoving = false;
|
||||
const bool attacking = ava2::IsPlayerAttacking();
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
// Client-side auto hunt state machine; see auto_hunt.h.
|
||||
#include "auto_hunt.h"
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
|
||||
namespace ava2 {
|
||||
namespace {
|
||||
float Distance(float ax, float az, float bx, float bz) {
|
||||
const float dx = ax - bx, dz = az - bz;
|
||||
return std::sqrt(dx * dx + dz * dz);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
const char* AutoHuntStateName(AutoHuntState state) {
|
||||
switch (state) {
|
||||
case AutoHuntState::Off: return "off";
|
||||
case AutoHuntState::Search: return "search";
|
||||
case AutoHuntState::Engage: return "engage";
|
||||
case AutoHuntState::Loot: return "loot";
|
||||
case AutoHuntState::Return: return "return";
|
||||
case AutoHuntState::Paused: return "paused";
|
||||
}
|
||||
return "off";
|
||||
}
|
||||
|
||||
void AutoHunt::Start(float x, float z) {
|
||||
m_anchorX = x;
|
||||
m_anchorZ = z;
|
||||
m_target = 0;
|
||||
m_moving = false;
|
||||
m_ignoreUntil.clear();
|
||||
m_state = AutoHuntState::Search;
|
||||
m_stateSince = 0;
|
||||
m_lastManual = 0;
|
||||
}
|
||||
|
||||
void AutoHunt::Stop() {
|
||||
m_state = AutoHuntState::Off;
|
||||
m_target = 0;
|
||||
m_moving = false;
|
||||
}
|
||||
|
||||
void AutoHunt::Enter(AutoHuntState state, uint32_t now) {
|
||||
m_state = state;
|
||||
m_stateSince = now;
|
||||
m_lastProgress = now;
|
||||
m_bestDistance = 1e30f;
|
||||
}
|
||||
|
||||
bool AutoHunt::Ignored(uint32_t vid, uint32_t now) const {
|
||||
auto it = m_ignoreUntil.find(vid);
|
||||
return it != m_ignoreUntil.end() && now < it->second;
|
||||
}
|
||||
|
||||
const AutoHuntMob* AutoHunt::FindMob(const AutoHuntInput& in, uint32_t vid) const {
|
||||
for (const auto& mob : in.mobs)
|
||||
if (mob.vid == vid) return &mob;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Nearest living mob inside the hunt area.
|
||||
const AutoHuntMob* AutoHunt::PickMob(const AutoHuntInput& in) const {
|
||||
const AutoHuntMob* best = nullptr;
|
||||
float bestDistance = 0;
|
||||
for (const auto& mob : in.mobs) {
|
||||
if (mob.stone && !options.attackStones) continue;
|
||||
if (Ignored(mob.vid, in.now)) continue;
|
||||
if (Distance(mob.x, mob.z, m_anchorX, m_anchorZ) > options.radius) continue;
|
||||
const float d = Distance(mob.x, mob.z, in.x, in.z);
|
||||
if (!best || d < bestDistance) { best = &mob; bestDistance = d; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
const AutoHuntItem* AutoHunt::PickItem(const AutoHuntInput& in) const {
|
||||
if (!options.pickUp) return nullptr;
|
||||
const AutoHuntItem* best = nullptr;
|
||||
float bestDistance = 0;
|
||||
for (const auto& item : in.items) {
|
||||
if (Ignored(item.vid, in.now)) continue;
|
||||
if (Distance(item.x, item.z, m_anchorX, m_anchorZ) > options.radius) continue;
|
||||
const float d = Distance(item.x, item.z, in.x, in.z);
|
||||
if (!best || d < bestDistance) { best = &item; bestDistance = d; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
void AutoHunt::GoTo(AutoHuntOutput& out, float x, float z, uint32_t now) {
|
||||
if (m_moving && now - m_lastPath < kRepathGap) return;
|
||||
out.move = AutoHuntOutput::Move::Go;
|
||||
out.moveX = x;
|
||||
out.moveZ = z;
|
||||
m_moving = true;
|
||||
m_lastPath = now;
|
||||
}
|
||||
|
||||
void AutoHunt::Halt(AutoHuntOutput& out) {
|
||||
if (!m_moving) return;
|
||||
out.move = AutoHuntOutput::Move::Stop;
|
||||
m_moving = false;
|
||||
}
|
||||
|
||||
void AutoHunt::Potions(const AutoHuntInput& in, AutoHuntOutput& out) {
|
||||
if (in.now - m_lastPotion < kPotionGap && m_lastPotion != 0) return;
|
||||
if (options.hpPercent > 0 && in.hpPercent < options.hpPercent && in.hpSlotUsable)
|
||||
out.useQuickSlot = options.hpSlot;
|
||||
else if (options.spPercent > 0 && in.spPercent < options.spPercent && in.spSlotUsable)
|
||||
out.useQuickSlot = options.spSlot;
|
||||
if (out.useQuickSlot >= 0) m_lastPotion = in.now;
|
||||
}
|
||||
|
||||
AutoHuntOutput AutoHunt::Update(const AutoHuntInput& in) {
|
||||
AutoHuntOutput out;
|
||||
if (m_state == AutoHuntState::Off) return out;
|
||||
const uint32_t now = in.now;
|
||||
if (in.dead) {
|
||||
Halt(out);
|
||||
Stop();
|
||||
out.stopped = true;
|
||||
return out;
|
||||
}
|
||||
Potions(in, out);
|
||||
|
||||
// Manual input wins; hunting resumes where the player left off.
|
||||
if (in.manual) {
|
||||
m_lastManual = now;
|
||||
if (m_state != AutoHuntState::Paused) {
|
||||
Enter(AutoHuntState::Paused, now);
|
||||
m_moving = false; // the player's own input owns the actor now
|
||||
m_target = 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
if (m_state == AutoHuntState::Paused) {
|
||||
if (now - m_lastManual < kResumeDelay) return out;
|
||||
m_anchorX = in.x;
|
||||
m_anchorZ = in.z;
|
||||
Enter(AutoHuntState::Search, now);
|
||||
}
|
||||
if (!in.canAct) return out;
|
||||
|
||||
for (auto it = m_ignoreUntil.begin(); it != m_ignoreUntil.end();)
|
||||
it = now >= it->second ? m_ignoreUntil.erase(it) : std::next(it);
|
||||
|
||||
// Progress watchdog for anything we walk to: give up when the distance stops shrinking.
|
||||
auto chase = [&](float distance, uint32_t vid) {
|
||||
if (distance < m_bestDistance - 50.0f) {
|
||||
m_bestDistance = distance;
|
||||
m_lastProgress = now;
|
||||
} else if (now - m_lastProgress > kChaseTimeout) {
|
||||
if (vid) m_ignoreUntil[vid] = now + kIgnoreTime;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if (m_state == AutoHuntState::Engage) {
|
||||
const AutoHuntMob* mob = FindMob(in, m_target);
|
||||
if (!mob || (mob->stone && !options.attackStones)) {
|
||||
// Killed (or gone): collect the drop before the next target.
|
||||
m_target = 0;
|
||||
const AutoHuntItem* item = PickItem(in);
|
||||
if (item) {
|
||||
m_target = item->vid;
|
||||
Enter(AutoHuntState::Loot, now);
|
||||
} else {
|
||||
Enter(AutoHuntState::Search, now);
|
||||
}
|
||||
} else if (Distance(mob->x, mob->z, m_anchorX, m_anchorZ) > options.radius * 1.5f) {
|
||||
m_target = 0;
|
||||
Enter(AutoHuntState::Return, now);
|
||||
} else {
|
||||
const float distance = Distance(mob->x, mob->z, in.x, in.z);
|
||||
if (distance <= in.attackRange + mob->radius) {
|
||||
Halt(out);
|
||||
out.attack = mob->vid;
|
||||
m_lastProgress = now;
|
||||
if (options.useSkills && !in.busy && !in.readySkillSlots.empty() &&
|
||||
(m_lastSkill == 0 || now - m_lastSkill >= kSkillGap)) {
|
||||
out.skillSlot = in.readySkillSlots.front();
|
||||
m_lastSkill = now;
|
||||
}
|
||||
} else if (chase(distance, mob->vid)) {
|
||||
GoTo(out, mob->x, mob->z, now);
|
||||
} else {
|
||||
m_target = 0;
|
||||
Halt(out);
|
||||
Enter(AutoHuntState::Search, now);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_state == AutoHuntState::Loot) {
|
||||
const AutoHuntItem* item = nullptr;
|
||||
for (const auto& candidate : in.items)
|
||||
if (candidate.vid == m_target) item = &candidate;
|
||||
if (!item || Ignored(m_target, now)) {
|
||||
m_target = 0;
|
||||
Enter(AutoHuntState::Search, now);
|
||||
} else {
|
||||
const float distance = Distance(item->x, item->z, in.x, in.z);
|
||||
if (distance <= kPickRange) {
|
||||
Halt(out);
|
||||
if (m_lastPick == 0 || now - m_lastPick >= kPickGap) {
|
||||
out.pick = item->vid;
|
||||
m_lastPick = now;
|
||||
}
|
||||
// Inventory full / someone else's drop: the server keeps refusing.
|
||||
if (now - m_stateSince > 5000) m_ignoreUntil[item->vid] = now + kIgnoreTime;
|
||||
} else if (chase(distance, item->vid)) {
|
||||
GoTo(out, item->x, item->z, now);
|
||||
} else {
|
||||
m_target = 0;
|
||||
Halt(out);
|
||||
Enter(AutoHuntState::Search, now);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_state == AutoHuntState::Return) {
|
||||
if (!PickMob(in)) {
|
||||
const float distance = Distance(m_anchorX, m_anchorZ, in.x, in.z);
|
||||
if (distance <= kPickRange) {
|
||||
Halt(out);
|
||||
Enter(AutoHuntState::Search, now);
|
||||
} else if (chase(distance, 0)) {
|
||||
GoTo(out, m_anchorX, m_anchorZ, now);
|
||||
return out;
|
||||
} else {
|
||||
// Cannot get back (blocked): hunt from here instead.
|
||||
Halt(out);
|
||||
m_anchorX = in.x;
|
||||
m_anchorZ = in.z;
|
||||
Enter(AutoHuntState::Search, now);
|
||||
}
|
||||
} else {
|
||||
Enter(AutoHuntState::Search, now);
|
||||
}
|
||||
}
|
||||
|
||||
// Search
|
||||
if (const AutoHuntMob* mob = PickMob(in)) {
|
||||
m_target = mob->vid;
|
||||
out.target = mob->vid;
|
||||
Enter(AutoHuntState::Engage, now);
|
||||
const float distance = Distance(mob->x, mob->z, in.x, in.z);
|
||||
m_bestDistance = distance;
|
||||
if (distance <= in.attackRange + mob->radius) {
|
||||
Halt(out);
|
||||
out.attack = mob->vid;
|
||||
} else {
|
||||
GoTo(out, mob->x, mob->z, now);
|
||||
}
|
||||
} else if (const AutoHuntItem* item = PickItem(in)) {
|
||||
m_target = item->vid;
|
||||
Enter(AutoHuntState::Loot, now);
|
||||
GoTo(out, item->x, item->z, now);
|
||||
} else if (Distance(m_anchorX, m_anchorZ, in.x, in.z) > kPickRange * 2) {
|
||||
Enter(AutoHuntState::Return, now);
|
||||
GoTo(out, m_anchorX, m_anchorZ, now);
|
||||
} else {
|
||||
Halt(out);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace ava2
|
||||
@@ -0,0 +1,112 @@
|
||||
// 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
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "game_type.h"
|
||||
#include "guild_state.h"
|
||||
#include "skill_cooldown.h"
|
||||
#include "auto_hunt.h"
|
||||
#include "python_system.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_render/TerrainHeightmap.h"
|
||||
@@ -37,6 +39,7 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -1103,6 +1106,106 @@ bool ProcessPlayerAttack(float cameraYaw, float frameDt, bool wasMoving) {
|
||||
return stopSent;
|
||||
}
|
||||
|
||||
// Mobile step 6 auto hunt (src/game/auto_hunt.h). Fills the logic's view of the world from the
|
||||
// same state manual play uses and carries out its decisions through the manual paths: actor move
|
||||
// target (main.cpp sends the move packets), PlayerNewAttack (= held attack key), ClickSkillSlot,
|
||||
// the pick-up packet and quickslot use.
|
||||
static AutoHunt s_autoHunt;
|
||||
|
||||
static bool IsAutoHuntSkillReady(int skillSlot, float now) {
|
||||
auto it = s_playerSkills.find(skillSlot);
|
||||
if (it == s_playerSkills.end() || it->second.index == 0 || it->second.level <= 0) return false;
|
||||
const int index = it->second.index;
|
||||
if (index == 121 || index == 122 || index == 123) return false; // fishing / combo
|
||||
if (GetSkillTypeById(uint32_t(index)) == 3 /* SKILL_TYPE_GUILD */) return false;
|
||||
if (it->second.cooldown.cooling(now, s_coolTimeEnabled)) return false;
|
||||
const auto* data = FindSkillDescription(uint32_t(index));
|
||||
const bool toggle = data && (data->attributes & (1u << 1 /* SKILL_ATTRIBUTE_TOGGLE */));
|
||||
return !(toggle && it->second.active);
|
||||
}
|
||||
|
||||
static bool IsAutoHuntPotionSlot(int global) {
|
||||
if (global < 0 || global >= int(s_playerQuickSlots.size())) return false;
|
||||
const auto& quick = s_playerQuickSlots[global];
|
||||
return quick.type == 1 /* SLOT_TYPE_INVENTORY */ && GetPlayerItemData(1, uint16_t(quick.pos)).count > 0;
|
||||
}
|
||||
|
||||
static int PointPercent(int cur, int max) {
|
||||
auto c = s_playerPoints.find(cur), m = s_playerPoints.find(max);
|
||||
if (c == s_playerPoints.end() || m == s_playerPoints.end() || m->second <= 0) return 100;
|
||||
return int(c->second * 100 / m->second);
|
||||
}
|
||||
|
||||
void ProcessAutoHunt() {
|
||||
if (!s_autoHunt.IsOn()) return;
|
||||
auto& manager = NetworkActorManager::Instance();
|
||||
auto* main = manager.GetMainInstance();
|
||||
if (!main || !main->m_pActorInstance) return;
|
||||
auto& inst = *main->m_pActorInstance;
|
||||
|
||||
AutoHuntInput in;
|
||||
in.now = GetServerMSec();
|
||||
in.x = inst.GetX();
|
||||
in.z = inst.GetZ();
|
||||
in.dead = inst.IsDead();
|
||||
in.canAct = inst.CanAct();
|
||||
in.busy = inst.IsAttacking() || inst.IsUsingSkill();
|
||||
float yaw;
|
||||
in.manual = s_isAtkKey || GetPlayerMovementYaw(0.0f, yaw) || IsPlayerMouseMoving();
|
||||
in.hpPercent = PointPercent(5 /* POINT_HP */, 6 /* POINT_MAX_HP */);
|
||||
in.spPercent = PointPercent(7 /* POINT_SP */, 8 /* POINT_MAX_SP */);
|
||||
in.attackRange = inst.IsBowMode() ? 900.0f : 150.0f;
|
||||
in.hpSlotUsable = IsAutoHuntPotionSlot(s_autoHunt.options.hpSlot);
|
||||
in.spSlotUsable = IsAutoHuntPotionSlot(s_autoHunt.options.spSlot);
|
||||
for (const auto& [vid, actor] : manager.GetActorDict()) {
|
||||
if (vid == main->m_dwVID || !actor.m_pActorInstance) continue;
|
||||
if (actor.m_bType != 0 && actor.m_bType != 2) continue; // TYPE_ENEMY / TYPE_STONE
|
||||
const auto& v = *actor.m_pActorInstance;
|
||||
if (v.IsDead()) continue;
|
||||
in.mobs.push_back({vid, v.GetX(), v.GetZ(), v.GetDefendingRadius(), actor.m_bType == 2});
|
||||
}
|
||||
for (const auto& [vid, item] : CPythonItem::Instance().GetGroundItems()) {
|
||||
if (!item->stOwnership.empty() && item->stOwnership != s_playerName) continue;
|
||||
in.items.push_back({vid, item->v3EndPosition.x, -item->v3EndPosition.y});
|
||||
}
|
||||
// The combat wheel shows quickslot pages 1-3 (ui_mobile_combat.py); page 4 is the potion belt.
|
||||
const float nowSec = CTimer::Instance().GetCurrentSecond();
|
||||
const int page = s_quickPage < 3 ? s_quickPage : 0;
|
||||
for (int local = 0; local < 8; ++local) {
|
||||
const auto& quick = s_playerQuickSlots[page * 8 + local];
|
||||
if (quick.type == 2 /* SLOT_TYPE_SKILL */ && IsAutoHuntSkillReady(quick.pos, nowSec))
|
||||
in.readySkillSlots.push_back(quick.pos);
|
||||
}
|
||||
|
||||
const AutoHuntOutput out = s_autoHunt.Update(in);
|
||||
if (out.move == AutoHuntOutput::Move::Go) {
|
||||
inst.SetMoveTarget(out.moveX, out.moveZ);
|
||||
} else if (out.move == AutoHuntOutput::Move::Stop) {
|
||||
inst.ClearMoveTarget();
|
||||
inst.StopMoving();
|
||||
}
|
||||
if (out.useQuickSlot >= 0) use_global_quick_slot(out.useQuickSlot);
|
||||
if (out.target && out.target != s_targetVID) {
|
||||
s_targetVID = out.target;
|
||||
PythonNetworkStream::Instance().SendTargetPacket(out.target);
|
||||
}
|
||||
if (out.attack) {
|
||||
if (const auto* victim = manager.GetActorData(out.attack); victim && victim->m_pActorInstance) {
|
||||
if (!inst.IsAttacking()) {
|
||||
const float dx = victim->m_pActorInstance->GetX() - inst.GetX();
|
||||
const float dz = victim->m_pActorInstance->GetZ() - inst.GetZ();
|
||||
inst.SetYaw(std::fmod(std::atan2(dx, dz) * 180.0f / 3.14159265f + 360.0f, 360.0f));
|
||||
}
|
||||
if (out.skillSlot >= 0) ClickSkillSlot(out.skillSlot);
|
||||
else PlayerNewAttack();
|
||||
}
|
||||
}
|
||||
if (out.pick) PythonNetworkStream::Instance().SendItemPickUpPacket(out.pick);
|
||||
if (out.stopped) player_window_call("OnAutoHuntStopped");
|
||||
}
|
||||
|
||||
bool IsAutoHuntOn() { return s_autoHunt.IsOn(); }
|
||||
|
||||
static float s_fCmrRotSpd = 0.0f;
|
||||
static uint32_t s_inGuildAreaID = 0xffffffff;
|
||||
|
||||
@@ -3524,6 +3627,93 @@ static PyObject* player_GetItemUnSealLeftTime(PyObject*, PyObject*) {
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
// Mobile step 6 auto hunt (ui_mobile_autohunt.py). Not in the original player module.
|
||||
static void auto_hunt_load();
|
||||
static PyObject* player_SetAutoHunt(PyObject*, PyObject* args) {
|
||||
int on = 0;
|
||||
if (!PyArg_ParseTuple(args, "i", &on)) return nullptr;
|
||||
auto_hunt_load();
|
||||
if (on && !s_autoHunt.IsOn()) {
|
||||
const auto* main = NetworkActorManager::Instance().GetMainInstance();
|
||||
if (main && main->m_pActorInstance) s_autoHunt.Start(main->m_pActorInstance->GetX(), main->m_pActorInstance->GetZ());
|
||||
} else if (!on && s_autoHunt.IsOn()) {
|
||||
s_autoHunt.Stop();
|
||||
if (auto* main = NetworkActorManager::Instance().GetMainInstance(); main && main->m_pActorInstance) {
|
||||
main->m_pActorInstance->ClearMoveTarget();
|
||||
main->m_pActorInstance->StopMoving();
|
||||
}
|
||||
}
|
||||
return PyInt_FromLong(s_autoHunt.IsOn());
|
||||
}
|
||||
static PyObject* player_IsAutoHunt(PyObject*, PyObject*) { return PyInt_FromLong(s_autoHunt.IsOn()); }
|
||||
static PyObject* player_GetAutoHuntState(PyObject*, PyObject*) {
|
||||
return Py_BuildValue("(si)", AutoHuntStateName(s_autoHunt.GetState()), int(s_autoHunt.GetTarget()));
|
||||
}
|
||||
static int* auto_hunt_int_option(const std::string& name) {
|
||||
auto& o = s_autoHunt.options;
|
||||
if (name == "hp_percent") return &o.hpPercent;
|
||||
if (name == "sp_percent") return &o.spPercent;
|
||||
if (name == "hp_slot") return &o.hpSlot;
|
||||
if (name == "sp_slot") return &o.spSlot;
|
||||
return nullptr;
|
||||
}
|
||||
static bool* auto_hunt_bool_option(const std::string& name) {
|
||||
auto& o = s_autoHunt.options;
|
||||
if (name == "skills") return &o.useSkills;
|
||||
if (name == "pickup") return &o.pickUp;
|
||||
if (name == "stones") return &o.attackStones;
|
||||
return nullptr;
|
||||
}
|
||||
// autohunt.cfg next to metin2.cfg (CPythonSystem config directory), "name value" per line.
|
||||
static std::string auto_hunt_config_path() {
|
||||
std::string directory = CPythonSystem::GetConfigDirectory();
|
||||
if (!directory.empty() && directory.back() != '/' && directory.back() != '\\') directory += '/';
|
||||
return directory + "autohunt.cfg";
|
||||
}
|
||||
static void auto_hunt_set(const std::string& name, int value) {
|
||||
if (name == "radius") s_autoHunt.options.radius = float(std::clamp(value, 300, 5000));
|
||||
else if (int* i = auto_hunt_int_option(name)) *i = name == "hp_slot" || name == "sp_slot" ? std::clamp(value, 0, 31) : std::clamp(value, 0, 100);
|
||||
else if (bool* b = auto_hunt_bool_option(name)) *b = value != 0;
|
||||
}
|
||||
static void auto_hunt_load() {
|
||||
static bool loaded = false;
|
||||
if (loaded) return;
|
||||
loaded = true;
|
||||
std::ifstream file(auto_hunt_config_path());
|
||||
std::string name; int value;
|
||||
while (file >> name >> value) auto_hunt_set(name, value);
|
||||
}
|
||||
static void auto_hunt_save() {
|
||||
const auto& o = s_autoHunt.options;
|
||||
std::ofstream file(auto_hunt_config_path(), std::ios::trunc);
|
||||
file << "radius " << int(o.radius) << "\nskills " << o.useSkills << "\npickup " << o.pickUp
|
||||
<< "\nstones " << o.attackStones << "\nhp_percent " << o.hpPercent << "\nsp_percent " << o.spPercent
|
||||
<< "\nhp_slot " << o.hpSlot << "\nsp_slot " << o.spSlot << "\n";
|
||||
}
|
||||
static PyObject* player_SetAutoHuntOption(PyObject*, PyObject* args) {
|
||||
char* name = nullptr; int value = 0;
|
||||
if (!PyArg_ParseTuple(args, "si", &name, &value)) return nullptr;
|
||||
const std::string key(name);
|
||||
if (key != "radius" && !auto_hunt_int_option(key) && !auto_hunt_bool_option(key)) {
|
||||
PyErr_Format(PyExc_KeyError, "%s", name);
|
||||
return nullptr;
|
||||
}
|
||||
auto_hunt_load();
|
||||
auto_hunt_set(key, value);
|
||||
auto_hunt_save();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject* player_GetAutoHuntOption(PyObject*, PyObject* args) {
|
||||
char* name = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s", &name)) return nullptr;
|
||||
auto_hunt_load();
|
||||
if (std::string(name) == "radius") return PyInt_FromLong(long(s_autoHunt.options.radius));
|
||||
if (int* i = auto_hunt_int_option(name)) return PyInt_FromLong(*i);
|
||||
if (bool* b = auto_hunt_bool_option(name)) return PyInt_FromLong(*b);
|
||||
PyErr_Format(PyExc_KeyError, "%s", name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void initPlayer() {
|
||||
static PyMethodDef methods[] = {
|
||||
{"GetAutoPotionInfo", player_GetAutoPotionInfo, METH_VARARGS, nullptr},
|
||||
@@ -3691,6 +3881,11 @@ void initPlayer() {
|
||||
{"GetGem", player_GetGem, METH_VARARGS, nullptr},
|
||||
{"SetEventGame", player_SetEventGame, METH_VARARGS, nullptr},
|
||||
{"GetEventGame", player_GetEventGame, METH_VARARGS, nullptr},
|
||||
{"SetAutoHunt", player_SetAutoHunt, METH_VARARGS, nullptr},
|
||||
{"IsAutoHunt", player_IsAutoHunt, METH_VARARGS, nullptr},
|
||||
{"GetAutoHuntState", player_GetAutoHuntState, METH_VARARGS, nullptr},
|
||||
{"SetAutoHuntOption", player_SetAutoHuntOption, METH_VARARGS, nullptr},
|
||||
{"GetAutoHuntOption", player_GetAutoHuntOption, METH_VARARGS, nullptr},
|
||||
{nullptr, nullptr, 0, nullptr}
|
||||
};
|
||||
NetworkActorManager::SetPartyMemberQuery(IsPartyMemberByVID);
|
||||
|
||||
@@ -99,6 +99,10 @@ void SetPlayerAttackKey(bool pressed);
|
||||
bool ProcessPlayerAttack(float cameraYaw, float frameDt, bool wasMoving);
|
||||
// The main actor is playing an attack motion (movement input is ignored meanwhile).
|
||||
bool IsPlayerAttacking();
|
||||
// Mobile auto hunt (src/game/auto_hunt.h), per frame before ProcessPlayerAttack: steers the main
|
||||
// actor and presses attack / skills / pick-up while player.SetAutoHunt(1) is on.
|
||||
void ProcessAutoHunt();
|
||||
bool IsAutoHuntOn();
|
||||
// True when handler is the window passed to player.SetGameWindow (game.GameWindow).
|
||||
bool IsPlayerGameWindow(const void* handler);
|
||||
void SetWeaponPower(uint32_t dwMinPower, uint32_t dwMaxPower, uint32_t dwMinMagicPower, uint32_t dwMaxMagicPower, uint32_t dwAddPower);
|
||||
|
||||
@@ -397,6 +397,8 @@ public:
|
||||
void Update() {}
|
||||
void Render() {}
|
||||
|
||||
// Port addition for the auto hunt driver (python_gameplay_modules.cpp ProcessAutoHunt).
|
||||
const TGroundItemInstanceMap& GetGroundItems() const { return m_GroundItemInstanceMap; }
|
||||
void GetInfo(std::string* pstInfo) {
|
||||
if (pstInfo) {
|
||||
pstInfo->append("Item: Inst " + std::to_string(m_GroundItemInstanceMap.size()));
|
||||
|
||||
Reference in New Issue
Block a user