1
This commit is contained in:
parent
8f2a0c7f99
commit
3afaa7a2cb
@ -6,6 +6,7 @@
|
||||
#include "matchteam.h"
|
||||
#include "matchmgr.h"
|
||||
#include "GGListener.h"
|
||||
#include "metamgr.h"
|
||||
|
||||
struct RawTeamMember
|
||||
{
|
||||
@ -35,6 +36,9 @@ void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
team->Update();
|
||||
},
|
||||
&timer_attacher.timer_list_);
|
||||
phase_= kMatchCombining;
|
||||
phase_start_tick_ = a8::XGetTickCount();
|
||||
countdown_ = MetaMgr::Instance()->match_team_time;
|
||||
AddRawMember(hdr, msg);
|
||||
}
|
||||
|
||||
@ -46,6 +50,7 @@ void MatchTeam::AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
member->socket_handle = hdr.socket_handle;
|
||||
member->msg = msg;
|
||||
raw_member_hash_[msg.account_id()] = member;
|
||||
curr_member_hash_.push_back(member);
|
||||
if (!first_member_) {
|
||||
first_member_ = member;
|
||||
}
|
||||
@ -64,7 +69,7 @@ bool MatchTeam::IsValidMember(const cs::CMJoin& msg)
|
||||
|
||||
void MatchTeam::Update()
|
||||
{
|
||||
if (master_team_ == this) {
|
||||
if (IsMasterTeam()) {
|
||||
UpdateMaster();
|
||||
} else {
|
||||
UpdateSlave();
|
||||
@ -79,7 +84,7 @@ void MatchTeam::SyncMatchInfo()
|
||||
member->FillMFMatchTeamMember(notifymsg.mutable_info()->add_members());
|
||||
}
|
||||
notifymsg.mutable_info()->set_phase(phase_);
|
||||
notifymsg.mutable_info()->set_countdown(countdown_);
|
||||
notifymsg.mutable_info()->set_countdown(phase_left_time_);
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (member->socket_handle != 0) {
|
||||
GGListener::Instance()->SendToClient(member->socket_handle, 0, notifymsg);
|
||||
@ -111,17 +116,25 @@ void MatchTeam::TryCombineTeam()
|
||||
|
||||
void MatchTeam::UpdateMaster()
|
||||
{
|
||||
phase_left_time_ = GetPhaseLeftTime();
|
||||
switch (phase_) {
|
||||
case kMatchCombining:
|
||||
{
|
||||
if (GetPredictMemberNum() < MAX_TEAM_NUM) {
|
||||
TryCombineTeam();
|
||||
}
|
||||
if (phase_left_time_ <= 0) {
|
||||
phase_ = kMatchChoose;
|
||||
phase_start_tick_ = a8::XGetTickCount();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kMatchChoose:
|
||||
{
|
||||
|
||||
if (phase_left_time_ <= 0) {
|
||||
phase_ = kMatchLock;
|
||||
phase_start_tick_ = a8::XGetTickCount();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kMatchLock:
|
||||
@ -239,5 +252,11 @@ std::string MatchTeam::GetTeamUUid()
|
||||
|
||||
bool MatchTeam::IsShuaRobotTime()
|
||||
{
|
||||
return false;
|
||||
return phase_ == kMatchCombining && phase_left_time_ <= MetaMgr::Instance()->match_robot_time;
|
||||
}
|
||||
|
||||
int MatchTeam::GetPhaseLeftTime()
|
||||
{
|
||||
int passtime = (a8::XGetTickCount() - phase_start_tick_) / 1000;
|
||||
return std::max(0, countdown_ - passtime);
|
||||
}
|
||||
|
@ -38,10 +38,15 @@ class MatchTeam
|
||||
bool CanCombine(MatchTeam* b);
|
||||
bool IsShuaRobotTime();
|
||||
void Combine(MatchTeam* b);
|
||||
bool IsMasterTeam() { return master_team_ == this; };
|
||||
bool IsSlaveTeam() { return master_team_ != this; };
|
||||
int GetPhaseLeftTime();
|
||||
|
||||
private:
|
||||
long long phase_start_tick_ = 0;
|
||||
int phase_= kMatchCombining;
|
||||
int countdown_ = 0;
|
||||
int phase_left_time_ = 0;
|
||||
long long create_tick_ = 0;
|
||||
std::map<std::string, std::shared_ptr<RawTeamMember>> raw_member_hash_;
|
||||
std::shared_ptr<RawTeamMember> first_member_;
|
||||
|
@ -578,6 +578,24 @@ private:
|
||||
map.Init2();
|
||||
}
|
||||
}
|
||||
if (MetaMgr::Instance()->match_team_time <= 0) {
|
||||
abort();
|
||||
}
|
||||
if (MetaMgr::Instance()->match_robot_time <= 0) {
|
||||
abort();
|
||||
}
|
||||
if (MetaMgr::Instance()->match_robot_time >= MetaMgr::Instance()->match_team_time) {
|
||||
abort();
|
||||
}
|
||||
if (MetaMgr::Instance()->match_choose_time <= 0) {
|
||||
abort();
|
||||
}
|
||||
if (MetaMgr::Instance()->match_lock_time <= 0) {
|
||||
abort();
|
||||
}
|
||||
if (MetaMgr::Instance()->match_lock_time >= MetaMgr::Instance()->match_choose_time) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void BindToMetaData()
|
||||
|
Loading…
x
Reference in New Issue
Block a user