351 lines
15 KiB
C++
351 lines
15 KiB
C++
#include "precompile.h"
|
|
|
|
#include "framemaker.h"
|
|
#include "human.h"
|
|
#include "room.h"
|
|
#include "typeconvert.h"
|
|
#include "metamgr.h"
|
|
#include "car.h"
|
|
#include "app.h"
|
|
|
|
cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
|
|
{
|
|
cs::SMUpdate* msg = new cs::SMUpdate;
|
|
{
|
|
Room* room = hum->room;
|
|
msg->set_frameno(room->GetFrameNo() / 2);
|
|
if (room->GetGasData().gas_mode == GasJump) {
|
|
cs::MFPlane* p = msg->mutable_plane();
|
|
TypeConvert::ToPb(room->plane.start_point, p->mutable_start_point());
|
|
TypeConvert::ToPb(room->plane.end_point, p->mutable_end_point());
|
|
TypeConvert::ToPb(room->plane.curr_pos, p->mutable_pos());
|
|
}
|
|
for (auto& itr : hum->new_objects) {
|
|
#ifdef DEBUG
|
|
if (hum->del_objects.find(itr->GetUniId()) != hum->del_objects.end()) {
|
|
abort();
|
|
}
|
|
#endif
|
|
if (itr != hum &&
|
|
itr->GetEntityType() == ET_Player &&
|
|
((Human*)itr)->HasBuffEffect(kBET_Fly)){
|
|
continue;
|
|
}
|
|
if (hum->IsPlayer() && itr->CanSeeMe(hum)) {
|
|
itr->FillMFObjectFull(room, (Human*)hum, msg->add_full_objects());
|
|
#ifdef DEBUG
|
|
if (itr->GetEntityType() == ET_Car) {
|
|
hum->SendDebugMsg(a8::Format("载具出现", {}));
|
|
}
|
|
#endif
|
|
}
|
|
#ifdef DEBUG
|
|
if (App::Instance()->HasFlag(2) && itr->GetEntityType() == ET_Player) {
|
|
room->BroadcastDebugMsg(a8::Format("投放 %d pos:%d,%d 出现",
|
|
{
|
|
itr->GetUniId(),
|
|
itr->GetPos().x,
|
|
itr->GetPos().y,
|
|
}));
|
|
}
|
|
#endif
|
|
}
|
|
for (auto& itr : hum->part_objects) {
|
|
Entity* entity = itr.first;
|
|
if (entity->IsDead(room) &&
|
|
hum->room->GetFrameNo() - entity->GetDeadFrameNo(room) > 10) {
|
|
continue;
|
|
} else {
|
|
if (room->GetGasData().gas_mode == GasJump &&
|
|
entity != hum &&
|
|
entity->GetEntityType() == ET_Player &&
|
|
((Human*)entity)->HasBuffEffect(kBET_Fly)) {
|
|
continue;
|
|
}
|
|
}
|
|
if (((Human*)hum)->GetPos().ManhattanDistance(entity->GetPos()) > VIEW_RANGE + 300) {
|
|
continue;
|
|
}
|
|
entity->FillMFObjectPart(room, (Human*)hum, msg->add_part_objects());
|
|
}
|
|
for (auto& itr : hum->del_objects) {
|
|
msg->add_del_objids(itr);
|
|
#ifdef DEBUG
|
|
if (App::Instance()->HasFlag(2)) {
|
|
room->BroadcastDebugMsg(a8::Format("投放 删除对象%d",
|
|
{
|
|
itr
|
|
}));
|
|
}
|
|
#endif
|
|
}
|
|
for (auto& itr : hum->out_objects) {
|
|
msg->add_out_objids(itr);
|
|
#ifdef DEBUG
|
|
if (App::Instance()->HasFlag(2)) {
|
|
room->BroadcastDebugMsg(a8::Format("投放 移除视野对象%d",
|
|
{
|
|
itr
|
|
}));
|
|
}
|
|
#endif
|
|
}
|
|
for (size_t idx : hum->shots_) {
|
|
if (idx < room->frame_event.shots_.size()) {
|
|
auto& tuple = room->frame_event.shots_[idx];
|
|
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
|
|
*msg->add_shots() = std::get<1>(tuple);
|
|
} else {
|
|
#ifdef DEBUG1
|
|
abort();
|
|
#endif
|
|
}
|
|
} else {
|
|
#ifdef DEBUG
|
|
abort();
|
|
#endif
|
|
}
|
|
}
|
|
for (size_t idx : hum->bullets_) {
|
|
if (idx < room->frame_event.bullets_.size()) {
|
|
auto& tuple = room->frame_event.bullets_[idx];
|
|
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
|
|
*msg->add_bullets() = std::get<1>(tuple);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->explosions_) {
|
|
if (idx < room->frame_event.explosions_.size()) {
|
|
auto& tuple = room->frame_event.explosions_[idx];
|
|
#if 1
|
|
{
|
|
#else
|
|
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
|
|
#endif
|
|
*msg->add_explosions() = std::get<1>(tuple);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->smokes_) {
|
|
if (idx < room->frame_event.smokes_.size()) {
|
|
auto& tuple = room->frame_event.smokes_[idx];
|
|
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
|
|
*msg->add_smokes() = std::get<1>(tuple);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->play_skills_) {
|
|
if (idx < room->frame_event.play_skills_.size()) {
|
|
auto& tuple = room->frame_event.play_skills_[idx];
|
|
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
|
|
*msg->add_play_skill_list() = std::get<1>(tuple);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->emotes_) {
|
|
if (idx < room->frame_event.emotes_.size()) {
|
|
auto& tuple = room->frame_event.emotes_[idx];
|
|
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
|
|
*msg->add_emotes() = std::get<1>(tuple);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_bullet_nums_) {
|
|
if (idx < room->frame_event.chged_bullet_nums_.size()) {
|
|
CreatureWeakPtr& target = room->frame_event.chged_bullet_nums_[idx];
|
|
if (target.Get()->GetCurrWeapon()) {
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target.Get()->GetUniId());
|
|
p->set_property_type(kPropBulletNum);
|
|
p->set_value(target.Get()->GetCurrWeapon()->ammo);
|
|
}
|
|
}
|
|
}
|
|
#if 0
|
|
for (size_t idx : hum->chged_tank_bullet_nums_) {
|
|
if (idx < room->frame_event.chged_tank_bullet_nums_.size()) {
|
|
Human* target = room->frame_event.chged_tank_bullet_nums_[idx];
|
|
if (target->GetCurrWeapon()) {
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target->GetUniId());
|
|
p->set_property_type(kPropTankBulletNum);
|
|
p->set_value(target->tank_weapon.ammo);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_tank_oil_max_) {
|
|
if (idx < room->frame_event.chged_tank_oil_max_.size()) {
|
|
Human* target = room->frame_event.chged_tank_oil_max_[idx];
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target->GetUniId());
|
|
p->set_property_type(kPropTankOil);
|
|
p->set_property_subtype(1);
|
|
p->set_value(target->tank_oil_max);
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_tank_oil_value_) {
|
|
if (idx < room->frame_event.chged_tank_oil_value_.size()) {
|
|
Human* target = room->frame_event.chged_tank_oil_value_[idx];
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target->GetUniId());
|
|
p->set_property_type(kPropTankOil);
|
|
p->set_property_subtype(0);
|
|
p->set_value(target->tank_oil_value);
|
|
}
|
|
}
|
|
#endif
|
|
for (size_t idx : hum->chged_buffs_) {
|
|
if (idx < room->frame_event.chged_buffs_.size()) {
|
|
auto p = msg->add_chged_buff_list();
|
|
*p = std::get<1>(room->frame_event.chged_buffs_[idx]);
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_skillcds_) {
|
|
if (idx < room->frame_event.chged_skillcds_.size()) {
|
|
auto tuple = room->frame_event.chged_skillcds_[idx];
|
|
CreatureWeakPtr target = std::get<0>(tuple);
|
|
int skill_id = std::get<1>(tuple);
|
|
int left_time = std::get<2>(tuple);
|
|
if (target.Get()) {
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target.Get()->GetUniId());
|
|
p->set_property_type(kPropSkillLeftTime);
|
|
p->set_property_subtype(skill_id);
|
|
p->set_value(left_time);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_skill_curr_times_) {
|
|
if (idx < room->frame_event.chged_skill_curr_times_.size()) {
|
|
auto tuple = room->frame_event.chged_skill_curr_times_[idx];
|
|
CreatureWeakPtr& target = std::get<0>(tuple);
|
|
int skill_id = std::get<1>(tuple);
|
|
int curr_times = std::get<2>(tuple);
|
|
if (target.Get()) {
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target.Get()->GetUniId());
|
|
p->set_property_type(kPropSkillCurrTimes);
|
|
p->set_property_subtype(skill_id);
|
|
p->set_value(curr_times);
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_hps_) {
|
|
if (idx < room->frame_event.chged_hps_.size()) {
|
|
CreatureWeakPtr& target = room->frame_event.chged_hps_[idx];
|
|
if (target.Get() && hum->CanSee(target.Get())) {
|
|
{
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target.Get()->GetUniId());
|
|
p->set_property_type(kPropHp);
|
|
p->set_value(target.Get()->GetHP());
|
|
}
|
|
{
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target.Get()->GetUniId());
|
|
p->set_property_type(kPropMaxHp);
|
|
p->set_value(target.Get()->GetMaxHP());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_items_) {
|
|
if (idx < room->frame_event.chged_items_.size()) {
|
|
auto& tuple = room->frame_event.chged_items_[idx];
|
|
{
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id((std::get<0>(tuple)).Get()->GetUniId());
|
|
p->set_property_type(kPropItem);
|
|
p->set_property_subtype(std::get<1>(tuple));
|
|
p->set_value(std::get<2>(tuple));
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_weapon_ammo_) {
|
|
if (idx < room->frame_event.chged_weapon_ammo_.size()) {
|
|
auto& tuple = room->frame_event.chged_weapon_ammo_[idx];
|
|
{
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id((std::get<0>(tuple)).Get()->GetUniId());
|
|
p->set_property_type(kPropWeaponAmmo);
|
|
p->set_property_subtype(std::get<1>(tuple));
|
|
p->set_value(std::get<2>(tuple));
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_zombieid_) {
|
|
if (idx < room->frame_event.chged_zombieids_.size()) {
|
|
auto& chg_hum = room->frame_event.chged_zombieids_[idx];
|
|
{
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(chg_hum.Get()->GetUniId());
|
|
p->set_property_type(kPropZombieId);
|
|
p->set_value(chg_hum.Get()->AsHuman()->meta->i->id());
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->dead_alive_objs_) {
|
|
if (idx < room->frame_event.dead_alive_objs_.size()) {
|
|
auto p = msg->add_dead_alive_objs();
|
|
p->add_values(std::get<0>(room->frame_event.dead_alive_objs_[idx]));
|
|
p->add_values(std::get<1>(room->frame_event.dead_alive_objs_[idx]));
|
|
p->add_values(std::get<2>(room->frame_event.dead_alive_objs_[idx]));
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_cars_) {
|
|
if (idx < room->frame_event.chged_cars_.size()) {
|
|
CreatureWeakPtr& target = room->frame_event.chged_cars_[idx];
|
|
if (target.Get() && target.Get()->IsHuman() && hum->CanSee(target.Get())) {
|
|
auto p = msg->add_chged_property_list();
|
|
p->set_obj_id(target.Get()->GetUniId());
|
|
p->set_property_type(kPropCar);
|
|
if (target.Get()->AsHuman()->GetCar()) {
|
|
p->set_property_subtype(target.Get()->AsHuman()->GetCar()->meta->i->id());
|
|
p->set_value(target.Get()->AsHuman()->GetSeat());
|
|
} else {
|
|
p->set_property_subtype(0);
|
|
p->set_value(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (size_t idx : hum->chged_props_) {
|
|
if (idx < room->frame_event.chged_props_.size()) {
|
|
auto& p = room->frame_event.chged_props_[idx];
|
|
auto& target = std::get<0>(p);
|
|
if (target.Get()) {
|
|
*msg->add_chged_property_list() = std::get<1>(p);
|
|
}
|
|
}
|
|
}
|
|
if (room->GetRoomMode() == kZombieMode && room->BattleStarted()) {
|
|
room->FillObjectPositions((Human*)hum, *msg);
|
|
}
|
|
if (room->frame_event.airdrops_.size() > 0) {
|
|
*msg->mutable_airdrop() = room->frame_event.airdrops_.Get(0);
|
|
}
|
|
if (room->frame_event.airraids_.size() > 0) {
|
|
*msg->mutable_airraid() = room->frame_event.airraids_.Get(0);
|
|
}
|
|
if (room->GetGasData().gas_mode == GasMoving) {
|
|
msg->set_gas_progress(room->GetGasData().gas_progress);
|
|
TypeConvert::ToPb(room->GetGasData().pos_old, msg->mutable_gas_pos_old());
|
|
}
|
|
if (room->GetFrameNo() - room->AliveCountChgFrameNo() <= 4 ||
|
|
room->GetFrameNo() - hum->join_frameno <= 2) {
|
|
msg->set_alive_count(room->AliveCount());
|
|
}
|
|
if (room->GetRoomMode() == kZombieMode) {
|
|
if (room->BattleStarted()) {
|
|
int game_left_time = MetaMgr::Instance()->zbmode_game_duration * 1000 -
|
|
(room->GetFrameNo() - room->GetBattleStartFrameNo()) * FRAME_RATE_MS;
|
|
game_left_time = std::max(0, game_left_time);
|
|
msg->set_game_left_time(game_left_time);
|
|
} else {
|
|
msg->set_game_left_time(MetaMgr::Instance()->zbmode_game_duration * 1000);
|
|
}
|
|
}
|
|
}
|
|
return msg;
|
|
}
|