添加地图对象共享机制
This commit is contained in:
parent
5236df1188
commit
dd8d5ab3e8
@ -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) {
|
||||
|
@ -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<MetaData::MapTplThing*>* spawn_points = nullptr;
|
||||
std::vector<MetaData::MapTplThing*>* loots = nullptr;
|
||||
std::vector<Building*>* 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();
|
||||
|
@ -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,
|
||||
|
@ -21,6 +21,7 @@ namespace metatable
|
||||
class Room;
|
||||
class Entity;
|
||||
class Obstacle;
|
||||
class Building;
|
||||
class MapService;
|
||||
class GridService;
|
||||
class RoomMgr : public a8::Singleton<RoomMgr>
|
||||
@ -72,5 +73,5 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
||||
MetaData::Map* map_meta_ = nullptr;
|
||||
std::vector<MetaData::MapTplThing*> spawn_points_;
|
||||
std::vector<MetaData::MapTplThing*> loots_;
|
||||
std::vector<const metatable::DropObjJson*> dropobjs_;
|
||||
std::vector<Building*> buildings_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user