diff --git a/server/gameserver/matchteam.cc b/server/gameserver/matchteam.cc index 49d138d..d293cfa 100644 --- a/server/gameserver/matchteam.cc +++ b/server/gameserver/matchteam.cc @@ -6,6 +6,7 @@ #include "matchmgr.h" #include "GGListener.h" #include "metamgr.h" +#include "roommgr.h" void RawTeamMember::FillMFMatchTeamMember(cs::MFMatchTeamMember* p) { @@ -32,7 +33,7 @@ void RawTeamMember::InitRobot() msg.set_account_id(a8::Format("6000_2005_%d", {++robot_idx})); { std::set refreshed_robot_set; - MetaData::Robot* robot_meta = MetaMgr::Instance()->RandRobot(refreshed_robot_set); + 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()); @@ -41,6 +42,8 @@ void RawTeamMember::InitRobot() skin->set_skin_id(robot_meta->skin_id[0]); skin->set_skin_lv(1); } + } else { + abort(); } } } @@ -337,6 +340,11 @@ std::string MatchTeam::GetTeamUUid() return first_member_->msg.team_uuid(); } +int MatchTeam::GetMapId() +{ + return first_member_->msg.mapid(); +} + bool MatchTeam::IsShuaRobotTime() { return phase_ == kMatchCombining && @@ -374,6 +382,7 @@ void MatchTeam::ShuaRobot() void MatchTeam::StartGame() { #if 0 + RoomMgr::Instance()->JoinTeam(this); for (auto& member : curr_member_hash_) { if (member->socket_handle != 0) { MatchMgr::Instance()->RemoveSocket(member->socket_handle); diff --git a/server/gameserver/matchteam.h b/server/gameserver/matchteam.h index d148577..06a4258 100644 --- a/server/gameserver/matchteam.h +++ b/server/gameserver/matchteam.h @@ -22,6 +22,11 @@ namespace cs class CMReconnect; } +namespace MetaData +{ + struct Robot; +} + struct RawTeamMember { class MatchTeam* team = nullptr; @@ -31,11 +36,11 @@ struct RawTeamMember bool is_robot = false; bool is_leader = false; int state = kMatchReadying; + MetaData::Robot* robot_meta = nullptr; void FillMFMatchTeamMember(cs::MFMatchTeamMember* msg); void InitRobot(); }; - struct timer_list; class MatchTeam { @@ -53,7 +58,9 @@ class MatchTeam bool IsValidMember(const cs::CMJoin& msg); void TryCombineTeam(); std::string GetTeamUUid(); + int GetMapId(); std::list>& GetCurrMembers() { return curr_member_hash_; }; + std::shared_ptr GetOwner() { return first_member_; }; private: void Update(); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index a871183..ed27b0c 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -231,7 +231,7 @@ Player* Room::NewPlayer() return hum; } -void Room::AddPlayer(Player* hum) +void Room::AddPlayer(Player* hum, BornPoint* init_born_point, bool no_matchteam) { if (gas_data_.gas_mode != GasInactive) { abort(); @@ -239,7 +239,11 @@ void Room::AddPlayer(Player* hum) while (human_hash_.size() >= GetRoomMaxPlayerNum()) { RandRemoveAndroid(); } - hum->born_point = AllocBornPoint(hum); + if (init_born_point) { + hum->born_point = init_born_point; + } else { + hum->born_point = AllocBornPoint(hum); + } if (!hum->born_point) { hum->SetPos(GetDefaultBornPoint()); } else { @@ -259,7 +263,9 @@ void Room::AddPlayer(Player* hum) AddToAccountHash(hum); AddToHumanHash(hum); AddToAliveHumanHash(hum); - MatchTeam(hum); + if (!no_matchteam) { + MatchTeam(hum); + } hum->PushJoinRoomMsg(); ++alive_count_; alive_count_chged_frameno_ = GetFrameNo(); @@ -965,6 +971,28 @@ bool Room::CanJoin(const std::string& accountid, return GetPlayerNum() < (int)GetRoomMaxPlayerNum(); } +bool Room::CanJoin(class MatchTeam* team) +{ + if (gas_data_.gas_mode != GasInactive) { + return false; + } + if (map_instance->map_id != team->GetMapId()) { + return false; + } + if (team->GetCurrMembers().size() != MAX_TEAM_NUM) { + return false; + } + if (GetPlayerNum() < (int)GetRoomMaxPlayerNum()) { + return false; + } + for (auto& member : team->GetCurrMembers()) { + if (GetPlayerByAccountId(member->msg.account_id())) { + return false; + } + } + return false; +} + void Room::OnPlayerOffline(Player* hum) { if (GetOnlinePlayerNum() <= 0) { @@ -1805,7 +1833,7 @@ void Room::RandRemoveAndroid() } if (!hum) { for (auto& pair : human_hash_) { - if (pair.second->IsAndroid()) { + if (pair.second->IsAndroid() && pair.second->team_uuid.empty()) { hum = pair.second; break; } @@ -3877,10 +3905,53 @@ void Room::AddTeam(class MatchTeam* team) if (team->GetCurrMembers().size() != MAX_TEAM_NUM) { return; } + Team* new_team = NewTeam(); + { + new_team->SetInitTeamMemberNum(MAX_TEAM_NUM); + new_team->SetAutoFill(true); + } + BornPoint* init_born_point = nullptr; for (auto& member : team->GetCurrMembers()) { cs::CMJoin& msg = member->msg; if (member->is_robot) { - + MetaData::Robot* robot_meta = member->robot_meta; + Android* hum = EntityFactory::Instance()->MakeAndroid(AllocUniid()); + hum->name = robot_meta->i->name(); + hum->meta = MetaMgr::Instance()->GetPlayer(robot_meta->i->hero_id()); + hum->robot_meta = robot_meta; + if (!init_born_point) { + init_born_point = AllocBornPoint(hum); + } + hum->born_point = init_born_point; + if (!hum->born_point) { + hum->SetPos(GetDefaultBornPoint()); + } else { + hum->SetPos(hum->born_point->RandPoint()); + } + a8::Vec2 attack_dir = hum->GetPos(); + attack_dir.Normalize(); + attack_dir.Rotate(a8::RandAngle()); + hum->SetAttackDir(attack_dir); + hum->SetMoveDir(attack_dir); + hum->room = this; + hum->Initialize(); + AddToEntityHash(hum); + AddToHumanHash(hum); + #if 0 + MatchTeam(hum); + #endif + ++alive_count_; + alive_count_chged_frameno_ = GetFrameNo(); + ++PerfMonitor::Instance()->alive_count; + refreshed_robot_set_.insert(robot_meta->i->id()); + { + AddToAliveHumanHash(hum); + AddToMoveableHash(hum); + grid_service->AddCreature(hum); + hum->FindLocation(); + hum->RefreshView(); + } + new_team->AddMember(hum); } else { Player* hum = NewPlayer(); hum->ProcPreSettlementInfo(member->msg.pre_settlement_info()); @@ -3900,6 +3971,8 @@ void Room::AddTeam(class MatchTeam* team) hum->ProcPrepareItems2(msg.prepare_items2()); hum->ProcSkillList(msg.skill_list()); PlayerMgr::Instance()->IncAccountNum(msg.account_id()); + new_team->AddMember(hum); } } + NotifyUiUpdate(); } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 46a45bf..34365cc 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -125,7 +125,7 @@ public: int GetRealPlayerNum() { return accountid_hash_.size();} Player* NewPlayer(); - void AddPlayer(Player* hum); + void AddPlayer(Player* hum, BornPoint* init_born_point = nullptr, bool no_matchteam = false); Human* FindEnemy(Human* hum); void AddTeam(class MatchTeam* team); @@ -185,6 +185,7 @@ public: int self_proto_version, int self_channel, int init_map_id); + bool CanJoin(class MatchTeam* team); void OnPlayerOffline(Player* hum); void FindLocationWithAabb(ColliderComponent* target_collider, const a8::Vec2& aabb_pos, diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 282cff3..d7bf926 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -16,6 +16,7 @@ #include "mapmgr.h" #include "perfmonitor.h" #include "matchmgr.h" +#include "matchteam.h" #include "framework/cpp/httpclientpool.h" #include "framework/cpp/utils.h" @@ -26,7 +27,7 @@ const int HUM_NUM_DOWN_LIMIT = 2500; static RoomType_e GetHumanRoomType(const cs::CMJoin& msg, int& game_times) { #if 1 - return RT_OldBrid1;; + return RT_OldBrid1; #endif game_times = 0; std::vector tmp_strings; @@ -318,7 +319,24 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, Room* RoomMgr::GetJoinableRoom(MatchTeam* team) { for (auto& pair : inactive_room_hash_) { + Room* room = pair.second; + if (room->CanJoin(team)) { + return room; + } } + int game_times = 0; + RoomType_e self_room_type = RT_OldBrid1; + time_t register_time = f8::ExtractRegisterTimeFromSessionId(team->GetOwner()->msg.session_id()); + int proto_version = team->GetOwner()->msg.proto_version(); + int channel = f8::ExtractChannelIdFromAccountId(team->GetOwner()->msg.account_id()); + + return CreateRoom(team->GetOwner()->msg, + self_room_type, + game_times, + register_time, + proto_version, + channel, + team->GetOwner()->msg.mapid()); } Room* RoomMgr::GetRoomByUuid(long long room_uuid) @@ -580,7 +598,11 @@ bool RoomMgr::IsGM(const std::string& account_id) void RoomMgr::JoinTeam(MatchTeam* team) { - + Room* room = GetJoinableRoom(team); + if (!room) { + return; + } + room->AddTeam(team); } std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map* team_hash)