This commit is contained in:
aozhiwei 2022-12-06 16:46:48 +08:00
parent 094717b4a3
commit 12cbc18a48

View File

@ -118,5 +118,34 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
behaviac::EBTStatus AndroidAgent::DoAttack()
{
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_;
}