aozhiwei 21ed634aad 1
2022-12-25 09:49:01 +08:00

1025 lines
33 KiB
C++

#include "precompile.h"
#include <math.h>
#include "cs_proto.pb.h"
#include "pbutils.h"
#include "ability.h"
#include "killmgr.h"
#include "room.h"
#include "player.h"
#include "human.h"
#include "weapon.h"
#include "buff.h"
#include "car.h"
#include "hero.h"
#include "loot.h"
#include "obstacle.h"
#include "roomobstacle.h"
#include "skill.h"
#include "skin.h"
#include "typeconvert.h"
#include "mt/Param.h"
#include "mt/Buff.h"
#include "mt/Equip.h"
#include "mt/Hero.h"
#include "mt/MapThing.h"
#include "mt/Skill.h"
void PBUtils::Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFActivePlayerData* player_data)
{
_Ability_FillMFAttrAdditionList
(self,
hum,
[player_data] ()
{
return player_data->add_attr_addition();
});
}
void PBUtils::Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFPlayerFull* full_data)
{
_Ability_FillMFAttrAdditionList
(self,
hum,
[full_data] ()
{
return full_data->add_attr_addition();
});
}
void PBUtils::_Ability_FillMFAttrAdditionList(Ability* self,
Human* hum,
std::function<cs::MFAttrAddition* ()> add_func
)
{
for (int attr_id = 0; attr_id < kHAT_End; ++attr_id) {
if (!(attr_id == 12 || attr_id == 33)) {
continue;
}
if (self->buff_attr_flag_[attr_id]) {
auto pb_attr = add_func();
pb_attr->set_attr_id(attr_id);
pb_attr->set_abs_val(self->buff_attr_abs_[attr_id]);
#if 1
pb_attr->set_rate_val(self->buff_attr_rate_[attr_id]);
#else
pb_attr->set_rate_val(self->buff_attr_rate_[attr_id] * 100);
#endif
}
}
}
/*
master.name
killer.name
dead.name
weapon.name
weapon.text_icon
image.id:
*/
void KillMgr::OnHumanDead(Human* dead_hum, KillInfo* info)
{
RollMsgHintInfo hint_info;
std::shared_ptr<cs::SMRollMsg> pb_msg = std::make_shared<cs::SMRollMsg>();
FillHintInfo(dead_hum, info, hint_info);
PreprocessRollMsg(pb_msg, hint_info);
BoradcastRollMsg(dead_hum, info, 0, pb_msg);
}
void KillMgr::PreprocessRollMsg(std::shared_ptr<cs::SMRollMsg> pb_msg,
RollMsgHintInfo& hint_info)
{
if (hint_info.hint_template) {
for (auto& tuple : *hint_info.hint_template) {
int el_type = std::get<0>(tuple);
std::string el_val = std::get<1>(tuple);
switch (el_type) {
case kTextElement:
{
auto e = pb_msg->add_elements();
e->set_element_type(el_type);
e->mutable_union_obj_1()->set_text(el_val);
}
break;
case kImageElement:
{
auto e = pb_msg->add_elements();
e->set_element_type(el_type);
e->mutable_union_obj_2()->set_id(a8::XValue(el_val));
}
break;
default:
{
std::string text;
if (hint_info.Replace(el_type, text)) {
if (el_type == kFieldIdxWeaponTextIcon) {
auto e = pb_msg->add_elements();
e->set_element_type(kImageElement);
e->mutable_union_obj_2()->set_id(a8::XValue(text));
} else {
auto e = pb_msg->add_elements();
e->set_element_type(kTextElement);
e->mutable_union_obj_1()->set_text(text);
}
}
}
break;
}
}
}
}
void KillMgr::BoradcastRollMsg(Human* dead_hum,
KillInfo* info,
int killer_team_id,
std::shared_ptr<cs::SMRollMsg> pb_msg)
{
std::shared_ptr<KillInfo> info_copy = std::make_shared<KillInfo>();
*info_copy = *info;
std::shared_ptr<cs::SMRollMsg> pb_msg_copy = std::make_shared<cs::SMRollMsg>();
pb_msg_copy = pb_msg;
dead_hum->room->xtimer.SetTimeoutEx
(
0,
[dead_hum, info_copy, pb_msg_copy, killer_team_id]
(int event, const a8::Args* args) mutable
{
if (a8::TIMER_EXEC_EVENT == event) {
KillMgr::Instance()->BoradcastRollMsgCb
(dead_hum,
info_copy.get(),
killer_team_id,
pb_msg_copy);
}
},
&dead_hum->xtimer_attacher);
}
void KillMgr::BoradcastRollMsgCb(Human* dead_hum,
KillInfo* info,
int killer_team_id,
std::shared_ptr<cs::SMRollMsg> pb_msg)
{
dead_hum->room->TraversePlayerList
(
[dead_hum, info, &pb_msg, killer_team_id]
(Player* hum) -> bool
{
for (int i = 0; i < pb_msg->elements_size(); ++i) {
auto element = pb_msg->mutable_elements(i);
if (element->element_type() == kTextElement) {
int color = element->mutable_union_obj_1()->color();
if (info->killer_id == hum->GetUniId()){
color = mt::Param::s().self_kill_color;
} else if (killer_team_id == hum->team_id) {
color = mt::Param::s().teammate_kill_color;
} else if (dead_hum == hum) {
color = mt::Param::s().self_bekill_color;
} else if (dead_hum->team_id == hum->team_id) {
color = mt::Param::s().teammate_bekill_color;
}
if (element->mutable_union_obj_1()->color() != color) {
element->mutable_union_obj_1()->set_color(color);
}
}
}
hum->SendNotifyMsg(*pb_msg);
return true;
});
}
void Weapon::ToPB(Creature* c, cs::MFWeapon* pb_obj)
{
pb_obj->set_weapon_uniid(a8::XValue(weapon_uniid).GetString());
pb_obj->set_weapon_id(weapon_id);
pb_obj->set_weapon_lv(1);
pb_obj->set_ammo(ammo);
pb_obj->set_volume(GetClipVolume(c));
}
void Buff::FillMFBuff(cs::MFBuff* buff_pb)
{
buff_pb->set_buff_id(meta->buff_id());
buff_pb->set_left_time(GetLeftTime());
buff_pb->set_lasting_time(GetLastingTime());
buff_pb->set_buff_uniid(buff_uniid);
if (owner->IsHuman() &&
(meta->buff_effect() == kBET_Driver ||
meta->buff_effect() == kBET_Passenger)) {
}
}
void Car::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Car);
cs::MFCarPart* p = part_data->mutable_union_obj_11();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
}
void Car::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Car);
cs::MFCarFull* p = full_data->mutable_union_obj_11();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
p->set_car_id(meta->id());
p->set_heroid(meta->heroid());
p->set_driver(driver_ ? driver_->GetUniId() : 0);
for (auto hum : passengers_) {
auto less_data = p->add_passengers();
hum->FillMFObjectLess(room, hum, less_data);
}
p->set_born_frameno(ceil(born_frameno_ / 2.0));
p->set_dead(dead);
p->set_health(GetHP());
p->set_max_health(GetMaxHP());
p->set_oil(cur_oil_);
p->set_max_oil(meta->max_oil());
if (GetCurrWeapon()) {
p->set_bullet_num(GetCurrWeapon()->ammo);
} else {
p->set_bullet_num(0);
}
p->set_seat_num(meta->_int_param2);
// 222
#if 0
FillBuffList(hum, p->mutable_buff_list());
#endif
}
void Hero::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Hero);
cs::MFHeroPart* p = part_data->mutable_union_obj_10();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
}
void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Hero);
cs::MFHeroFull* p = full_data->mutable_union_obj_10();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
p->set_heroid(meta->id());
p->set_master_uniid(master.Get() ? master.Get()->GetUniId() : 0);
p->set_dead(dead);
p->set_health(GetHP());
p->set_max_health(GetMaxHP());
// 222
#if 0
FillBuffList(hum, p->mutable_buff_list());
#endif
}
void Loot::FillMFObjectPart( Room* room, Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Loot);
cs::MFLootPart* p = part_data->mutable_union_obj_5();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
}
void Loot::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Loot);
cs::MFLootFull* p = full_data->mutable_union_obj_5();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(born_pos, p->mutable_born_pos());
p->set_item_id(item_id);
p->set_count(count);
p->set_item_level(item_level);
if (show_anim && room->GetFrameNo() <= create_frame_no + 1) {
p->set_show_anim(true);
}
}
void Obstacle::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Obstacle);
cs::MFObstaclePart* p = part_data->mutable_union_obj_2();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
if (std::abs(scale - 1.0f) > 0.00001f) {
p->set_scale(scale);
}
}
void Obstacle::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Obstacle);
if (IsClientCached(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfReadCache);
full_data->set_obj_uniid(GetUniId());
full_data->set_object_flags(object_flags);
return;
}
cs::MFObstacleFull* p = full_data->mutable_union_obj_2();
if (CanClientCache(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfWriteCache);
#if 0
full_data->set_obj_uniid(GetUniId());
#endif
full_data->set_object_flags(object_flags);
AddClientCache(hum);
}
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
if (std::abs(scale - 1.0f) > 0.00001f) {
p->set_scale(scale);
}
p->set_obstacle_id(meta->thing_id());
p->set_health(GetHealth(room));
p->set_dead(IsDead(room));
p->set_dead_at_thisframe(IsDead(room) ? GetDeadFrameNo(room) <= room->GetFrameNo() : false);
if (!IsPermanent()) {
RoomObstacle* ob = (RoomObstacle*)this;
p->set_born_frameno(ceil(ob->born_frameno / 2.0));
}
if (meta->thing_type() == kObstacleHideHouse) {
#if 0
if (GetInteractionData(hum)) {
#if 1
p->set_button_name("3");
#else
p->set_button_name("脱离");
#endif
} else {
#if 1
p->set_button_name("2");
#else
p->set_button_name("躲藏");
#endif
}
#endif
} else {
if (IsOpenInteraction()) {
if (IsDead(hum->room)) {
p->set_button_name("");
} else {
#if 1
p->set_button_name("1");
#else
p->set_button_name("开启");
#endif
}
}
}
if (meta->thing_type() == kObstacleStrengthenWall) {
p->set_rotate(rotate_ * 180);
}
}
void Skill::FillMFSkill(cs::MFSkill* skill_pb)
{
skill_pb->set_skill_id(meta->skill_id());
skill_pb->set_left_time(GetLeftTime());
skill_pb->set_cd_time(GetCd());
skill_pb->set_curr_times(GetCurrTimes());
skill_pb->set_max_times(GetMaxTimes());
if (minor_type_) {
int minor_left_time = std::max
(0,
minor_cd_time_ - (int)((owner->room->GetFrameNo() - minor_frameno_) * FRAME_RATE_MS));
skill_pb->set_minor_type(minor_type_);
skill_pb->set_minor_left_time(minor_left_time);
skill_pb->set_minor_cd_time(minor_cd_time_);
skill_pb->set_left_time(GetCd());
#ifdef DEBUG
a8::XPrintf("type: %d, lefttime:%d cd_time:%d\n", {
minor_type_,
minor_left_time,
minor_cd_time_
});
#endif
}
}
void Skin::ToPB(cs::MFSkin* pb_obj)
{
pb_obj->set_skin_id(skin_id);
pb_obj->set_skin_lv(skin_lv);
}
void PBUtils::Human_SendSMPvePassWave(Human* self, int new_wave, int pve_max_wave, int wait_time)
{
cs::SMPvePassWave notify_msg;
notify_msg.set_new_wave(new_wave);
notify_msg.set_pve_max_wave(pve_max_wave);
notify_msg.set_pve_max_wave(wait_time);
self->SendNotifyMsg(notify_msg);
}
void PBUtils::Human_FillMFObjectPart(Human* self, Room* room, Human* hum, cs::MFObjectPart* part_data)
{
#if 0
part_data->set_object_type(ET_Player);
cs::MFPlayerPart* p = part_data->mutable_union_obj_1();
p->set_obj_uniid(GetUniId());
p->set_speed(GetSpeed() * SERVER_FRAME_RATE);
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
#endif
}
void PBUtils::Human_FillMFObjectLess(Human* self, Room* room, Human* hum, cs::MFPlayerFull* full_data)
{
#if 0
cs::MFPlayerFull* p = full_data;
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
p->set_health(GetHP());
p->set_max_health(GetMaxHP());
p->set_dead(dead);
p->set_downed(downed);
p->set_disconnected(disconnected);
for (auto itr : skins) {
auto skin = p->add_skin();
itr.ToPB(skin);
}
p->set_backpack(backpack);
p->set_helmet(helmet);
p->set_chest(chest);
p->set_shoot_offset_x(shoot_offset.x);
p->set_shoot_offset_y(shoot_offset.y);
GetCurrWeapon()->ToPB(this, p->mutable_weapon());
PBUtils::Ability_FillMFAttrAdditionList(GetAbility().get(), this, p);
if (GetCar()) {
p->set_car_uniid(GetCar()->car_uniid);
p->set_car_seat(GetSeat());
} else {
p->set_car_uniid(0);
p->set_car_seat(0);
}
#endif
}
void PBUtils::Human_FillMFObjectFull(Human* self, Room* room, Human* hum, cs::MFObjectFull* full_data)
{
#if 0
full_data->set_object_type(ET_Player);
cs::MFPlayerFull* p = full_data->mutable_union_obj_1();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
p->set_health(GetHP());
p->set_max_health(GetMaxHP());
p->set_dead(dead);
p->set_downed(downed);
p->set_disconnected(disconnected);
p->set_speed(GetSpeed() * SERVER_FRAME_RATE);
for (auto itr : skins) {
auto skin = p->add_skin();
itr.ToPB(skin);
}
p->set_backpack(backpack);
p->set_helmet(helmet);
p->set_chest(chest);
GetCurrWeapon()->ToPB(this, p->mutable_weapon());
p->set_energy_shield(energy_shield);
p->set_shoot_offset_x(shoot_offset.x);
p->set_shoot_offset_y(shoot_offset.y);
#if 1
{
p->set_max_energy_shield(max_energy_shield);
}
#endif
if (guild_id != 0) {
p->set_guild_id(guild_id);
}
if (vip_lv != 0) {
p->set_vip_lv(vip_lv);
}
if (head_frame != 0) {
p->set_head_frame(head_frame);
}
if (sex != 0) {
p->set_sex(sex);
}
if (!user_data.empty()) {
p->set_user_data(user_data);
}
p->set_vip(vip);
p->set_kill_count(stats.kills);
if (emoji1 != 0) {
p->set_emoji1(emoji1);
}
if (emoji2 != 0) {
p->set_emoji2(emoji2);
}
if (parachute != 0) {
p->set_parachute(parachute);
}
if (IsPlayer()) {
int i = 0;
}
if (follow_target.Get()) {
p->set_follow_target(follow_target.Get()->GetUniId());
#ifdef DEBUG
a8::XPrintf("DoFollow1 %d->%d\n", {GetUniId(), follow_target.Get()->GetUniId()});
#endif
}
// 222
#if 0
FillBodyState(p->mutable_states());
FillBuffList(hum, p->mutable_buff_list());
FillSkillList(p->mutable_skill_list());
#endif
if (dead) {
p->set_killer_name(stats.killer_name);
p->set_killer_id(stats.killer_id);
if (real_dead){
p->set_can_revive(false);
} else {
p->set_can_revive(true);
int countdown = 0;
if (!revive_timer.expired()) {
countdown = std::ceil(room->xtimer.GetRemainTime(revive_timer) / SERVER_FRAME_RATE);
} else {
f8::UdpLog::Instance()->Warning
("Human::FillMFObjectfull revive_timer == nullptr "
"dead_frameno:%d dead_times:%d alive_count:%d "
"room.frameno:%d",
{
dead_frameno,
stats.dead_times,
room->AliveCount(),
room->GetFrameNo()
});
}
countdown = std::max(0, countdown - kReviveTimeAdd);
p->set_revive_countdown(countdown);
}
}
p->set_charid(meta->id());
if (GetCar()) {
p->set_car_uniid(GetCar()->car_uniid);
p->set_car_seat(GetSeat());
} else {
p->set_car_uniid(0);
p->set_car_seat(0);
}
if (GetBuffByEffectId(kBET_HoldShield)) {
p->set_shield_hp(shield_hp_);
p->set_shield_max_hp(shield_max_hp_);
}
#endif
}
void PBUtils::Human_FillMFObjectImage(Human* self, Room* room, Human* hum, cs::MFCharacterImage* image_data)
{
#if 0
image_data->set_obj_uniid(GetUniId());
image_data->set_cur_weapon_idx(GetCurrWeapon()->weapon_idx);
GetCurrWeapon()->ToPB(this, image_data->mutable_weapon());
#endif
}
void PBUtils::Human_FillMFPlayerStats(Human* self, cs::MFPlayerStats* stats_pb)
{
#if 0
stats_pb->set_player_id(GetUniId());
stats_pb->set_player_avatar_url(avatar_url);
stats_pb->set_charid(meta->id());
stats_pb->set_team_id(team_id);
stats_pb->set_nickname(name);
int alive_time = room->GetFrameNo() * FRAME_RATE_MS;
if (!dead) {
stats_pb->set_time_alive(alive_time);
} else {
alive_time = (dead_frameno - room->GetBattleStartFrameNo()) * FRAME_RATE_MS;
if (room->GetBattleStartFrameNo() <= 0) {
alive_time = 0;
}
alive_time = std::max(alive_time, 0);
stats_pb->set_time_alive(alive_time);
}
stats_pb->set_kills(stats.kills);
stats_pb->set_damage_amount(stats.damage_amount_out);
stats_pb->set_heal_amount(stats.heal_amount);
stats_pb->set_assist(stats.assist);
stats_pb->set_rescue(stats.rescue_member);
stats_pb->set_pve_wave(stats.pve_wave);
stats_pb->set_revive(stats.revive);
stats_pb->set_rank_chg(stats.rank_chg);
stats_pb->set_history_time_alive(stats.history_time_alive);
stats_pb->set_history_kills(stats.history_kills);
stats_pb->set_history_damage_amount(stats.history_damage_amount);
stats_pb->set_history_heal_amount(stats.history_heal_amount);
stats_pb->set_gold(stats.gold);
#if 1
stats_pb->set_score(stats.pve_rank_score);
#else
stats_pb->set_score(stats.score);
#endif
stats_pb->set_pass_score(stats.pass_score);
stats_pb->set_rank_score(stats.rank_score);
stats_pb->set_has_pass(has_pass);
stats_pb->set_dead(dead);
stats_pb->set_killer_id(stats.killer_id);
stats_pb->set_killer_name(stats.killer_name);
{
Player* killer = room->GetPlayerByUniId(stats.killer_id);
if (killer) {
stats_pb->set_killer_avatar_url(killer->avatar_url);
stats_pb->set_killer_account_id(killer->account_id);
} else {
stats_pb->set_killer_avatar_url("");
stats_pb->set_killer_account_id("");
}
}
stats_pb->set_account_id(account_id);
if (guild_id != 0) {
stats_pb->set_guild_id(guild_id);
}
stats_pb->set_rescue_guild_member(stats.rescue_guild_member);
for (auto& pair : stats.items) {
auto p = stats_pb->add_items();
p->set_key(pair.first);
p->set_value(pair.second);
}
for (auto& pair : stats.extra_drop) {
auto p = stats_pb->add_extra_drop();
p->set_key(pair.first);
p->set_value(pair.second);
}
if (vip_lv != 0) {
stats_pb->set_vip_lv(vip_lv);
}
if (head_frame != 0) {
stats_pb->set_head_frame(head_frame);
}
if (sex != 0) {
stats_pb->set_sex(sex);
}
{
for (auto& skin : skins) {
auto pb_skin = stats_pb->add_skin();
skin.ToPB(pb_skin);
}
}
// 222
#if 0
*stats_pb->mutable_hero_stats() = stats.pb_hero_stats;
*stats_pb->mutable_weapons_stats() = stats.pb_weapons_stats;
#endif
#endif
}
void PBUtils::Human_FillMFTeamData(Human* self, Human* hum, cs::MFTeamData* team_data, bool is_game_over)
{
#if 0
{
last_sync_teamdata_frameno_ = room->GetFrameNo();
team_data->set_team_id(team_id);
team_data->set_player_id(GetUniId());
team_data->set_hero_id(meta->id());
team_data->set_score(stats.pve_rank_score);
if (is_game_over || !real_dead || room->GetFrameNo() - GetRealDeadFrameNo(room) < 4) {
TypeConvert::ToPb(GetPos(), team_data->mutable_pos());
TypeConvert::ToPb(GetAttackDir(), team_data->mutable_dir());
team_data->set_health(GetHP());
team_data->set_max_health(GetMaxHP());
team_data->set_dead(dead);
team_data->set_downed(downed);
}
#if 1
team_data->set_dead(dead);
#endif
if (is_game_over || room->GetGasData().GetGasMode() == GasInactive) {
team_data->set_name(name);
}
if (room->GetGasData().GetGasMode() != GasInactive &&
room->GetFrameNo() - room->GetBattleStartFrameNo() < 4) {
team_data->set_name(name);
team_data->set_disconnected(socket_handle == 0);
}
if (is_game_over) {
team_data->set_account_id(account_id);
team_data->set_avatar_url(avatar_url);
team_data->set_user_value1(user_value1);
team_data->set_user_value2(user_value2);
team_data->set_user_value3(user_value3);
if (guild_id != 0) {
team_data->set_guild_id(guild_id);
}
}
if (vip_lv != 0) {
team_data->set_vip_lv(vip_lv);
}
if (head_frame != 0) {
team_data->set_head_frame(head_frame);
}
if (sex != 0) {
team_data->set_sex(sex);
}
if (room->GetGasData().GetGasMode() == GasInactive ||
room->GetFrameNo() - room->GetBattleStartFrameNo() < 4) {
team_data->set_user_data(user_data);
}
#if 0
if (HasBuffEffect(kBET_Jump) && GetTeam()) {
bool can_follow = hum->CanFollow(this);
if (can_follow) {
team_data->set_can_follow(can_follow);
}
}
#endif
{
for (auto itr : skins) {
auto skin = team_data->add_skin();
itr.ToPB(skin);
}
}
}
#endif
}
void PBUtils::Human_FillSMGameOver(Human* self, cs::SMGameOver& msg)
{
#if 0
int alive_team_num = room->GetAliveTeamNum();
if (stats.victory) {
msg.set_watchable(false);
} else {
if (room->GetAliveTeamNum() > 1) {
msg.set_watchable(true);
} else {
if (room->IsPveRoom()) {
msg.set_watchable(!room->IsGameOver());
} else {
msg.set_watchable(false);
}
}
}
msg.set_map_id(room->GetMapMeta()->map_id());
msg.set_team_id(team_id);
msg.set_team_rank(GetTeam()->team_rank);
msg.set_personal_rank(stats.rank);
if (room->IsPveRoom()) {
stats.pve_wave = room->pve_data.GetPassedWave();
msg.set_game_over(room->IsGameOver());
} else {
msg.set_game_over(room->IsGameOver() || (alive_team_num == 1));
}
msg.set_victory(stats.victory);
msg.set_room_uuid(a8::XValue(room->GetRoomUuid()));
msg.set_total_human_num(room->GetHumanNum());
msg.set_alive_human_num(room->AliveCount());
if (GetTeam()) {
GetTeam()->TraverseMembers
(
[this, &msg] (Human* member) -> bool
{
{
member->FillMFTeamData(this, msg.add_team_data(), true);
cs::MFPlayerStats* p = msg.add_player_stats();
member->FillMFPlayerStats(p);
}
return true;
});
}
{
msg.set_total_team_num(room->GetTeamNum());
if (room->IsPveRoom()) {
msg.set_pve_wave(room->pve_data.GetPassedWave());
msg.set_pve_max_wave(room->pve_data.max_wave);
msg.set_pve_instance_id(room->pve_instance->gemini_id());
msg.set_pve_boss_killed(room->pve_data.boss_state == 2 ? 1 : 0);
}
}
TypeConvert::ToPb(stats.over_reward, msg.mutable_reward());
{
if (!stats.over_reward.total_ceg.empty()) {
auto p = msg.add_spoils_items();
p->add_values("10001");
p->add_values(stats.over_reward.total_ceg);
}
for (auto& tuple : stats.over_reward.items) {
auto p = msg.add_spoils_items();
p->add_values(a8::XValue(std::get<0>(tuple)).GetString());
p->add_values(std::get<1>(tuple));
}
}
{
if (room->IsPveRoom()) {
msg.set_mode(GetTeam()->GetMemberNum() <= 1 ? 1 : 2);
msg.set_my_rank(room->pve_data.GetPassedWave());
msg.set_max_rank(room->pve_data.max_wave);
} else {
if (GetTeam()->GetMemberNum() <= 1) {
msg.set_mode(1);
msg.set_my_rank(stats.rank);
msg.set_max_rank(room->GetHumanNum());
} else {
if (GetTeam()->team_rank <= 0) {
msg.set_mode(1);
msg.set_my_rank(stats.rank);
msg.set_max_rank(room->GetHumanNum());
} else {
msg.set_mode(2);
msg.set_my_rank(GetTeam()->team_rank);
msg.set_max_rank(room->GetTeamNum());
}
}
}
}
#if 1
if (room->GetBattleStartFrameNo() <= 0 &&
dead_frameno) {
msg.set_team_rank(0);
msg.set_personal_rank(0);
msg.set_my_rank(0);
}
#endif
if (IsPlayer()) {
Player* p = (Player*)this;
if (!p->settlement) {
p->settlement = std::make_shared<cs::MFSettlement>();
FillMFSettlement(&msg, p->settlement.get());
}
*msg.mutable_settlement() = *p->settlement;
}
#endif
}
void PBUtils::Human_FillMFActivePlayerData(Human* self, cs::MFActivePlayerData* player_data)
{
#if 0
#ifdef DEBUG1
a8::XPrintf("FillMFActivePlayerData isPlayer:%d id:%d name:%s need_sync_active_player:%d send_msg_times:%d\n",
{
IsPlayer() ? 1 : 0,
GetUniId(),
name,
need_sync_active_player ? 1 : 0,
send_msg_times
});
#endif
{
player_data->set_action_type(action_type);
if (action_type != AT_None) {
int duration = std::max(0,
action_duration -
(int)((room->GetFrameNo() - action_frameno) * 1.0f / SERVER_FRAME_RATE) * 1000
);
player_data->set_action_item_id(action_item_id);
player_data->set_action_duration(duration);
player_data->set_action_target_id(action_target_id);
player_data->set_action_frameno(action_frameno);
#if 1
if (action_type == AT_UseItem) {
const mt::Equip* item_meta = mt::Equip::GetByIdBySlotId(action_item_id);
if (item_meta) {
player_data->set_action_item_id(item_meta->id());
int action_param = 0;
switch (action_item_id) {
case IS_HEALTHKIT:
case IS_SHEN_BAO:
{
action_param = item_meta->heal();
}
break;
case IS_PAIN_KILLER:
{
action_param = item_meta->heal() * item_meta->time();
}
break;
default:
{
}
break;
}
player_data->set_action_param(action_param);
}
}
#endif
}
}
#if 1
for (auto itr : skins) {
auto skin = player_data->add_skin();
itr.ToPB(skin);
}
#else
skin.ToPB(player_data->mutable_skin());
#endif
player_data->set_backpack(backpack);
player_data->set_helmet(helmet);
player_data->set_chest(chest);
player_data->set_health(GetHP());
player_data->set_max_health(GetMaxHP());
player_data->set_cur_weapon_idx(GetCurrWeapon()->weapon_idx);
player_data->set_cur_scope(curr_scope_idx);
if (HasBuffEffect(kBET_InWater)) {
player_data->set_dive_oxygen_max(mt::Param::s().dive_oxygen_total);
player_data->set_dive_oxygen_curr(oxygen_);
}
for (auto& weapon : weapons) {
auto p = player_data->add_weapons();
weapon.ToPB(this, p);
}
for (auto& inv : GetInventoryData()) {
player_data->add_inventory(inv.num);
}
player_data->set_energy_shield(energy_shield);
#if 1
{
player_data->set_max_energy_shield(max_energy_shield);
}
#endif
// 222
#if 0
FillBodyState(player_data->mutable_states());
FillItemList(player_data->mutable_items());
FillSkillList(player_data->mutable_skill_list());
#endif
player_data->set_shoot_offset_x(shoot_offset.x);
player_data->set_shoot_offset_y(shoot_offset.y);
PBUtils::Ability_FillMFAttrAdditionList(GetAbility().get(), this, player_data);
if (GetBuffByEffectId(kBET_HoldShield)) {
player_data->set_shield_hp(shield_hp_);
player_data->set_shield_max_hp(shield_max_hp_);
}
#endif
}
void PBUtils::Human_FillMFGasData(Human* self, cs::MFGasData* gas_data)
{
#if 0
gas_data->set_mode(room->GetGasData().GetGasMode());
if (room->GetGasData().GetGasMode() == GasInactive) {
long long duration = room->GetGasInactiveTime() * SERVER_FRAME_RATE -
(room->GetFrameNo() - room->GetGasData().gas_start_frameno);
gas_data->set_duration(std::max(duration * 50, (long long)1000) / 1000);
} else if (room->GetGasData().GetGasMode() == GasJump) {
gas_data->set_duration(0);
} else if (room->GetGasData().GetGasMode() == GasMoving) {
if (room->GetGasData().new_area_meta->shrink_speed() > 0.01f) {
long long duration = (room->GetGasData().old_area_meta->rad() - room->GetGasData().new_area_meta->rad()) /
room->GetGasData().new_area_meta->shrink_speed();
++duration;
gas_data->set_duration(++duration);
} else {
gas_data->set_duration(0);
}
} else {
if (room->GetGasData().old_area_meta->wait_time() <= 0) {
gas_data->set_duration(0);
} else {
long long duration = room->GetGasData().old_area_meta->wait_time() * 20 -
(room->GetFrameNo() - room->GetGasData().gas_start_frameno);
gas_data->set_duration(std::max(duration * 50, (long long)1000) / 1000);
}
if (room->IsPveRoom()) {
gas_data->set_duration(0);
}
}
// 333
{
glm::vec3 v3(room->GetGasData().pos_old.x, 0.0f, room->GetGasData().pos_old.y);
TypeConvert::ToPb(v3, gas_data->mutable_pos_old());
}
{
glm::vec3 v3(room->GetGasData().pos_new.x, 0.0f, room->GetGasData().pos_new.y);
TypeConvert::ToPb(v3, gas_data->mutable_pos_new());
}
gas_data->set_rad_old(room->GetGasData().rad_old);
gas_data->set_rad_new(room->GetGasData().rad_new);
#endif
}