1
This commit is contained in:
parent
6a18bf87a5
commit
8b5d30762b
@ -17,7 +17,7 @@ namespace MetaData
|
||||
assert(strings2.size() == 2);
|
||||
rand_space += a8::XValue(strings[1]).GetInt();
|
||||
template_list.push_back(std::make_tuple(
|
||||
strings[0],
|
||||
strings2[0],
|
||||
rand_space
|
||||
));
|
||||
}
|
||||
@ -148,4 +148,36 @@ namespace MetaData
|
||||
}
|
||||
}
|
||||
|
||||
void MapTplThing::Init()
|
||||
{
|
||||
rand_space = 0;
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(i->things(), strings, '\n');
|
||||
for (auto& str : strings) {
|
||||
std::vector<std::string> strings2;
|
||||
a8::Split(str, strings2, ':');
|
||||
assert(strings.size() == 2);
|
||||
rand_space += a8::XValue(strings2[1]).GetInt();
|
||||
things.push_back(std::make_tuple(
|
||||
a8::XValue(strings2[0]),
|
||||
rand_space
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int MapTplThing::RandThing()
|
||||
{
|
||||
if (rand_space <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int rnd = rand() % rand_space;
|
||||
for (auto& tuple : things) {
|
||||
if (std::get<1>(tuple) > rnd) {
|
||||
return std::get<0>(tuple);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,4 +76,15 @@ namespace MetaData
|
||||
int total_weight = 0;
|
||||
};
|
||||
|
||||
struct MapTplThing
|
||||
{
|
||||
const metatable::MapTplThingJson* i = nullptr;
|
||||
|
||||
void Init();
|
||||
int RandThing();
|
||||
|
||||
std::vector<std::tuple<int, int>> things;
|
||||
int rand_space = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -39,10 +39,11 @@ public:
|
||||
std::map<int, MetaData::MapThing*> mapthing_hash;
|
||||
std::map<int, MetaData::Building*> building_hash;
|
||||
std::map<int, MetaData::Drop*> drop_hash;
|
||||
std::map<std::string, std::list<metatable::MapTplThingJson>> maptpl_meta_hash;
|
||||
std::map<std::string, std::vector<MetaData::MapTplThing>> maptpl_hash;
|
||||
|
||||
void Load()
|
||||
{
|
||||
std::string res_path;
|
||||
if (!f8::IsOnlineEnv()) {
|
||||
res_path = a8::Format("/var/data/conf_test/game%d/gameserver/res/", {GAME_ID});
|
||||
} else {
|
||||
@ -76,7 +77,29 @@ private:
|
||||
for (auto& meta : map_meta_list) {
|
||||
MetaData::Map& item = a8::FastAppend(map_list);
|
||||
item.i = &meta;
|
||||
item.Init();
|
||||
gamemap_hash[item.i->map_id()] = &item;
|
||||
#if 0
|
||||
{
|
||||
for (auto& tuple : item.template_list) {
|
||||
auto itr = maptpl_meta_hash.find(std::get<0>(tuple));
|
||||
if (itr == maptpl_meta_hash.end()) {
|
||||
maptpl_meta_hash[std::get<0>(tuple)] = std::list<metatable::MapTplThingJson>();
|
||||
itr = maptpl_meta_hash.find(std::get<0>(tuple));
|
||||
}
|
||||
f8::ReadJsonMetaFile(res_path + std::get<0>(tuple) + ".json", itr->second);
|
||||
}
|
||||
for (auto& pair : maptpl_meta_hash) {
|
||||
std::vector<MetaData::MapTplThing> things;
|
||||
for (auto& itr : pair.second) {
|
||||
auto& thing = a8::FastAppend(things);
|
||||
thing.i = &itr;
|
||||
thing.Init();
|
||||
}
|
||||
maptpl_hash[pair.first] = things;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
for (auto& meta : safearea_meta_list) {
|
||||
@ -134,9 +157,10 @@ private:
|
||||
building_hash[item.i->_building_id()] = &item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
std::string res_path;
|
||||
};
|
||||
|
||||
void MetaMgr::Init()
|
||||
@ -213,3 +237,9 @@ MetaData::SafeArea* MetaMgr::GetSafeArea(int area_id)
|
||||
auto itr = loader_->safearea_hash.find(area_id);
|
||||
return itr != loader_->safearea_hash.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
std::vector<MetaData::MapTplThing>* MetaMgr::GetMapTplThing(std::string& map_name)
|
||||
{
|
||||
auto itr = loader_->maptpl_hash.find(map_name);
|
||||
return itr != loader_->maptpl_hash.end() ? &itr->second : nullptr;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
||||
MetaData::Building* GetBuilding(int building_id);
|
||||
MetaData::Drop* GetDrop(int drop_id);
|
||||
MetaData::SafeArea* GetSafeArea(int area_id);
|
||||
std::vector<MetaData::MapTplThing>* GetMapTplThing(std::string& map_name);
|
||||
|
||||
private:
|
||||
MetaDataLoader* loader_ = nullptr;
|
||||
|
@ -140,6 +140,6 @@ message MapTplThingJson
|
||||
optional string name = 2;
|
||||
optional string things = 3;
|
||||
optional int32 weight = 4;
|
||||
optional float x = 5;
|
||||
optional float y = 6;
|
||||
// optional float x = 5;
|
||||
// optional float y = 6;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user