This commit is contained in:
aozhiwei 2023-04-07 19:09:51 +08:00
parent e5f590b9d1
commit f4a4f60553
2 changed files with 6 additions and 30 deletions

View File

@ -61,7 +61,7 @@
</node> </node>
<node class="DecoratorWeight" id="14"> <node class="DecoratorWeight" id="14">
<property DecorateWhenChildEnds="false" /> <property DecorateWhenChildEnds="false" />
<property Weight="const int 0" /> <property Weight="const int 5" />
<node class="Action" id="15"> <node class="Action" id="15">
<property Method="Self.AndroidAgent::DoAttack()" /> <property Method="Self.AndroidAgent::DoAttack()" />
<property ResultOption="BT_INVALID" /> <property ResultOption="BT_INVALID" />
@ -69,7 +69,7 @@
</node> </node>
<node class="DecoratorWeight" id="20"> <node class="DecoratorWeight" id="20">
<property DecorateWhenChildEnds="false" /> <property DecorateWhenChildEnds="false" />
<property Weight="const int 0" /> <property Weight="const int 1" />
<node class="IfElse" id="21"> <node class="IfElse" id="21">
<node class="Condition" id="22"> <node class="Condition" id="22">
<property Operator="Equal" /> <property Operator="Equal" />

View File

@ -244,39 +244,14 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
( (
CreatureWeakPtr owner; CreatureWeakPtr owner;
CreatureWeakPtr target; CreatureWeakPtr target;
CreatureWeakPtr last_attacker;
long long last_attacked_frameno = 0;
long long last_frameno = 0; long long last_frameno = 0;
long long last_pursuit_frameno = 0; long long last_pursuit_frameno = 0;
std::weak_ptr<EventHandlerPtr> handler;
); );
context->owner = GetOwner()->GetWeakPtrRef(); context->owner = GetOwner()->GetWeakPtrRef();
context->target = enemy->GetWeakPtrRef(); context->target = enemy->GetWeakPtrRef();
context->last_frameno = GetOwner()->room->GetFrameNo(); context->last_frameno = GetOwner()->room->GetFrameNo();
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo(); context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
#if 0
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);
}
});
#endif
auto co = std::make_shared<BtCoroutine>(context, "CoPursuit"); auto co = std::make_shared<BtCoroutine>(context, "CoPursuit");
co->runing_cb = co->runing_cb =
@ -294,19 +269,20 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo(); context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else { } else {
bool is_shot = false; bool is_shot = false;
if (GlmHelper::Norm(dir) > 300) { float distance = GlmHelper::Norm(dir) - GetAttackRange();
if (distance > 0.001f) {
if (GetOwner()->GetMovement()->GetPathSize() < 1) { if (GetOwner()->GetMovement()->GetPathSize() < 1) {
GlmHelper::Normalize(dir); GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir); GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir); GetOwner()->SetAttackDir(dir);
GetOwner()->GetMovement()->CalcTargetPos(200); GetOwner()->GetMovement()->CalcTargetPos(distance + 60);
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo(); context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else { } else {
if (GetOwner()->room->GetFrameNo() - context->last_pursuit_frameno > SERVER_FRAME_RATE * 1) { if (GetOwner()->room->GetFrameNo() - context->last_pursuit_frameno > SERVER_FRAME_RATE * 1) {
GlmHelper::Normalize(dir); GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir); GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir); GetOwner()->SetAttackDir(dir);
GetOwner()->GetMovement()->CalcTargetPos(200); GetOwner()->GetMovement()->CalcTargetPos(distance + 60);
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo(); context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} }
} }