This commit is contained in:
aozhiwei 2021-09-27 11:36:29 +00:00
parent 27a7bdc6a6
commit 8f2a0c7f99
3 changed files with 98 additions and 15 deletions

View File

@ -30,6 +30,7 @@ void MatchMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
team = new MatchTeam(); team = new MatchTeam();
team->Init(hdr, msg); team->Init(hdr, msg);
team_hash_[msg.team_uuid()] = team; team_hash_[msg.team_uuid()] = team;
team->TryCombineTeam();
} else { } else {
team->AddRawMember(hdr, msg); team->AddRawMember(hdr, msg);
} }

View File

@ -36,11 +36,6 @@ void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg)
}, },
&timer_attacher.timer_list_); &timer_attacher.timer_list_);
AddRawMember(hdr, msg); AddRawMember(hdr, msg);
{
if (GetPredictMemberNum() < MAX_TEAM_NUM) {
TryCombineTeam();
}
}
} }
void MatchTeam::AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg) void MatchTeam::AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg)
@ -94,15 +89,24 @@ void MatchTeam::SyncMatchInfo()
void MatchTeam::TryCombineTeam() void MatchTeam::TryCombineTeam()
{ {
MatchTeam* matched_team = nullptr; if (GetPredictMemberNum() < MAX_TEAM_NUM) {
MatchMgr::Instance()->TraverseTeam MatchTeam* matched_team = nullptr;
( MatchMgr::Instance()->TraverseTeam
[this, &matched_team] (MatchTeam* team, bool& stop) (
{ [this, &matched_team] (MatchTeam* team, bool& stop)
if (team == this) { {
return; if (team == this) {
} return;
}); }
if (CanCombine(team)) {
matched_team = team;
stop = true;
}
});
if (matched_team) {
Combine(matched_team);
}
}
} }
void MatchTeam::UpdateMaster() void MatchTeam::UpdateMaster()
@ -164,3 +168,76 @@ int MatchTeam::GetPredictMemberNum()
} }
return num; return num;
} }
bool MatchTeam::HasSameCurrMember(MatchTeam* b)
{
bool has = false;
for (auto& a_member : curr_member_hash_) {
for (auto& b_member : b->curr_member_hash_) {
if (a_member->msg.account_id() == b_member->msg.account_id()) {
has = true;
break;
}
}
}
return has;
}
bool MatchTeam::CanCombine(MatchTeam* b)
{
if (this == b) {
return false;
}
//已合并
if (master_team_ != this){
return false;
}
//已合并
if (b->master_team_ != b) {
return false;
}
if (phase_ != kMatchCombining) {
return false;
}
if (b->phase_ != kMatchCombining) {
return false;
}
if (IsShuaRobotTime()) {
return false;
}
if (b->IsShuaRobotTime()) {
return false;
}
if (!b->combined_team_hash_.empty()) {
return false;
}
if (GetPredictMemberNum() + b->GetPredictMemberNum() > MAX_TEAM_NUM) {
return false;
}
if (combined_team_hash_.find(b->GetTeamUUid()) != combined_team_hash_.end()) {
return false;
}
if (HasSameCurrMember(b)) {
return false;
}
return true;
}
void MatchTeam::Combine(MatchTeam* b)
{
combined_team_hash_[b->GetTeamUUid()] = b;
b->master_team_ = this;
for (auto& member : b->curr_member_hash_) {
curr_member_hash_.push_back(member);
}
}
std::string MatchTeam::GetTeamUUid()
{
return first_member_->msg.team_uuid();
}
bool MatchTeam::IsShuaRobotTime()
{
return false;
}

View File

@ -24,15 +24,20 @@ class MatchTeam
void AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg); void AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg);
bool IsRawMember(const std::string& account_id); bool IsRawMember(const std::string& account_id);
bool IsValidMember(const cs::CMJoin& msg); bool IsValidMember(const cs::CMJoin& msg);
void TryCombineTeam();
std::string GetTeamUUid();
private: private:
void Update(); void Update();
void UpdateMaster(); void UpdateMaster();
void UpdateSlave(); void UpdateSlave();
void SyncMatchInfo(); void SyncMatchInfo();
void TryCombineTeam();
int GetPredictMemberNum(); int GetPredictMemberNum();
int GetRawMemberNum() { return raw_member_hash_.size(); }; int GetRawMemberNum() { return raw_member_hash_.size(); };
bool HasSameCurrMember(MatchTeam* b);
bool CanCombine(MatchTeam* b);
bool IsShuaRobotTime();
void Combine(MatchTeam* b);
private: private:
int phase_= kMatchCombining; int phase_= kMatchCombining;