diff --git a/server/gameserver/hero_agent.cc b/server/gameserver/hero_agent.cc index 98895b85..32aadb6e 100644 --- a/server/gameserver/hero_agent.cc +++ b/server/gameserver/hero_agent.cc @@ -61,18 +61,9 @@ HeroAgent::~HeroAgent() void HeroAgent::Exec() { behaviac::EBTStatus status = f8::BtMgr::Instance()->BtExec(this); - #if 0 - if (status == behaviac::BT_RUNNING && - coroutine_ && - coroutine_->GetContext()->HasEvent()) { - status_= behaviac::BT_INVALID; - auto old_coroutine = coroutine_; - coroutine_ = nullptr; - owner_->shot_hold = false; - old_coroutine->GetContext()->FireEvent(this); - old_coroutine = nullptr; + if (status == behaviac::BT_RUNNING) { + CheckCoroutineEvent(); } - #endif } void HeroAgent::SetOwner(Creature* owner) @@ -943,8 +934,37 @@ bool HeroAgent::PreEnterCoroutine(int co_id, behaviac::EBTStatus& status) return true; } co->status = co->runing_cb(); - if (co->status != behaviac::BT_RUNNING) { - } status = co->status; + if (co->status != behaviac::BT_RUNNING) { + list_del_init(&co->entry); + coroutines_hash_.erase(itr); + } return true; } + +void HeroAgent::CheckCoroutineEvent() +{ + int co_id = -1; + { + list_head* pos = nullptr; + list_head* next = nullptr; + list_head* head = &coroutines_list_; + list_for_each_safe(pos, next, head) { + BtCoroutine* co = list_entry(pos, BtCoroutine, entry); + if (co->GetContext()->HasEvent()) { + co_id = co->GetId(); + break; + } + } + } + if (co_id >= 0) { + auto itr = coroutines_hash_.find(co_id); + if (itr == coroutines_hash_.end()) { + abort(); + } + auto co = itr->second; + coroutines_hash_.clear(); + INIT_LIST_HEAD(&coroutines_list_); + co->GetContext()->FireEvent(this); + } +} diff --git a/server/gameserver/hero_agent.h b/server/gameserver/hero_agent.h index c8b1050f..5c6c0de5 100644 --- a/server/gameserver/hero_agent.h +++ b/server/gameserver/hero_agent.h @@ -143,6 +143,7 @@ protected: bool PreEnterCoroutine(int co_id, behaviac::EBTStatus& status); behaviac::EBTStatus StartCoroutine(std::shared_ptr coroutine); bool InternalUseSkill(int skill_id, int& wait_time); + void CheckCoroutineEvent(); private: Creature* owner_ = nullptr;