1
This commit is contained in:
parent
c6da6a8bb2
commit
de01061484
@ -381,6 +381,10 @@ behaviac::EBTStatus HeroAgent::SearchEnemy(float range)
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (target) {
|
||||
current_target_agent->SetTarget(target);
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
|
||||
@ -532,24 +536,31 @@ behaviac::EBTStatus HeroAgent::CoFindPathEx(const glm::vec3& pos, float distance
|
||||
}
|
||||
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, "CoFindPathEx");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context, distance] ()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
bool ret = owner_->GetMovement()->FindPath(context->target_pos, distance);
|
||||
if (ret) {
|
||||
context->find_ok = true;
|
||||
} else {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
return behaviac::BT_RUNNING;
|
||||
};
|
||||
return StartCoroutine(co);
|
||||
}
|
||||
|
@ -94,3 +94,8 @@ float TargetAgent::GetShotRange()
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void TargetAgent::SetTarget(Creature* target)
|
||||
{
|
||||
target_ = target->GetWeakPtrRef();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
float GetShotRange();
|
||||
|
||||
void SetOwner(Creature* owner);
|
||||
void SetTarget(Creature* target);
|
||||
virtual Room* GetRoom() override;
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user