diff --git a/server/gameserver/framemaker.cc b/server/gameserver/framemaker.cc index 3d3829ae..c9e975f5 100644 --- a/server/gameserver/framemaker.cc +++ b/server/gameserver/framemaker.cc @@ -10,6 +10,7 @@ #include "car.h" #include "app.h" #include "perfmonitor.h" +#include "incubator.h" void FrameMaker::Debug_FullObject(Human* hum) { @@ -164,6 +165,10 @@ void FrameMaker::PostProcess(cs::SMUpdate* msg, Room* room, Human* hum, FrameDat room->GetFrameNo() - hum->join_frameno <= 2) { msg->set_alive_count(room->AliveCount()); } + if (room->IsPveRoom()) { + int left_time = room->GetIncubator()->GetPveLeftTime(); + msg->set_game_left_time(left_time); + } } void FrameMaker::SerializeLootObjects(cs::SMUpdate* msg, Room* room, Human* hum, FrameData* framedata) diff --git a/server/gameserver/incubator.cc b/server/gameserver/incubator.cc index 9797da90..e287fd74 100644 --- a/server/gameserver/incubator.cc +++ b/server/gameserver/incubator.cc @@ -20,15 +20,12 @@ void Incubator::Init() }, &xtimer_attacher_.timer_list_); if (room->IsPveRoom()) { - #if 0 - room->pve_data.wave = 1; - #endif room->pve_data.max_wave = room->pve_mode_meta->mode_time.size(); int wave = 0; int total_time = 0; for (int time : room->pve_mode_meta->mode_time) { total_time += time; - room->xtimer.AddDeadLineTimerAndAttach + xtimer_list* timer = room->xtimer.AddDeadLineTimerAndAttach ( total_time * SERVER_FRAME_RATE / 2, a8::XParams() @@ -40,6 +37,7 @@ void Incubator::Init() incubator->SpawnWaveMon(param.param1.GetInt()); }, &xtimer_attacher_.timer_list_); + wave_timers_.push_back(timer); ++wave; } } @@ -248,6 +246,7 @@ void Incubator::SpawnWaveMon(int wave) if (room->IsGameOver()) { return; } + curr_wave_ = wave; room->OnEnterNewWave(wave); if (wave < 0) { abort(); @@ -308,3 +307,14 @@ void Incubator::SpawnWaveMon(int wave) } ++room->pve_data.wave; } + +int Incubator::GetPveLeftTime() +{ + if (curr_wave_ >= wave_timers_.size() || + curr_wave_ < 0) { + abort(); + } + xtimer_list* timer = wave_timers_[curr_wave_]; + int remain_time = room->xtimer.GetRemainTime(timer); + return remain_time * FRAME_RATE_MS; +} diff --git a/server/gameserver/incubator.h b/server/gameserver/incubator.h index 621ab255..41d0e225 100644 --- a/server/gameserver/incubator.h +++ b/server/gameserver/incubator.h @@ -15,6 +15,7 @@ class Incubator void RecycleAndroid(Human* hum); void ActiveAndroid(Human* hum, Human* android); bool IsTimeOut() { return timeout_; }; + int GetPveLeftTime(); private: bool CanSee(Human* hum, Human* exclude_hum); @@ -22,7 +23,9 @@ private: void SpawnWaveMon(int wave); private: + int curr_wave_= 0; bool timeout_ = false; std::vector hold_humans_; + std::vector wave_timers_; a8::XTimerAttacher xtimer_attacher_; };