This commit is contained in:
aozhiwei 2019-05-05 15:33:47 +08:00
parent 0b66e7d927
commit bcf9fa317a
4 changed files with 26 additions and 2 deletions

View File

@ -964,5 +964,13 @@ void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg)
void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& 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);
}
} }

View File

@ -592,6 +592,21 @@ bool Room::OverBorder(const Vector2D pos, float radius)
return false; return false;
} }
Human* Room::GetWatchWarTarget(Human* hum)
{
std::vector<Human*> 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() int Room::NewTeam()
{ {
++current_teamid; ++current_teamid;

View File

@ -82,6 +82,7 @@ public:
void OnHumanDie(Human* hum); void OnHumanDie(Human* hum);
bool OverBorder(const Vector2D pos, float radius); bool OverBorder(const Vector2D pos, float radius);
Human* GetWatchWarTarget(Human* hum);
private: private:
unsigned short AllocUniid(); unsigned short AllocUniid();

View File

@ -662,7 +662,7 @@ message CMWatchWar
//error_code == 0 , //error_code == 0 ,
message SMWatchWar message SMWatchWar
{ {
optional int32 error_code = 1; // optional int32 error_code = 1 [default = 0]; // 0: 1:
optional string error_msg = 2; // optional string error_msg = 2; //
} }