501 lines
17 KiB
C++
501 lines
17 KiB
C++
#include "precompile.h"
|
|
|
|
#include "metadata.h"
|
|
#include "metamgr.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) {
|
|
size_t slot = a8::XValue(strings2[0]);
|
|
size_t num = a8::XValue(strings2[1]);
|
|
if (slot >= 0 && slot < volume.size()){
|
|
volume[slot] = num;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void EquipUpgrade::Init()
|
|
{
|
|
const int MAX_LV = 20;
|
|
for (int j = 0; j < MAX_LV; ++j) {
|
|
std::array<float, kHAT_End>& attrs = a8::FastAppend(level_attrs);
|
|
for (size_t k = 0; k < kHAT_End; ++k) {
|
|
attrs[k] = 0;
|
|
}
|
|
}
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->attr_type(), strings, '|');
|
|
int level = 1;
|
|
for (auto& str : strings) {
|
|
if (str.empty()) {
|
|
continue;
|
|
}
|
|
++level;
|
|
std::vector<std::string> strings2;
|
|
a8::Split(str, strings2, ';');
|
|
for (auto& str2 : strings2) {
|
|
std::vector<std::string> strings3;
|
|
a8::Split(str2, strings3, ':');
|
|
if (strings3.size() != 2) {
|
|
abort();
|
|
}
|
|
int attr_type = a8::XValue(strings3[0]);
|
|
int attr_value = a8::XValue(strings3[1]);
|
|
if (attr_type <= kHAT_End) {
|
|
level_attrs[level][attr_type] = attr_value;
|
|
}
|
|
}
|
|
}//end for strings
|
|
for (int i = level; i < MAX_LV; ++i) {
|
|
level_attrs[i] = level_attrs[level];
|
|
}
|
|
}
|
|
}
|
|
|
|
float EquipUpgrade::GetAttrValue(int level, int attr_type)
|
|
{
|
|
if (level < 1) {
|
|
return 0;
|
|
}
|
|
if (level > (int)level_attrs.size()) {
|
|
return 0;
|
|
}
|
|
if (attr_type <= kHAT_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) {
|
|
size_t slot = a8::XValue(strings2[0]);
|
|
size_t 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 (size_t ii = 0; ii < itemids.size(); ++ii) {
|
|
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 + 1);
|
|
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()
|
|
{
|
|
metatable::MapTplThingJson* mutable_i = (metatable::MapTplThingJson*)i;
|
|
if (mutable_i->object_type() == "spawn_point") {
|
|
mutable_i->set__object_type(kMOT_SpawnPoint);
|
|
} else {
|
|
mutable_i->set__object_type(kMOT_Object);
|
|
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()
|
|
{
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->buff_list(), strings, '|');
|
|
for (auto& str : strings) {
|
|
buff_list.insert(a8::XValue(str));
|
|
}
|
|
}
|
|
{
|
|
const google::protobuf::Descriptor* descriptor = i->GetDescriptor();
|
|
const google::protobuf::Reflection* reflection = i->GetReflection();
|
|
for (int idx = 1; idx <= 100; ++idx) {
|
|
MetaData::SkillPhase phase;
|
|
{
|
|
auto field_desc = descriptor->FindFieldByName(a8::Format("phase%d_time_offset", {idx}));
|
|
if (!field_desc) {
|
|
break;
|
|
}
|
|
phase.phase_idx = phases.size() + 1;
|
|
phase.time_offset = reflection->GetInt32(*(metatable::Skill*)i, field_desc);
|
|
}
|
|
{
|
|
auto field_desc = descriptor->FindFieldByName(a8::Format("phase%d_func", {idx}));
|
|
phase.func_id = (SkillFunc_e)reflection->GetInt32(*(metatable::Skill*)i, field_desc);
|
|
}
|
|
{
|
|
auto field_desc = descriptor->FindFieldByName(a8::Format("phase%d_param1", {idx}));
|
|
phase.param1_str = reflection->GetString(*(metatable::Skill*)i, field_desc);
|
|
}
|
|
{
|
|
auto field_desc = descriptor->FindFieldByName(a8::Format("phase%d_param2", {idx}));
|
|
phase.param2_str = reflection->GetString(*(metatable::Skill*)i, field_desc);
|
|
}
|
|
{
|
|
auto field_desc = descriptor->FindFieldByName(a8::Format("phase%d_param3", {idx}));
|
|
phase.param3_str = reflection->GetString(*(metatable::Skill*)i, field_desc);
|
|
}
|
|
if (phase.func_id != kSkill_FuncNone) {
|
|
phase.param1 = a8::XValue(phase.param1_str);
|
|
phase.param2 = a8::XValue(phase.param2_str);
|
|
phase.param3 = a8::XValue(phase.param3_str);
|
|
phases.push_back(phase);
|
|
}
|
|
}
|
|
}
|
|
{
|
|
for (int buff_id : buff_list) {
|
|
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
|
|
if (!buff_meta) {
|
|
abort();
|
|
}
|
|
auto itr = trigger_type_buffs.find(buff_meta->i->trigger_type());
|
|
if (itr != trigger_type_buffs.end()) {
|
|
itr->second.insert(buff_meta);
|
|
} else {
|
|
trigger_type_buffs[buff_meta->i->trigger_type()] = std::set<MetaData::Buff*>({buff_meta});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Buff::Init()
|
|
{
|
|
param1 = a8::XValue(i->buff_param1()).GetDouble();
|
|
param2 = a8::XValue(i->buff_param2()).GetDouble();
|
|
param3 = a8::XValue(i->buff_param3()).GetDouble();
|
|
param4 = a8::XValue(i->buff_param4()).GetDouble();
|
|
}
|
|
|
|
bool Buff::EffectCanStack()
|
|
{
|
|
return i->buff_effect() == kBET_ChgAttr;
|
|
}
|
|
|
|
void Dress::Init()
|
|
{
|
|
for (int j = 0; j < i->max_lv(); ++j) {
|
|
std::array<float, kHAT_End>& attrs = a8::FastAppend(level_attrs);
|
|
for (size_t k = 0; k < kHAT_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 < kHAT_End) {
|
|
if (attr_level >= 0 && attr_level < i->max_lv()) {
|
|
for (int j = 1; j < i->max_lv(); ++j) {
|
|
if (j % attr_type == 0) {
|
|
level_attrs[j][attr_type] = attr_value * (j / attr_level);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
float Dress::GetAttrValue(int level, int attr_type)
|
|
{
|
|
if (level < 1) {
|
|
return 0;
|
|
}
|
|
if (level > (int)level_attrs.size()) {
|
|
return 0;
|
|
}
|
|
if (attr_type < kHAT_End) {
|
|
return level_attrs[level][attr_type];
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void RankReward::Init()
|
|
{
|
|
}
|
|
|
|
}
|