This commit is contained in:
aozhiwei 2023-04-05 14:33:59 +08:00
parent f936461640
commit 56eab70fe4
2 changed files with 2 additions and 27 deletions

View File

@ -120,7 +120,7 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
);
context->owner = GetOwner()->GetWeakPtrRef();
context->last_frameno = GetOwenr()->room->GetFrameNo();
context->last_frameno = GetOwner()->room->GetFrameNo();
context->handler = GetOwner()->GetTrigger()->AddListener
(
kAttacked,

View File

@ -73,9 +73,6 @@ behaviac::EBTStatus HeroAgent::DoRandomWalk()
[this, context] ()
{
if (GetOwner()->GetMovement()->GetPathSize() <= 0) {
if (!context->handler.expired()) {
GetOwner()->GetTrigger()->RemoveEventHandler(context->handler);
}
return behaviac::BT_SUCCESS;
} else {
return behaviac::BT_RUNNING;
@ -121,6 +118,7 @@ behaviac::EBTStatus HeroAgent::DoRandomShot()
);
context->owner = GetOwner()->GetWeakPtrRef();
context->last_frameno = GetOwner()->room->GetFrameNo();
context->handler = GetOwner()->GetTrigger()->AddListener
(
kAttacked,
@ -325,37 +323,14 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
(
CreatureWeakPtr owner;
CreatureWeakPtr target;
CreatureWeakPtr last_attacker;
long long last_attacked_frameno = 0;
long long last_frameno = 0;
long long last_pursuit_frameno = 0;
std::weak_ptr<EventHandlerPtr> handler;
);
context->owner = GetOwner()->GetWeakPtrRef();
context->target = enemy->GetWeakPtrRef();
context->last_frameno = GetOwner()->room->GetFrameNo();
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
context->handler = GetOwner()->GetTrigger()->AddListener
(
kAttacked,
[context_wp = context->GetWp()] (const a8::Args& args)
{
if (context_wp.expired()) {
auto context = context_wp.lock();
Creature* c = args.Get<Creature*>(0);
context->last_attacker = c->GetWeakPtrRef();
context->last_attacked_frameno = c->room->GetFrameNo();
}
});
context->_destory_cb =
(
[context = context.get()] ()
{
if (context->owner.Get()) {
context->owner.Get()->GetTrigger()->RemoveEventHandler(context->handler);
}
});
auto co = std::make_shared<BtCoroutine>(context, "CoPursuit");
co->runing_cb =