1
This commit is contained in:
parent
b9bfdd4371
commit
2475503eab
@ -4,6 +4,7 @@
|
||||
#include "room.h"
|
||||
#include "creature.h"
|
||||
#include "human.h"
|
||||
#include "movehelper.h"
|
||||
|
||||
BaseAgent::BaseAgent():behaviac::Agent()
|
||||
{
|
||||
@ -64,11 +65,44 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
|
||||
(
|
||||
[this, target, frameno, last_pursuit_frameno] () mutable
|
||||
{
|
||||
if (GetOwner()->room->GetFrameNo() - frameno > SERVER_FRAME_RATE * 10 ||
|
||||
!target.Get() || target.Get()->dead) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
}
|
||||
if (GetOwner()->room->GetFrameNo() - frameno > SERVER_FRAME_RATE * 10 ||
|
||||
!target.Get() || target.Get()->dead) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
a8::Vec2 dir = target.Get()->GetPos() - GetOwner()->GetPos();
|
||||
if (dir.Norm() <= 1.0f) {
|
||||
GetOwner()->GetMoveHelper()->CalcTargetPos(60);
|
||||
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
|
||||
} else {
|
||||
bool is_shot = false;
|
||||
if (dir.Norm() > 300) {
|
||||
if (GetOwner()->GetMoveHelper()->GetPathSize() < 1) {
|
||||
dir.Normalize();
|
||||
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) {
|
||||
dir.Normalize();
|
||||
GetOwner()->SetMoveDir(dir);
|
||||
GetOwner()->SetAttackDir(dir);
|
||||
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
|
||||
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dir.Normalize();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return behaviac::BT_RUNNING;
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user