From c1b20c8ac14c8bbab8674f1d302befbcdbb6895f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 11 Sep 2019 10:49:08 +0800 Subject: [PATCH] 1 --- server/gameserver/constant.h | 6 ++ server/gameserver/metadata.cc | 6 ++ server/gameserver/room.cc | 95 +++++++++++++++---------- server/gameserver/room.h | 3 + server/tools/protobuild/metatable.proto | 2 + 5 files changed, 75 insertions(+), 37 deletions(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 7992237..8abcf49 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -170,6 +170,12 @@ enum PropertyType_e kPropTankOil = 7 }; +enum MapObjectType_e +{ + kMOT_Object = 1, + kMOT_SpawnPoint = 2 +}; + const char* const PROJ_NAME_FMT = "game%d_gameserver"; const char* const PROJ_ROOT_FMT = "/data/logs/%s"; diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index 6edd151..ea4e678 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -326,6 +326,12 @@ namespace MetaData ) ); } + metatable::MapTplThingJson* mutable_i = (metatable::MapTplThingJson*)i; + if (mutable_i->object_type() == "spawn_point") { + mutable_i->set__object_type(kMOT_SpawnPoint); + } else { + mutable_i->set__object_type(kMOT_Object); + } } int MapTplThing::RandThing() diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 25adf3c..dea370f 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -358,45 +358,19 @@ void Room::CreateThings() if (things) { for (auto& thing_tpl : *things) { if (thing_tpl.i->weight() >= rand() % 10000) { - int thing_id = thing_tpl.RandThing(); - MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id); - if (thing_meta) { - if (thing_meta->i->is_house()) { - CreateBuilding(thing_id, thing_tpl.i->x(), thing_tpl.i->y()); - } else { - CreateObstacle(thing_id, thing_tpl.i->x(), thing_tpl.i->y()); + switch (thing_tpl.i->_object_type()) { + case kMOT_Object: + { + CreateMapObject(thing_tpl); } - } else if (thing_id == BORN_POINT_THINGID) { - CreateBornPoint(thing_tpl.i->x(), - thing_tpl.i->y(), - thing_tpl.i->width(), - thing_tpl.i->height(), - thing_tpl.i->param1() - ); - } else { - MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(thing_id); - if (equip_meta) { - int entity_uniid = CreateLoot(equip_meta->i->id(), - a8::Vec2( - thing_tpl.i->x(), - thing_tpl.i->y() - ), - 1, - 1 - ); - if (entity_uniid && equip_meta->i->is_luck() == 2) { - Entity* loot_entity = GetEntityByUniId(entity_uniid); - if (loot_entity && loot_entity->entity_type == ET_Loot) { - ((Loot*)loot_entity)->bullet_num = equip_meta->i->clip_volume(); - ((Loot*)loot_entity)->param1 = MetaMgr::Instance()->max_oil; - ((Loot*)loot_entity)->param2 = MetaMgr::Instance()->max_oil; - CarObject car; - car.car_id = equip_meta->i->id(); - car.pos = loot_entity->pos; - car_hash_[loot_entity->entity_uniid] = car; - } - } + break; + case kMOT_SpawnPoint: + { + CreateMapSpawnPoint(thing_tpl); } + break; + default: + break; } } } @@ -1536,3 +1510,50 @@ BornPoint* Room::AllocBornPoint(Human* hum) } return born_point; } + +void Room::CreateMapObject(MetaData::MapTplThing& thing_tpl) +{ + int thing_id = thing_tpl.RandThing(); + MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id); + if (thing_meta) { + if (thing_meta->i->is_house()) { + CreateBuilding(thing_id, thing_tpl.i->x(), thing_tpl.i->y()); + } else { + CreateObstacle(thing_id, thing_tpl.i->x(), thing_tpl.i->y()); + } + } else { + MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(thing_id); + if (equip_meta) { + int entity_uniid = CreateLoot(equip_meta->i->id(), + a8::Vec2( + thing_tpl.i->x(), + thing_tpl.i->y() + ), + 1, + 1 + ); + if (entity_uniid && equip_meta->i->is_luck() == 2) { + Entity* loot_entity = GetEntityByUniId(entity_uniid); + if (loot_entity && loot_entity->entity_type == ET_Loot) { + ((Loot*)loot_entity)->bullet_num = equip_meta->i->clip_volume(); + ((Loot*)loot_entity)->param1 = MetaMgr::Instance()->max_oil; + ((Loot*)loot_entity)->param2 = MetaMgr::Instance()->max_oil; + CarObject car; + car.car_id = equip_meta->i->id(); + car.pos = loot_entity->pos; + car_hash_[loot_entity->entity_uniid] = car; + } + } + } + } +} + +void Room::CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl) +{ + CreateBornPoint(thing_tpl.i->x(), + thing_tpl.i->y(), + thing_tpl.i->width(), + thing_tpl.i->height(), + thing_tpl.i->param1() + ); +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 085adb6..e2baf6a 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -14,6 +14,7 @@ namespace MetaData struct SafeArea; struct Building; struct AirLine; + struct MapTplThing; } struct timer_list; @@ -122,6 +123,8 @@ private: void NotifyWxVoip(); void CreateBornPoint(int x, int y, int width, int height, int hum_limit); BornPoint* AllocBornPoint(Human* hum); + void CreateMapObject(MetaData::MapTplThing& thing_tpl); + void CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl); private: int elapsed_time_ = 0; diff --git a/server/tools/protobuild/metatable.proto b/server/tools/protobuild/metatable.proto index 50f0d4b..d664b7f 100755 --- a/server/tools/protobuild/metatable.proto +++ b/server/tools/protobuild/metatable.proto @@ -253,4 +253,6 @@ message MapTplThingJson optional float param1 = 9; optional float param2 = 10; optional float param3 = 11; + optional string object_type = 12; + optional int32 _object_type = 13; } \ No newline at end of file