This commit is contained in:
aozhiwei 2019-07-23 16:23:42 +08:00
parent 630c90bffc
commit 7156ca8aee
5 changed files with 173 additions and 14 deletions

View File

@ -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<std::string> strings1;
a8::Split(extra_drop, strings1, '|');
for (std::string& str1 : strings1) {
std::vector<std::string> 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;
}

View File

@ -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;

View File

@ -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;

View File

@ -104,6 +104,8 @@ struct PlayerStats
int weapon_id = 0;
int rank = 0;
int cup = 0;
std::vector<std::pair<int, int>> extra_drop;
};
struct HumanAbility

View File

@ -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:(广)
}
//