diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 16367df..bced104 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -964,5 +964,13 @@ void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg) void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg) { - + cs::SMWatchWar respmsg; + Human* target = room->GetWatchWarTarget(this); + if (target) { + SendNotifyMsg(respmsg); + target->FollowTarget(target); + } else { + respmsg.set_error_code(1); + SendNotifyMsg(respmsg); + } } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index a4888f3..0e7d688 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -592,6 +592,21 @@ bool Room::OverBorder(const Vector2D pos, float radius) return false; } +Human* Room::GetWatchWarTarget(Human* hum) +{ + std::vector humans; + for (auto& pair : human_hash_) { + if (pair.first != hum->entity_uniid) { + humans.push_back(pair.second); + } + } + if (!humans.empty()) { + Human* target = humans[rand() % humans.size()]; + return target; + } + return nullptr; +} + int Room::NewTeam() { ++current_teamid; diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 138b9f4..b38714c 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -82,6 +82,7 @@ public: void OnHumanDie(Human* hum); bool OverBorder(const Vector2D pos, float radius); + Human* GetWatchWarTarget(Human* hum); private: unsigned short AllocUniid(); diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index a27ebfa..f3df5f9 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -662,7 +662,7 @@ message CMWatchWar //观战error_code == 0 时关闭结算界面,回到战斗界面 message SMWatchWar { - optional int32 error_code = 1; //错误码 + optional int32 error_code = 1 [default = 0]; //错误码 0:成功 1:失败 optional string error_msg = 2; //错误信息 }