diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 4e59d47..60d8c6f 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -264,8 +264,6 @@ const int GUN_SLOT2 = 2; const int FRAG_SLOT = 3; const int SMOKE_SLOT = 4; -const int MAP_HEIGHT = 32*65; -const int MAP_WIDTH = 32*75; const int MAP_CELL_WIDTH = 64 * 8; const int MAP_GRID_WIDTH = 64; diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index b1878a8..291f01c 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -14,35 +14,6 @@ namespace MetaData void Map::Init() { - rand_space = 0; - { - std::vector strings; - a8::Split(i->template_list(), strings, '|'); - for (auto& str : strings) { - std::vector strings2; - a8::Split(str, strings2, ':'); - assert(strings2.size() == 2); - rand_space += a8::XValue(strings2[1]).GetInt(); - template_list.push_back(std::make_tuple( - strings2[0], - rand_space - )); - } - } - } - - std::string Map::RandTemplate() - { - if (rand_space <= 0) { - return ""; - } - int rnd = rand() % rand_space; - for (auto& tpl : template_list) { - if (rnd <= std::get<1>(tpl)) { - return std::get<0>(tpl); - } - } - return ""; } void Equip::Init() diff --git a/server/gameserver/metadata.h b/server/gameserver/metadata.h index 16c6b31..eacbd0f 100755 --- a/server/gameserver/metadata.h +++ b/server/gameserver/metadata.h @@ -20,11 +20,7 @@ namespace MetaData { const metatable::Map* i = nullptr; - std::vector> template_list; - int rand_space = 0; - void Init(); - std::string RandTemplate(); }; struct Attr diff --git a/server/gameserver/metamgr.cc b/server/gameserver/metamgr.cc index 64e2f93..5568f78 100755 --- a/server/gameserver/metamgr.cc +++ b/server/gameserver/metamgr.cc @@ -61,6 +61,7 @@ public: std::map> maptpl_meta_hash; std::map> maptpl_hash; std::map> born_point_hash; + std::map> maptpl_size_hash; std::map dress_hash; std::map tank_hash; std::map driver_hash; @@ -147,32 +148,41 @@ private: gamemap_hash[item.i->map_id()] = &item; #if 1 { - for (auto& tuple : item.template_list) { - auto itr = maptpl_meta_hash.find(std::get<0>(tuple)); + { + auto itr = maptpl_meta_hash.find(meta.template_name()); if (itr == maptpl_meta_hash.end()) { - maptpl_meta_hash[std::get<0>(tuple)] = std::list(); - itr = maptpl_meta_hash.find(std::get<0>(tuple)); + maptpl_meta_hash[meta.template_name()] = std::list(); + itr = maptpl_meta_hash.find(meta.template_name()); } else { itr->second.clear(); } - f8::ReadJsonMetaFile(res_path + std::get<0>(tuple) + ".json", itr->second); + f8::ReadJsonMetaFile(res_path + meta.template_name() + ".json", itr->second); } for (auto& pair : maptpl_meta_hash) { std::vector things; std::vector born_point; + int map_width = 0; + int map_height = 0; for (auto& itr : pair.second) { if (itr.is_born_point()) { auto& thing = a8::FastAppend(born_point); thing.i = &itr; thing.Init(); + } else if (itr.is_map_info()) { + map_width = itr.map_width(); + map_height = itr.map_height(); } else { auto& thing = a8::FastAppend(things); thing.i = &itr; thing.Init(); } } + if (map_width < MAP_GRID_WIDTH || map_height < MAP_GRID_WIDTH) { + abort(); + } maptpl_hash[pair.first] = things; born_point_hash[pair.first] = born_point; + maptpl_size_hash[pair.first] = std::make_tuple(map_width, map_height); if (born_point.size() != ROOM_MAX_PLAYER_NUM) { abort(); } @@ -359,6 +369,15 @@ MetaData::Map* MetaMgr::GetMap(int map_id) return itr != loader_->gamemap_hash.end() ? itr->second : nullptr; } +MetaData::Map* MetaMgr::RandMap() +{ + std::vector map_list; + for (auto& pair : loader_->gamemap_hash) { + map_list.push_back(pair.second); + } + return !map_list.empty() ? map_list[rand() % map_list.size()] : nullptr; +} + MetaData::MapThing* MetaMgr::GetMapThing(int mapthing_id) { auto itr = loader_->mapthing_hash.find(mapthing_id); @@ -413,6 +432,18 @@ std::vector* MetaMgr::GetMapBornPoints(const std::string& return itr != loader_->born_point_hash.end() ? &itr->second : nullptr; } +bool MetaMgr::GetMapTplSize(const std::string& map_name, int& width, int& height) +{ + auto itr = loader_->maptpl_size_hash.find(map_name); + if (itr != loader_->maptpl_size_hash.end()) { + width = std::get<0>(itr->second); + height = std::get<1>(itr->second); + return true; + } else { + return false; + } +} + MetaData::Skill* MetaMgr::GetSkill(int skill_id) { auto itr = loader_->skill_hash.find(skill_id); @@ -477,3 +508,4 @@ MetaData::Robot* MetaMgr::GetRobot(int robot_id) auto itr = loader_->robot_hash.find(robot_id); return itr != loader_->robot_hash.end() ? itr->second : nullptr; } + diff --git a/server/gameserver/metamgr.h b/server/gameserver/metamgr.h index 8232841..b834fa9 100755 --- a/server/gameserver/metamgr.h +++ b/server/gameserver/metamgr.h @@ -20,6 +20,7 @@ class MetaMgr : public a8::Singleton double GetSysParamAsFloat(const std::string& param_name, double def_val = 0.0f); std::string GetSysParamAsString(const std::string& param_name, const char* def_val = ""); MetaData::Map* GetMap(int map_id); + MetaData::Map* RandMap(); MetaData::MapThing* GetMapThing(int mapthing_id); MetaData::Player* GetPlayer(int id); MetaData::Equip* GetEquip(int id); @@ -29,6 +30,7 @@ class MetaMgr : public a8::Singleton MetaData::SafeArea* GetSafeArea(int area_id); std::vector* GetMapTplThing(const std::string& map_name); std::vector* GetMapBornPoints(const std::string& map_name); + bool GetMapTplSize(const std::string& map_name, int& width, int& height); MetaData::Skill* GetSkill(int skill_id); MetaData::Buff* GetBuff(int buff_id); MetaData::Attr* GetAttrById(int attr_id); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 8cdae87..1fac101 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -39,8 +39,8 @@ void Room::Init() xtimer.Init(RoomXGetTickCount, this, 100, 100); xtimer_attacher.xtimer = &xtimer; frame_event.room = this; - grid_service.Init(MAP_WIDTH, MAP_HEIGHT, MAP_CELL_WIDTH * 8); - map_service.Init(MAP_WIDTH / MAP_GRID_WIDTH, MAP_HEIGHT / MAP_GRID_WIDTH, MAP_GRID_WIDTH); + grid_service.Init(map_width, map_height, MAP_CELL_WIDTH * 8); + map_service.Init(map_width / MAP_GRID_WIDTH, map_height / MAP_GRID_WIDTH, MAP_GRID_WIDTH); CreateThings(); if (App::Instance()->HasFlag(1)) { @@ -356,7 +356,6 @@ void Room::ScatterDrop(a8::Vec2 center, int drop_id) void Room::CreateThings() { - map_tpl_name = map_meta->RandTemplate(); std::vector* things = MetaMgr::Instance()->GetMapTplThing(map_tpl_name); if (things) { for (auto& thing_tpl : *things) { @@ -530,14 +529,14 @@ void Room::CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv) entity->pos = pos; #if 1 { - if (entity->pos.x >= MAP_WIDTH) { - entity->pos.x = MAP_WIDTH - 1; + if (entity->pos.x >= map_width) { + entity->pos.x = map_width - 1; } if (entity->pos.x < 1.0f) { entity->pos.x = 1.0f; } - if (entity->pos.y >= MAP_HEIGHT) { - entity->pos.y = MAP_HEIGHT - 1; + if (entity->pos.y >= map_height) { + entity->pos.y = map_height - 1; } if (entity->pos.y < 1.0f) { entity->pos.y = 1.0f; @@ -661,14 +660,14 @@ bool Room::OverBorder(const a8::Vec2 pos, float radius) return true; } int right_x = pos.x + radius; - if (right_x > MAP_WIDTH) { + if (right_x > map_width) { return true; } } //检查y轴 { int up_y = pos.y + radius; - if (up_y > MAP_HEIGHT) { + if (up_y > map_height) { return true; } int down_y = pos.y - radius; diff --git a/server/gameserver/room.h b/server/gameserver/room.h index cf42834..e7e143a 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -31,6 +31,8 @@ public: long long room_uuid = 0; MetaData::Map* map_meta = nullptr; std::string map_tpl_name; + int map_width = 0; + int map_height = 0; FrameEvent frame_event; FrameMaker frame_maker; long long frame_no = 0; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 07d7c87..7c7855c 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -53,7 +53,13 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) if (GetRoomByUuid(room->room_uuid)) { abort(); } - room->map_meta = MetaMgr::Instance()->GetMap(1001); + if (App::Instance()->HasFlag(5)) { + room->map_meta = MetaMgr::Instance()->GetMap(1); + } else { + room->map_meta = MetaMgr::Instance()->RandMap(); + } + room->map_tpl_name = room->map_meta->i->template_name(); + assert(MetaMgr::Instance()->GetMapTplSize(room->map_tpl_name, room->map_width, room->map_height)); room->Init(); inactive_room_hash_[room->room_uuid] = room; room_hash_[room->room_uuid] = room; @@ -72,6 +78,8 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) { cs::SMMapInfo notifymsg; notifymsg.set_map_id(room->map_meta->i->map_id()); + notifymsg.set_map_width(room->map_width); + notifymsg.set_map_height(room->map_height); GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); } } diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index 71d7ffd..60a96a4 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -690,6 +690,8 @@ message SMJoinedNotify message SMMapInfo { optional int32 map_id = 1; //地图id + optional int32 map_width = 2; //地图宽度 + optional int32 map_height = 3; //地图高度 repeated MFMapObject objects = 6; //地图对象 } diff --git a/server/tools/protobuild/metatable.proto b/server/tools/protobuild/metatable.proto index 0553673..d3a6525 100755 --- a/server/tools/protobuild/metatable.proto +++ b/server/tools/protobuild/metatable.proto @@ -22,7 +22,7 @@ message Attr message Map { required int32 map_id = 1; //地图id - required string template_list = 2; //模板列表 + optional string template_name = 2; //模板列表 required string map_name = 3; //地图名 } @@ -277,4 +277,7 @@ message MapTplThingJson required float y = 6; required int32 is_born_point = 7; required string born_angle = 8; + optional int32 is_map_info = 9; + optional int32 map_width = 10; + optional int32 map_height = 11; } \ No newline at end of file