This commit is contained in:
aozhiwei 2021-09-28 02:21:51 +00:00
parent ca77e15acc
commit e250e63ef3
7 changed files with 104 additions and 15 deletions

View File

@ -112,10 +112,17 @@ std::tuple<std::string, MatchTeam*>* MatchMgr::GetMatchInfo(int socket_handle)
void MatchMgr::RemoveTeam(const std::string& team_uuid) void MatchMgr::RemoveTeam(const std::string& team_uuid)
{ {
auto itr = team_hash_.find(team_uuid);
if (itr != team_hash_.end()) {
delete itr->second;
team_hash_.erase(itr);
}
} }
void MatchMgr::RemoveSocket(int socket_handle) void MatchMgr::RemoveSocket(int socket_handle)
{ {
auto itr = socket_hash_.find(socket_handle);
if (itr != socket_hash_.end()) {
socket_hash_.erase(itr);
}
} }

View File

@ -2,25 +2,35 @@
#include <a8/timer.h> #include <a8/timer.h>
#include "cs_proto.pb.h"
#include "matchteam.h" #include "matchteam.h"
#include "matchmgr.h" #include "matchmgr.h"
#include "GGListener.h" #include "GGListener.h"
#include "metamgr.h" #include "metamgr.h"
struct RawTeamMember void RawTeamMember::FillMFMatchTeamMember(cs::MFMatchTeamMember* msg)
{ {
MatchTeam* team = nullptr;
long long add_tick = 0;
int socket_handle = 0;
cs::CMJoin msg;
void FillMFMatchTeamMember(cs::MFMatchTeamMember* msg) }
void RawTeamMember::InitRobot()
{
static long long robot_idx = 1000;
msg.set_account_id(a8::Format("6000_2005_%d", {++robot_idx}));
{ {
std::set<int> refreshed_robot_set;
MetaData::Robot* robot_meta = MetaMgr::Instance()->RandRobot(refreshed_robot_set);
if (robot_meta) {
msg.set_hero_id(robot_meta->i->hero_id());
msg.set_name(robot_meta->i->name());
auto skin = msg.add_skins();
if (!robot_meta->skin_id.empty()) {
skin->set_skin_id(robot_meta->skin_id[0]);
skin->set_skin_lv(1);
} }
}
}; }
}
void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg) void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{ {
@ -149,9 +159,15 @@ void MatchTeam::UpdateMaster()
switch (phase_) { switch (phase_) {
case kMatchCombining: case kMatchCombining:
{ {
if (IsShuaRobotTime()) {
if (curr_member_hash_.size() < MAX_TEAM_NUM) {
ShuaRobot();
}
} else {
if (GetPredictMemberNum() < MAX_TEAM_NUM) { if (GetPredictMemberNum() < MAX_TEAM_NUM) {
TryCombineTeam(); TryCombineTeam();
} }
}
if (phase_left_time_ <= 0) { if (phase_left_time_ <= 0) {
phase_ = kMatchChoose; phase_ = kMatchChoose;
phase_start_tick_ = a8::XGetTickCount(); phase_start_tick_ = a8::XGetTickCount();
@ -301,6 +317,18 @@ std::shared_ptr<RawTeamMember> MatchTeam::GetMemberBySocket(int socket_handle)
return std::shared_ptr<RawTeamMember>(); return std::shared_ptr<RawTeamMember>();
} }
void MatchTeam::ShuaRobot()
{
for (int i = curr_member_hash_.size(); i < MAX_TEAM_NUM; ++i) {
std::shared_ptr<RawTeamMember> member = std::make_shared<RawTeamMember>();
member->team = this;
member->add_tick = a8::XGetTickCount();
member->is_robot = true;
member->InitRobot();
curr_member_hash_.push_back(member);
}
}
void MatchTeam::StartGame() void MatchTeam::StartGame()
{ {
for (auto& member : curr_member_hash_) { for (auto& member : curr_member_hash_) {

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "cs_proto.pb.h"
enum MatchTeamPhase_e enum MatchTeamPhase_e
{ {
kMatchCombining = 1, kMatchCombining = 1,
@ -13,8 +15,19 @@ namespace cs
class CMReconnect; class CMReconnect;
} }
struct RawTeamMember
{
class MatchTeam* team = nullptr;
long long add_tick = 0;
int socket_handle = 0;
cs::CMJoin msg;
bool is_robot = false;
void FillMFMatchTeamMember(cs::MFMatchTeamMember* msg);
void InitRobot();
};
struct timer_list; struct timer_list;
struct RawTeamMember;
class MatchTeam class MatchTeam
{ {
public: public:
@ -31,6 +44,7 @@ class MatchTeam
bool IsValidMember(const cs::CMJoin& msg); bool IsValidMember(const cs::CMJoin& msg);
void TryCombineTeam(); void TryCombineTeam();
std::string GetTeamUUid(); std::string GetTeamUUid();
std::list<std::shared_ptr<RawTeamMember>>& GetCurrMembers() { return curr_member_hash_; };
private: private:
void Update(); void Update();
@ -47,6 +61,7 @@ class MatchTeam
bool IsSlaveTeam() { return master_team_ != this; }; bool IsSlaveTeam() { return master_team_ != this; };
int GetPhaseLeftTime(); int GetPhaseLeftTime();
std::shared_ptr<RawTeamMember> GetMemberBySocket(int socket_handle); std::shared_ptr<RawTeamMember> GetMemberBySocket(int socket_handle);
void ShuaRobot();
void StartGame(); void StartGame();
private: private:

View File

@ -33,6 +33,7 @@
#include "mapmgr.h" #include "mapmgr.h"
#include "incubator.h" #include "incubator.h"
#include "team.h" #include "team.h"
#include "matchteam.h"
const int SHUA_RANGE = 580; const int SHUA_RANGE = 580;
@ -3870,3 +3871,24 @@ void Room::OnBattleStart()
} }
battle_starting_ = false; battle_starting_ = false;
} }
void Room::AddTeam(class MatchTeam* team)
{
if (team->GetCurrMembers().size() != MAX_TEAM_NUM) {
return;
}
for (auto& member : team->GetCurrMembers()) {
if (member->is_robot) {
} else {
Player* hum = NewPlayer();
hum->ProcPreSettlementInfo(member->msg.pre_settlement_info());
PlayerMgr::Instance()->
CreatePlayerByCMJoin(hum,
0,//hdr.ip_saddr,
member->socket_handle,
member->msg
);
}
}
}

View File

@ -71,6 +71,7 @@ struct CarObject
bool taken = false; bool taken = false;
}; };
class MatchTeam;
class Room class Room
{ {
public: public:
@ -127,6 +128,8 @@ public:
void AddPlayer(Player* hum); void AddPlayer(Player* hum);
Human* FindEnemy(Human* hum); Human* FindEnemy(Human* hum);
void AddTeam(class MatchTeam* team);
void RemoveObjectLater(RoomEntity* entity); void RemoveObjectLater(RoomEntity* entity);
void RemoveObjectLater(RoomObstacle* entity); void RemoveObjectLater(RoomObstacle* entity);

View File

@ -315,6 +315,12 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
msg.mapid()); msg.mapid());
} }
Room* RoomMgr::GetJoinableRoom(MatchTeam* team)
{
for (auto& pair : inactive_room_hash_) {
}
}
Room* RoomMgr::GetRoomByUuid(long long room_uuid) Room* RoomMgr::GetRoomByUuid(long long room_uuid)
{ {
auto itr = room_hash_.find(room_uuid); auto itr = room_hash_.find(room_uuid);
@ -572,6 +578,11 @@ bool RoomMgr::IsGM(const std::string& account_id)
return gm_hash_.find(account_id) != gm_hash_.end(); return gm_hash_.find(account_id) != gm_hash_.end();
} }
void RoomMgr::JoinTeam(MatchTeam* team)
{
}
std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash) std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash)
{ {
std::string data; std::string data;

View File

@ -47,6 +47,7 @@ struct RoomInitInfo
}; };
class Room; class Room;
class MatchTeam;
class RoomMgr : public a8::Singleton<RoomMgr> class RoomMgr : public a8::Singleton<RoomMgr>
{ {
public: public:
@ -69,6 +70,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
Room* GetRoomByUuid(long long uuid); Room* GetRoomByUuid(long long uuid);
void AddOverRoom(long long room_uuid); void AddOverRoom(long long room_uuid);
bool IsGM(const std::string& account_id); bool IsGM(const std::string& account_id);
void JoinTeam(MatchTeam* team);
private: private:
void InstallReportStateTimer(); void InstallReportStateTimer();
@ -79,6 +81,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
int creator_register_time, int creator_register_time,
int proto_version, int proto_version,
int channel); int channel);
Room* GetJoinableRoom(MatchTeam* team);
void ReportServerState(int instance_id, const std::string& host, int port); void ReportServerState(int instance_id, const std::string& host, int port);
void FreeOverRoom(long long room_uuid); void FreeOverRoom(long long room_uuid);
bool IsLimitJoin(); bool IsLimitJoin();