From 2e4749584e3018613e23504054572033cdc8ccbe Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Dec 2022 14:12:11 +0800 Subject: [PATCH] 1 --- server/gameserver/android_agent.cc | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/server/gameserver/android_agent.cc b/server/gameserver/android_agent.cc index 7b911870..d5bb813f 100644 --- a/server/gameserver/android_agent.cc +++ b/server/gameserver/android_agent.cc @@ -158,19 +158,11 @@ behaviac::EBTStatus AndroidAgent::DoPursuit() return behaviac::BT_FAILURE; } - a8::Vec2 dir = enemy->GetPos() - GetOwner()->GetPos(); - dir.Normalize(); - GetOwner()->SetMoveDir(dir); - GetOwner()->SetAttackDir(dir); - - bool shot_ok = false; - a8::Vec2 shot_dir = dir; - GetOwner()->Shot(shot_dir, shot_ok, 0, 0); - CreatureWeakPtr target = enemy->GetWeakPtrRef(); long long last_frameno = GetOwner()->room->GetFrameNo(); + long long last_pursuit_frameno = GetOwner()->room->GetFrameNo(); status_runing_cb_ = - [this, last_frameno, target] () mutable + [this, last_frameno, target, last_pursuit_frameno] () mutable { if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 10 && target.Get()) { @@ -179,8 +171,30 @@ behaviac::EBTStatus AndroidAgent::DoPursuit() } else { a8::Vec2 dir = target.Get()->GetPos() - GetOwner()->GetPos(); dir.Normalize(); - GetOwner()->SetMoveDir(dir); - GetOwner()->SetAttackDir(dir); + bool is_shot = false; + if (dir.Norm() > 500) { + if (GetOwner()->GetMoveHelper()->GetPathSize() < 1) { + GetOwner()->SetMoveDir(dir); + GetOwner()->SetAttackDir(dir); + GetOwner()->GetMoveHelper()->CalcTargetPos(200); + 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()->Shot(shot_dir, shot_ok, 0, 0); + } return behaviac::BT_RUNNING; }