diff --git a/server/gameserver/human.h b/server/gameserver/human.h index dce735f..3dc2e4b 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -63,6 +63,8 @@ class Human : public Entity int curr_scope_idx = 0; std::vector inventory; + bool need_sync_team_data = false; + bool need_sync_teammate_data = false; bool need_sync_active_player = false; HumanFrameData frame_data; @@ -73,7 +75,7 @@ class Human : public Entity int pain_killer_frameno = 0; xtimer_list* pain_killer_timer = nullptr; - std::set friends; + std::set* team_members = nullptr; Human(); virtual ~Human() override; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index d4a3dee..8620665 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -931,6 +931,12 @@ void Player::MakeUpdateMsg() } } } + if (need_sync_team_data) { + need_sync_team_data = false; + } + if (need_sync_teammate_data) { + need_sync_teammate_data = false; + } if (send_update_msg_times == 0) { room->FetchBuilding(this); } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index f429f07..8362c5a 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1,5 +1,7 @@ #include "precompile.h" +#include + #include #include #include @@ -17,6 +19,7 @@ #include "loot.h" #include "collision.h" #include "roommgr.h" +#include "app.h" const int ROOM_MAX_PLAYER_NUM = 50; #if 0 @@ -39,6 +42,7 @@ Room::~Room() void Room::Init() { xtimer.Init(RoomXGetTickCount, this, 100, 100); + xtimer_attacher.xtimer = &xtimer; ShuaAndroid(); CreateThings(); @@ -54,10 +58,22 @@ void Room::Init() } } ); + if (App::Instance()->flags.find(1) != App::Instance()->flags.end()) { + xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * 3, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Room* room = (Room*)param.sender.GetUserData(); + room->AutoMatchTeam(); + }, + &xtimer_attacher.timer_list_); + } } void Room::UnInit() { + xtimer_attacher.ClearTimerList(); if (!stats_timer_) { a8::Timer::Instance()->DeleteTimer(stats_timer_); stats_timer_ = nullptr; @@ -875,3 +891,27 @@ void Room::OutputDebugLog() } profile.max_rundelay = 0; } + +void Room::AutoMatchTeam() +{ + std::vector humans; + for (auto& pair : human_hash_) { + humans.push_back(pair.second); + } + std::random_shuffle(humans.begin(), humans.end()); + std::set* team_members = nullptr; + for (size_t i = 0; i < humans.size(); ++i) { + if (i % 4 == 0) { + ++current_teamid; + team_hash_[current_teamid] = std::set(); + auto itr = team_hash_.find(current_teamid); + team_members = &itr->second; + } + humans[i]->team_id = current_teamid; + humans[i]->team_members = team_members; + humans[i]->need_sync_team_data = true; + humans[i]->need_sync_teammate_data = true; + humans[i]->need_sync_active_player = true; + team_members->insert(humans[i]); + } +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index d365f3f..bf16d2b 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -85,15 +85,19 @@ private: bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad, Vector2D& out_pos); void OutputDebugLog(); + void AutoMatchTeam(); private: timer_list* stats_timer_ = nullptr; int elapsed_time_ = 0; int alive_count_ = 0; + a8::XTimerAttacher xtimer_attacher; + int current_teamid = 0; unsigned short current_uniid = 0; RoomState_e state_ = RS_Inactive; + std::map> team_hash_; std::map accountid_hash_; std::map moveable_hash_; std::map uniid_hash_; diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index e2a75ef..3bce2bf 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -615,7 +615,7 @@ message SMUpdate optional MFVector2D gas_pos_old = 30; //毒圈当前圆心坐标 optional MFGasData gas_data = 17; //毒圈数据 repeated MFTeamData team_data = 18; //活跃玩家队伍数据 - repeated MFTeammateInfo teammate_data = 19; //同队队友数据(自己的队友数据) + optional MFTeammateInfo teammate_data = 19; //同队队友数据(自己的队友数据) repeated MFBullet bullets = 20; //子弹 repeated MFShot shots = 21; //射击 repeated MFExplosion explosions = 22; //爆炸