This commit is contained in:
aozhiwei 2023-06-21 18:53:05 +08:00
parent 95039c2f76
commit 7c4989671c
4 changed files with 14 additions and 115 deletions

View File

@ -86,18 +86,6 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
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);
}
@ -167,17 +155,6 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
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);
}
@ -255,11 +232,6 @@ behaviac::EBTStatus AndroidAgent::DoAttack()
return behaviac::BT_RUNNING;
}
};
co->event_cb =
[this, context]
(bool is_test, bool& has_event) mutable
{
};
return StartCoroutine(co);
}
@ -360,11 +332,6 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
return behaviac::BT_RUNNING;
}
};
co->event_cb =
[this, context]
(bool is_test, bool& has_event) mutable
{
};
return StartCoroutine(co);
}

View File

@ -67,7 +67,7 @@ void BtEvent::FireEvent(BaseAgent* agent)
bool BtCoroutine::HasEvent()
{
return false;
}
void BtCoroutine::FireEvent()
@ -115,23 +115,19 @@ bool BaseAgent::IsGameOver()
void BaseAgent::Exec()
{
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
DumpBt(this);
#endif
bool has_event = false;
coroutine_->event_cb(true, has_event);
if (has_event) {
status_= behaviac::BT_INVALID;
auto old_coroutine = coroutine_;
coroutine_ = nullptr;
GetOwner()->shot_hold = false;
old_coroutine->event_cb(false, has_event);
old_coroutine = nullptr;
status_= behaviac::BT_INVALID;
auto old_coroutine = coroutine_;
coroutine_ = nullptr;
GetOwner()->shot_hold = false;
old_coroutine->FireEvent();
old_coroutine = nullptr;
#ifdef DEBUG1
a8::XPrintf("FireEvent OnAttacked\n", {});
a8::XPrintf("FireEvent OnAttacked\n", {});
#endif
}
}
}
@ -189,14 +185,12 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
return behaviac::BT_FAILURE;
}
auto context = A8_MAKE_SMART_ANON_STRUCT_SHARED
auto context = MAKE_BTCONTEXT
(
CreatureWeakPtr owner;
CreatureWeakPtr target;
long long frameno = 0;
long long last_pursuit_frameno = 0;
);
context->owner = GetOwner()->GetWeakPtrRef();
context->target = target;
context->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;
};
co->event_cb =
[this, context]
(bool is_test, bool& has_event) mutable
{
};
return StartCoroutine(co);
}
@ -355,17 +344,6 @@ behaviac::EBTStatus BaseAgent::DoIdle(int min_time, int max_time)
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);
}

View File

@ -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> \
{ \
@ -34,14 +34,14 @@ struct Context : public BtContext, public std::enable_shared_from_this<Context>
}; \
auto context = std::make_shared<Context>(); \
context->owner = owner; \
}()
return context; \
}(GetOwner()->GetWeakPtrRef(), this)
struct BtCoroutine
{
std::any context;
const char* name = nullptr;
std::function<behaviac::EBTStatus()> runing_cb;
std::function<void(bool, bool&)> event_cb;
long long sleep_end_frameno = 0;
int sleep_time = 0;

View File

@ -79,17 +79,6 @@ behaviac::EBTStatus HeroAgent::DoRandomWalk()
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);
}
@ -154,17 +143,6 @@ behaviac::EBTStatus HeroAgent::DoRandomShot()
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);
}
@ -273,15 +251,6 @@ behaviac::EBTStatus HeroAgent::DoAttack()
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);
}
@ -382,11 +351,6 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
return behaviac::BT_RUNNING;
}
};
co->event_cb =
[this, context]
(bool is_test, bool& has_event) mutable
{
};
return StartCoroutine(co);
}
@ -465,11 +429,6 @@ behaviac::EBTStatus HeroAgent::DoHelpAttack(int target_uniid)
return behaviac::BT_RUNNING;
}
};
co->event_cb =
[this, context]
(bool is_test, bool& has_event) mutable
{
};
return StartCoroutine(co);
}
@ -594,11 +553,6 @@ behaviac::EBTStatus HeroAgent::DoFollowMaster()
return behaviac::BT_RUNNING;
}
};
co->event_cb =
[this, context]
(bool is_test, bool& has_event) mutable
{
};
return StartCoroutine(co);
}