diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index d7c5675..cc5e15f 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -49,6 +49,8 @@ void Room::Init() xtimer_attacher.xtimer = &xtimer; CreateSpawnPoints(); + CreateLoots(); + CreateDropObjs(); ShuaAndroid(); } @@ -1385,6 +1387,58 @@ void Room::CreateSpawnPoints() } } +void Room::CreateLoots() +{ + if (loots) { + for (auto& thing_tpl : *loots) { + int thing_id = thing_tpl->RandThing(); + 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->equip_type() == EQUIP_TYPE_CAR) { + 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->GetPos(); + car_hash_[loot_entity->entity_uniid] = car; + } + } + } + } + } +} + +void Room::CreateDropObjs() +{ + if (buildings) { + for (auto& building : *buildings) { + for (auto& obj : building->meta->i->dropobj()) { + CreateLoot(obj.id(), + a8::Vec2( + building->GetX() + obj.x() - building->meta->i->tilewidth() / 2.0, + building->GetY() + obj.y() - building->meta->i->tileheight() / 2.0 + ), + 1, + 1 + ); + } + } + } +} + void Room::IncBornPointHumanNum(BornPoint* point, Human* hum) { switch (hum->entity_subtype) { diff --git a/server/gameserver/room.h b/server/gameserver/room.h index f7517c3..22d4557 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -17,6 +17,11 @@ namespace MetaData struct MapTplThing; } +namespace metatable +{ + class DropObjJson; +} + struct timer_list; struct xtimer_list; class Entity; @@ -51,6 +56,8 @@ public: RoomType_e room_type = RT_NewBrid; long long last_add_player_tick = 0; std::vector* spawn_points = nullptr; + std::vector* loots = nullptr; + std::vector* buildings = nullptr; ~Room(); void Init(); @@ -127,6 +134,8 @@ private: void NotifyWxVoip(); BornPoint* AllocBornPoint(Human* hum); void CreateSpawnPoints(); + void CreateLoots(); + void CreateDropObjs(); void IncBornPointHumanNum(BornPoint* point, Human* hum); void DecBornPointHumanNum(BornPoint* point, Human* hum); void SecondRandPoint(); diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 4ce49d8..4bcada0 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -136,6 +136,8 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) room->room_type = self_room_type; room->room_uuid = App::Instance()->NewUuid(); room->spawn_points = &spawn_points_; + room->loots = &loots_; + room->buildings = &buildings_; if (GetRoomByUuid(room->room_uuid)) { abort(); } @@ -470,9 +472,7 @@ void RoomMgr::CreateBuilding(int thing_id, float building_x, float building_y) } } } - for (auto& obj : building_meta->i->dropobj()) { - dropobjs_.push_back(&obj); - } + buildings_.push_back(building); } Obstacle* RoomMgr::InternalCreateObstacle(int id, float x, float y, diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 53f574c..af4d230 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -21,6 +21,7 @@ namespace metatable class Room; class Entity; class Obstacle; +class Building; class MapService; class GridService; class RoomMgr : public a8::Singleton @@ -72,5 +73,5 @@ class RoomMgr : public a8::Singleton MetaData::Map* map_meta_ = nullptr; std::vector spawn_points_; std::vector loots_; - std::vector dropobjs_; + std::vector buildings_; };