121 lines
3.5 KiB
C++
121 lines
3.5 KiB
C++
#include "precompile.h"
|
|
|
|
#include "mapmgr.h"
|
|
#include "room.h"
|
|
#include "mapinstance.h"
|
|
#include "roommgr.h"
|
|
|
|
#include "mt/Map.h"
|
|
#include "mt/PveGemini.h"
|
|
#include "mt/PveGeminiMode.h"
|
|
#include "mt/PveGeminiContent.h"
|
|
|
|
void MapMgr::Init()
|
|
{
|
|
mt::Map::Traverse
|
|
(
|
|
[this] (const mt::Map* map_meta, bool& stop)
|
|
{
|
|
if (map_meta->map_id() != 2001) {
|
|
return;
|
|
}
|
|
auto map_instance = std::make_shared<MapInstance>();
|
|
map_instance->map_id = map_meta->map_id();
|
|
map_instance->Init();
|
|
instance_hash_[map_instance->map_id] = map_instance;
|
|
instance_list_.push_back(map_instance);
|
|
{
|
|
auto itr = mode_hash_.find(map_meta->map_mode());
|
|
if (itr != mode_hash_.end()) {
|
|
itr->second.push_back(map_instance);
|
|
} else {
|
|
mode_hash_[map_meta->map_mode()] =
|
|
std::vector<std::shared_ptr<MapInstance>>({map_instance});
|
|
}
|
|
}
|
|
});
|
|
#if 0
|
|
if (mode_hash_.find(kZombieMode) == mode_hash_.end()) {
|
|
A8_ABORT();
|
|
}
|
|
#endif
|
|
if (mode_hash_.find(kChiJiMode) == mode_hash_.end()) {
|
|
A8_ABORT();
|
|
}
|
|
#ifdef DMAP3D
|
|
MetaMgr::Instance()->CheckMapSpawnPoint();
|
|
#endif
|
|
}
|
|
|
|
void MapMgr::UnInit()
|
|
{
|
|
for (auto& pair : instance_hash_) {
|
|
pair.second->UnInit();
|
|
}
|
|
instance_hash_.clear();
|
|
}
|
|
|
|
void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info)
|
|
{
|
|
if (init_info.pve_instance_id) {
|
|
init_info.room_mode = (RoomMode_e)((rand() % 2) + 1 + (int)kChiJiMode);
|
|
room->pve_mode_meta = mt::PveGeminiMode::GetById(init_info.room_mode);
|
|
if (!room->pve_mode_meta) {
|
|
abort();
|
|
}
|
|
init_info.init_map_id = room->pve_mode_meta->map_id();
|
|
room->pve_instance = mt::PveGemini::GetById(init_info.pve_instance_id);
|
|
if (!room->pve_instance) {
|
|
#ifdef DEBUG
|
|
abort();
|
|
#else
|
|
init_info.pve_instance_id = 10001;
|
|
room->pve_instance = MetaMgr::Instance()->GetPveGemini(init_info.pve_instance_id);
|
|
#endif
|
|
}
|
|
if (!room->pve_instance) {
|
|
abort();
|
|
}
|
|
#ifdef DEBUG
|
|
a8::XPrintf("attachRoom pve_instance_id:%d room_mode:%d\n",
|
|
{
|
|
init_info.pve_instance_id,
|
|
init_info.room_mode
|
|
});
|
|
#endif
|
|
}
|
|
#ifdef MAP3D
|
|
init_info.init_map_id = 2001;
|
|
auto map_instance = GetMapInstance(init_info.init_map_id);
|
|
#else
|
|
MapInstance* map_instance = init_info.init_map_id == 0 ?
|
|
RandMapInstance(init_info.room_mode) : GetMapInstance(init_info.init_map_id);
|
|
if (!map_instance) {
|
|
map_instance = RandMapInstance(init_info.room_mode);
|
|
} else if (map_instance->GetMapMeta()->i->map_mode() != init_info.room_mode) {
|
|
#ifdef DEBUG
|
|
#else
|
|
if (!room->pve_instance) {
|
|
map_instance = RandMapInstance(init_info.room_mode);
|
|
}
|
|
#endif
|
|
}
|
|
#endif
|
|
if (!map_instance) {
|
|
A8_ABORT();
|
|
}
|
|
map_instance->AttachRoom(room, init_info);
|
|
}
|
|
|
|
std::shared_ptr<MapInstance> MapMgr::GetMapInstance(int map_id)
|
|
{
|
|
auto itr = instance_hash_.find(map_id);
|
|
return itr != instance_hash_.end() ? itr->second : nullptr;
|
|
}
|
|
|
|
std::shared_ptr<MapInstance> MapMgr::RandMapInstance(int map_mode)
|
|
{
|
|
auto itr = mode_hash_.find(map_mode);
|
|
return itr != mode_hash_.end() ? itr->second[rand() % itr->second.size()] : nullptr;
|
|
}
|