1
This commit is contained in:
parent
95039c2f76
commit
7c4989671c
@ -86,18 +86,6 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
has_event = context->last_attacker.Get() && !context->last_attacker.Get()->dead ? true : false;
|
|
||||||
if (!is_test && has_event) {
|
|
||||||
FireEvent("OnAttacked",
|
|
||||||
context->last_attacker.Get()->GetUniId(),
|
|
||||||
context->last_attacked_frameno);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,17 +155,6 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
has_event = context->last_attacker.Get() && !context->last_attacker.Get()->dead ? true : false;
|
|
||||||
if (!is_test && has_event) {
|
|
||||||
FireEvent("OnAttacked",
|
|
||||||
context->last_attacker.Get()->GetUniId(),
|
|
||||||
context->last_attacked_frameno);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,11 +232,6 @@ behaviac::EBTStatus AndroidAgent::DoAttack()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,11 +332,6 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ void BtEvent::FireEvent(BaseAgent* agent)
|
|||||||
|
|
||||||
bool BtCoroutine::HasEvent()
|
bool BtCoroutine::HasEvent()
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtCoroutine::FireEvent()
|
void BtCoroutine::FireEvent()
|
||||||
@ -115,23 +115,19 @@ bool BaseAgent::IsGameOver()
|
|||||||
void BaseAgent::Exec()
|
void BaseAgent::Exec()
|
||||||
{
|
{
|
||||||
behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this);
|
behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this);
|
||||||
if (status == behaviac::BT_RUNNING && coroutine_ && coroutine_->event_cb) {
|
if (status == behaviac::BT_RUNNING && coroutine_ && coroutine_->HasEvent()) {
|
||||||
#ifdef DEBUG1
|
#ifdef DEBUG1
|
||||||
DumpBt(this);
|
DumpBt(this);
|
||||||
#endif
|
#endif
|
||||||
bool has_event = false;
|
status_= behaviac::BT_INVALID;
|
||||||
coroutine_->event_cb(true, has_event);
|
auto old_coroutine = coroutine_;
|
||||||
if (has_event) {
|
coroutine_ = nullptr;
|
||||||
status_= behaviac::BT_INVALID;
|
GetOwner()->shot_hold = false;
|
||||||
auto old_coroutine = coroutine_;
|
old_coroutine->FireEvent();
|
||||||
coroutine_ = nullptr;
|
old_coroutine = nullptr;
|
||||||
GetOwner()->shot_hold = false;
|
|
||||||
old_coroutine->event_cb(false, has_event);
|
|
||||||
old_coroutine = nullptr;
|
|
||||||
#ifdef DEBUG1
|
#ifdef DEBUG1
|
||||||
a8::XPrintf("FireEvent OnAttacked\n", {});
|
a8::XPrintf("FireEvent OnAttacked\n", {});
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,14 +185,12 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
|
|||||||
return behaviac::BT_FAILURE;
|
return behaviac::BT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto context = A8_MAKE_SMART_ANON_STRUCT_SHARED
|
auto context = MAKE_BTCONTEXT
|
||||||
(
|
(
|
||||||
CreatureWeakPtr owner;
|
|
||||||
CreatureWeakPtr target;
|
CreatureWeakPtr target;
|
||||||
long long frameno = 0;
|
long long frameno = 0;
|
||||||
long long last_pursuit_frameno = 0;
|
long long last_pursuit_frameno = 0;
|
||||||
);
|
);
|
||||||
context->owner = GetOwner()->GetWeakPtrRef();
|
|
||||||
context->target = target;
|
context->target = target;
|
||||||
context->frameno = GetOwner()->room->GetFrameNo();
|
context->frameno = GetOwner()->room->GetFrameNo();
|
||||||
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
|
context->last_pursuit_frameno = GetOwner()->room->GetFrameNo();
|
||||||
@ -273,11 +267,6 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
|
|||||||
}
|
}
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,17 +344,6 @@ behaviac::EBTStatus BaseAgent::DoIdle(int min_time, int max_time)
|
|||||||
return behaviac::BT_SUCCESS;
|
return behaviac::BT_SUCCESS;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
has_event = context->last_attacker.Get() && !context->last_attacker.Get()->dead ? true : false;
|
|
||||||
if (!is_test && has_event) {
|
|
||||||
FireEvent("OnAttacked",
|
|
||||||
context->last_attacker.Get()->GetUniId(),
|
|
||||||
context->last_attacked_frameno);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAKE_BTCONTEXT(owner, ...) \
|
#define MAKE_BTCONTEXT(...) \
|
||||||
[] () \
|
[] (CreatureWeakPtr owner, BaseAgent* agent) \
|
||||||
{ \
|
{ \
|
||||||
struct Context : public BtContext, public std::enable_shared_from_this<Context> \
|
struct Context : public BtContext, public std::enable_shared_from_this<Context> \
|
||||||
{ \
|
{ \
|
||||||
@ -34,14 +34,14 @@ struct Context : public BtContext, public std::enable_shared_from_this<Context>
|
|||||||
}; \
|
}; \
|
||||||
auto context = std::make_shared<Context>(); \
|
auto context = std::make_shared<Context>(); \
|
||||||
context->owner = owner; \
|
context->owner = owner; \
|
||||||
}()
|
return context; \
|
||||||
|
}(GetOwner()->GetWeakPtrRef(), this)
|
||||||
|
|
||||||
struct BtCoroutine
|
struct BtCoroutine
|
||||||
{
|
{
|
||||||
std::any context;
|
std::any context;
|
||||||
const char* name = nullptr;
|
const char* name = nullptr;
|
||||||
std::function<behaviac::EBTStatus()> runing_cb;
|
std::function<behaviac::EBTStatus()> runing_cb;
|
||||||
std::function<void(bool, bool&)> event_cb;
|
|
||||||
long long sleep_end_frameno = 0;
|
long long sleep_end_frameno = 0;
|
||||||
int sleep_time = 0;
|
int sleep_time = 0;
|
||||||
|
|
||||||
|
@ -79,17 +79,6 @@ behaviac::EBTStatus HeroAgent::DoRandomWalk()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
has_event = context->last_attacker.Get() && !context->last_attacker.Get()->dead ? true : false;
|
|
||||||
if (!is_test && has_event) {
|
|
||||||
FireEvent("OnAttacked",
|
|
||||||
context->last_attacker.Get()->GetUniId(),
|
|
||||||
context->last_attacked_frameno);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,17 +143,6 @@ behaviac::EBTStatus HeroAgent::DoRandomShot()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
has_event = context->last_attacker.Get() && !context->last_attacker.Get()->dead ? true : false;
|
|
||||||
if (!is_test && has_event) {
|
|
||||||
FireEvent("OnAttacked",
|
|
||||||
context->last_attacker.Get()->GetUniId(),
|
|
||||||
context->last_attacked_frameno);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,15 +251,6 @@ behaviac::EBTStatus HeroAgent::DoAttack()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
has_event = context->last_attacker.Get() && !context->last_attacker.Get()->dead ? true : false;
|
|
||||||
if (!is_test && has_event) {
|
|
||||||
FireEvent("OnMasterAttackTarget", context->last_attacker.Get()->GetUniId());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,11 +351,6 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,11 +429,6 @@ behaviac::EBTStatus HeroAgent::DoHelpAttack(int target_uniid)
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,11 +553,6 @@ behaviac::EBTStatus HeroAgent::DoFollowMaster()
|
|||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
co->event_cb =
|
|
||||||
[this, context]
|
|
||||||
(bool is_test, bool& has_event) mutable
|
|
||||||
{
|
|
||||||
};
|
|
||||||
return StartCoroutine(co);
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user