修复队伍合并问题
This commit is contained in:
parent
8a8d5370b5
commit
3238fc42d1
@ -1358,22 +1358,36 @@ void Room::MatchTeam(Human* hum)
|
||||
if (!hum->team_uuid.empty()) {
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second != hum) {
|
||||
if (!hum->team_uuid.empty() && pair.second->team_uuid == hum->team_uuid) {
|
||||
if (!pair.second->GetTeam()) {
|
||||
Team* new_team = NewTeam();
|
||||
new_team->SetInitTeamMemberNum(hum->init_team_member_num);
|
||||
new_team->AddMember(pair.second);
|
||||
}
|
||||
if (!pair.second->GetTeam()->IsFull()) {
|
||||
if (pair.second->team_uuid == hum->team_uuid) {
|
||||
if (pair.second->GetTeam() && !pair.second->GetTeam()->IsFull()) {
|
||||
pair.second->GetTeam()->AddMember(hum);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end for human_hash_
|
||||
if (MetaMgr::Instance()->prebattle_combine_team) {
|
||||
if (!hum->GetTeam() && hum->auto_fill && combineable_team_hash_.size() > 1) {
|
||||
for (auto& pair : combineable_team_hash_) {
|
||||
Team* team = pair.second;
|
||||
if (team->CanCombine(hum)) {
|
||||
team->AddMember(hum);
|
||||
team->AddCombineMemberNum(hum->init_team_member_num);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
}
|
||||
|
||||
if (!hum->GetTeam()) {
|
||||
NewTeam()->AddMember(hum);
|
||||
Team* new_team = NewTeam();
|
||||
new_team->SetInitTeamMemberNum(hum->init_team_member_num);
|
||||
new_team->SetAutoFill(hum->auto_fill);
|
||||
new_team->AddMember(hum);
|
||||
if (hum->IsPlayer() && hum->auto_fill) {
|
||||
combineable_team_hash_[new_team->GetTeamId()] = new_team;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,6 +356,7 @@ private:
|
||||
|
||||
std::set<int> refreshed_robot_set_;
|
||||
std::map<int, Team*> team_hash_;
|
||||
std::map<int, Team*> combineable_team_hash_;
|
||||
std::map<std::string, Player*> accountid_hash_;
|
||||
std::map<int, MoveableEntity*> moveable_hash_;
|
||||
std::map<int, Entity*> uniid_hash_;
|
||||
|
@ -47,6 +47,8 @@ void Team::AddMember(Human* member)
|
||||
{
|
||||
if (!first_member_) {
|
||||
first_member_ = member;
|
||||
init_team_member_num_ = member->init_team_member_num;
|
||||
combined_team_member_num_ = member->init_team_member_num;
|
||||
}
|
||||
member->team_id = team_id_;
|
||||
member->SetTeam(this);
|
||||
@ -124,3 +126,13 @@ Human* Team::GetMemberByUniId(int member_id)
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Team::CanCombine(Human* member)
|
||||
{
|
||||
return !IsFull() && (combined_team_member_num_ + member->init_team_member_num < MAX_TEAM_NUM);
|
||||
}
|
||||
|
||||
void Team::AddCombineMemberNum(int member_num)
|
||||
{
|
||||
combined_team_member_num_ += member_num;
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ class Team
|
||||
Room* room = nullptr;
|
||||
|
||||
void SetInitTeamMemberNum(int init_num) { init_team_member_num_ = init_num; };
|
||||
void SetAutoFill(bool auto_fill) { auto_fill_ = auto_fill; };
|
||||
bool IsAutoFill() { return auto_fill_; };
|
||||
int GetTeamId() { return team_id_; }
|
||||
void SetTeamId(int team_id) { team_id_ = team_id; }
|
||||
void TraverseMembers(std::function<bool (Human*)> func);
|
||||
@ -20,12 +22,16 @@ class Team
|
||||
bool IsFull();
|
||||
void CombineBornPoint();
|
||||
void CombineTeam(Team* b_team);
|
||||
bool CanCombine(Human* member);
|
||||
void AddCombineMemberNum(int member_num);
|
||||
Human* GetMemberByUniId(int member_id);
|
||||
int GetInitTeamMemberNum() { return init_team_member_num_; };
|
||||
|
||||
private:
|
||||
int team_id_ = 0;
|
||||
int init_team_member_num_ = 0;
|
||||
int combined_team_member_num_ = 0;
|
||||
std::set<Human*> members_;
|
||||
Human* first_member_ = nullptr;
|
||||
bool auto_fill_ = false;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user