diff --git a/server/gameserver/hero_agent.cc b/server/gameserver/hero_agent.cc index c8bda02c..742a3332 100644 --- a/server/gameserver/hero_agent.cc +++ b/server/gameserver/hero_agent.cc @@ -931,5 +931,48 @@ float HeroAgent::GetHPRate() behaviac::EBTStatus HeroAgent::CoGetRunAwayPoint() { + PRE_ENTER_COROUTINE(); + if (!current_target_agent->IsValid()) { + return behaviac::BT_FAILURE; + } + auto context = MAKE_BTCONTEXT + ( + int try_count = 0; + int step_len = 50; + ); + auto co = std::make_shared(context, co_id, "CoGetRunAwayPoint"); + co->runing_cb = + [this, context] () + { + if (owner_->dead) { + return behaviac::BT_FAILURE; + } + if (!current_target_agent->IsValid()) { + return behaviac::BT_FAILURE; + } + glm::vec3 gas_center = GlmHelper::Vec2ToVec3(owner_->room->GetGasData().pos_new); + gas_center.y = owner_->GetPos().ToGlmVec3().y; + if (GlmHelper::IsEqual2D(owner_->GetPos().ToGlmVec3(), + gas_center)) { + out_point0 = gas_center; + return behaviac::BT_SUCCESS; + } + + glm::vec3 dir = gas_center - owner_->GetPos().ToGlmVec3(); + GlmHelper::Normalize(dir); + + glm::vec3 center = owner_->GetPos().ToGlmVec3() + + dir * (50.0f + (float)(context->try_count + 1) * context->step_len); + owner_->room->map_instance->Scale(center); + glm::vec3 point; + bool ok = owner_->room->map_instance->FindConnectableNearestPoint(center, 50, point); + if (ok) { + owner_->room->map_instance->UnScale(point); + out_point0 = point; + return behaviac::BT_SUCCESS; + } + return behaviac::BT_FAILURE; + }; + return StartCoroutine(co); }