1
This commit is contained in:
parent
5cf7397ddf
commit
7ff312185a
@ -79,12 +79,23 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
|
||||
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
||||
(
|
||||
kAttacked,
|
||||
[this] (const std::vector<std::any>& args)
|
||||
{
|
||||
Creature* c = std::any_cast<Creature*>(args.at(0));
|
||||
FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
|
||||
});
|
||||
|
||||
return StartCoroutine
|
||||
(
|
||||
[this] ()
|
||||
[this, handler] ()
|
||||
{
|
||||
if (GetOwner()->GetMoveHelper()->GetPathSize() <= 0) {
|
||||
status_ = behaviac::BT_SUCCESS;
|
||||
if (!handler.expired()) {
|
||||
GetOwner()->GetTrigger()->RemoveEventHandler(handler);
|
||||
}
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
return behaviac::BT_RUNNING;
|
||||
@ -109,14 +120,24 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
|
||||
a8::Vec2 shot_dir = dir;
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
|
||||
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
||||
(
|
||||
kAttacked,
|
||||
[this] (const std::vector<std::any>& args)
|
||||
{
|
||||
Creature* c = std::any_cast<Creature*>(args.at(0));
|
||||
FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
|
||||
});
|
||||
|
||||
long long last_frameno = GetOwner()->room->GetFrameNo();
|
||||
return StartCoroutine
|
||||
(
|
||||
[this, last_frameno] ()
|
||||
[this, last_frameno, handler] ()
|
||||
{
|
||||
if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 3) {
|
||||
status_ = behaviac::BT_SUCCESS;
|
||||
if (!handler.expired()) {
|
||||
GetOwner()->GetTrigger()->RemoveEventHandler(handler);
|
||||
}
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
bool shot_ok = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user