This commit is contained in:
aozhiwei 2022-12-06 16:44:57 +08:00
parent d4eb937be5
commit 094717b4a3

View File

@ -84,7 +84,36 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
behaviac::EBTStatus AndroidAgent::DoRandomShot() behaviac::EBTStatus AndroidAgent::DoRandomShot()
{ {
return behaviac::BT_SUCCESS; if (status_ == behaviac::BT_RUNNING) {
return status_runing_cb_();
}
a8::Vec2 dir = GetOwner()->GetMoveDir();
dir.Rotate((10 + rand() % 360)/ 180.0f);
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);
long long last_frameno = GetOwner()->room->GetFrameNo();
status_runing_cb_ =
[this, last_frameno] ()
{
if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 3) {
status_ = behaviac::BT_SUCCESS;
return behaviac::BT_SUCCESS;
} else {
bool shot_ok = false;
a8::Vec2 shot_dir = GetOwner()->GetAttackDir();
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
return behaviac::BT_RUNNING;
}
};
status_ = behaviac::BT_RUNNING;
return status_;
} }
behaviac::EBTStatus AndroidAgent::DoAttack() behaviac::EBTStatus AndroidAgent::DoAttack()