This commit is contained in:
aozhiwei 2022-12-09 11:47:21 +08:00
parent 67e48dd9a0
commit 96ed1ff9ef
3 changed files with 15 additions and 13 deletions

View File

@ -47,7 +47,6 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
Creature* c = std::any_cast<Creature*>(args.at(0)); Creature* c = std::any_cast<Creature*>(args.at(0));
*last_attacker = c->GetWeakPtrRef(); *last_attacker = c->GetWeakPtrRef();
*last_attacked_frameno = c->room->GetFrameNo(); *last_attacked_frameno = c->room->GetFrameNo();
//FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
}); });
return StartCoroutine return StartCoroutine
@ -63,9 +62,12 @@ 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& has_event) [this, last_attacker, last_attacked_frameno] (bool is_test, bool& has_event)
{ {
has_event = last_attacker->Get() ? true : false;
if (!is_test && has_event) {
FireEvent("OnAttacked", last_attacker->Get()->GetUniId(), *last_attacked_frameno);
}
}, },
"CoIdle" "CoIdle"
); );
@ -109,7 +111,7 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
} }
}, },
[this] (bool& has_event) [this] (bool is_test, bool& has_event)
{ {
}, },
@ -159,7 +161,7 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
} }
}, },
[this] (bool& has_event) [this] (bool is_test, bool& has_event)
{ {
}, },
@ -201,7 +203,7 @@ behaviac::EBTStatus AndroidAgent::DoAttack()
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
} }
}, },
[this] (bool& has_event) [this] (bool is_test, bool& has_event)
{ {
}, },
@ -267,7 +269,7 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
} }
}, },
[this] (bool& has_event) [this] (bool is_test, bool& has_event)
{ {
}, },

View File

@ -27,11 +27,11 @@ void BaseAgent::Exec()
behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this); behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this);
if (status == behaviac::BT_RUNNING && event_cb_) { if (status == behaviac::BT_RUNNING && event_cb_) {
bool has_event = false; bool has_event = false;
event_cb_(has_event); event_cb_(true, has_event);
if (has_event) { if (has_event) {
status_= behaviac::BT_INVALID; status_= behaviac::BT_INVALID;
runing_cb_ = nullptr; runing_cb_ = nullptr;
event_cb_(has_event); event_cb_(false, has_event);
} }
} }
} }
@ -62,7 +62,7 @@ behaviac::EBTStatus BaseAgent::DoRunningCb()
} }
behaviac::EBTStatus BaseAgent::StartCoroutine(std::function<behaviac::EBTStatus()> cb, behaviac::EBTStatus BaseAgent::StartCoroutine(std::function<behaviac::EBTStatus()> cb,
std::function<void(bool&)> event_cb, std::function<void(bool, bool&)> event_cb,
const char* name) const char* name)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -136,7 +136,7 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
} }
return behaviac::BT_RUNNING; return behaviac::BT_RUNNING;
}, },
[this] (bool& has_event) [this] (bool is_test, bool& has_event)
{ {
}, },

View File

@ -27,7 +27,7 @@ public:
protected: protected:
behaviac::EBTStatus DoRunningCb(); behaviac::EBTStatus DoRunningCb();
behaviac::EBTStatus StartCoroutine(std::function<behaviac::EBTStatus()> cb, behaviac::EBTStatus StartCoroutine(std::function<behaviac::EBTStatus()> cb,
std::function<void(bool&)> event_cb, std::function<void(bool, bool&)> event_cb,
const char* name); const char* name);
protected: protected:
@ -38,7 +38,7 @@ protected:
#endif #endif
behaviac::EBTStatus status_= behaviac::BT_SUCCESS; behaviac::EBTStatus status_= behaviac::BT_SUCCESS;
std::function<behaviac::EBTStatus()> runing_cb_; std::function<behaviac::EBTStatus()> runing_cb_;
std::function<void(bool&)> event_cb_; std::function<void(bool, bool&)> event_cb_;
private: private:
Creature* owner_ = nullptr; Creature* owner_ = nullptr;