game2001/server/gameserver/metadata.cc
aozhiwei a988f6bfde 1
2019-06-20 11:33:50 +08:00

417 lines
14 KiB
C++

#include "precompile.h"
#include "metadata.h"
namespace MetaData
{
void Parameter::Init()
{
int_val = a8::XValue(i->param_value());
float_val = a8::XValue(i->param_value());
str_val = a8::XValue(i->param_value()).GetString();
}
void Map::Init()
{
rand_space = 0;
{
std::vector<std::string> strings;
a8::Split(i->template_list(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
rand_space += a8::XValue(strings2[1]).GetInt();
template_list.push_back(std::make_tuple(
strings2[0],
rand_space
));
}
}
}
std::string Map::RandTemplate()
{
if (rand_space <= 0) {
return "";
}
int rnd = rand() % rand_space;
for (auto& tpl : template_list) {
if (rnd <= std::get<1>(tpl)) {
return std::get<0>(tpl);
}
}
return "";
}
void Equip::Init()
{
{
std::vector<std::string> strings;
a8::Split(i->bullet_born_offset(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() >= 2);
bullet_born_offset.push_back(std::make_tuple(
a8::XValue(strings2[0]).GetDouble(),
a8::XValue(strings2[1]).GetDouble(),
strings2.size() > 2 ? a8::XValue(strings2[2]).GetDouble() : 0
)
);
}
}
{
std::vector<std::string> strings;
a8::Split(i->volume(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
if (strings2.size() >= 2) {
int slot = a8::XValue(strings2[0]);
int num = a8::XValue(strings2[1]);
if (slot >= 0 && slot < volume.size()){
volume[slot] = num;
}
}
}
}
}
void EquipUpgrade::Init()
{
for (size_t j = 0; j < i->max_lv(); ++j) {
std::array<float, EA_End>& attrs = a8::FastAppend(level_attrs);
for (size_t k = 0; k < EA_End; ++k) {
attrs[k] = 0;
}
}
{
std::vector<std::string> strings;
a8::Split(i->attr_type(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
if (strings2.size() != 3) {
abort();
}
int attr_type = a8::XValue(strings2[0]);
int attr_level = a8::XValue(strings2[1]);
float attr_value = a8::XValue(strings2[2]).GetDouble();
if (attr_type < EA_End) {
if (attr_level >= 0 && attr_level < i->max_lv()) {
for (size_t j = 1; j < i->max_lv(); ++j) {
if (j % attr_type == 0) {
level_attrs[j][attr_type] = attr_value;
}
}
}
}
}
}
}
float EquipUpgrade::GetAttrValue(int level, int attr_type)
{
if (level < 1) {
return 0;
}
if (level > level_attrs.size()) {
return 0;
}
if (attr_type < EA_End) {
return level_attrs[level][attr_type];
}
return 0;
}
void Player::Init()
{
{
std::vector<std::string> strings;
a8::Split(i->volume(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
if (strings2.size() >= 2) {
int slot = a8::XValue(strings2[0]);
int num = a8::XValue(strings2[1]);
if (slot >= 0 && slot < volume.size()){
volume[slot] = num;
}
}
}
}
}
void Robot::Init()
{
}
void Drop::Init()
{
std::vector<std::string> item_list;
{
a8::Split(i->item_id(), item_list, '|');
}
std::vector<std::string> num_list;
{
a8::Split(i->num(), num_list, '|');
}
std::vector<std::string> weight_list;
{
a8::Split(i->weight(), weight_list, '|');
}
assert(item_list.size() == num_list.size() &&
item_list.size() == weight_list.size());
total_weight = 0;
for (size_t i = 0; i < item_list.size(); ++i) {
total_weight += a8::XValue(weight_list[i]).GetInt();
std::vector<int> itemids;
{
std::vector<std::string> strings;
a8::Split(item_list[i], strings, ':');
for (auto& str : strings) {
itemids.push_back(a8::XValue(str).GetInt());
}
}
std::vector<int> nums;
{
std::vector<std::string> strings;
a8::Split(num_list[i], strings, ':');
for (auto& str : strings) {
nums.push_back(a8::XValue(str).GetInt());
}
}
assert(itemids.size() == nums.size());
#if 1
std::vector<int> item_lvs;
for (auto& itr : itemids) {
item_lvs.push_back(1);
}
#endif
if (this->i->type() == 1) {
auto item_tuple = std::make_tuple(
itemids,
nums,
item_lvs,
a8::XValue(weight_list[i]).GetInt()
);
items.push_back(item_tuple);
} else {
auto item_tuple = std::make_tuple(
itemids,
nums,
item_lvs,
total_weight
);
items.push_back(item_tuple);
}
}
assert(i->type() == 1 || i->type() == 2);
}
void Drop::RandItems(std::vector<std::tuple<int, int, int>>& drop_items)
{
if (i->type() == 1) {
for (auto& item : items) {
if ((rand() % 10000) <= std::get<3>(item)) {
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
drop_items.push_back(std::make_tuple(
std::get<0>(item)[i],
std::get<1>(item)[i],
std::get<2>(item)[i]
));
}
}
}
} else if (total_weight > 0) {
int rnd = rand() % total_weight;
for (auto& item : items) {
if (std::get<3>(item) >= rnd) {
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
drop_items.push_back(std::make_tuple(
std::get<0>(item)[i],
std::get<1>(item)[i],
std::get<2>(item)[i]
));
}
break;
}
}
}
}
void Building::Init()
{
for (auto& door_meta : i->doorobj()) {
Door* p_door = nullptr;
for (auto& door : doors) {
if (door.door_id == door_meta.id()) {
p_door = &door;
break;
}
}
if (!p_door) {
p_door = &a8::FastAppend(doors);
p_door->door_id = door_meta.id();
}
switch (door_meta.type()) {
case 1:
{
p_door->state0 = &door_meta;
}
break;
case 2:
{
p_door->state1 = &door_meta;
}
break;
}
}//end for
for (auto& door : doors) {
if (door.door_id == 0 ||
!door.state0 || !door.state1) {
abort();
} else {
#if 0
if (door.state1->x() < door.state0.x()) {
if (door.state1.y() < door.state0.y()) {
} else {
}
}
#endif
}
}
metatable::BuildingJson* building_meta = (metatable::BuildingJson*)i;
for (auto& loot : *building_meta->mutable_lootobj()) {
loot.set__rand_space(0);
std::vector<std::string> strings;
a8::Split(loot.things(), strings, '\n');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
loot.set__rand_space(
loot._rand_space() +
a8::XValue(strings2[1]).GetInt()
);
auto p = loot.add__things();
p->set_key(a8::XValue(strings2[0]));
p->set_value(loot._rand_space());
}
}
}
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(strings2.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;
}
void AirLine::Init()
{
{
std::vector<std::string> strings;
a8::Split(i->start_point(), strings, ':');
start_point_x = a8::XValue(strings[0]).GetDouble();
start_point_y = a8::XValue(strings[1]).GetDouble();
}
{
std::vector<std::string> strings;
a8::Split(i->end_point(), strings, ':');
end_point_x = a8::XValue(strings[0]).GetDouble();
end_point_y = a8::XValue(strings[1]).GetDouble();
}
}
void Skill::Init()
{
value1 = a8::XValue(i->value1()).GetDouble();
value2 = a8::XValue(i->value2()).GetDouble();
area = a8::XValue(i->area()).GetDouble();
last_time = a8::XValue(i->last_time()).GetInt();
}
void Dress::Init()
{
for (size_t j = 0; j < i->max_lv(); ++j) {
std::array<float, EA_End>& attrs = a8::FastAppend(level_attrs);
for (size_t k = 0; k < EA_End; ++k) {
attrs[k] = 0;
}
}
{
std::vector<std::string> strings;
a8::Split(i->attr_type(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
if (strings2.size() != 3) {
abort();
}
int attr_type = a8::XValue(strings2[0]);
int attr_level = a8::XValue(strings2[1]);
float attr_value = a8::XValue(strings2[2]).GetDouble();
if (attr_type < EA_End) {
if (attr_level >= 0 && attr_level < i->max_lv()) {
for (size_t j = 1; j < i->max_lv(); ++j) {
if (j % attr_type == 0) {
level_attrs[j][attr_type] = attr_value;
}
}
}
}
}
}
}
float Dress::GetAttrValue(int level, int attr_type)
{
if (level < 1) {
return 0;
}
if (level > level_attrs.size()) {
return 0;
}
if (attr_type < EA_End) {
return level_attrs[level][attr_type];
}
return 0;
}
}