diff --git a/server/gameserver/new_hero_agent.cc b/server/gameserver/new_hero_agent.cc index 25098e84..cb35fde1 100644 --- a/server/gameserver/new_hero_agent.cc +++ b/server/gameserver/new_hero_agent.cc @@ -344,37 +344,205 @@ behaviac::EBTStatus HeroAgent::CoIdle(int min_val, int max_val) behaviac::EBTStatus HeroAgent::CoMoveCurrentTargetRaycast() { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoMoveCurrentTargetRaycast"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } behaviac::EBTStatus HeroAgent::CoShotCurrentTargetRaycast() { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoShotCurrentTargetRaycast"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } behaviac::EBTStatus HeroAgent::CoMoveMasterRaycast() { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoMoveMasterRaycast"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } behaviac::EBTStatus HeroAgent::CoFindPath(const glm::vec3& pos) { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoFindPath"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } behaviac::EBTStatus HeroAgent::CoFindPathEx(const glm::vec3& pos, float distance) { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoFindPathEx"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } behaviac::EBTStatus HeroAgent::CoStartMove(float distance) { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoStartMove"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } behaviac::EBTStatus HeroAgent::CoSleep(int time) { - abort(); + if (status_ == behaviac::BT_RUNNING) { + return DoRunningCb(); + } + auto context = MAKE_BTCONTEXT + ( + a8::XTimerWp timer_ptr; + ); + context->timer_ptr = owner_->room->xtimer.SetTimeoutWpEx + ( + 1000 / FRAME_RATE_MS, + [] (int event, const a8::Args* args) + { + }, + &owner_->xtimer_attacher); + auto co = std::make_shared(context, "CoSleep"); + co->runing_cb = + [this, context] () + { + if (!context->timer_ptr.expired()) { + return behaviac::BT_RUNNING; + } else { + return behaviac::BT_SUCCESS; + } + }; + return StartCoroutine(co); } Room* HeroAgent::GetRoom()