From 7156ca8aee646e9e5e56b4b4eae09c37880239d3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 23 Jul 2019 16:23:42 +0800 Subject: [PATCH] 1 --- server/gameserver/human.cc | 157 +++++++++++++++++++++++++ server/gameserver/human.h | 6 + server/gameserver/room.cc | 19 +-- server/gameserver/types.h | 2 + server/tools/protobuild/cs_proto.proto | 3 + 5 files changed, 173 insertions(+), 14 deletions(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index c47c7ce..cded458 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1555,6 +1555,15 @@ void Human::RecalcBaseAttr() ability.max_hp = ability.hp; } +void Human::SendGameOver() +{ + if (entity_subtype == kEST_Player) { + if (!sending_gameover_) { + InternalSendGameOver(); + } + } +} + void Human::_UpdateMove(int speed) { for (int i = 0; i < speed; ++i) { @@ -2007,3 +2016,151 @@ void Human::InternalShot(MetaData::Equip* bullet_meta, int skill_id, size_t offs } OnAttack(); } + +void Human::FillSMGameOver(cs::SMGameOver& msg) +{ + msg.set_team_id(team_id); + msg.set_team_rank(stats.rank); + msg.set_team_allcnt(1); + msg.set_game_over(room->game_over); + msg.set_victory(!dead); + msg.set_room_uuid(a8::XValue(room->room_uuid)); + + cs::MFPlayerStats* p = msg.add_player_stats(); + { + p->set_rank(stats.rank); + p->set_player_id(entity_uniid); + p->set_player_avatar_url(avatar_url); + p->set_account_id(account_id); + p->set_kills(stats.kills); + p->set_cup(stats.cup); + p->set_dead_times(stats.dead_times); + + for (auto& pair : stats.extra_drop) { + auto p1 = p->add_extra_drop(); + p1->set_key(pair.first); + p1->set_value(pair.second); + } + } +} + +void Human::GenBattleReportData(a8::MutableXObject* params) +{ + params->SetVal("account_id", account_id); + params->SetVal("session_id", session_id); + params->SetVal("map_id", room->map_meta->i->map_id()); + params->SetVal("map_name", room->map_meta->i->map_name()); + params->SetVal("map_tpl_name", room->map_tpl_name); + params->SetVal("game_time", time(nullptr)); + params->SetVal("hurt", stats.damage_amount_in); + params->SetVal("rank", stats.rank); + params->SetVal("kills", stats.kills); + params->SetVal("harm", stats.damage_amount_out); + params->SetVal("skill", 0); + params->SetVal("tank1_skill", 0); + params->SetVal("tank2_skill", 0); + params->SetVal("tank3_skill", 0); + params->SetVal("coin_num", 0); + params->SetVal("score", 0); + params->SetVal("room_uuid", room->room_uuid); +} + +void Human::InternalSendGameOver() +{ + if (entity_subtype != kEST_Player) { + return; + } + a8::MutableXObject* params = a8::MutableXObject::NewObject(); + GenBattleReportData(params); + auto on_ok = [] (a8::XParams& param, a8::XObject& data) + { + long long room_uuid = param.sender; + int hum_uniid = param.param1; + Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); + if (room) { + room->pending_request--; + Entity* entity = room->GetEntityByUniId(hum_uniid); + if (entity && entity->entity_type == kET_Player) { + Human* hum = (Human*)entity; + hum->sending_gameover_ = false; + hum->already_report_battle_ = true; + hum->stats.history_time_alive = data.Get("alive_time_his"); + hum->stats.history_kills = data.Get("kill_his"); + hum->stats.history_damage_amount = data.Get("harm_his"); + hum->stats.history_heal_amount = data.Get("add_HP_his"); + { + std::string extra_drop = data.Get("extra_drop").GetString(); + std::vector strings1; + a8::Split(extra_drop, strings1, '|'); + for (std::string& str1 : strings1) { + std::vector strings2; + a8::Split(str1, strings2, ':'); + if (strings2.size() == 2) { + hum->stats.extra_drop.push_back(std::make_pair( + a8::XValue(strings2[0]).GetInt(), + a8::XValue(strings2[1]).GetInt() + ) + ); + } + } + } + cs::SMGameOver msg; + hum->FillSMGameOver(msg); + hum->SendNotifyMsg(msg); + if (!hum->sent_game_end_ && hum->entity_subtype == kEST_Player) { + GameLog::Instance()->GameEnd((Player*)hum); + hum->sent_game_end_ = true; + } + } + } + }; + auto on_error = [] (a8::XParams& param, const std::string& response) + { + a8::UdpLog::Instance()->Error("battleReport http error params: %s response: %s", + { + param.param2, + response + }); + long long room_uuid = param.sender; + int hum_uniid = param.param1; + Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); + if (room) { + room->pending_request--; + Entity* entity = room->GetEntityByUniId(hum_uniid); + if (entity && entity->entity_type == kET_Player) { + Human* hum = (Human*)entity; + hum->sending_gameover_ = false; + ++hum->send_gameover_trycount_; + if (hum->send_gameover_trycount_ < 10){ + hum->SendGameOver(); + } + } + } + }; + std::string url; + if (!f8::IsOnlineEnv()) { + if (App::Instance()->HasFlag(3)) { + url = "http://game2002api.the7ys.com/webapp/index.php?c=Role&a=battleReport"; + } else { + url = "https://game2002api-test.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + } + } else { + url = "https://game2002api.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + } + room->pending_request++; + std::string data; + params->ToUrlEncodeStr(data); + f8::HttpClientPool::Instance()->HttpGet( + a8::XParams() + .SetSender(room->room_uuid) + .SetParam1(entity_uniid) + .SetParam2(data), + on_ok, + on_error, + url.c_str(), + *params, + room->room_uuid + ); + delete params; + sending_gameover_ = true; +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 52ba406..aa5e624 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -199,6 +199,7 @@ class Human : public Entity void GrassTempShow(); float* GetAbilityById(int attr_id); void RecalcBaseAttr(); + void SendGameOver(); protected: void _UpdateMove(int speed); @@ -213,6 +214,9 @@ private: Buff* GetBuffById(int buff_id); void ProcSkillPhase(MetaData::SkillPhase* phase); void InternalShot(MetaData::Equip* bullet_meta, int skill_id, size_t offset_idx); + void FillSMGameOver(cs::SMGameOver& msg); + void GenBattleReportData(a8::MutableXObject* params); + void InternalSendGameOver(); protected: long long last_shot_frameno_ = 0; @@ -259,6 +263,8 @@ private: bool sent_game_end_ = false; Tank tank_; + long long send_gameover_trycount_ = 0; + bool sending_gameover_ = false; xtimer_list* grass_hide_timer_list_ = nullptr; xtimer_list* leave_grass_timer_list_ = nullptr; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index e636628..8fe7f76 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1071,25 +1071,16 @@ void Room::BattleReport() if (a->stats.damage_amount_out > b->stats.damage_amount_out) { return true; } + if (a->stats.last_kill_timeseq < b->stats.last_kill_timeseq) { + return true; + } return false; }); - cs::SMGameOver msg; - msg.set_room_uuid(a8::XValue(room_uuid).GetString()); int rank = 1; for (Human* hum : human_list) { - auto p = msg.add_player_stats(); - p->set_rank(rank++); - p->set_player_id(hum->entity_uniid); - p->set_player_avatar_url(hum->avatar_url); - p->set_account_id(hum->account_id); - p->set_kills(hum->stats.kills); - p->set_dead_times(hum->stats.dead_times); - } - for (Human* hum : human_list) { - if (hum->entity_subtype == kEST_Player) { - hum->SendNotifyMsg(msg); - } + hum->stats.rank = rank++; + hum->SendGameOver(); } game_over = true; game_over_frameno = frameno; diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 0702a28..25c1cdd 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -104,6 +104,8 @@ struct PlayerStats int weapon_id = 0; int rank = 0; + int cup = 0; + std::vector> extra_drop; }; struct HumanAbility diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index da34fa5..ddc7c3c 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -538,6 +538,9 @@ message MFPlayerStats optional int32 kills = 5; //击杀敌人数 optional int32 dead_times = 6; //死亡次数 + optional int32 cup = 7; //奖杯 + + repeated MFPair extra_drop = 12; //额外掉落,key:item_id value:数量(看广告) } //玩家战斗中统计