135 lines
3.6 KiB
C++
135 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include <f8/timer.h>
|
|
|
|
#include "netdata.h"
|
|
|
|
namespace cs
|
|
{
|
|
class MFMatchTeamMember;
|
|
class CMJoin;
|
|
class CMMatchCancel;
|
|
class CMMatchChoose;
|
|
class CMMatchStartGame;
|
|
class CMMatchCancelStartGame;
|
|
class CMMatchSendMsg;
|
|
class CMMatchBroadcastMsg;
|
|
}
|
|
|
|
enum MatchTeamPhase_e
|
|
{
|
|
kMatchCombining = 1,
|
|
kMatchChoose = 2,
|
|
kMatchLock = 3,
|
|
kMatchStartGame = 4,
|
|
kMatchWaitStart = 5
|
|
};
|
|
|
|
enum MatchTeamMember_e
|
|
{
|
|
kMatchReadying = 0,
|
|
kMatchPrepare = 1,
|
|
};
|
|
|
|
namespace cs
|
|
{
|
|
class CMJoin;
|
|
class CMReconnect;
|
|
}
|
|
|
|
struct RawTeamMember
|
|
{
|
|
class MatchTeam* team = nullptr;
|
|
std::shared_ptr<BattleDataContext> battle_context;
|
|
long long battle_uuid = 0;
|
|
int is_valid_battle = 0;
|
|
std::string payload;
|
|
long long add_tick = 0;
|
|
int socket_handle = 0;
|
|
std::shared_ptr<cs::CMJoin> msg;
|
|
bool is_robot = false;
|
|
bool is_leader = false;
|
|
int state = kMatchReadying;
|
|
int choose_hero_times = 0;
|
|
const mt::Robot* robot_meta = nullptr;
|
|
RawTeamMember();
|
|
void FillMFMatchTeamMember(cs::MFMatchTeamMember* msg);
|
|
void InitRobot();
|
|
};
|
|
|
|
class MatchTeam
|
|
{
|
|
public:
|
|
enum { HID = HID_MatchTeam };
|
|
|
|
public:
|
|
f8::Attacher timer_attacher;
|
|
~MatchTeam();
|
|
|
|
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 _CMMatchCancelStartGame(f8::MsgHdr& hdr, const cs::CMMatchCancelStartGame& msg);
|
|
void _CMMatchSendMsg(f8::MsgHdr& hdr, const cs::CMMatchSendMsg& msg);
|
|
void _CMMatchBroadcastMsg(f8::MsgHdr& hdr, const cs::CMMatchBroadcastMsg& 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();
|
|
int GetMapId();
|
|
std::list<std::shared_ptr<RawTeamMember>>& GetCurrMembers() { return curr_member_hash_; };
|
|
std::shared_ptr<RawTeamMember> GetOwner() { return first_member_; };
|
|
int GetInitMemberNum();
|
|
int GetSlotNum();
|
|
bool HaveEmptySlot();
|
|
int GetEmptySlotNum();
|
|
|
|
private:
|
|
void Update();
|
|
void UpdateMaster();
|
|
void UpdateSlave();
|
|
void SyncMatchInfo();
|
|
bool HasSameCurrMember(MatchTeam* b);
|
|
bool ProtoIsCompatible(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();
|
|
void ChooseLeader();
|
|
void AutoChoose(bool force = false);
|
|
void AutoPrepare();
|
|
bool IsAllPrepare();
|
|
void UpdateTeamState();
|
|
void CheckChoose();
|
|
void CheckPrepare();
|
|
int GetValidSocketNum();
|
|
void RemoveTeam();
|
|
|
|
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_;
|
|
long long last_auto_choose_tick_ = 0;
|
|
long long last_auto_prepare_tick_ = 0;
|
|
int all_player_choose_times_ = 0;
|
|
int all_player_prepare_times_ = 0;
|
|
|
|
std::map<std::string, MatchTeam*> combined_team_hash_;
|
|
MatchTeam* master_team_ = nullptr;
|
|
|
|
std::list<std::shared_ptr<RawTeamMember>> curr_member_hash_;
|
|
};
|