1
This commit is contained in:
parent
96ed1ff9ef
commit
57eba9e3b3
@ -62,10 +62,17 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
|
|||||||
return behaviac::BT_SUCCESS;
|
return behaviac::BT_SUCCESS;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[this, last_attacker, last_attacked_frameno] (bool is_test, bool& has_event)
|
[this, timer_ptr, handler, last_attacker, last_attacked_frameno]
|
||||||
|
(bool is_test, bool& has_event) mutable
|
||||||
{
|
{
|
||||||
has_event = last_attacker->Get() ? true : false;
|
has_event = last_attacker->Get() && !last_attacker->Get()->dead ? true : false;
|
||||||
if (!is_test && has_event) {
|
if (!is_test && has_event) {
|
||||||
|
if (!timer_ptr.expired()) {
|
||||||
|
GetOwner()->room->xtimer.DeleteTimer(timer_ptr);
|
||||||
|
}
|
||||||
|
if (!handler.expired()) {
|
||||||
|
GetOwner()->GetTrigger()->RemoveEventHandler(handler);
|
||||||
|
}
|
||||||
FireEvent("OnAttacked", last_attacker->Get()->GetUniId(), *last_attacked_frameno);
|
FireEvent("OnAttacked", last_attacker->Get()->GetUniId(), *last_attacked_frameno);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -89,13 +96,16 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
|
|||||||
return behaviac::BT_FAILURE;
|
return behaviac::BT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<CreatureWeakPtr> last_attacker = std::make_shared<CreatureWeakPtr>();
|
||||||
|
std::shared_ptr<long long> last_attacked_frameno = std::make_shared<long long>(0);
|
||||||
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
||||||
(
|
(
|
||||||
kAttacked,
|
kAttacked,
|
||||||
[this] (const std::vector<std::any>& args)
|
[this, last_attacker, last_attacked_frameno] (const std::vector<std::any>& args)
|
||||||
{
|
{
|
||||||
Creature* c = std::any_cast<Creature*>(args.at(0));
|
Creature* c = std::any_cast<Creature*>(args.at(0));
|
||||||
FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
|
*last_attacker = c->GetWeakPtrRef();
|
||||||
|
*last_attacked_frameno = c->room->GetFrameNo();
|
||||||
});
|
});
|
||||||
|
|
||||||
return StartCoroutine
|
return StartCoroutine
|
||||||
@ -111,9 +121,16 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[this] (bool is_test, bool& has_event)
|
[this, handler, last_attacker, last_attacked_frameno]
|
||||||
|
(bool is_test, bool& has_event) mutable
|
||||||
{
|
{
|
||||||
|
has_event = last_attacker->Get() && !last_attacker->Get()->dead ? true : false;
|
||||||
|
if (!is_test && has_event) {
|
||||||
|
if (!handler.expired()) {
|
||||||
|
GetOwner()->GetTrigger()->RemoveEventHandler(handler);
|
||||||
|
}
|
||||||
|
FireEvent("OnAttacked", last_attacker->Get()->GetUniId(), *last_attacked_frameno);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"CoRandomWalk"
|
"CoRandomWalk"
|
||||||
);
|
);
|
||||||
@ -134,13 +151,16 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
|
|||||||
a8::Vec2 shot_dir = dir;
|
a8::Vec2 shot_dir = dir;
|
||||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||||
|
|
||||||
|
std::shared_ptr<CreatureWeakPtr> last_attacker = std::make_shared<CreatureWeakPtr>();
|
||||||
|
std::shared_ptr<long long> last_attacked_frameno = std::make_shared<long long>(0);
|
||||||
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
||||||
(
|
(
|
||||||
kAttacked,
|
kAttacked,
|
||||||
[this] (const std::vector<std::any>& args)
|
[this, last_attacker, last_attacked_frameno] (const std::vector<std::any>& args)
|
||||||
{
|
{
|
||||||
Creature* c = std::any_cast<Creature*>(args.at(0));
|
Creature* c = std::any_cast<Creature*>(args.at(0));
|
||||||
FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
|
*last_attacker = c->GetWeakPtrRef();
|
||||||
|
*last_attacked_frameno = c->room->GetFrameNo();
|
||||||
});
|
});
|
||||||
|
|
||||||
long long last_frameno = GetOwner()->room->GetFrameNo();
|
long long last_frameno = GetOwner()->room->GetFrameNo();
|
||||||
@ -161,11 +181,18 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[this] (bool is_test, bool& has_event)
|
[this, handler, last_attacker, last_attacked_frameno]
|
||||||
|
(bool is_test, bool& has_event) mutable
|
||||||
{
|
{
|
||||||
|
has_event = last_attacker->Get() && !last_attacker->Get()->dead ? true : false;
|
||||||
|
if (!is_test && has_event) {
|
||||||
|
if (!handler.expired()) {
|
||||||
|
GetOwner()->GetTrigger()->RemoveEventHandler(handler);
|
||||||
|
}
|
||||||
|
FireEvent("OnAttacked", last_attacker->Get()->GetUniId(), *last_attacked_frameno);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"CoRandomShot"
|
"CoRandomShot"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user