This commit is contained in:
aozhiwei 2024-03-25 21:02:00 +08:00
parent 2ae8fe18cc
commit 4484436629
3 changed files with 17 additions and 0 deletions

View File

@ -184,6 +184,18 @@ bool CustomBattle::AllIsJoined()
return ok;
}
bool CustomBattle::AllIsReady()
{
bool ok = true;
for (auto& pair : member_id_hash_) {
if (!pair.second->IsReady()) {
ok = false;
break;
}
}
return ok;
}
int CustomBattle::GetMemberNum()
{
return member_id_hash_.size();
@ -304,5 +316,8 @@ void CustomBattle::OnEnter(std::shared_ptr<cs::CMJoin> join_msg, long ip_saddr,
void CustomBattle::OnMemberReady(CustomMember* member)
{
if (state_ == 0 && AllIsReady()) {
state_ = 1;
}
NotifyState();
}

View File

@ -34,6 +34,7 @@ class CustomBattle
std::shared_ptr<CustomTeam> GetTeamByTeamUuid(const std::string& team_uuid);
std::shared_ptr<CustomMember> GetObByAccountId(const std::string& account_id);
bool AllIsJoined();
bool AllIsReady();
int GetMemberNum();
int GetTeamNum();
void TraverseMemberList(std::function<bool (CustomMember*)> func);

View File

@ -32,6 +32,7 @@ class CustomMember
std::shared_ptr<BattleDataContext>& GetNetData() { return battle_context_; };
void _CMBattlePreSetReady(f8::MsgHdr* hdr, const cs::CMBattlePreSetReady& msg);
bool IsAndroid();
bool IsReady() { return is_ready_; }
private:
std::shared_ptr<cs::CMJoin> join_msg_;