1
This commit is contained in:
parent
dc1ff597df
commit
67d5e43e7c
@ -11,6 +11,7 @@
|
||||
#include "btcontext.h"
|
||||
#include "btevent.h"
|
||||
#include "btcoroutine.h"
|
||||
#include "mapinstance.h"
|
||||
|
||||
#include "f8/btmgr.h"
|
||||
|
||||
@ -480,11 +481,49 @@ behaviac::EBTStatus BaseAgent::CoRunGas()
|
||||
}
|
||||
auto context = MAKE_BTCONTEXT
|
||||
(
|
||||
int try_count = 0;
|
||||
long long frameno = 0;
|
||||
bool find_ok = false;
|
||||
glm::vec3 target_pos;
|
||||
);
|
||||
|
||||
context->frameno = GetOwner()->room->GetFrameNo();
|
||||
auto co = std::make_shared<BtCoroutine>(context, "CoRunGas");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
{
|
||||
if (GetOwner()->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (GetSafeAreaRadius() < 200) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
glm::vec3 gas_center = glm::vec3(
|
||||
GetOwner()->room->GetGasData().pos_new.x,
|
||||
0,
|
||||
GetOwner()->room->GetGasData().pos_new.y
|
||||
);
|
||||
if (GlmHelper::IsEqual2D(GetOwner()->GetPos().ToGlmVec3(),
|
||||
gas_center)) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
++context->try_count;
|
||||
if (context->try_count > 3) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
gas_center.y = GetOwner()->GetPos().ToGlmVec3().y;
|
||||
glm::vec3 dir = gas_center - GetOwner()->GetPos().ToGlmVec3();
|
||||
|
||||
glm::vec3 center = GetOwner()->GetPos().ToGlmVec3() +
|
||||
dir * (30.0f + (float)context->try_count * 50.0f);
|
||||
GetOwner()->room->map_instance->Scale(center);
|
||||
glm::vec3 point;
|
||||
bool ok = GetOwner()->room->map_instance->FindConnectableNearestPoint(center, 50, point);
|
||||
if (ok) {
|
||||
GetOwner()->room->map_instance->Scale(point);
|
||||
context->find_ok = true;
|
||||
context->target_pos = point;
|
||||
}
|
||||
return behaviac::BT_RUNNING;
|
||||
};
|
||||
return StartCoroutine(co);
|
||||
|
Loading…
x
Reference in New Issue
Block a user