This commit is contained in:
aozhiwei 2023-10-18 16:59:04 +08:00
parent c6da6a8bb2
commit de01061484
3 changed files with 30 additions and 13 deletions

View File

@ -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);
}

View File

@ -94,3 +94,8 @@ float TargetAgent::GetShotRange()
}
return 0.0f;
}
void TargetAgent::SetTarget(Creature* target)
{
target_ = target->GetWeakPtrRef();
}

View File

@ -25,6 +25,7 @@ public:
float GetShotRange();
void SetOwner(Creature* owner);
void SetTarget(Creature* target);
virtual Room* GetRoom() override;
private: