421 lines
18 KiB
C++
421 lines
18 KiB
C++
#include "precompile.h"
|
|
|
|
#include <a8/mutable_xobject.h>
|
|
|
|
#include "framemaker.h"
|
|
#include "human.h"
|
|
#include "room.h"
|
|
#include "typeconvert.h"
|
|
#include "metamgr.h"
|
|
#include "car.h"
|
|
#include "app.h"
|
|
|
|
void FrameMaker::Debug_FullObject(Human* hum)
|
|
{
|
|
if (!hum->framedata_.new_objects.empty()) {
|
|
a8::MutableXObject* out_data = a8::MutableXObject::NewArray();
|
|
for (auto& pair : hum->framedata_.new_objects) {
|
|
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
|
xobj->SetVal("uniid", pair.first);
|
|
if (pair.second.Get()) {
|
|
xobj->SetVal("matched", 1);
|
|
xobj->SetVal("type", pair.second.Get()->GetEntityType());
|
|
xobj->SetVal("pos", a8::Format("%d,%d",
|
|
{pair.second.Get()->GetPos().x,
|
|
pair.second.Get()->GetPos().y}));
|
|
} else {
|
|
xobj->SetVal("matched", 0);
|
|
xobj->SetVal("type", 0);
|
|
xobj->SetVal("pos", a8::Format("%d,%d",
|
|
{0,
|
|
0}));
|
|
}
|
|
out_data->Push(*xobj);
|
|
}
|
|
hum->SendDebugMsg(a8::Format("view_debug frameno:%d server_full_obj:%s",
|
|
{
|
|
hum->room->GetFrameNo(),
|
|
out_data->ToJsonStr()
|
|
}));
|
|
}
|
|
}
|
|
|
|
void FrameMaker::Debug_OutObject(Human* hum)
|
|
{
|
|
if (!hum->framedata_.out_objects.empty()) {
|
|
a8::MutableXObject* out_data = a8::MutableXObject::NewArray();
|
|
for (auto& itr : hum->framedata_.out_objects) {
|
|
int uniid = itr;
|
|
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
|
xobj->SetVal("uniid", uniid);
|
|
Entity* entity = hum->room->GetEntityByUniId(uniid);
|
|
if (entity) {
|
|
xobj->SetVal("matched", 1);
|
|
xobj->SetVal("pos", a8::Format("%d,%d", {entity->GetPos().x, entity->GetPos().y}));
|
|
} else {
|
|
xobj->SetVal("matched", 0);
|
|
xobj->SetVal("pos", a8::Format("%d,%d", {0, 0}));
|
|
}
|
|
out_data->Push(*xobj);
|
|
}
|
|
hum->SendDebugMsg(a8::Format("view_debug frameno:%d server_out_obj:%s",
|
|
{
|
|
hum->room->GetFrameNo(),
|
|
out_data->ToJsonStr()
|
|
}));
|
|
}
|
|
}
|
|
|
|
cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
|
|
{
|
|
FrameData* framedata = &hum->framedata_;
|
|
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());
|
|
}
|
|
#ifdef DEBUG
|
|
Debug_FullObject(hum);
|
|
#endif
|
|
for (auto& pair : framedata->new_objects) {
|
|
Entity* e = pair.second.Get();
|
|
if (!e) {
|
|
continue;
|
|
}
|
|
#ifdef DEBUG
|
|
if (framedata->del_objects.find(e->GetUniId()) != framedata->del_objects.end()) {
|
|
abort();
|
|
}
|
|
#endif
|
|
if (e != hum &&
|
|
e->GetEntityType() == ET_Player &&
|
|
((Human*)e)->HasBuffEffect(kBET_Fly)){
|
|
continue;
|
|
}
|
|
if ((hum->IsPlayer() || hum->HasObserver()) && e->CanSeeMe(hum)) {
|
|
e->FillMFObjectFull(room, (Human*)hum, msg->add_full_objects());
|
|
#ifdef DEBUG
|
|
if (e->GetEntityType() == ET_Car) {
|
|
hum->SendDebugMsg(a8::Format("载具出现", {}));
|
|
}
|
|
#endif
|
|
}
|
|
#ifdef DEBUG
|
|
if (App::Instance()->HasFlag(2) && e->GetEntityType() == ET_Player) {
|
|
room->BroadcastDebugMsg(a8::Format("投放 %d pos:%d,%d 出现",
|
|
{
|
|
e->GetUniId(),
|
|
e->GetPos().x,
|
|
e->GetPos().y,
|
|
}));
|
|
}
|
|
#endif
|
|
}
|
|
{
|
|
int deleted_uniid = 0;
|
|
for (auto& pair : framedata->part_objects) {
|
|
Entity* entity = pair.second.object.Get();
|
|
if (!entity) {
|
|
#ifdef DEBUG
|
|
abort();
|
|
#endif
|
|
deleted_uniid = pair.first;
|
|
continue;
|
|
}
|
|
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 0
|
|
if (((Human*)hum)->GetPos().ManhattanDistance(entity->GetPos()) > VIEW_RANGE + 300) {
|
|
continue;
|
|
}
|
|
#endif
|
|
entity->FillMFObjectPart(room, (Human*)hum, msg->add_part_objects());
|
|
}
|
|
if (deleted_uniid > 0) {
|
|
framedata->part_objects.erase(deleted_uniid);
|
|
}
|
|
}
|
|
for (auto& itr : framedata->del_objects) {
|
|
msg->add_del_objids(itr);
|
|
#ifdef DEBUG
|
|
if (App::Instance()->HasFlag(2)) {
|
|
room->BroadcastDebugMsg(a8::Format("投放 删除对象%d",
|
|
{
|
|
itr
|
|
}));
|
|
}
|
|
#endif
|
|
}
|
|
#ifdef DEBUG
|
|
Debug_OutObject(hum);
|
|
#endif
|
|
for (auto& itr : framedata->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 : framedata->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 : framedata->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 : framedata->del_bullets_) {
|
|
if (idx < room->frame_event.del_bullets_.size()) {
|
|
int bullet_uniid = room->frame_event.del_bullets_[idx];
|
|
msg->add_del_bullets(bullet_uniid);
|
|
}
|
|
}
|
|
for (size_t idx : framedata->explosions_) {
|
|
if (idx < room->frame_event.explosions_.size()) {
|
|
auto& tuple = room->frame_event.explosions_[idx];
|
|
*msg->add_explosions() = std::get<1>(tuple);
|
|
#ifdef DEBUG
|
|
a8::XPrintf("AddExplosion %d, %s pos=%d,%d effect:%d\n",
|
|
{
|
|
hum->GetUniId(),
|
|
hum->name,
|
|
std::get<1>(tuple).pos().x(),
|
|
std::get<1>(tuple).pos().y(),
|
|
std::get<1>(tuple).effect()
|
|
});
|
|
#endif
|
|
}
|
|
}
|
|
for (size_t idx : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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 : framedata->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->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());
|
|
}
|
|
}
|
|
return msg;
|
|
}
|