diff --git a/server/gameserver/android_agent.cc b/server/gameserver/android_agent.cc index 0607f4a7..3d17d770 100644 --- a/server/gameserver/android_agent.cc +++ b/server/gameserver/android_agent.cc @@ -84,7 +84,36 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk() 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()