From 9b33e85aedff45ed16da8b2534ff638673f3f1b2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 29 Apr 2019 16:57:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0maps.json=E8=AF=BB?= =?UTF-8?q?=E8=A1=A8=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/building.cc | 2 +- server/gameserver/human.cc | 104 +++++++++++++++++++++--- server/gameserver/human.h | 3 +- server/gameserver/metadata.cc | 19 +++++ server/gameserver/metamgr.cc | 3 +- server/gameserver/obstacle.cc | 2 +- server/gameserver/room.cc | 18 ++-- server/gameserver/roommgr.h | 2 +- server/gameserver/types.h | 1 + server/tools/protobuild/metatable.proto | 13 ++- 10 files changed, 142 insertions(+), 25 deletions(-) diff --git a/server/gameserver/building.cc b/server/gameserver/building.cc index 67c8400..1d71fbc 100644 --- a/server/gameserver/building.cc +++ b/server/gameserver/building.cc @@ -49,7 +49,7 @@ void Building::FillMFObjectFull(cs::MFObjectFull* full_data) p->set_obj_uniid(entity_uniid); pos.ToPB(p->mutable_pos()); - p->set_building_id(meta->i->_building_id()); + p->set_building_id(meta->i->mapid()); } ColliderComponent* Building::GetBoxBound() diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 8a35a0f..6381c10 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -12,7 +12,10 @@ #include "collision.h" #include "building.h" #include "hero.h" +#include "app.h" +#include "roommgr.h" +#include "framework/cpp/utils.h" #include "framework/cpp/httpclientpool.h" Human::Human():Entity() @@ -454,9 +457,11 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id) Entity* hum = room->GetEntityByUniId(killer_id); if (hum && hum->entity_type == ET_Player) { ((Human*)hum)->stats.kills++; + ((Human*)hum)->kill_humans.insert(this); } stats.killer_id = killer_id; stats.killer_name = killer_name; + stats.weapon_id = weapon_id; dead = true; health = 0.0f; dead_frameno = room->frame_no; @@ -1192,9 +1197,63 @@ void Human::SendUpdateMsg() void Human::UpdateGameOver() { + #if 0 + 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) { + Entity* entity = room->GetEntityByUniId(hum_uniid); + if (entity && entity->entity_type == ET_Player) { + Human* hum = (Human*)entity; + } + } + }; + auto on_error = [] (a8::XParams& param, const std::string& response) + { + long long room_uuid = param.sender; + int hum_uniid = param.param1; + Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); + if (room) { + Entity* entity = room->GetEntityByUniId(hum_uniid); + if (entity && entity->entity_type == ET_Player) { + Human* hum = (Human*)entity; + ++hum->send_gameover_trycount; + if (hum->send_gameover_trycount < 10){ + hum->send_gameover = true; + } + } + } + }; + std::string url; + if (!f8::IsOnlineEnv()) { + if (App::Instance()->flags.find(3) != App::Instance()->flags.end()) { + url = "http://http://192.168.100.41/webapp/index.php?c=Role&a=battleReport"; + } else { + url = "https://game2001api-test.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + } + } else { + url = "https://game2001api.kingsome.cn/webapp/index.php?c=Role&a=battleReport"; + } + f8::HttpClientPool::Instance()->HttpGet( + a8::XParams() + .SetSender(room->room_uuid) + .SetParam1(entity_uniid), + on_ok, + on_error, + url.c_str(), + *params, + rand() + ); + delete params; + #else cs::SMGameOver msg; FillSMGameOver(msg); SendNotifyMsg(msg); + #endif send_gameover = false; } @@ -1223,7 +1282,7 @@ void Human::ClearFrameData() } } -void Human::BattleReport() +void Human::GenBattleReportData(a8::MutableXObject* params) { int rank = 0; { @@ -1252,7 +1311,6 @@ void Human::BattleReport() } } } - a8::MutableXObject* params = a8::MutableXObject::NewObject(); params->SetVal("account_id", account_id); params->SetVal("map_name", room->map_meta->i->map_name()); params->SetVal("game_time", time(nullptr)); @@ -1267,29 +1325,51 @@ void Human::BattleReport() params->SetVal("alive_time", dead_frameno * 1000.0f / SERVER_FRAME_RATE); } params->SetVal("team_status", team_id != 0); - params->SetVal("snipe_kill", 0); - params->SetVal("rifle_kill", 0); - params->SetVal("pistol_kill", 0); - params->SetVal("submachine_kill", 0); - { - #if 0 - MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(lethal_weapon); + + int snipe_kill = 0; + int rifle_kill = 0; + int pistol_kill = 0; + int submachine_kill = 0; + for (Human* hum : kill_humans) { + MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(hum->lethal_weapon); if (equip_meta) { switch (equip_meta->i->equip_subtype()) { case 7: { - params->SetVal("snipe_kill", 0); + //狙击枪 + ++snipe_kill; + } + break; + case 5: + { + //步枪 + ++rifle_kill; + } + break; + case 2: + { + //手枪 + ++pistol_kill; + } + break; + case 3: + { + //冲锋枪 + ++submachine_kill; } break; } } - #endif } + params->SetVal("snipe_kill", snipe_kill); + params->SetVal("rifle_kill", rifle_kill); + params->SetVal("pistol_kill", pistol_kill); + params->SetVal("submachine_kill", submachine_kill); + params->SetVal("rescue_member", stats.rescue_member); { int coin_num = (rank * MetaMgr::Instance()->rank_param) + (stats.kills * MetaMgr::Instance()->kill_param); params->SetVal("coin_num", coin_num); } params->SetVal("score", 0); - delete params; } diff --git a/server/gameserver/human.h b/server/gameserver/human.h index cb772ad..0273142 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -88,6 +88,7 @@ class Human : public Entity PlayerStats stats; bool send_gameover = false; + int send_gameover_trycount = 0; int pain_killer_frameno = 0; int pain_killer_lastingtime = 0; @@ -168,7 +169,7 @@ class Human : public Entity private: void ClearFrameData(); - void BattleReport(); + void GenBattleReportData(a8::MutableXObject* params); protected: long long last_shot_frameno_ = 0; diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index 53ea3c3..e1553a0 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -226,6 +226,25 @@ namespace MetaData #endif } } + + metatable::BuildingJson* building_meta = (metatable::BuildingJson*)i; + for (auto& loot : *building_meta->mutable_lootobj()) { + loot.set__rand_space(0); + std::vector strings; + a8::Split(loot.things(), strings, '\n'); + for (auto& str : strings) { + std::vector strings2; + a8::Split(str, strings2, ':'); + assert(strings2.size() == 2); + loot.set__rand_space( + loot._rand_space() + + a8::XValue(strings2[1]).GetInt() + ); + auto p = loot.add__things(); + p->set_key(a8::XValue(strings2[0])); + p->set_value(loot._rand_space()); + } + } } void MapTplThing::Init() diff --git a/server/gameserver/metamgr.cc b/server/gameserver/metamgr.cc index 6f34831..c1445cf 100755 --- a/server/gameserver/metamgr.cc +++ b/server/gameserver/metamgr.cc @@ -208,9 +208,8 @@ private: for (auto& meta : building_meta_list) { MetaData::Building& item = a8::FastAppend(building_list); item.i = &meta; - meta.set__building_id(building_id++); item.Init(); - building_hash[item.i->_building_id()] = &item; + building_hash[item.i->mapid()] = &item; } } diff --git a/server/gameserver/obstacle.cc b/server/gameserver/obstacle.cc index 9f81a4f..d682d88 100644 --- a/server/gameserver/obstacle.cc +++ b/server/gameserver/obstacle.cc @@ -96,7 +96,7 @@ void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data) p->set_door_old_state((int)door_state); p->set_door_new_state((int)door_state); p->set_door_house_uniid(door_house_uniid); - p->set_door_house_id(building->meta->i->_building_id()); + p->set_door_house_id(building->meta->i->mapid()); if (door_state == DoorStateClose) { p->set_door_width(door_state0->width()); p->set_door_height(door_state0->height()); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 76919bd..c6c1082 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -392,11 +392,19 @@ void Room::CreateBuilding(int thing_id, float building_x, float building_y) for (auto& obj : building_meta->i->lootobj()) { float x = building->pos.x + obj.x() - building->meta->i->tilewidth() / 2.0; float y = building->pos.y + obj.y() - building->meta->i->tileheight() / 2.0; - InternalCreateObstacle(obj.id(), x, y, - [building] (Obstacle* entity) - { - entity->building = building; - }); + if (obj._rand_space() > 0) { + int rnd = rand () % obj._rand_space(); + for (auto& pair : obj._things()) { + if (rnd <= pair.value()) { + InternalCreateObstacle(pair.key(), x, y, + [building] (Obstacle* entity) + { + entity->building = building; + }); + break; + } + } + } } for (auto& obj : building_meta->i->dropobj()) { CreateLoot(obj.id(), diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 34bc400..5f8f5d5 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -23,10 +23,10 @@ class RoomMgr : public a8::Singleton void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg); void RemoveFromInactiveRoomHash(long long room_uuid); int RoomNum(); + Room* GetRoomByUuid(long long uuid); private: Room* GetJoinableRoom(const std::string& account_id); - Room* GetRoomByUuid(long long uuid); private: std::map inactive_room_hash_; diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 177416c..7090d6d 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -60,6 +60,7 @@ struct PlayerStats int killer_id = 0; std::string killer_name; + int weapon_id = 0; }; diff --git a/server/tools/protobuild/metatable.proto b/server/tools/protobuild/metatable.proto index 447ba00..0dfbe00 100755 --- a/server/tools/protobuild/metatable.proto +++ b/server/tools/protobuild/metatable.proto @@ -1,5 +1,11 @@ package metatable; +message MFPair +{ + optional int32 key = 1; //key + optional int32 value = 2; //val +} + message Parameter { optional string param_name = 1; @@ -165,7 +171,10 @@ message LootObjJson { optional float x = 1; optional float y = 2; - optional int32 id = 3; + optional int32 weight = 3; + optional string things = 4; + repeated MFPair _things = 5; + optional int32 _rand_space = 6; } message BuildingJson @@ -178,7 +187,7 @@ message BuildingJson repeated StaticObjJson staticObj = 6; repeated LootObjJson lootObj = 7; - optional int32 _building_id = 20; + optional int32 mapId = 20; } message MapTplThingJson