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:
co-authored by
Claude Opus 5.5
parent
a1e7da68a4
commit
569afb1378
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user