#include "precompile.h" #include "metadata.h" #include "metamgr.h" #include "framework/cpp/utils.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 strings; a8::Split(i->template_list(), strings, '|'); for (auto& str : strings) { std::vector 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::vector strings; a8::Split(i->airdrops(), strings, '|'); for (auto& str : strings) { airdrops.push_back(a8::XValue(str).GetInt()); } } { std::vector strings; a8::Split(i->game_start_buff_list(), strings, ':'); for (auto& str : strings) { buff_list.push_back(a8::XValue(str).GetInt()); } } { std::vector strings; a8::Split(i->refresh_robot(), strings, '|'); if (strings.size() != 2) { abort(); } { std::vector strings2; a8::Split(strings[0], strings2, '-'); if (strings2.size() != 2) { abort(); } refresh_robot_min_num = a8::XValue(strings2[0]); refresh_robot_max_num = a8::XValue(strings2[1]); } { std::vector strings2; a8::Split(strings[1], strings2, '-'); if (strings2.size() != 2) { abort(); } refresh_robot_min_time = a8::XValue(strings2[0]); refresh_robot_max_time = a8::XValue(strings2[1]); } if (refresh_robot_min_num >= refresh_robot_max_num) { abort(); } if (refresh_robot_min_time >= refresh_robot_max_time) { abort(); } if (refresh_robot_min_num <= 0 || refresh_robot_max_num <= 0 || refresh_robot_min_time <= 0 || refresh_robot_max_time <= 0) { abort(); } } first_safearea_center = a8::Vec2(i->map_width() / 2.0f, i->map_height() / 2.0f); if (!i->first_safearea_center().empty()) { std::vector strings; a8::Split(i->first_safearea_center(), strings, ':'); if (strings.size() != 2) { abort(); } first_safearea_center = a8::Vec2(a8::XValue(strings[0]).GetDouble(), a8::XValue(strings[1]).GetDouble()); } if (i->player() < 10) { abort(); } } 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 MapThing::Init() { std::vector strings; a8::Split(i->buff_list(), strings, '|'); for (const std::string& tmp_str : strings) { buff_list.push_back(a8::XValue(tmp_str)); } } void Equip::Init() { { std::vector strings; a8::Split(i->bullet_born_offset(), strings, '|'); for (auto& str : strings) { std::vector 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 strings; a8::Split(i->volume(), strings, '|'); for (auto& str : strings) { std::vector 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; } } } } { int_param1 = a8::XValue(i->param1()); float_param1 = a8::XValue(i->param1()).GetDouble(); } { int_param2 = a8::XValue(i->param2()); float_param2 = a8::XValue(i->param2()).GetDouble(); } } int Equip::GetWeaponIdx() { int weapon_idx = -1; if (i->equip_type() == EQUIP_TYPE_WEAPON) { if (i->equip_subtype() == 1) { return 0; } else { return GUN_SLOT1; } } return weapon_idx; } void EquipUpgrade::Init() { const int MAX_LV = 20; for (int j = 0; j < MAX_LV; ++j) { std::array& attrs = a8::FastAppend(level_attrs); for (size_t k = 0; k < kHAT_End; ++k) { attrs[k] = 0; } } { std::vector strings; if (!i->spera_attr().empty()) { a8::Split(i->spera_attr(), strings, '|'); } else { a8::Split(i->attr_type(), strings, '|'); } int level = 1; for (auto& str : strings) { if (str.empty()) { continue; } ++level; std::vector strings2; a8::Split(str, strings2, ';'); for (auto& str2 : strings2) { std::vector 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 strings; a8::Split(i->volume(), strings, '|'); for (auto& str : strings) { std::vector 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; } } } } { std::vector strings; a8::Split(i->init_buffs(), strings, '|'); for (auto& str : strings) { init_buffs.push_back(a8::XValue(str)); } } } void Robot::Init() { } void Drop::Init() { std::vector item_list; { a8::Split(i->item_id(), item_list, '|'); } std::vector num_list; { a8::Split(i->num(), num_list, '|'); } std::vector 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 itemids; { std::vector strings; a8::Split(item_list[i], strings, ':'); for (auto& str : strings) { itemids.push_back(a8::XValue(str).GetInt()); } } std::vector nums; { std::vector 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 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>& 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 strings; a8::Split(loot.things(), strings, '\n'); for (auto& str : strings) { std::vector 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 strings; a8::Split(i->things(), strings, '\n'); for (auto& str : strings) { std::vector 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 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 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 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) { #if 1 return; #else abort(); #endif } 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({buff_meta}); } } } } bool Skill::IsTurnOverSkill() { return !phases.empty() && phases[0].func_id == kSkill_TurnOver; } 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(); { std::vector strings; a8::Split(i->immune_buffeffect_list(), strings, '|'); for (auto& str : strings) { immune_buffeffect.insert(a8::XValue(str)); } } { std::vector strings; a8::Split(i->buff_param2(), strings, ':'); for (auto& str : strings) { param2_int_list.push_back(a8::XValue(str).GetInt()); } } { std::vector strings; a8::Split(i->post_remove_action(), strings, '|'); for (auto& str : strings) { std::vector strings2; a8::Split(str, strings2, ':'); if (strings2.size() > 2) { std::vector strings3; a8::Split(strings2[1], strings3, ';'); if (strings2[0] == "remove_buff_by_id" || strings2[0] == "remove_buff_by_effect") { auto& action = a8::FastAppend(post_remove_action); if (strings2[0] == "remove_buff_by_id") { std::get<0>(action) = kRemoveBuffByIdAction; } else if (strings2[0] == "remove_buff_by_effect") { std::get<0>(action) = kRemoveBuffByEffectAction; } for (auto& str3 : strings3) { if (!str3.empty()) { std::get<1>(action).push_back(a8::XValue(str3)); } } } } } } { std::vector strings; a8::Split(i->buff_param1(), strings, '|'); for (auto& str : strings) { std::vector strings2; a8::Split(str, strings2, ':'); if (strings2.size() >= 4) { int through_wall = a8::XValue(strings2[0]); float x = a8::XValue(strings2[1]).GetDouble(); float y = a8::XValue(strings2[2]).GetDouble(); int hero_id = a8::XValue(strings2[3]); hero_infos.push_back ( std::make_tuple(through_wall, x, y, hero_id) ); } } } if (i->buff_effect() == kBET_BatchAddBuff) { std::vector strings1; a8::Split(i->buff_param1(), strings1, '|'); for (auto& str1 : strings1) { std::vector strings2; a8::Split(str1, strings2, '|'); for (auto& str2 : strings2) { if (str2.size() < 1) { abort(); } auto& p = a8::FastAppend(batch_add_list); if (str2[0] != '!') { //概率 std::vector strings3; a8::Split(str2, strings3, ':'); if (strings3.size() != 2) { abort(); } if (a8::XValue(strings3[1]).GetInt() <= 0) { abort(); } std::get<0>(p) = -1; std::get<1>(p).push_back ( std::make_tuple(a8::XValue(strings3[0]), a8::XValue(strings3[1])) ); } else { //权重 std::vector strings3; a8::Split(str2, strings3, '$'); int rand_space = 0; for (const std::string& str3 : strings3) { std::vector strings4; a8::Split(str3, strings4, ':'); if (strings4.size() != 2) { abort(); } std::string tmp_str = strings4[0]; a8::ReplaceString(tmp_str, "!", ""); int buff_id = a8::XValue(tmp_str); int weight = a8::XValue(strings4[1]); if (weight <= 0) { abort(); } rand_space += weight; std::get<1>(p).push_back ( std::make_tuple(buff_id, rand_space) ); } std::get<0>(p) = rand_space; } } int i = 0; } } } bool Buff::EffectCanStack() { return i->buff_effect() == kBET_ChgAttr; } bool Buff::IsImmuneBuffEffect(int buff_effect) { return immune_buffeffect.find(buff_effect) != immune_buffeffect.end(); } void Dress::Init() { for (int j = 0; j < i->max_lv(); ++j) { std::array& attrs = a8::FastAppend(level_attrs); for (size_t k = 0; k < kHAT_End; ++k) { attrs[k] = 0; } } { std::vector strings; a8::Split(i->attr_type(), strings, '|'); for (auto& str : strings) { std::vector 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() { } void AI::Init() { { std::vector strings; a8::Split(i->random_move_idle_time(), strings, ';'); if (!i->random_move_idle_time().empty()) { random_move_idle_time_ = std::make_tuple ( a8::XValue(strings[0]).GetInt(), a8::XValue(strings[1]).GetInt() ); } else { random_move_idle_time_ = std::make_tuple ( 2, 3 ); } } { std::vector strings; a8::Split(i->random_move_time(), strings, ';'); if (!i->random_move_time().empty()) { random_move_time_ = std::make_tuple ( a8::XValue(strings[0]).GetInt(), a8::XValue(strings[1]).GetInt() ); } else { random_move_time_ = std::make_tuple ( 3, 5 ); } } } int AI::GetMoveIdleTime() { return a8::RandEx( std::get<0>(random_move_idle_time_), std::get<1>(random_move_idle_time_) ); } int AI::GetMoveTime() { return a8::RandEx( std::get<0>(random_move_time_), std::get<1>(random_move_time_) ); } }