This commit is contained in:
aozhiwei 2023-06-28 18:34:03 +08:00
parent 87a8e7dbb6
commit 27d1fada8d
2 changed files with 66 additions and 10 deletions

View File

@ -334,18 +334,78 @@ behaviac::EBTStatus BaseAgent::SelectUseableSkill(const behaviac::vector<int> sk
behaviac::EBTStatus BaseAgent::CoFindPathToCurrentTarget(float distance)
{
if (status_ == behaviac::BT_RUNNING) {
return DoRunningCb();
}
if (!current_target_.Get()) {
return behaviac::BT_FAILURE;
}
return behaviac::BT_SUCCESS;
bool ret = GetOwner()->GetMovement()->FindPath(current_target_.Get()->GetPos().ToGlmVec3(), distance);
if (!ret) {
return behaviac::BT_FAILURE;
}
auto context = MAKE_BTCONTEXT
(
);
#ifdef DEBUG
a8::XPrintf("CoFindPathToCurrentTarget %d\n", {current_target_.Get()->GetUniId()});
#endif
auto co = std::make_shared<BtCoroutine>(context, "CoFindPathToCurrentTarget");
co->runing_cb =
[this, context] ()
{
if (GetOwner()->dead) {
return behaviac::BT_FAILURE;
}
if (GetOwner()->GetMovement()->GetPathSize() <= 0) {
return behaviac::BT_SUCCESS;
}
return behaviac::BT_RUNNING;
};
return StartCoroutine(co);
}
behaviac::EBTStatus BaseAgent::CoMoveToCurrentTarget(float distance)
{
if (status_ == behaviac::BT_RUNNING) {
return DoRunningCb();
}
if (!current_target_.Get()) {
return behaviac::BT_FAILURE;
}
return behaviac::BT_SUCCESS;
if (GlmHelper::IsEqual2D(GetOwner()->GetPos().ToGlmVec3(),
current_target_.Get()->GetPos().ToGlmVec3())) {
return behaviac::BT_SUCCESS;
}
auto context = MAKE_BTCONTEXT
(
CreatureWeakPtr target;
);
context->target = current_target_;
glm::vec3 dir = GetOwner()->GetPos().CalcDir(context->target.Get()->GetPos());
GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMovement()->CalcTargetPos(60);
#ifdef DEBUG
a8::XPrintf("CoMoveToCurrentTarget %d\n", {current_target_.Get()->GetUniId()});
#endif
auto co = std::make_shared<BtCoroutine>(context, "CoMoveToCurrentTarget");
co->runing_cb =
[this, context] ()
{
if (GetOwner()->dead) {
return behaviac::BT_FAILURE;
}
if (GetOwner()->GetMovement()->GetPathSize() <= 0) {
return behaviac::BT_SUCCESS;
}
return behaviac::BT_RUNNING;
};
return StartCoroutine(co);
}
bool BaseAgent::CurrentTargetIsValid()

View File

@ -2352,19 +2352,15 @@ void Creature::UpdateMove()
if (room->GetGasData().GetGasMode() == GasInactive &&
room->IsSandTableRoom()) {
} else {
GetMovement()->CalcTargetPos(mt::Param::s().move_step_len);
if (!GetMovement()->UpdatePosition()) {
#if 1
{
#else
if (IsPlayer()) {
#endif
if (IsPlayer() || HasBuffEffect(kBET_Sprint)) {
GetMovement()->CalcTargetPos(mt::Param::s().move_step_len);
if (!GetMovement()->UpdatePosition()) {
if (HasBuffEffect(kBET_Sprint)) {
SprintBuff* buff = (SprintBuff*)GetBuffByEffectId(kBET_Sprint);
if (buff) {
buff->SprintEnd();
}
} else {
} else if (IsPlayer()) {
ShortFindPath();
}
}