1
This commit is contained in:
commit
1d0125cb53
@ -219,7 +219,6 @@ void MatchTeam::Update()
|
||||
} else {
|
||||
UpdateSlave();
|
||||
}
|
||||
master_team_->SyncMatchInfo();
|
||||
if (phase_ == kMatchStartGame && IsMasterTeam()) {
|
||||
StartGame();
|
||||
}
|
||||
@ -321,6 +320,7 @@ void MatchTeam::UpdateMaster()
|
||||
}
|
||||
break;
|
||||
}
|
||||
master_team_->SyncMatchInfo();
|
||||
}
|
||||
|
||||
void MatchTeam::UpdateSlave()
|
||||
@ -440,6 +440,16 @@ bool MatchTeam::CanCombine(MatchTeam* b)
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (GetValidSocketNum() <= 0) {
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("CanCombine 21\n", {});
|
||||
#endif
|
||||
}
|
||||
if (b->GetValidSocketNum() <= 0) {
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("CanCombine 22\n", {});
|
||||
#endif
|
||||
}
|
||||
if (HasSameCurrMember(b)) {
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("CanCombine 11\n", {});
|
||||
@ -513,7 +523,9 @@ void MatchTeam::ShuaRobot()
|
||||
|
||||
void MatchTeam::StartGame()
|
||||
{
|
||||
RoomMgr::Instance()->JoinTeam(this);
|
||||
if (GetValidSocketNum() > 0) {
|
||||
RoomMgr::Instance()->JoinTeam(this);
|
||||
}
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (member->socket_handle != 0) {
|
||||
MatchMgr::Instance()->RemoveSocket(member->socket_handle);
|
||||
@ -548,8 +560,10 @@ void MatchTeam::AutoChoose(bool force)
|
||||
if (member->choose_hero_times <= 0) {
|
||||
if (member->is_robot){
|
||||
++member->choose_hero_times;
|
||||
break;
|
||||
} else if (force) {
|
||||
++member->choose_hero_times;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -568,7 +582,30 @@ bool MatchTeam::IsAllPrepare()
|
||||
|
||||
void MatchTeam::UpdateTeamState()
|
||||
{
|
||||
|
||||
{
|
||||
bool all_choose = true;
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (!member->is_robot && member->choose_hero_times <= 0 && member->socket_handle != 0) {
|
||||
all_choose = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (all_choose) {
|
||||
++all_player_choose_times_;
|
||||
}
|
||||
}
|
||||
{
|
||||
bool all_prepare = true;
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (!member->is_robot && member->state != kMatchPrepare && member->socket_handle != 0) {
|
||||
all_prepare = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (all_prepare) {
|
||||
++all_player_prepare_times_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MatchTeam::CheckChoose()
|
||||
@ -582,7 +619,7 @@ void MatchTeam::CheckChoose()
|
||||
AutoChoose();
|
||||
last_auto_choose_tick_ = a8::XGetTickCount();
|
||||
} else {
|
||||
if (a8::XGetTickCount() - last_auto_choose_tick_ > (last_auto_choose_tick_ % 3000)) {
|
||||
if (a8::XGetTickCount() - last_auto_choose_tick_ > (last_auto_choose_tick_ % 2000)) {
|
||||
AutoChoose();
|
||||
last_auto_choose_tick_ = a8::XGetTickCount();
|
||||
}
|
||||
@ -595,4 +632,41 @@ void MatchTeam::CheckPrepare()
|
||||
if (phase_ != kMatchChoose) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (phase_left_time_ <= 10 || all_player_prepare_times_ > 0) {
|
||||
if (last_auto_prepare_tick_ <= 0) {
|
||||
AutoPrepare();
|
||||
last_auto_prepare_tick_ = a8::XGetTickCount();
|
||||
} else {
|
||||
if (a8::XGetTickCount() - last_auto_prepare_tick_ > (last_auto_prepare_tick_ % 2000)) {
|
||||
AutoPrepare();
|
||||
last_auto_prepare_tick_ = a8::XGetTickCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MatchTeam::AutoPrepare()
|
||||
{
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (member->choose_hero_times > 0 &&
|
||||
member->state != kMatchPrepare &&
|
||||
member->socket_handle == 0) {
|
||||
member->state = kMatchPrepare;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int MatchTeam::GetValidSocketNum()
|
||||
{
|
||||
int valid_socket_num = 0;
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (member->socket_handle != 0) {
|
||||
if (MatchMgr::Instance()->GetMatchInfo(member->socket_handle)) {
|
||||
++valid_socket_num;
|
||||
}
|
||||
}
|
||||
}
|
||||
return valid_socket_num;
|
||||
}
|
||||
|
@ -83,10 +83,12 @@ class MatchTeam
|
||||
void StartGame();
|
||||
void ChooseLeader();
|
||||
void AutoChoose(bool force = false);
|
||||
void AutoPrepare();
|
||||
bool IsAllPrepare();
|
||||
void UpdateTeamState();
|
||||
void CheckChoose();
|
||||
void CheckPrepare();
|
||||
int GetValidSocketNum();
|
||||
|
||||
private:
|
||||
long long phase_start_tick_ = 0;
|
||||
@ -97,8 +99,9 @@ class MatchTeam
|
||||
std::map<std::string, std::shared_ptr<RawTeamMember>> raw_member_hash_;
|
||||
std::shared_ptr<RawTeamMember> first_member_;
|
||||
long long last_auto_choose_tick_ = 0;
|
||||
long long last_auto_prepare_tick_ = 0;
|
||||
int all_player_choose_times_ = 0;
|
||||
int all_player_parpre_times_ = 0;
|
||||
int all_player_prepare_times_ = 0;
|
||||
|
||||
std::map<std::string, MatchTeam*> combined_team_hash_;
|
||||
MatchTeam* master_team_ = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user