1
This commit is contained in:
parent
527cc1f33c
commit
daf1efdd4b
@ -491,24 +491,32 @@ behaviac::EBTStatus HeroAgent::CoFindPath(const glm::vec3& pos)
|
|||||||
}
|
}
|
||||||
auto context = MAKE_BTCONTEXT
|
auto context = MAKE_BTCONTEXT
|
||||||
(
|
(
|
||||||
a8::XTimerWp timer_ptr;
|
bool find_ok = false;
|
||||||
|
glm::vec3 target_pos;
|
||||||
);
|
);
|
||||||
context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx
|
context->target_pos = pos;
|
||||||
(
|
|
||||||
1000 / FRAME_RATE_MS,
|
|
||||||
[] (int event, const a8::Args* args)
|
|
||||||
{
|
|
||||||
},
|
|
||||||
&owner_->xtimer_attacher);
|
|
||||||
auto co = std::make_shared<BtCoroutine>(context, "CoFindPath");
|
auto co = std::make_shared<BtCoroutine>(context, "CoFindPath");
|
||||||
co->runing_cb =
|
co->runing_cb =
|
||||||
[this, context] ()
|
[this, context, pos] ()
|
||||||
{
|
{
|
||||||
if (!context->timer_ptr.expired()) {
|
if (owner_->dead) {
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_FAILURE;
|
||||||
} else {
|
|
||||||
return behaviac::BT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
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);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user