diff --git a/server/gameserver/android_agent.cc b/server/gameserver/android_agent.cc index e8fdbd2b..560c561b 100644 --- a/server/gameserver/android_agent.cc +++ b/server/gameserver/android_agent.cc @@ -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); } diff --git a/server/gameserver/base_agent.cc b/server/gameserver/base_agent.cc index dee4c8c1..dfb5b4b1 100644 --- a/server/gameserver/base_agent.cc +++ b/server/gameserver/base_agent.cc @@ -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); } diff --git a/server/gameserver/base_agent.h b/server/gameserver/base_agent.h index cd92f1d6..0a0db081 100644 --- a/server/gameserver/base_agent.h +++ b/server/gameserver/base_agent.h @@ -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 \ { \ @@ -34,14 +34,14 @@ struct Context : public BtContext, public std::enable_shared_from_this }; \ auto context = std::make_shared(); \ context->owner = owner; \ -}() +return context; \ +}(GetOwner()->GetWeakPtrRef(), this) struct BtCoroutine { std::any context; const char* name = nullptr; std::function runing_cb; - std::function event_cb; long long sleep_end_frameno = 0; int sleep_time = 0; diff --git a/server/gameserver/hero_agent.cc b/server/gameserver/hero_agent.cc index 3e7f0c2f..80f6039c 100644 --- a/server/gameserver/hero_agent.cc +++ b/server/gameserver/hero_agent.cc @@ -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); }