From 3c3c897625168f3772359627654d3f124209f7cf Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 20 Jul 2020 14:44:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=A3=9E=E6=9C=BA?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/android.ai.cc | 6 + server/gameserver/human.h | 2 +- server/gameserver/player.cc | 6 +- server/gameserver/room.cc | 196 +++++++++++++++++++++---- server/gameserver/room.h | 7 + server/tools/protobuild/cs_msgid.proto | 1 + server/tools/protobuild/cs_proto.proto | 7 +- 7 files changed, 193 insertions(+), 32 deletions(-) diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index a230eb5..41f017a 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -90,6 +90,9 @@ void AndroidAI::ChangeToState(AndroidState_e to_state) void AndroidAI::DoMove() { Human* hum = (Human*)owner; + if (hum->room->IsWaitingStart()) { + return; + } if (a8::HasBitFlag(hum->status, HS_Fly)) { return; } @@ -118,6 +121,9 @@ void AndroidAI::DoAttack() a8::HasBitFlag(hum->status, HS_Jump)) { return; } + if (hum->room->IsWaitingStart()) { + return; + } if (hum->room->gas_data.gas_mode == GasInactive) { return; } diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 545ebc4..8646816 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -118,7 +118,7 @@ class Human : public Entity std::set kill_humans; Human* last_tank_attacker = nullptr; long long last_tank_attack_idx = 0; - const BornPoint* born_point = nullptr; + BornPoint* born_point = nullptr; bool shot_start = false; bool shot_hold = false; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 4aa742b..e8ec1f8 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -107,7 +107,9 @@ void Player::UpdateMove() if (action_type == AT_Relive) { CancelAction(); } - if (dead || a8::HasBitFlag(status, HS_Fly)) { + if (dead || + room->IsWaitingStart() || + a8::HasBitFlag(status, HS_Fly)) { moving = false; moved_frames = 0; last_collision_door = nullptr; @@ -137,6 +139,8 @@ void Player::UpdateMove() void Player::UpdateShot() { if (dead || + downed || + room->IsWaitingStart() || a8::HasBitFlag(status, HS_Fly) || a8::HasBitFlag(status, HS_Jump) ) { shot_start = false; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index fbcbf64..5bb086b 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -952,45 +952,72 @@ void Room::UpdateGasInactive() { if (frame_no - gas_data.gas_start_frameno >= MetaMgr::Instance()->gas_inactive_time * SERVER_FRAME_RATE) { + #if 1 + gas_data.gas_mode = GasWaiting; + gas_data.old_area_meta = MetaMgr::Instance()->GetSafeArea(30001); + gas_data.new_area_meta = MetaMgr::Instance()->GetSafeArea(30002); + gas_data.gas_progress = gas_data.old_area_meta->i->rad(); + gas_data.gas_start_frameno = frame_no; + gas_data.pos_old = a8::Vec2(map_meta->i->map_width() / 2.0f, + map_meta->i->map_height() / 2.0f); + gas_data.pos_old_bk = gas_data.pos_old; + { + bool gen_ok = GenSmallCircle(gas_data.pos_old, + gas_data.old_area_meta->i->rad(), + gas_data.new_area_meta->i->rad(), + gas_data.pos_new); + assert(gen_ok); + } + gas_data.rad_old = gas_data.old_area_meta->i->rad(); + gas_data.rad_new = gas_data.new_area_meta->i->rad(); + battle_start_frameno_ = frame_no; + #else gas_data.gas_mode = GasJump; gas_data.gas_start_frameno = frame_no; + #endif if (human_hash_.size() < ROOM_MAX_PLAYER_NUM) { CreateAndroid(ROOM_MAX_PLAYER_NUM - human_hash_.size()); - NotifyUiUpdate(); } + NotifyUiUpdate(); CombineTeam(); - ShuaPlane(); + NotifyGameStart(); NotifyWxVoip(); InitAirDrop(); RoomMgr::Instance()->ActiveRoom(room_uuid); + #if 0 + ShuaPlane(); int auto_jump_interval = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_interval"); - auto_jump_timer_ = xtimer.AddRepeatTimerAndAttach(SERVER_FRAME_RATE * auto_jump_interval, - a8::XParams() - .SetSender(this), - [] (const a8::XParams& param) - { - Room* room = (Room*)param.sender.GetUserData(); - int auto_jump_min_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_min_num"); - int auto_jump_max_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_max_num"); - int jump_num = a8::RandEx(auto_jump_min_num, auto_jump_max_num); - if (room->last_player_jump_pos.Distance(room->plane.curr_pos) < 64 * 8) { - jump_num = 1 + rand() % 2; - } - for (int i = 0; i < jump_num; ++i) { - room->TouchHumanList( - a8::XParams() - .SetSender(room), - [] (Human* hum, a8::XParams& param) -> bool - { - if (a8::HasBitFlag(hum->status, HS_Fly) && hum->entity_subtype != EST_Player) { - hum->DoJump(); - return false; - } - return true; - }); - } - }, - &xtimer_attacher.timer_list_); + auto_jump_timer_ = xtimer.AddRepeatTimerAndAttach + (SERVER_FRAME_RATE * auto_jump_interval, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Room* room = (Room*)param.sender.GetUserData(); + int auto_jump_min_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_min_num"); + int auto_jump_max_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_max_num"); + int jump_num = a8::RandEx(auto_jump_min_num, auto_jump_max_num); + if (room->last_player_jump_pos.Distance(room->plane.curr_pos) < 64 * 8) { + jump_num = 1 + rand() % 2; + } + for (int i = 0; i < jump_num; ++i) { + room->TouchHumanList + ( + a8::XParams() + .SetSender(room), + [] (Human* hum, a8::XParams& param) -> bool + { + if (a8::HasBitFlag(hum->status, HS_Fly) && + hum->entity_subtype != EST_Player) { + hum->DoJump(); + return false; + } + return true; + }); + } + }, + &xtimer_attacher.timer_list_); + #endif } } @@ -1544,3 +1571,114 @@ void Room::CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl) born_point.thing_tpl = &thing_tpl; born_point_hash_[AllocUniid()] = born_point; } + +void Room::SecondRandPoint() +{ + for (auto& pair : accountid_hash_) { + Human* hum = pair.second; + hum->born_point = AllocBornPoint(hum); + } + CombineTeamBornPoint(); +} + +void Room::NotifyGameStart() +{ + cs::SMGameStart msg; + for (auto& pair : accountid_hash_) { + pair.second->SendNotifyMsg(msg); + } + + waiting_start_ = true; + xtimer.AddDeadLineTimerAndAttach + (SERVER_FRAME_RATE * 2, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Room* room = (Room*)param.sender.GetUserData(); + room->waiting_start_ = false; + }, + &xtimer_attacher.timer_list_); + xtimer.AddDeadLineTimerAndAttach + (SERVER_FRAME_RATE * 1, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Room* room = (Room*)param.sender.GetUserData(); + room->SecondRandPoint(); + }, + &xtimer_attacher.timer_list_); +} + +void Room::CombineTeamBornPoint() +{ + for (auto& pair : team_hash_) { + Human* target = nullptr; + for (Human* hum : pair.second) { + if (!target) { + target = hum; + } else { + if (target->born_point) { + if (hum->born_point) { + DecBornPointHumanNum(hum->born_point, hum); + } + hum->born_point = target->born_point; + if (hum->born_point) { + IncBornPointHumanNum(hum->born_point, hum); + } + } + } //end if + if (!hum->born_point) { + hum->pos = a8::Vec2(DEFAULT_BORN_POINT_X + rand() % 100, + DEFAULT_BORN_POINT_Y + rand() % 200); + } else { + hum->pos = hum->born_point->RandPoint(); + } + hum->FindLocation(); + hum->RefreshView(); + grid_service.MoveHuman(hum); + } + } +} + +void Room::IncBornPointHumanNum(BornPoint* point, Human* hum) +{ + switch (hum->entity_subtype) { + case EST_Player: + { + ++point->player_num; + } + break; + case EST_Android: + { + ++point->android_num; + } + break; + default: + { + } + break; + } +} + +void Room::DecBornPointHumanNum(BornPoint* point, Human* hum) +{ + switch (hum->entity_subtype) { + case EST_Player: + { + --point->player_num; + } + break; + case EST_Android: + { + --point->android_num; + } + break; + default: + { + + } + break; + } +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index ae3390d..e576365 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -59,6 +59,7 @@ public: Player* GetPlayerByAccountId(const std::string& accountid); Player* GetPlayerByUniId(int uniid); Entity* GetEntityByUniId(int uniid); + bool IsWaitingStart() { return waiting_start_; } void AddPlayer(Player* hum); Human* FindEnemy(Human* hum); @@ -130,6 +131,11 @@ private: BornPoint* AllocBornPoint(Human* hum); void CreateMapObject(MetaData::MapTplThing& thing_tpl); void CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl); + void SecondRandPoint(); + void NotifyGameStart(); + void CombineTeamBornPoint(); + void IncBornPointHumanNum(BornPoint* point, Human* hum); + void DecBornPointHumanNum(BornPoint* point, Human* hum); private: int elapsed_time_ = 0; @@ -137,6 +143,7 @@ private: MetaData::AirLine* airline_ = nullptr; a8::XTimerAttacher xtimer_attacher; xtimer_list* auto_jump_timer_ = nullptr; + bool waiting_start_ = false; int current_teamid = 0; int current_uniid = 0; diff --git a/server/tools/protobuild/cs_msgid.proto b/server/tools/protobuild/cs_msgid.proto index 7421f83..d583841 100644 --- a/server/tools/protobuild/cs_msgid.proto +++ b/server/tools/protobuild/cs_msgid.proto @@ -36,4 +36,5 @@ enum SMMessageId_e _SMDebugMsg = 1010; _SMWxVoip = 1011; _SMUiUpdate = 1012; + _SMGameStart = 1013; } diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index ac99fb7..ce6f50e 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -868,4 +868,9 @@ message SMUiUpdate optional int32 alive_count = 1; //存活数量 optional int32 kill_count = 2; //击杀数 repeated MFCar car_list = 3; //载具列表 -} \ No newline at end of file +} + +//游戏开始 +message SMGameStart +{ +} From 580a9e1519831113bb448d22b801fbe017b07d22 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 20 Jul 2020 14:49:04 +0800 Subject: [PATCH 2/2] 1 --- server/tools/protobuild/cs_proto.proto | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index ce6f50e..f63ef25 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -413,6 +413,9 @@ message MFObjectFull optional MFProjectileFull union_obj_8 = 9; optional MFSmokeFull union_obj_9 = 10; optional MFHeroFull union_obj_10 = 11; + + optional int32 obj_uniid = 14; //唯一id + optional int32 object_flags = 15; //对象标志位 1<<0: 存缓存 1<<1:读缓存 } //活跃玩家数据(当前) @@ -874,3 +877,4 @@ message SMUiUpdate message SMGameStart { } +