1
This commit is contained in:
parent
50d35e27aa
commit
1e9dda9c16
@ -406,6 +406,7 @@ void AndroidAI::UpdateAttack()
|
|||||||
if (distance > GetAttackRange()) {
|
if (distance > GetAttackRange()) {
|
||||||
#ifdef MAP3D
|
#ifdef MAP3D
|
||||||
ChangeToStateNewAI(ASE_Pursuit);
|
ChangeToStateNewAI(ASE_Pursuit);
|
||||||
|
return;
|
||||||
#else
|
#else
|
||||||
if (ai_meta->i->pursuit_radius() <= 0) {
|
if (ai_meta->i->pursuit_radius() <= 0) {
|
||||||
//站桩
|
//站桩
|
||||||
@ -464,24 +465,19 @@ void AndroidAI::UpdateRandomWalk()
|
|||||||
void AndroidAI::UpdatePursuit()
|
void AndroidAI::UpdatePursuit()
|
||||||
{
|
{
|
||||||
Human* myself = (Human*)owner;
|
Human* myself = (Human*)owner;
|
||||||
if (node_->target.Get()) {
|
if (node_->param1 > 0){
|
||||||
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
|
if (node_->exec_frame_num > 10 * 20) {
|
||||||
if (!myself->HasBuffEffect(kBET_Jump) &&
|
node_->exec_frame_num = 0;
|
||||||
!myself->HasBuffEffect(kBET_PeaceMode) &&
|
if (std::abs(myself->GetPos().x - node_->target.Get()->GetPos().x) < 0.0001f &&
|
||||||
!a8::HasBitFlag(myself->status, CS_DisableAttack) &&
|
std::abs(myself->GetPos().y - node_->target.Get()->GetPos().y) < 0.0001f) {
|
||||||
distance < GetAttackRange()) {
|
node_->param1 = 0;
|
||||||
ChangeToStateNewAI(ASE_Attack);
|
|
||||||
} else {
|
|
||||||
#ifdef MAP3D
|
|
||||||
if (node_->exec_frame_num > 100 * 2) {
|
|
||||||
ChangeToStateNewAI(ASE_Thinking);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
a8::Vec3 center;
|
a8::Vec3 center;
|
||||||
glm::vec3 random_pt;
|
glm::vec3 random_pt;
|
||||||
center.x = myself->GetPos().x / 10.0f;
|
center.x = node_->target.Get()->GetPos().x / 10.0f;
|
||||||
center.y = 0;
|
center.y = 0;
|
||||||
center.z = myself->GetPos().y / 10.0f;
|
center.z = node_->target.Get()->GetPos().y / 10.0f;
|
||||||
int ret = myself->room->map_instance->FindRandomPointAroundCircle
|
int ret = myself->room->map_instance->FindRandomPointAroundCircle
|
||||||
(0,
|
(0,
|
||||||
center,
|
center,
|
||||||
@ -489,7 +485,15 @@ void AndroidAI::UpdatePursuit()
|
|||||||
random_pt
|
random_pt
|
||||||
);
|
);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
a8::Vec3 start = center;
|
random_pt.x = center.x;
|
||||||
|
random_pt.y = center.y;
|
||||||
|
random_pt.z = center.z;
|
||||||
|
|
||||||
|
a8::Vec3 start;
|
||||||
|
start.x = myself->GetPos().x / 10.f;
|
||||||
|
start.y = 0;
|
||||||
|
start.z = myself->GetPos().y / 10.f;
|
||||||
|
|
||||||
a8::Vec3 end;
|
a8::Vec3 end;
|
||||||
end.x = random_pt.x;
|
end.x = random_pt.x;
|
||||||
end.y = random_pt.y;
|
end.y = random_pt.y;
|
||||||
@ -504,9 +508,134 @@ void AndroidAI::UpdatePursuit()
|
|||||||
);
|
);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
myself->GetMoveHelper()->ClearPath();
|
myself->GetMoveHelper()->ClearPath();
|
||||||
myself->GetMoveHelper()->AddPaths(center, paths);
|
myself->GetMoveHelper()->AddPaths(start, paths);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("findpath failed1\n", {});
|
||||||
|
node_->param1 = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("findpath failed2\n", {});
|
||||||
|
node_->param1 = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
++node_->param1;
|
||||||
|
if (std::abs(myself->GetPos().x - node_->target.Get()->GetPos().x) < 0.0001f &&
|
||||||
|
std::abs(myself->GetPos().y - node_->target.Get()->GetPos().y) < 0.0001f) {
|
||||||
|
node_->param1 = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
a8::Vec3 center;
|
||||||
|
glm::vec3 random_pt;
|
||||||
|
center.x = node_->target.Get()->GetPos().x / 10.0f;
|
||||||
|
center.y = 0;
|
||||||
|
center.z = node_->target.Get()->GetPos().y / 10.0f;
|
||||||
|
int ret = myself->room->map_instance->FindRandomPointAroundCircle
|
||||||
|
(0,
|
||||||
|
center,
|
||||||
|
GetAttackRange() / 10.f,
|
||||||
|
random_pt
|
||||||
|
);
|
||||||
|
if (ret > 0) {
|
||||||
|
random_pt.x = center.x;
|
||||||
|
random_pt.y = center.y;
|
||||||
|
random_pt.z = center.z;
|
||||||
|
|
||||||
|
|
||||||
|
a8::Vec3 start;
|
||||||
|
start.x = myself->GetPos().x / 10.f;
|
||||||
|
start.y = 0;
|
||||||
|
start.z = myself->GetPos().y / 10.f;
|
||||||
|
|
||||||
|
a8::Vec3 end;
|
||||||
|
end.x = random_pt.x;
|
||||||
|
end.y = random_pt.y;
|
||||||
|
end.z = random_pt.z;
|
||||||
|
std::vector<a8::Vec3> paths;
|
||||||
|
int ret = myself->room->map_instance->FindStraightPath
|
||||||
|
(
|
||||||
|
0,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
paths
|
||||||
|
);
|
||||||
|
if (ret > 0) {
|
||||||
|
myself->GetMoveHelper()->ClearPath();
|
||||||
|
myself->GetMoveHelper()->AddPaths(start, paths);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("findpath failed3\n", {});
|
||||||
|
node_->param1 = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("findpath failed4\n", {});
|
||||||
|
node_->param1 = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (node_->target.Get()) {
|
||||||
|
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
|
||||||
|
if (!myself->HasBuffEffect(kBET_Jump) &&
|
||||||
|
!myself->HasBuffEffect(kBET_PeaceMode) &&
|
||||||
|
!a8::HasBitFlag(myself->status, CS_DisableAttack) &&
|
||||||
|
distance < GetAttackRange()) {
|
||||||
|
ChangeToStateNewAI(ASE_Attack);
|
||||||
|
} else {
|
||||||
|
#ifdef MAP3D
|
||||||
|
if (node_->param1 == 0) {
|
||||||
|
++node_->param1;
|
||||||
|
a8::Vec3 center;
|
||||||
|
glm::vec3 random_pt;
|
||||||
|
center.x = myself->GetPos().x / 10.0f;
|
||||||
|
center.y = 0;
|
||||||
|
center.z = myself->GetPos().y / 10.0f;
|
||||||
|
int ret = myself->room->map_instance->FindRandomPointAroundCircle
|
||||||
|
(0,
|
||||||
|
center,
|
||||||
|
GetAttackRange() / 10.f,
|
||||||
|
random_pt
|
||||||
|
);
|
||||||
|
if (ret > 0) {
|
||||||
|
random_pt.x = center.x;
|
||||||
|
random_pt.y = center.y;
|
||||||
|
random_pt.z = center.z;
|
||||||
|
|
||||||
|
a8::Vec3 start;
|
||||||
|
start.x = myself->GetPos().x / 10.f;
|
||||||
|
start.y = 0;
|
||||||
|
start.z = myself->GetPos().y / 10.f;
|
||||||
|
|
||||||
|
a8::Vec3 end;
|
||||||
|
end.x = random_pt.x;
|
||||||
|
end.y = random_pt.y;
|
||||||
|
end.z = random_pt.z;
|
||||||
|
std::vector<a8::Vec3> paths;
|
||||||
|
int ret = myself->room->map_instance->FindStraightPath
|
||||||
|
(
|
||||||
|
0,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
paths
|
||||||
|
);
|
||||||
|
if (ret > 0) {
|
||||||
|
myself->GetMoveHelper()->ClearPath();
|
||||||
|
myself->GetMoveHelper()->AddPaths(start, paths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (node_->exec_frame_num > 100 * 2) {
|
||||||
|
ChangeToStateNewAI(ASE_Thinking);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (node_->exec_frame_num > 100 * 2) {
|
if (node_->exec_frame_num > 100 * 2) {
|
||||||
ChangeToStateNewAI(ASE_RandomWalk);
|
ChangeToStateNewAI(ASE_RandomWalk);
|
||||||
@ -514,7 +643,10 @@ void AndroidAI::UpdatePursuit()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef MAP3D
|
||||||
|
#else
|
||||||
ChangeToStateNewAI(ASE_RandomWalk);
|
ChangeToStateNewAI(ASE_RandomWalk);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,6 +718,9 @@ void AndroidAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
break;
|
break;
|
||||||
case ASE_RandomWalk:
|
case ASE_RandomWalk:
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("update to ASE_RandomWalk\n", {});
|
||||||
|
#endif
|
||||||
moving_ = true;
|
moving_ = true;
|
||||||
node_->target.Reset();
|
node_->target.Reset();
|
||||||
#if 1
|
#if 1
|
||||||
@ -610,7 +745,13 @@ void AndroidAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
break;
|
break;
|
||||||
case ASE_Pursuit:
|
case ASE_Pursuit:
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("update to ASE_Pursuit\n", {});
|
||||||
|
#endif
|
||||||
moving_ = true;
|
moving_ = true;
|
||||||
|
#if 1
|
||||||
|
node_->param1 = 0;
|
||||||
|
#else
|
||||||
if (node_->target.Get()) {
|
if (node_->target.Get()) {
|
||||||
a8::Vec2 move_dir = node_->target.Get()->GetPos() - hum->GetPos();
|
a8::Vec2 move_dir = node_->target.Get()->GetPos() - hum->GetPos();
|
||||||
move_dir.Normalize();
|
move_dir.Normalize();
|
||||||
@ -618,6 +759,7 @@ void AndroidAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
hum->GetMoveHelper()->CalcTargetPos(500);
|
hum->GetMoveHelper()->CalcTargetPos(500);
|
||||||
hum->SetAttackDir(hum->GetMoveDir());
|
hum->SetAttackDir(hum->GetMoveDir());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -637,15 +779,20 @@ Creature* AndroidAI::GetTarget()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Creature* target = nullptr;
|
Creature* target = nullptr;
|
||||||
|
#if MAP3D
|
||||||
|
myself->room->TraverseAlivePlayers
|
||||||
|
(
|
||||||
|
a8::XParams(),
|
||||||
|
[myself, &target] (Human* hum, a8::XParams& param)
|
||||||
|
{
|
||||||
|
target = hum;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
#else
|
||||||
myself->TraverseProperTargets
|
myself->TraverseProperTargets
|
||||||
(
|
(
|
||||||
[myself, &target] (Creature* hum, bool& stop)
|
[myself, &target] (Creature* hum, bool& stop)
|
||||||
{
|
{
|
||||||
#if MAP3D
|
|
||||||
if (hum->IsPlayer()) {
|
|
||||||
target = hum;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (hum->HasBuffEffect(kBET_Camouflage)) {
|
if (hum->HasBuffEffect(kBET_Camouflage)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -663,8 +810,8 @@ Creature* AndroidAI::GetTarget()
|
|||||||
} else {
|
} else {
|
||||||
target = hum;
|
target = hum;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
if (target) {
|
if (target) {
|
||||||
node_->nearest_human.Attach(target);
|
node_->nearest_human.Attach(target);
|
||||||
node_->last_check_nearest_human_frameno = myself->room->GetFrameNo();
|
node_->last_check_nearest_human_frameno = myself->room->GetFrameNo();
|
||||||
|
@ -2027,6 +2027,7 @@ void Human::_UpdateMove(int speed)
|
|||||||
new_pos.y = out_pos.z;
|
new_pos.y = out_pos.z;
|
||||||
//SetPos(new_pos);
|
//SetPos(new_pos);
|
||||||
} else {
|
} else {
|
||||||
|
#if 0
|
||||||
GetMoveHelper()->CalcTargetPos(500);
|
GetMoveHelper()->CalcTargetPos(500);
|
||||||
if (GetMoveHelper()->GetMovePosition(out_pos)) {
|
if (GetMoveHelper()->GetMovePosition(out_pos)) {
|
||||||
a8::Vec2 new_pos;
|
a8::Vec2 new_pos;
|
||||||
@ -2034,6 +2035,7 @@ void Human::_UpdateMove(int speed)
|
|||||||
new_pos.y = out_pos.z;
|
new_pos.y = out_pos.z;
|
||||||
//SetPos(new_pos);
|
//SetPos(new_pos);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
room->grid_service->MoveCreature(this);
|
room->grid_service->MoveCreature(this);
|
||||||
CheckSpecObject();
|
CheckSpecObject();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "movehelper.h"
|
#include "movehelper.h"
|
||||||
@ -75,13 +76,13 @@ bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
|
|||||||
|
|
||||||
void MoveHelper::CalcTargetPos(float distance)
|
void MoveHelper::CalcTargetPos(float distance)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
|
||||||
if (paths_.size() > 1) {
|
|
||||||
a8::XPrintf("CalcTargetPos old_size:%d\n", {paths_.size()});
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
ClearPath();
|
ClearPath();
|
||||||
Creature* c = (Creature*)owner_;
|
Creature* c = (Creature*)owner_;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (!c->IsPlayer()) {
|
||||||
|
a8::XPrintf("CalcTaretPos old_size:%d\n", {paths_.size()});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
glm::vec3 start;
|
glm::vec3 start;
|
||||||
glm::vec3 end;
|
glm::vec3 end;
|
||||||
glm::vec3 hit_point;
|
glm::vec3 hit_point;
|
||||||
@ -177,14 +178,29 @@ void MoveHelper::ClearPath()
|
|||||||
|
|
||||||
void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
|
void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
|
||||||
{
|
{
|
||||||
|
if (paths.empty()) {
|
||||||
|
abort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
glm::vec3 last_pos;
|
glm::vec3 last_pos;
|
||||||
last_pos.x = start.x * 10.f;
|
last_pos.x = start.x;
|
||||||
last_pos.y = start.y * 10.f;
|
last_pos.y = start.y;
|
||||||
last_pos.z = start.z * 10.f;
|
last_pos.z = start.z;
|
||||||
|
|
||||||
for (size_t i = 0; i < paths.size(); ++i) {
|
size_t i = 0;
|
||||||
|
if (std::abs(last_pos.x - paths[0].x) < 0.00001f &&
|
||||||
|
std::abs(last_pos.z - paths[0].z) < 0.00001f) {
|
||||||
|
if (paths.size() < 2) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
for (; i < paths.size(); ++i) {
|
||||||
MovePathPoint* p = new MovePathPoint();
|
MovePathPoint* p = new MovePathPoint();
|
||||||
p->src_pos = last_pos;
|
p->src_pos = last_pos;
|
||||||
|
p->src_pos.x *= 10.f;
|
||||||
|
p->src_pos.y *= 10.f;
|
||||||
|
p->src_pos.z *= 10.f;
|
||||||
|
|
||||||
p->tar_pos.x = paths[i].x * 10.f;
|
p->tar_pos.x = paths[i].x * 10.f;
|
||||||
p->tar_pos.y = paths[i].y * 10.f;
|
p->tar_pos.y = paths[i].y * 10.f;
|
||||||
@ -195,11 +211,11 @@ void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
|
|||||||
glm::vec2 src_pos;
|
glm::vec2 src_pos;
|
||||||
glm::vec2 tar_pos;
|
glm::vec2 tar_pos;
|
||||||
|
|
||||||
src_pos.x = p->src_pos.x * 10.f;
|
src_pos.x = p->src_pos.x;
|
||||||
src_pos.y = p->src_pos.y * 10.f;
|
src_pos.y = p->src_pos.z;
|
||||||
|
|
||||||
tar_pos.x = p->tar_pos.x * 10.f;
|
tar_pos.x = p->tar_pos.x;
|
||||||
tar_pos.y = p->tar_pos.y * 10.f;
|
tar_pos.y = p->tar_pos.z;
|
||||||
|
|
||||||
{
|
{
|
||||||
a8::Vec2 v1;
|
a8::Vec2 v1;
|
||||||
@ -213,12 +229,22 @@ void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
|
|||||||
p->distance = v1.Distance(v2);
|
p->distance = v1.Distance(v2);
|
||||||
}
|
}
|
||||||
glm::vec2 dir = tar_pos - src_pos;
|
glm::vec2 dir = tar_pos - src_pos;
|
||||||
glm::normalize(dir);
|
dir = glm::normalize(dir);
|
||||||
|
|
||||||
|
if (isnan(dir.x)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (isnan(dir.y)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
p->dir.x = dir.x;
|
p->dir.x = dir.x;
|
||||||
p->dir.y = 0;
|
p->dir.y = 0;
|
||||||
p->dir.z = dir.y;
|
p->dir.z = dir.y;
|
||||||
|
|
||||||
|
last_pos.x = paths[i].x;
|
||||||
|
last_pos.y = paths[i].y;
|
||||||
|
last_pos.z = paths[i].z;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
a8::XPrintf("AddPaths size:%d i:%d src_pos:%f,%f tar_pos:%f:%f\n",
|
a8::XPrintf("AddPaths size:%d i:%d src_pos:%f,%f tar_pos:%f:%f\n",
|
||||||
{
|
{
|
||||||
|
@ -790,7 +790,7 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
|||||||
if (std::fabs(new_move_dir.x - GetMoveDir().x) > 0.00001f ||
|
if (std::fabs(new_move_dir.x - GetMoveDir().x) > 0.00001f ||
|
||||||
std::fabs(new_move_dir.y - GetMoveDir().y) > 0.00001f) {
|
std::fabs(new_move_dir.y - GetMoveDir().y) > 0.00001f) {
|
||||||
SetMoveDir(new_move_dir);
|
SetMoveDir(new_move_dir);
|
||||||
GetMoveHelper()->CalcTargetPos(100);
|
GetMoveHelper()->CalcTargetPos(500);
|
||||||
}
|
}
|
||||||
moving = true;
|
moving = true;
|
||||||
}
|
}
|
||||||
|
@ -3700,7 +3700,8 @@ int Room::GetOnlinePlayerNum()
|
|||||||
size_t Room::GetRoomMaxPlayerNum()
|
size_t Room::GetRoomMaxPlayerNum()
|
||||||
{
|
{
|
||||||
#ifdef MAP3D
|
#ifdef MAP3D
|
||||||
return 2;
|
return map_meta_->i->player();
|
||||||
|
//return 2;
|
||||||
#else
|
#else
|
||||||
if (pve_instance) {
|
if (pve_instance) {
|
||||||
return pve_human_num;
|
return pve_human_num;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user