From eec0c16a7206575185e4c7143dee3a2a154f4576 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 2 Dec 2022 10:59:49 +0800 Subject: [PATCH] 1 --- server/gameserver/android.ai.cc | 44 ++++++++++++++++++++ server/gameserver/mapinstance.cc | 71 +++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index f7accbd6..1d7defa1 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -314,6 +314,7 @@ void AndroidAI::UpdateIdle() void AndroidAI::UpdateThinking() { + #if MAP3D Human* hum = (Human*)owner; if (hum->room->GetGasData().GetGasMode() == GasInactive || hum->room->IsWaitingStart() || @@ -343,6 +344,37 @@ void AndroidAI::UpdateThinking() } } } + #else + Human* hum = (Human*)owner; + if (hum->room->GetGasData().GetGasMode() == GasInactive || + hum->room->IsWaitingStart() || + hum->HasBuffEffect(kBET_Jump) || + hum->HasBuffEffect(kBET_PeaceMode) || + a8::HasBitFlag(hum->status, CS_DisableAttack)) { + if (hum->room->IsWaitingStart()) { + ChangeToStateNewAI(ASE_Idle); + } else { + ChangeToStateNewAI(ASE_RandomWalk); + } + } else { + Creature* target = GetTarget(); + if (target) { + node_->target.Attach(target); + ChangeToStateNewAI(ASE_Attack); + } else { + if (hum->room->GetFrameNo() >= node_->next_random_move_frameno) { + if ((rand() % 7) < 4) { + ChangeToStateNewAI(ASE_Idle); + } else { + ChangeToStateNewAI(ASE_RandomWalk); + } + } else { + ChangeToStateNewAI(ASE_Idle); + node_->param1 = node_->next_random_move_frameno - hum->room->GetFrameNo(); + } + } + } + #endif } void AndroidAI::UpdateAttack() @@ -435,9 +467,12 @@ void AndroidAI::UpdatePursuit() distance < GetAttackRange()) { ChangeToStateNewAI(ASE_Attack); } else { +#ifdef MAP3D +#else if (node_->exec_frame_num > 100 * 2) { ChangeToStateNewAI(ASE_RandomWalk); } +#endif } } else { ChangeToStateNewAI(ASE_RandomWalk); @@ -567,6 +602,11 @@ Creature* AndroidAI::GetTarget() ( [myself, &target] (Creature* hum, bool& stop) { +#if MAP3D + if (hum->IsPlayer()) { + target = hum; + } +#else if (hum->HasBuffEffect(kBET_Camouflage)) { return; } @@ -584,14 +624,18 @@ Creature* AndroidAI::GetTarget() } else { target = hum; } +#endif }); if (target) { node_->nearest_human.Attach(target); node_->last_check_nearest_human_frameno = myself->room->GetFrameNo(); float distance = myself->GetPos().Distance(target->GetPos()); +#ifdef MAP3D +#else if (distance > GetAttackRange()) { target = nullptr; } +#endif } return target; } diff --git a/server/gameserver/mapinstance.cc b/server/gameserver/mapinstance.cc index 60763d54..125703c5 100644 --- a/server/gameserver/mapinstance.cc +++ b/server/gameserver/mapinstance.cc @@ -1,5 +1,7 @@ #include "precompile.h" +#include "DetourCommon.h" + #include "mapinstance.h" #include "mapservice.h" #include "gridservice.h" @@ -672,7 +674,74 @@ int MapInstance::FindStraightPath(int layer, const a8::Vec3& end, std::vector& paths) { - return 0; + float spos[3]; + spos[0] = start.x; + spos[1] = start.y; + spos[2] = start.z; + + float epos[3]; + epos[0] = end.x; + epos[1] = end.y; + epos[2] = end.z; + + dtQueryFilter filter; + filter.setIncludeFlags(0xffff); + filter.setExcludeFlags(0); + + const float extents[3] = {2.f, 4.f, 2.f}; + + dtPolyRef startRef = INVALID_NAVMESH_POLYREF; + dtPolyRef endRef = INVALID_NAVMESH_POLYREF; + + float startNearestPt[3]; + float endNearestPt[3]; + navmesh_query_->findNearestPoly(spos, extents, &filter, &startRef, startNearestPt); + navmesh_query_->findNearestPoly(epos, extents, &filter, &endRef, endNearestPt); + + if (!startRef || !endRef) { + return NAV_ERROR_NEARESTPOLY; + } + + dtPolyRef polys[MAX_POLYS]; + int npolys; + float straightPath[MAX_POLYS * 3]; + unsigned char straightPathFlags[MAX_POLYS]; + dtPolyRef straightPathPolys[MAX_POLYS]; + int nstraightPath; + int pos = 0; + + navmesh_query_->findPath(startRef, endRef, startNearestPt, endNearestPt, &filter, polys, &npolys, MAX_POLYS); + nstraightPath = 0; + + if (npolys) { + + float epos1[3]; + dtVcopy(epos1, endNearestPt); + + if (polys[npolys-1] != endRef) { + navmesh_query_->closestPointOnPoly(polys[npolys-1], endNearestPt, epos1, 0); + } + + navmesh_query_->findStraightPath(startNearestPt, + endNearestPt, + polys, + npolys, + straightPath, + straightPathFlags, + straightPathPolys, + &nstraightPath, + MAX_POLYS); + for(int i = 0; i < nstraightPath * 3; ) { + a8::Vec3 currpos; + currpos.x = straightPath[i++]; + currpos.y = straightPath[i++]; + currpos.z = straightPath[i++]; + paths.push_back(currpos); + pos++; + } + } + + return pos; } int MapInstance::FindRandomPointAroundCircle(int layer,