This commit is contained in:
aozhiwei 2022-12-07 14:55:45 +08:00
parent 2e4749584e
commit 31c819ee66
7 changed files with 32 additions and 23 deletions

View File

@ -5,6 +5,7 @@
#include "room.h" #include "room.h"
#include "app.h" #include "app.h"
#include "android_agent.h" #include "android_agent.h"
#include "movehelper.h"
#include "framework/cpp/btmgr.h" #include "framework/cpp/btmgr.h"

View File

@ -3,6 +3,7 @@
#include "android_agent.h" #include "android_agent.h"
#include "android.h" #include "android.h"
#include "room.h" #include "room.h"
#include "movehelper.h"
AndroidAgent::AndroidAgent():BaseAgent() AndroidAgent::AndroidAgent():BaseAgent()
{ {
@ -164,38 +165,42 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
status_runing_cb_ = status_runing_cb_ =
[this, last_frameno, target, last_pursuit_frameno] () mutable [this, last_frameno, target, last_pursuit_frameno] () mutable
{ {
if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 10 && if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 10 ||
target.Get()) { !target.Get() || target.Get()->dead) {
status_ = behaviac::BT_SUCCESS; status_ = behaviac::BT_SUCCESS;
return behaviac::BT_SUCCESS; return behaviac::BT_SUCCESS;
} else { } else {
a8::Vec2 dir = target.Get()->GetPos() - GetOwner()->GetPos(); a8::Vec2 dir = target.Get()->GetPos() - GetOwner()->GetPos();
dir.Normalize(); if (dir.Norm() <= 1.0f) {
bool is_shot = false; GetOwner()->GetMoveHelper()->CalcTargetPos(60);
if (dir.Norm() > 500) { last_pursuit_frameno = GetOwner()->room->GetFrameNo();
if (GetOwner()->GetMoveHelper()->GetPathSize() < 1) { } else {
GetOwner()->SetMoveDir(dir); bool is_shot = false;
GetOwner()->SetAttackDir(dir); dir.Normalize();
GetOwner()->GetMoveHelper()->CalcTargetPos(200); if (dir.Norm() > 500) {
last_pursuit_frameno = GetOwner()->room->GetFrameNo(); if (GetOwner()->GetMoveHelper()->GetPathSize() < 1) {
} else {
if (GetOwner()->room->GetFrameNo() - last_pursuit_frameno > SERVER_FRAME_RATE * 1) {
GetOwner()->SetMoveDir(dir); GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir); GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200); GetOwner()->GetMoveHelper()->CalcTargetPos(200);
last_pursuit_frameno = GetOwner()->room->GetFrameNo(); last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else {
if (GetOwner()->room->GetFrameNo() - last_pursuit_frameno > SERVER_FRAME_RATE * 1) {
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
}
} }
} else {
is_shot = true;
}
if (is_shot) {
bool shot_ok = false;
a8::Vec2 shot_dir = dir;
GetOwner()->SetAttackDir(dir);
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
} }
} else {
is_shot = true;
} }
if (is_shot) {
bool shot_ok = false;
a8::Vec2 shot_dir = dir;
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
}
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
} }
}; };

View File

@ -23,7 +23,7 @@ bool BaseAgent::HasTarget(float range)
{ {
Human* enemy = GetOwner()->room->FindEnemy(GetOwner()->AsHuman()); Human* enemy = GetOwner()->room->FindEnemy(GetOwner()->AsHuman());
if (enemy) { if (enemy) {
float distance = (enemy->GetPos() - GetOwner()->GetPos()).Norm(); float distance = enemy->GetPos().Distance(GetOwner()->GetPos());
return distance <= range; return distance <= range;
} }
return false; return false;

View File

@ -15,6 +15,7 @@
#include "bullet.h" #include "bullet.h"
#include "skillhelper.h" #include "skillhelper.h"
#include "shot.h" #include "shot.h"
#include "movehelper.h"
#include "framework/cpp/utils.h" #include "framework/cpp/utils.h"

View File

@ -6,7 +6,6 @@
#include "ability.h" #include "ability.h"
#include "weapon.h" #include "weapon.h"
#include "battledatacontext.h" #include "battledatacontext.h"
#include "movehelper.h"
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
@ -68,6 +67,7 @@ class Team;
class Car; class Car;
class Trigger; class Trigger;
class DelayAddBuffHandle; class DelayAddBuffHandle;
class MoveHelper;
class Creature : public MoveableEntity class Creature : public MoveableEntity
{ {
public: public:

View File

@ -39,6 +39,7 @@
#include "shot.h" #include "shot.h"
#include "battledatacontext.h" #include "battledatacontext.h"
#include "mapinstance.h" #include "mapinstance.h"
#include "movehelper.h"
const int kReviveTimeAdd = 12; const int kReviveTimeAdd = 12;
const int kSkinNum = 4; const int kSkinNum = 4;

View File

@ -24,6 +24,7 @@
#include "team.h" #include "team.h"
#include "httpproxy.h" #include "httpproxy.h"
#include "roommgr.h" #include "roommgr.h"
#include "movehelper.h"
const int kREVIVE_BUFF_ID = 1005; const int kREVIVE_BUFF_ID = 1005;