89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "cs_proto.pb.h"
|
|
|
|
enum MatchTeamPhase_e
|
|
{
|
|
kMatchCombining = 1,
|
|
kMatchChoose = 2,
|
|
kMatchLock = 3
|
|
};
|
|
|
|
enum MatchTeamMember_e
|
|
{
|
|
kMatchReadying = 0,
|
|
kMatchPrepare = 2,
|
|
};
|
|
|
|
namespace cs
|
|
{
|
|
class CMJoin;
|
|
class CMReconnect;
|
|
}
|
|
|
|
struct RawTeamMember
|
|
{
|
|
class MatchTeam* team = nullptr;
|
|
long long add_tick = 0;
|
|
int socket_handle = 0;
|
|
cs::CMJoin msg;
|
|
bool is_robot = false;
|
|
bool is_leader = false;
|
|
int state = kMatchReadying;
|
|
void FillMFMatchTeamMember(cs::MFMatchTeamMember* msg);
|
|
void InitRobot();
|
|
};
|
|
|
|
|
|
struct timer_list;
|
|
class MatchTeam
|
|
{
|
|
public:
|
|
a8::TimerAttacher timer_attacher;
|
|
|
|
void Init(f8::MsgHdr& hdr, const cs::CMJoin& msg);
|
|
|
|
void _CMMatchCancel(f8::MsgHdr& hdr, const cs::CMMatchCancel& msg);
|
|
void _CMMatchChoose(f8::MsgHdr& hdr, const cs::CMMatchChoose& msg);
|
|
void _CMMatchStartGame(f8::MsgHdr& hdr, const cs::CMMatchStartGame& msg);
|
|
|
|
void AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg);
|
|
bool IsRawMember(const std::string& account_id);
|
|
bool IsValidMember(const cs::CMJoin& msg);
|
|
void TryCombineTeam();
|
|
std::string GetTeamUUid();
|
|
std::list<std::shared_ptr<RawTeamMember>>& GetCurrMembers() { return curr_member_hash_; };
|
|
|
|
private:
|
|
void Update();
|
|
void UpdateMaster();
|
|
void UpdateSlave();
|
|
void SyncMatchInfo();
|
|
int GetPredictMemberNum();
|
|
int GetRawMemberNum() { return raw_member_hash_.size(); };
|
|
bool HasSameCurrMember(MatchTeam* b);
|
|
bool CanCombine(MatchTeam* b);
|
|
bool IsShuaRobotTime();
|
|
void Combine(MatchTeam* b);
|
|
bool IsMasterTeam() { return master_team_ == this; };
|
|
bool IsSlaveTeam() { return master_team_ != this; };
|
|
int GetPhaseLeftTime();
|
|
std::shared_ptr<RawTeamMember> GetMemberBySocket(int socket_handle);
|
|
void ShuaRobot();
|
|
void StartGame();
|
|
|
|
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_;
|
|
|
|
std::map<std::string, MatchTeam*> combined_team_hash_;
|
|
MatchTeam* master_team_ = nullptr;
|
|
|
|
std::list<std::shared_ptr<RawTeamMember>> curr_member_hash_;
|
|
};
|