73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include "precompile.h"
|
|
|
|
#include "mapmgr.h"
|
|
#include "room.h"
|
|
#include "mapinstance.h"
|
|
#include "roommgr.h"
|
|
#include "debugcmd.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->IsOpen()) {
|
|
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 (mode_hash_.find(kPvpMode) == mode_hash_.end()) {
|
|
A8_ABORT();
|
|
}
|
|
if (mode_hash_.find(kPveMode) == mode_hash_.end()) {
|
|
A8_ABORT();
|
|
}
|
|
}
|
|
|
|
void MapMgr::UnInit()
|
|
{
|
|
for (auto& pair : instance_hash_) {
|
|
pair.second->UnInit();
|
|
}
|
|
instance_hash_.clear();
|
|
}
|
|
|
|
void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info)
|
|
{
|
|
auto map_instance = GetMapInstance(init_info.init_map_id);
|
|
if (!map_instance) {
|
|
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;
|
|
}
|