Level 120: autohunt large targets, boss hit range, QUEST_INFO size

- QUEST_INFO: take the full packet size from the flags (server built it short)
- Bosses get the huge-race 500 centre hit test, like AVA2 IsBoss()
- Autohunt: defending reach as body size for large targets, walk straight
  at a body in reach when the planner finds no path, escalating skip for a
  target it keeps stalling on, new anchor after a teleport, immune skip only
  on an explicit 0-damage packet
- ava2-dungeons README: hydra range notes, snow key stack note

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-17 11:59:54 +09:00
co-authored by Claude Opus 5.5
parent a1e7da68a4
commit 569afb1378
11 changed files with 189 additions and 43 deletions
+1
View File
@@ -936,6 +936,7 @@ void CActorInstance::__Initialize()
m_eActorType = TYPE_PC;
m_eRace = 0;
m_bRankIndex = 0;
m_eShape = 0;
m_eHair = 0;
+7
View File
@@ -267,6 +267,10 @@ class CActorInstance : public IActorInstance, public IFlyTargetableObject
bool IsNPC();
bool IsEnemy();
bool IsStone();
// PORT: AVA2 - mob_proto rank; bosses (>= 4) are attacked like IS_HUGE_RACE.
bool IsBoss() { return m_bRankIndex >= 4; }
BYTE GetRank() { return m_bRankIndex; }
void SetRank(BYTE bNewRank) { m_bRankIndex = bNewRank; }
bool IsWarp();
bool IsGoto();
bool IsObject();
@@ -326,6 +330,8 @@ class CActorInstance : public IActorInstance, public IFlyTargetableObject
void UpdateAdvancingPointInstance();
BOOL IsClickableDistanceDestInstance(CActorInstance & rkInstDst, float fDistance);
// PORT: farthest ground distance from the actor's position to the edge of a defending sphere.
float GetDefendingReach();
bool AvoidObject(const CGraphicObjectInstance& c_rkBGObj);
bool IsBlockObject(const CGraphicObjectInstance& c_rkBGObj);
@@ -723,6 +729,7 @@ class CActorInstance : public IActorInstance, public IFlyTargetableObject
DWORD m_eActorType;
DWORD m_eRace;
BYTE m_bRankIndex;
DWORD m_eShape;
DWORD m_eHair;
BOOL m_isPreInput;
+18 -2
View File
@@ -145,6 +145,22 @@ BOOL CActorInstance::IsClickableDistanceDestInstance(CActorInstance & rkInstDst,
return FALSE;
}
float CActorInstance::GetDefendingReach()
{
TPixelPosition kPPos;
GetPixelPosition(&kPPos);
float fReach = 0.0f;
for (auto& rkPtInst : m_DefendingPointInstanceList)
for (auto& rkSphere : rkPtInst.SphereInstanceVector)
{
// Same frame as IsClickableDistanceDestInstance: the actor position and the spheres are both world space.
const float fGround = std::hypot(rkSphere.v3Position.x - kPPos.x, rkSphere.v3Position.y - kPPos.y);
fReach = std::max(fReach, fGround + rkSphere.fRadius);
}
return fReach;
}
void CActorInstance::InputNormalAttackCommand(float fDirRot)
{
if (!__CanInputNormalAttackCommand())
@@ -569,7 +585,7 @@ bool CActorInstance::__CanPushDestActor(CActorInstance& rkActorDst)
// 거대 몬스터 밀림 제외
extern bool IS_HUGE_RACE(unsigned int vnum);
if (IS_HUGE_RACE(rkActorDst.GetRace()))
if (IS_HUGE_RACE(rkActorDst.GetRace()) || rkActorDst.IsBoss())
return false;
if (rkActorDst.IsStun())
@@ -643,7 +659,7 @@ void CActorInstance::__ProcessDataAttackSuccess(const NRaceData::TAttackData & c
// #0000780: [M2KR] 수룡 타격구 문제
extern bool IS_HUGE_RACE(unsigned int vnum);
if (IS_HUGE_RACE(rVictim.GetRace()))
if (IS_HUGE_RACE(rVictim.GetRace()) || rVictim.IsBoss())
{
vec3Effect = c_rv3Position;
}
@@ -338,7 +338,7 @@ BOOL CActorInstance::__NormalAttackProcess(CActorInstance & rVictim)
float fDistance = D3DXVec3LengthSq(&v3Distance);
extern bool IS_HUGE_RACE(unsigned int vnum);
if (IS_HUGE_RACE(rVictim.GetRace()))
if (IS_HUGE_RACE(rVictim.GetRace()) || rVictim.IsBoss())
{
if (fDistance >= 500.0f*500.0f)
return FALSE;
@@ -460,7 +460,7 @@ BOOL CActorInstance::__NormalAttackProcess(CActorInstance & rVictim)
// #0000780: [M2KR] 수룡 타격구 문제
extern bool IS_HUGE_RACE(unsigned int vnum);
if (IS_HUGE_RACE(rVictim.GetRace()))
if (IS_HUGE_RACE(rVictim.GetRace()) || rVictim.IsBoss())
{
v3HitPosition = (GetPosition() + sub.v3Position) * 0.5f;
}
+15 -7
View File
@@ -25,13 +25,22 @@ inline bool Segment(Point a, Point b, const Walkable& walkable) {
}
return true;
}
// The point `body` short of goal on the way from p: a large target's own cells (a hydra on the
// water) need not be walkable, only the line up to its edge.
inline Point Toward(Point p, Point goal, float body) {
const float d=Distance(p,goal);
if (body<=0 || d<=0) return goal;
if (d<=body) return p;
return {goal.x+(p.x-goal.x)*body/d, goal.y+(p.y-goal.y)*body/d};
}
// Empty means unreachable within the loaded data/search budget, never permission to walk straight.
inline std::vector<Point> FindPath(Point start, Point goal, float arrival, const Walkable& walkable,
int budget=3500) {
int budget=3500, float body=0.f) {
if (!std::isfinite(start.x) || !std::isfinite(start.y) || !std::isfinite(goal.x) ||
!std::isfinite(goal.y) || arrival < 0 || budget <= 0 || Distance(start,goal)>40000.f) return {};
if (Distance(start,goal) <= arrival && Segment(start,goal,walkable)) return {start};
if (Segment(start,goal,walkable)) return {goal};
!std::isfinite(goal.y) || arrival < 0 || body < 0 || budget <= 0 || Distance(start,goal)>40000.f) return {};
auto reaches=[&](Point p) { return Segment(p,Toward(p,goal,body),walkable); };
if (Distance(start,goal) <= arrival && reaches(start)) return {start};
if (reaches(start)) return {Toward(start,goal,body)};
constexpr float cell=100.f;
// Grid is relative to the exact starting position, so the first step cannot cross an unchecked edge.
const int extent = int(std::ceil(Distance(start,goal)/cell))+25;
@@ -61,8 +70,7 @@ inline std::vector<Point> FindPath(Point start, Point goal, float arrival, const
--budget;
const float cost=nodes[id].cost; // inserts below may rehash the map
const Point p=point(e.x,e.y);
if (Distance(p,goal)<=std::max(arrival,cell) &&
Segment(p,goal,walkable)) { finish=id; break; }
if (Distance(p,goal)<=std::max(arrival,cell) && reaches(p)) { finish=id; break; }
for (int dy=-1;dy<=1;++dy) for (int dx=-1;dx<=1;++dx) {
if (!dx && !dy) continue;
const int x=e.x+dx,y=e.y+dy;
@@ -82,7 +90,7 @@ inline std::vector<Point> FindPath(Point start, Point goal, float arrival, const
reverse.push_back(point(id%width-extent,id/width-extent));
std::reverse(reverse.begin(),reverse.end());
if (reverse.empty()) reverse.push_back(start);
if (Distance(reverse.back(),goal)>arrival) reverse.push_back(goal);
if (Distance(reverse.back(),goal)>arrival) reverse.push_back(Toward(reverse.back(),goal,body));
// Greedy line-of-sight smoothing, retaining every necessary turn.
std::vector<Point> result;
Point from=start;
+4
View File
@@ -842,6 +842,10 @@ bool CInstanceBase::Create(const SCreateData& c_rkCreateData)
m_GraphicThingInstance.ChangeMaterial(strFileName.c_str());
}
// PORT: AVA2 - a boss is hit like a huge race (CActorInstance::IsBoss).
const CPythonNonPlayer::TMobTable* pMobTable = CPythonNonPlayer::Instance().GetTable(GetRace());
if (pMobTable)
m_GraphicThingInstance.SetRank(pMobTable->bRank);
return true;
}
@@ -1915,7 +1915,18 @@ bool CPythonNetworkStream::RecvQuestInfoPacket()
return false;
}
if (!Peek(QuestInfo.size))
// The server writes the header before it adds the optional fields to size, so the size field
// cannot be trusted: wait for the whole packet as the flags describe it.
int iFullSize = sizeof(TPacketGCQuestInfo);
if (QuestInfo.flag & QUEST_SEND_IS_BEGIN) iFullSize += sizeof(BYTE);
if (QuestInfo.flag & QUEST_SEND_TITLE) iFullSize += 30 + 1;
if (QuestInfo.flag & QUEST_SEND_CLOCK_NAME) iFullSize += 16 + 1;
if (QuestInfo.flag & QUEST_SEND_CLOCK_VALUE) iFullSize += sizeof(int);
if (QuestInfo.flag & QUEST_SEND_COUNTER_NAME) iFullSize += 16 + 1;
if (QuestInfo.flag & QUEST_SEND_COUNTER_VALUE) iFullSize += sizeof(int);
if (QuestInfo.flag & QUEST_SEND_ICON_FILE) iFullSize += 24 + 1;
if (!Peek(std::max<int>(QuestInfo.size, iFullSize)))
{
Tracen("Recv Quest Info Packet Error #2");
return false;
+7 -4
View File
@@ -757,9 +757,10 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
bool __AutoHunt_CastSkill(DWORD slot, float now);
bool __AutoHunt_UpdateMount(CInstanceBase& main, float now);
bool __AutoHunt_UpdateRecovery(CInstanceBase& main, float now);
bool __AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path);
bool __AutoHunt_MoveTo(const TPixelPosition& goal, float arrival, float now);
bool __AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path, float body = 0.f);
bool __AutoHunt_MoveTo(const TPixelPosition& goal, float arrival, float now, float body = 0.f);
void __AutoHunt_ResetMovement();
void __AutoHunt_WalkAt(CInstanceBase& main, const TPixelPosition& goal, float now);
void __AutoHunt_MigrateSkills();
bool __AutoHunt_IsTargetAllowed(CInstanceBase& main, CInstanceBase& target); // PORT extension
DWORD __AutoHunt_FindCloseTarget(CInstanceBase& main, int* count = nullptr);
@@ -786,18 +787,19 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
TPixelPosition m_kAutoHuntPathGoal = {}, m_kAutoHuntPathLastPosition = {};
DWORD m_dwAutoHuntScanTarget = 0;
float m_fAutoHuntTargetScanTime = 0;
float m_fAutoHuntPathTime = 0, m_fAutoHuntPathMoveTime = 0;
float m_fAutoHuntPathTime = 0, m_fAutoHuntPathMoveTime = 0, m_fAutoHuntDirectUntil = 0;
SAutoHuntConfig m_kAutoHuntConfig;
bool m_isAutoHuntConfigLoaded;
int m_eAutoHuntState;
int m_eAutoHuntStopReason;
TPixelPosition m_kPPosAutoHuntAnchor;
TPixelPosition m_kPPosAutoHuntLast; // position at the previous update, to notice a teleport
std::string m_stAutoHuntMapName;
float m_fAutoHuntResumeTime;
DWORD m_dwAutoHuntTargetVID;
float m_fAutoHuntStateTime; // when the current target / item / state began
float m_fAutoHuntProgressTime; // last time the target got closer or was hit
float m_fAutoHuntFirstHitTime; // first hit on the target, 0 before it
float m_fAutoHuntFirstHitTime; // first blocked (damage 0) hit on the target, 0 before it
float m_fAutoHuntDamageTime; // last hit on the target that did damage
float m_fAutoHuntBestDistance;
float m_fAutoHuntNextActionTime;
@@ -807,6 +809,7 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
bool m_isAutoHuntNoHPPotion;
bool m_isAutoHuntNoSPPotion;
std::map<DWORD, float> m_kMap_dwAutoHuntSkipVID; // actor vid -> ignored until
std::map<DWORD, int> m_kMap_dwAutoHuntStallCount; // actor vid -> engagements that made no progress
std::map<DWORD, float> m_kMap_dwAutoHuntSkipItem; // ground item vid -> ignored until
bool m_isAutoHuntGathering;
float m_fAutoHuntGatherStartTime;
+107 -25
View File
@@ -17,6 +17,7 @@
#include "../EterBase/Timer.h"
#include <cmath>
#include <set>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
@@ -38,6 +39,8 @@ const float c_fAutoHuntNoProgressTime = 4.0f; // neither closer to the target no
const float c_fAutoHuntTargetTimeout = 60.0f;
const float c_fAutoHuntSkipTime = 30.0f; // an unreachable target is left alone this long
const float c_fAutoHuntNoDamageTime = 4.0f; // hitting a target that takes no damage (Meley's stone statues)
const float c_fAutoHuntTeleportDistance = 2000.0f; // one update's move past this is a teleport
const float c_fAutoHuntDirectReach = 600.0f; // how far past its body a large target is walked at without a path
const float c_fAutoHuntImmuneSkipTime = 60.0f; // such a target stays immune until the stage moves on
const float c_fAutoHuntLootDelay = 0.6f; // drops land a moment after the kill
const float c_fAutoHuntLootTimeout = 15.0f;
@@ -99,6 +102,7 @@ void CPythonPlayer::AutoHunt_SetEnabled(bool isEnable)
__AutoHunt_ResetMovement();
m_iAutoHuntMountState = 0;
pkInstMain->NEW_GetPixelPosition(&m_kPPosAutoHuntAnchor);
m_kPPosAutoHuntLast = m_kPPosAutoHuntAnchor;
m_stAutoHuntMapName = CPythonBackground::Instance().GetWarpMapName();
m_eAutoHuntState = AUTO_HUNT_SEARCH;
m_eAutoHuntStopReason = AUTO_HUNT_STOP_NONE;
@@ -111,6 +115,7 @@ void CPythonPlayer::AutoHunt_SetEnabled(bool isEnable)
m_isAutoHuntNoHPPotion = false;
m_isAutoHuntNoSPPotion = false;
m_kMap_dwAutoHuntSkipVID.clear();
m_kMap_dwAutoHuntStallCount.clear();
m_kMap_dwAutoHuntSkipItem.clear();
m_kSet_dwAutoHuntGathered.clear();
m_isAutoHuntGathering = false;
@@ -354,7 +359,6 @@ void CPythonPlayer::AutoHunt_OnHit(DWORD victim)
{
if (AutoHunt_IsEnabled() && m_eAutoHuntState == AUTO_HUNT_ENGAGE && victim == m_dwAutoHuntTargetVID) {
m_fAutoHuntProgressTime = CTimer::Instance().GetCurrentSecond();
if (!m_fAutoHuntFirstHitTime) m_fAutoHuntFirstHitTime = m_fAutoHuntProgressTime;
}
}
@@ -363,15 +367,29 @@ void CPythonPlayer::AutoHunt_OnDamage(DWORD victim, int damage)
{
if (!AutoHunt_IsEnabled() || victim != m_dwAutoHuntTargetVID) return;
AutoHuntTrace("damage %d on target %u", damage, unsigned(victim));
if (damage > 0) m_fAutoHuntDamageTime = CTimer::Instance().GetCurrentSecond();
// Only an explicit blocked hit starts the no-damage clock: a hit the server never answered says nothing.
const float now = CTimer::Instance().GetCurrentSecond();
if (damage > 0) m_fAutoHuntDamageTime = now;
else if (!m_fAutoHuntFirstHitTime) m_fAutoHuntFirstHitTime = now;
}
// How far short of a target's centre its body starts. Ordinary mobs give 0; a hydra on the water
// is attacked from the deck, so neither the path nor the line of sight has to enter its cells.
static float __AutoHunt_TargetBody(CInstanceBase& target)
{
return std::max(0.f, target.GetGraphicThingInstanceRef().GetDefendingReach() - 150.f);
}
bool CPythonPlayer::__AutoHunt_CanAttackHere(CInstanceBase& main, CInstanceBase& target)
{
if (main.IsInSafe() || !main.NEW_IsClickableDistanceDestInstance(target)) return false;
TPixelPosition goal; target.NEW_GetPixelPosition(&goal);
const float body = __AutoHunt_TargetBody(target);
// A large target's defending sphere is in reach once it is clickable; its edge is often over cells
// the player cannot enter (a hydra beside the deck), so there is no line to test.
if (body > 0.f) return true;
std::vector<TPixelPosition> line;
return __AutoHunt_BuildPath(goal, 0.f, line) && line.size() == 1 && PixelDistance(line.back(), goal) < 1.f;
return __AutoHunt_BuildPath(goal, 0.f, line, body) && line.size() == 1 && PixelDistance(line.back(), goal) <= body + 1.f;
}
DWORD CPythonPlayer::__AutoHunt_FindCloseTarget(CInstanceBase& main, int* count)
@@ -446,16 +464,25 @@ DWORD CPythonPlayer::__AutoHunt_FindTarget(CInstanceBase& rkInstMain, float fNow
TPixelPosition position; target->NEW_GetPixelPosition(&position);
if (PixelDistance(position,m_kPPosAutoHuntAnchor)<=m_kAutoHuntConfig.iRange) candidates.push_back(target);
}
// A large target is as near as its edge: a hydra beside the deck comes before the crew behind it.
// Keys are taken once; a body follows the animation and must not change during the sort.
std::map<CInstanceBase*,float> edge;
for (auto* target:candidates) edge[target]=rkInstMain.GetDistance(target)-__AutoHunt_TargetBody(*target);
std::sort(candidates.begin(),candidates.end(),[&](CInstanceBase* a,CInstanceBase* b) {
if (a->IsStone()!=b->IsStone()) return bool(a->IsStone());
return rkInstMain.GetDistance(a)<rkInstMain.GetDistance(b);
return edge[a]<edge[b];
});
int attempts=0;
for (auto* target:candidates) {
if (++attempts>4) break;
TPixelPosition goal; target->NEW_GetPixelPosition(&goal);
std::vector<TPixelPosition> path;
if (__AutoHunt_BuildPath(goal,100.f,path)) return m_dwAutoHuntScanTarget=target->GetVirtualID();
const float body=__AutoHunt_TargetBody(*target);
if (__AutoHunt_BuildPath(goal,100.f+body,path,body)) return m_dwAutoHuntScanTarget=target->GetVirtualID();
// Close to a large target the engage walks straight at it (see AUTO_HUNT_ENGAGE).
if (body>0.f && rkInstMain.GetDistance(target)<body+c_fAutoHuntDirectReach) return m_dwAutoHuntScanTarget=target->GetVirtualID();
AutoHuntTrace("no path to %u (race %u, distance %.0f, body %.0f)", unsigned(target->GetVirtualID()),
unsigned(target->GetRace()), rkInstMain.GetDistance(target), body);
m_kMap_dwAutoHuntSkipVID[target->GetVirtualID()]=fNow+5.f;
}
return 0;
@@ -478,7 +505,8 @@ DWORD CPythonPlayer::__AutoHunt_FindGatheredTarget(CInstanceBase& rkInstMain)
if (++attempts>4) break;
TPixelPosition goal; target->NEW_GetPixelPosition(&goal);
std::vector<TPixelPosition> path;
if (__AutoHunt_BuildPath(goal,100.f,path)) return target->GetVirtualID();
const float body=__AutoHunt_TargetBody(*target);
if (__AutoHunt_BuildPath(goal,100.f+body,path,body)) return target->GetVirtualID();
m_kMap_dwAutoHuntSkipVID[target->GetVirtualID()]=now+5.f;
}
return 0;
@@ -774,6 +802,22 @@ void CPythonPlayer::__Update_AutoHunt()
__AutoHunt_Stop(AUTO_HUNT_STOP_MAP);
return;
}
// A teleport inside the map (a dungeon moving its party to the next floor) starts a new hunt
// area there: the old anchor would leave every monster out of range.
{
TPixelPosition here; rkInstMain.NEW_GetPixelPosition(&here);
if (PixelDistance(here, m_kPPosAutoHuntLast) > c_fAutoHuntTeleportDistance)
{
AutoHuntTrace("teleported %.0f; new anchor %.0f,%.0f", PixelDistance(here, m_kPPosAutoHuntLast), here.x, here.y);
__ClearReservedAction(); __ClearAutoAttackTargetActorID(); __AutoHunt_ResetMovement();
m_kPPosAutoHuntAnchor = here;
m_dwAutoHuntTargetVID = 0; m_dwAutoHuntItemID = 0;
m_kMap_dwAutoHuntSkipVID.clear(); m_kMap_dwAutoHuntStallCount.clear(); m_kMap_dwAutoHuntSkipItem.clear();
m_eAutoHuntState = AUTO_HUNT_SEARCH;
m_fAutoHuntStateTime = fNow;
}
m_kPPosAutoHuntLast = here;
}
if (rkInstMain.IsDead()) {
AutoHunt_OnDeath();
@@ -967,7 +1011,9 @@ void CPythonPlayer::__Update_AutoHunt()
fNow - m_fAutoHuntStateTime > c_fAutoHuntTargetTimeout)
{
if (isImmune) AutoHuntTrace("target %u takes no damage; skipped", unsigned(m_dwAutoHuntTargetVID));
m_kMap_dwAutoHuntSkipVID[m_dwAutoHuntTargetVID] = fNow + (isImmune ? c_fAutoHuntImmuneSkipTime : 3.f);
// A target that keeps stalling (two out of reach alternate forever otherwise) waits longer each time.
const int stalls = std::min(++m_kMap_dwAutoHuntStallCount[m_dwAutoHuntTargetVID], 5);
m_kMap_dwAutoHuntSkipVID[m_dwAutoHuntTargetVID] = fNow + (isImmune ? c_fAutoHuntImmuneSkipTime : 3.f * (1 << (stalls - 1)));
m_fAutoHuntCrowdUntil = fNow + 3.f;
__ClearAutoAttackTargetActorID();
__ClearReservedAction(); __AutoHunt_ResetMovement(); rkInstMain.NEW_Stop();
@@ -982,7 +1028,19 @@ void CPythonPlayer::__Update_AutoHunt()
if (__AutoHunt_CanAttackHere(rkInstMain, *pkInstVictim)) {
if (!m_vecAutoHuntPath.empty()) rkInstMain.NEW_Stop();
__AutoHunt_ResetMovement();
} else if (!__AutoHunt_MoveTo(goal,100.f,fNow)) {
} else if (const float body=__AutoHunt_TargetBody(*pkInstVictim); body>0.f && fNow<m_fAutoHuntDirectUntil) {
__AutoHunt_WalkAt(rkInstMain, goal, fNow);
return;
} else if (!__AutoHunt_MoveTo(goal,100.f+body,fNow,body)) {
// No planned way to a large target's edge (deck rails, water): walk straight at it. Movement
// collision stops the player at the edge, and the no-progress clock gives up from there.
if (body>0.f && rkInstMain.GetDistance(pkInstVictim)<body+c_fAutoHuntDirectReach) {
AutoHuntTrace("walking straight at %u (distance %.0f, body %.0f)", unsigned(m_dwAutoHuntTargetVID), fDistance, body);
__AutoHunt_ResetMovement();
m_fAutoHuntDirectUntil=fNow+1.f;
__AutoHunt_WalkAt(rkInstMain, goal, fNow);
return;
}
m_kMap_dwAutoHuntSkipVID[m_dwAutoHuntTargetVID]=fNow+c_fAutoHuntSkipTime;
__ClearAutoAttackTargetActorID(); __ClearReservedAction(); rkInstMain.NEW_Stop();
m_dwAutoHuntTargetVID=0; m_eAutoHuntState=AUTO_HUNT_SEARCH; return;
@@ -1076,6 +1134,16 @@ void CPythonPlayer::__Update_AutoHunt()
}
}
void CPythonPlayer::__AutoHunt_WalkAt(CInstanceBase& main, const TPixelPosition& goal, float now)
{
__ClearAutoAttackTargetActorID();
__ClearReservedAction();
if (!main.IsUsingSkill() && now>=m_fAutoHuntPathMoveTime) {
m_fAutoHuntPathMoveTime=now+0.5f;
main.NEW_MoveToDestPixelPositionDirection(goal);
}
}
void CPythonPlayer::__AutoHunt_ResetMovement()
{
m_vecAutoHuntPath.clear();
@@ -1085,35 +1153,49 @@ void CPythonPlayer::__AutoHunt_ResetMovement()
m_fAutoHuntTargetScanTime=0;
}
bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path)
bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path, float body)
{
auto* main=NEW_GetMainActorPtr();
auto& background=CPythonBackground::Instance();
if (!main || !background.IsMapReady()) return false;
TPixelPosition start; main->NEW_GetPixelPosition(&start);
const float bound=std::max(float(m_kAutoHuntConfig.iRange),PixelDistance(start,m_kPPosAutoHuntAnchor))+200.f;
struct CollisionProbe {
CDynamicSphereInstance sphere;
const std::set<CGraphicObjectInstance*>* ignore=nullptr;
std::set<CGraphicObjectInstance*>* hits=nullptr;
bool blocked=false;
void operator()(CGraphicObjectInstance* object) {
if (blocked || !object || (ignore && ignore->count(object)) || !object->CollisionDynamicSphere(sphere)) return;
if (hits) hits->insert(object); else blocked=true;
}
};
auto probeAt=[&](float x,float y,CollisionProbe& probe) {
const float height=background.GetHeight(x,y);
probe.sphere.v3Position=D3DXVECTOR3(x,-y,height+50.f);
probe.sphere.v3LastPosition=probe.sphere.v3Position;
probe.sphere.fRadius=25.f;
CCullingManager::Instance().ForInRange(Vector3d(x,-y,height+50.f),100.f,&probe);
};
// Volumes the player already stands in (a large monster's own collision) do not block: the
// client's movement test only stops a sphere entering one.
std::set<CGraphicObjectInstance*> around;
{ CollisionProbe probe; probe.hits=&around; probeAt(start.x,start.y,probe); }
auto walkable=[&](AutoHuntNavigation::Point p) {
if (std::hypot(p.x-m_kPPosAutoHuntAnchor.x,p.y-m_kPPosAutoHuntAnchor.y)>bound) return false;
// Where the player already stands is walkable whatever the attribute map says (a ship's deck
// over blocked water).
if (std::hypot(p.x-start.x,p.y-start.y)<1.f) return true;
// Missing/unloaded terrain is not a traversable cell. A small footprint keeps turns off wall edges.
for (const auto offset : {AutoHuntNavigation::Point{0,0}, {25,0}, {-25,0}, {0,25}, {0,-25}}) {
BYTE attr=0;
if (!background.GetAttr(p.x+offset.x,p.y+offset.y,&attr) || (attr&CTerrainImpl::ATTRIBUTE_BLOCK)) return false;
}
struct CollisionProbe {
CDynamicSphereInstance sphere;
bool blocked=false;
void operator()(CGraphicObjectInstance* object) {
if (!blocked && object && object->CollisionDynamicSphere(sphere)) blocked=true;
}
} probe;
const float height=background.GetHeight(p.x,p.y);
probe.sphere.v3Position=D3DXVECTOR3(p.x,-p.y,height+50.f);
probe.sphere.v3LastPosition=probe.sphere.v3Position;
probe.sphere.fRadius=25.f;
CCullingManager::Instance().ForInRange(Vector3d(p.x,-p.y,height+50.f),100.f,&probe);
CollisionProbe probe; probe.ignore=&around;
probeAt(p.x,p.y,probe);
return !probe.blocked;
};
const auto points=AutoHuntNavigation::FindPath({start.x,start.y},{goal.x,goal.y},arrival,walkable);
const auto points=AutoHuntNavigation::FindPath({start.x,start.y},{goal.x,goal.y},arrival,walkable,3500,body);
path.clear();
for (const auto& point:points) {
TPixelPosition position=goal; position.x=point.x; position.y=point.y;
@@ -1122,14 +1204,14 @@ bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arriv
return !path.empty();
}
bool CPythonPlayer::__AutoHunt_MoveTo(const TPixelPosition& goal, float arrival, float now)
bool CPythonPlayer::__AutoHunt_MoveTo(const TPixelPosition& goal, float arrival, float now, float body)
{
auto* main=NEW_GetMainActorPtr();
if (!main) return false;
TPixelPosition here; main->NEW_GetPixelPosition(&here);
if (m_fAutoHuntPathTime<=0 || (now-m_fAutoHuntPathTime>=1.f &&
(PixelDistance(goal,m_kAutoHuntPathGoal)>100.f || !main->IsWalking()))) {
if (!__AutoHunt_BuildPath(goal,arrival,m_vecAutoHuntPath)) return false;
if (!__AutoHunt_BuildPath(goal,arrival,m_vecAutoHuntPath,body)) return false;
m_kAutoHuntPathGoal=goal; m_fAutoHuntPathTime=now;
m_fAutoHuntPathMoveTime=0;
}
@@ -1190,7 +1272,7 @@ bool CPythonPlayer::__AutoHunt_UpdateRecovery(CInstanceBase& main, float now)
__AutoHunt_UpdatePotion(main,now);
const int maxHP=GetStatus(POINT_MAX_HP);
if (now-m_fAutoHuntStateTime<5.f || maxHP<=0 || int64_t(GetStatus(POINT_HP))*100<int64_t(maxHP)*70) return true;
m_kMap_dwAutoHuntSkipVID.clear(); m_kMap_dwAutoHuntSkipItem.clear();
m_kMap_dwAutoHuntSkipVID.clear(); m_kMap_dwAutoHuntStallCount.clear(); m_kMap_dwAutoHuntSkipItem.clear();
__AutoHunt_ResetMovement();
m_eAutoHuntState=AUTO_HUNT_SEARCH; m_fAutoHuntStateTime=now;
m_fAutoHuntNextActionTime=0; m_fAutoHuntNextSkillTime=0;
+11 -1
View File
@@ -32,5 +32,15 @@ int main() {
// Start/finish and negative map-relative coordinates retain their exact positions.
auto negative=FindPath({-23,-47},{-1023,-47},0,free);
assert(negative.size()==1 && negative.back().x==-1023 && negative.back().y==-47);
std::puts("autohunt navigation: direct, detour, sealed, thin wall, corners, budget, unloaded and coordinates passed");
// A large target standing in unwalkable cells (a hydra on the water) is reached at its edge.
auto lake=[](Point p) { return Distance(p,{1000,0})>300; };
assert(FindPath({0,0},{1000,0},100,lake).empty());
auto shore=FindPath({0,0},{1000,0},450,lake,3500,350);
assert(!shore.empty());
prev={0,0};
for (auto p:shore) { assert(lake(p) && Segment(prev,p,lake)); prev=p; }
assert(Distance(prev,{1000,0})<=450);
auto around=FindPath({0,0},{1000,0},450,[&](Point p) { return lake(p) && wall(p); },3500,350);
assert(around.size()>1 && Distance(around.back(),{1000,0})<=450);
std::puts("autohunt navigation: direct, detour, sealed, thin wall, corners, budget, unloaded, coordinates and large targets passed");
}
+5 -1
View File
@@ -12,7 +12,11 @@ GM 测试:`/level 120`,`/item 25168`(或 25169、25170),再 `/warp`
服务端需要 metin2-server 的 L4 改动:`port_ava2_dungeon.cpp`(新增的 quest 函数)、QUEST_ATTACK_EVENT(`<vnum>.attack`,赤龙每次被打时触发)、赤龙和九头蛇的 HP 辅助函数。另外,龙之雕像(6230)一下打不死,最多剩 1 HP,只有任务的 `npc.dead_by_vnum` 能杀死它。AVA2 原版没有这层保护:第 8 层的阈值是 30000 HP,暴击高的玩家可能一下把雕像打死,副本就卡住了。
自动狩猎能打赤龙巢穴:雕像石化后,攻击只会显示“格挡”(伤害 0);如果连续 4 秒都打不出伤害,就换下一个目标,并在 60 秒内不再选它。
冰雪地下城第 2 层(30331)和第 8 层(30333)用钥匙开封印石时,任务的 `item.remove()` 会删掉整组钥匙,不是只扣 1 个。AVA2 和 40250 都是这样,没有改。玩家应该一次只带 1 个钥匙去开。
自动狩猎能打赤龙巢穴:雕像石化后,攻击只会显示“格挡”(伤害 0)。如果 4 秒内只出现格挡,就换下一个目标,并在 60 秒内不再选它。
船防的九头蛇(6812)在水面上,玩家站在甲板上离它的中心约 620。服务端原来只允许 300 的近战距离(AVA2 是 600,也不够),每一击都被丢掉。现在首领级怪物放宽到 800;客户端也像 AVA2 一样,对首领按巨型怪物处理(中心距离 500)。自动狩猎会把大型目标的防御半径当成身体大小,寻路失败但目标已在范围内时,直接朝它走过去。
## 文件