This commit is contained in:
aozhiwei 2022-12-07 09:41:11 +08:00
parent 3cdeace217
commit a1a027b0c8
3 changed files with 41 additions and 0 deletions

View File

@ -148,3 +148,42 @@ behaviac::EBTStatus AndroidAgent::DoAttack()
status_ = behaviac::BT_RUNNING;
return status_;
}
behaviac::EBTStatus AndroidAgent::DoPursuit()
{
if (status_ == behaviac::BT_RUNNING) {
return status_runing_cb_();
}
Human* enemy = GetOwner()->room->FindEnemy(GetOwner()->AsHuman());
if (!enemy) {
return behaviac::BT_FAILURE;
}
a8::Vec2 dir = enemy->GetPos() - GetOwner()->GetPos();
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_;
}

View File

@ -18,6 +18,7 @@ public:
behaviac::EBTStatus DoRandomWalk();
behaviac::EBTStatus DoRandomShot();
behaviac::EBTStatus DoAttack();
behaviac::EBTStatus DoPursuit();
private:
Android* owner_ = nullptr;

View File

@ -2,6 +2,7 @@
#include "base_agent.h"
#include "room.h"
#include "creature.h"
BaseAgent::BaseAgent():behaviac::Agent()
{