This commit is contained in:
aozhiwei 2023-04-05 14:46:41 +08:00
parent 56eab70fe4
commit cb5f01beff

View File

@ -210,58 +210,34 @@ behaviac::EBTStatus HeroAgent::DoAttack()
context->target = enemy->GetWeakPtrRef(); context->target = enemy->GetWeakPtrRef();
context->last_frameno = GetOwner()->room->GetFrameNo(); context->last_frameno = GetOwner()->room->GetFrameNo();
#if 0
std::weak_ptr<EventHandlerPtr> handler;
if (GetOwner()->AsHero()->master.Get()) { if (GetOwner()->AsHero()->master.Get()) {
handler = GetOwner()->AsHero()->master.Get()->GetTrigger()->AddListener context->handler = GetOwner()->AsHero()->master.Get()->GetTrigger()->AddListener
( (
kBulletHitEvent, kBulletHitEvent,
[this, last_attacker, last_attacked_frameno] (const a8::Args& args) [context_wp = context->GetWp()] (const a8::Args& args)
{ {
Creature* c = args.Get<Creature*>(1); if (!context_wp.expired()) {
*last_attacker = c->GetWeakPtrRef(); auto context = context_wp.lock();
*last_attacked_frameno = c->room->GetFrameNo(); Creature* c = args.Get<Creature*>(1);
context->last_attacker = c->GetWeakPtrRef();
context->last_attacked_frameno = c->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();
}
});
#endif
#if 0
context->_destory_cb = context->_destory_cb =
( (
[context = context.get()] () [context = context.get()] ()
{ {
if (context->owner.Get()) { if (!context->handler.expired() && context->owner.Get()) {
context->owner.Get()->GetTrigger()->RemoveEventHandler(context->handler); if (context->owner.Get()->IsEntityType(ET_Hero)) {
} Hero* hero = (Hero*)context->owner.Get();
});
auto holder = std::make_shared<a8::Holder>
(
[owner = GetOwner()->GetWeakPtrRef(), handler] (const a8::Args& args) mutable
{
if (!handler.expired() && owner.Get()) {
if (owner.Get()->IsEntityType(ET_Hero)) {
Hero* hero = (Hero*)owner.Get();
if (hero->master.Get()) { if (hero->master.Get()) {
hero->master.Get()->GetTrigger()->RemoveEventHandler(handler); hero->master.Get()->GetTrigger()->RemoveEventHandler(context->handler);
} }
} }
} }
}); });
#endif
auto co = std::make_shared<BtCoroutine>(context, "CoAttack"); auto co = std::make_shared<BtCoroutine>(context, "CoAttack");
co->runing_cb = co->runing_cb =
[this, context] () [this, context] ()