This commit is contained in:
aozhiwei 2023-10-17 19:37:00 +08:00
parent 527cc1f33c
commit daf1efdd4b

View File

@ -491,24 +491,32 @@ behaviac::EBTStatus HeroAgent::CoFindPath(const glm::vec3& pos)
}
auto context = MAKE_BTCONTEXT
(
a8::XTimerWp timer_ptr;
bool find_ok = false;
glm::vec3 target_pos;
);
context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx
(
1000 / FRAME_RATE_MS,
[] (int event, const a8::Args* args)
{
},
&owner_->xtimer_attacher);
context->target_pos = pos;
auto co = std::make_shared<BtCoroutine>(context, "CoFindPath");
co->runing_cb =
[this, context] ()
[this, context, pos] ()
{
if (!context->timer_ptr.expired()) {
return behaviac::BT_RUNNING;
} else {
return behaviac::BT_SUCCESS;
if (owner_->dead) {
return behaviac::BT_FAILURE;
}
if (context->find_ok) {
if (owner_->GetMovement()->GetPathSize() <= 0) {
return behaviac::BT_SUCCESS;
} else {
return behaviac::BT_RUNNING;
}
}
owner_->room->map_instance->Scale(context->target_pos);
bool ret = owner_->GetMovement()->FindPath(context->target_pos, 0);
if (ret) {
context->find_ok = true;
} else {
return behaviac::BT_FAILURE;
}
return behaviac::BT_RUNNING;
};
return StartCoroutine(co);
}