观战逻辑ok

This commit is contained in:
aozhiwei 2019-04-30 18:02:47 +08:00
parent d232fa37bd
commit e2bce87588
3 changed files with 71 additions and 1 deletions

View File

@ -1202,10 +1202,40 @@ void Human::SendUpdateMsg()
last_sync_gas_frameno = room->gas_data.gas_start_frameno;
FillMFGasData(msg->mutable_gas_data());
}
bool refreshed_view = false;
std::set<Entity*> view_objects;
for (Human* observer : observers_) {
if (observer != this && !observer->follow_synced_active_player) {
msg->set_active_player_id(entity_uniid);
FillMFActivePlayerData(msg->mutable_active_player_data());
if (!refreshed_view) {
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list) {
view_objects.insert(hum);
}
for (Entity* entity : cell->entity_list) {
switch (entity->entity_type) {
case ET_Building:
case ET_Obstacle:
case ET_Hero:
{
view_objects.insert(entity);
}
break;
default:
{
}
break;
}
}
}
for (Entity* entity : view_objects) {
if (new_objects.find(entity) == new_objects.end()) {
entity->FillMFObjectFull(msg->add_full_objects());
}
}
refreshed_view = true;
}
observer->follow_synced_active_player = true;
} else {
if (active_player_data_pb) {
@ -1300,6 +1330,19 @@ void Human::UpdateGameOver()
send_gameover = false;
}
void Human::FollowTarget(Human* target)
{
if (target == this) {
return;
}
if (follow_target_) {
follow_target_->RemoveObserver(this);
}
target->AddObserver(this);
follow_target_ = target;
follow_synced_active_player = false;
}
void Human::ClearFrameData()
{
if (!new_objects.empty()) {

View File

@ -167,6 +167,7 @@ class Human : public Entity
GGListener::Instance()->SendToClient(socket_handle, 0, msg);
}
void UpdateGameOver();
void FollowTarget(Human* target);
private:
void ClearFrameData();

View File

@ -109,7 +109,7 @@ void Room::Update(int delta_time)
}
}
if (frame_no % 2 == 0) {
for (auto& pair : accountid_hash_) {
for (auto& pair : human_hash_) {
pair.second->SendUpdateMsg();
}
frame_event.Clear();
@ -690,6 +690,32 @@ void Room::UpdateGas()
}
return true;
});
for (auto& pair : accountid_hash_) {
if (App::Instance()->flags.find(4) != App::Instance()->flags.end()) {
xtimer.AddRepeatTimerAndAttach(SERVER_FRAME_RATE * 5,
a8::XParams()
.SetSender(this)
.SetParam1(pair.second->entity_uniid),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
Human* hum = room->GetPlayerByUniId(param.param1);
if (hum) {
std::vector<Human*> humans;
for (auto& pair : room->human_hash_) {
if (pair.first != param.param1.GetInt()) {
humans.push_back(pair.second);
}
}
if (!humans.empty()) {
Human* target = humans[rand() % humans.size()];
hum->FollowTarget(target);
}
}
},
&xtimer_attacher.timer_list_);
}
}
gas_data.gas_mode = GasWaiting;
gas_data.old_area_meta = MetaMgr::Instance()->GetSafeArea(30001);
gas_data.new_area_meta = MetaMgr::Instance()->GetSafeArea(30002);