aozhiwei c1d79c7dd2 1
2023-04-06 14:52:53 +08:00

314 lines
11 KiB
C++

#include "precompile.h"
#include <f8/udplog.h>
#include "mt/MetaMgr.h"
#include "mt/Hero.h"
#include "mt/Equip.h"
IMPL_TABLE(mt::Hero)
namespace mt
{
void Hero::Init1()
{
{
int total_weight = 0;
std::vector<std::string> strings;
a8::Split(dead_drop(), strings, '|');
for (const std::string& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
int drop_id = a8::XValue(strings2[0]);
int weight = strings2.size() > 1 ? a8::XValue(strings2[1]).GetInt() : 10000;
total_weight += weight;
_dead_drop.push_back
(std::make_tuple(
drop_id,
total_weight
)
);
}
}
{
std::vector<std::string> strings;
a8::Split(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;
}
}
}
}
{
std::vector<std::string> strings;
a8::Split(init_buffs(), strings, '|');
for (auto& str : strings) {
_init_buffs.push_back(a8::XValue(str));
}
}
{
std::vector<std::string> strings;
a8::Split(pre_appear_effect(), strings, '|');
#if 0
a8::XPrintf("%d,pre_appear_effect:%s\n", {i->id(), pre_appear_effect()});
#endif
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
if (strings2.size() >= 2) {
int thing_id = a8::XValue(strings2[0]);
int time = a8::XValue(strings2[1]);
_pre_appear_effect.push_back(std::make_tuple(thing_id, time));
}
}
}
{
_pve_score = std::make_tuple(0, 0);
if (!pve_score().empty()) {
std::vector<std::string> strings;
a8::Split(pve_score(), strings, '|');
if (strings.size() != 2) {
abort();
}
_pve_score = std::make_tuple(a8::XValue(strings[0]).GetInt(), a8::XValue(strings[1]).GetInt());
if (std::get<0>(_pve_score) <= 0 ||
std::get<1>(_pve_score) <= 0) {
abort();
}
}
}
{
#if 0
if (jump_speed() < 0.0001f) {
jump_speed_ = 1.0f;
}
if (fall_speed() < 0.0001f) {
fall_speed_ = 1.0f;
}
#endif
if (aim_speed() < 0.0001f) {
aim_speed_ = 1.0f;
}
if (shoot_speed() < 0.0001f) {
shoot_speed_ = 1.0f;
}
if (reload_speed() < 0.0001f) {
reload_speed_ = 1.0f;
}
if (medicine_speed() < 0.0001f) {
medicine_speed_ = 1.0f;
}
if (swim_speed() < 0.0001f) {
swim_speed_ = 1.0f;
}
}
}
int Hero::RandDrop() const
{
if (HasDrop()) {
int total_weight = std::get<1>(_dead_drop[_dead_drop.size() - 1]);
int rnd = rand() % total_weight;
for (auto& tuple : _dead_drop) {
if (rnd < std::get<1>(tuple)) {
return std::get<0>(tuple);
}
}
}
return 0;
}
void Hero::StaticPostInit()
{
LoadHeroAndEquipShotData();
Equip::AdjustMuzzlePos();
}
const HeroShotAnimation* Hero::GetShotAnimi(int shotfire) const
{
auto itr = shot_animations.find(shotfire);
return itr != shot_animations.end() ? &itr->second : nullptr;
}
void Hero::LoadHeroAndEquipShotData()
{
a8::XObject xobj;
xobj.ReadFromFile(mt::MetaMgr::Instance()->GetResDir() + "shot_animation.json");
{
auto hero_list_xobj = xobj.At("hero");
std::vector<std::string> keys;
hero_list_xobj->GetKeys(keys);
for (auto& key : keys) {
auto hero_xobj = hero_list_xobj->At(key);
int hero_id = a8::XValue(key);
std::vector<std::string> keys2;
hero_xobj->GetKeys(keys2);
#if 1
{
const mt::Hero* hero_meta = Hero::GetById(hero_id);
if (hero_meta) {
mt::Hero* mut_hero_meta = (mt::Hero*)hero_meta;
auto size_xobj = hero_xobj->At("size");
mut_hero_meta->hit_radius_ = size_xobj->At("radius")->AsXValue().GetDouble() * 10;
}
}
#endif
for (auto& key2 : keys2) {
auto anim_xobj = hero_xobj->At(key2);
int id = a8::XValue(key2);
int t = anim_xobj->At("t") ? anim_xobj->At("t")->AsXValue().GetInt() : 0;
float r_x = 0;
float r_y = 0;
float r_z = 0;
if (anim_xobj->At("r") && anim_xobj->At("r")->IsObject()) {
r_x = anim_xobj->At("r")->At("x")->AsXValue().GetDouble();
r_y = anim_xobj->At("r")->At("y")->AsXValue().GetDouble();
r_z = anim_xobj->At("r")->At("z")->AsXValue().GetDouble();
}
float l_x = 0;
float l_y = 0;
float l_z = 0;
if (anim_xobj->At("l") && anim_xobj->At("l")->IsObject()) {
l_x = anim_xobj->At("l")->At("x")->AsXValue().GetDouble();
l_y = anim_xobj->At("l")->At("y")->AsXValue().GetDouble();
l_z = anim_xobj->At("l")->At("z")->AsXValue().GetDouble();
}
float p3_x = 0;
float p3_y = 0;
float p3_z = 0;
if (anim_xobj->At("p3") && anim_xobj->At("p3")->IsObject()) {
p3_x = anim_xobj->At("p3")->At("x")->AsXValue().GetDouble();
p3_y = anim_xobj->At("p3")->At("y")->AsXValue().GetDouble();
p3_z = anim_xobj->At("p3")->At("z")->AsXValue().GetDouble();
}
float p4_x = 0;
float p4_y = 0;
float p4_z = 0;
if (anim_xobj->At("p4") && anim_xobj->At("p4")->IsObject()) {
p4_x = anim_xobj->At("p4")->At("x")->AsXValue().GetDouble();
p4_y = anim_xobj->At("p4")->At("y")->AsXValue().GetDouble();
p4_z = anim_xobj->At("p4")->At("z")->AsXValue().GetDouble();
}
float p5_x = 0;
float p5_y = 0;
float p5_z = 0;
if (anim_xobj->At("p5") && anim_xobj->At("p5")->IsObject()) {
p5_x = anim_xobj->At("p5")->At("x")->AsXValue().GetDouble();
p5_y = anim_xobj->At("p5")->At("y")->AsXValue().GetDouble();
p5_z = anim_xobj->At("p5")->At("z")->AsXValue().GetDouble();
}
{
const mt::Hero* hero_meta = mt::Hero::GetById(hero_id);
if (hero_meta) {
mt::HeroShotAnimation anim;
anim.id = id;
anim.t = t;
anim.r_x = r_x;
anim.r_y = r_y;
anim.r_z = r_z;
anim.l_x = l_x;
anim.l_y = l_y;
anim.l_z = l_z;
anim.p3_x = p3_x;
anim.p3_y = p3_y;
anim.p3_z = p3_z;
anim.p4_x = p4_x;
anim.p4_y = p4_y;
anim.p4_z = p4_z;
anim.p5_x = p5_x;
anim.p5_y = p5_y;
anim.p5_z = p5_z;
((mt::Hero*)hero_meta)->shot_animations[id] = anim;
}
}
#if 0
f8::UdpLog::Instance()->Info
("shot animation hero_id:%d anim_id:%d t:%f r_x:%f r_y:%f r_z:%f l_x:%f l_y:%f l_z:%f",
{
hero_id,
id,
t,
r_x,
r_y,
r_z,
l_x,
l_y,
l_z
});
#endif
}
}
}
{
auto equip_list_xobj = xobj.At("equip");
std::vector<std::string> keys;
equip_list_xobj->GetKeys(keys);
for (auto& key : keys) {
int equip_id = a8::XValue(key);
auto equip_xobj = equip_list_xobj->At(key);
const mt::Equip* equip_meta = mt::Equip::GetById(equip_id);
if (!equip_meta) {
abort();
}
std::vector<std::string> lv_keys;
equip_xobj->GetKeys(lv_keys);
for (auto& lv_key : lv_keys) {
int equip_lv = a8::XValue(lv_key);
auto equip_lv_xobj = equip_xobj->At(lv_key);
float x = equip_lv_xobj->At("x")->AsXValue().GetDouble();
float y = equip_lv_xobj->At("y")->AsXValue().GetDouble();
float z = equip_lv_xobj->At("z")->AsXValue().GetDouble();
float movex = equip_lv_xobj->At("movex") ?
equip_lv_xobj->At("movex")->AsXValue().GetDouble() : 0;
float movey = equip_lv_xobj->At("movey") ?
equip_lv_xobj->At("movey")->AsXValue().GetDouble() : 0;
float movez = equip_lv_xobj->At("movez") ?
equip_lv_xobj->At("movez")->AsXValue().GetDouble() : 0;
auto pos = std::make_shared<std::tuple<float, float, float>>
(
x,
y,
z
);
((mt::Equip*)equip_meta)->AddMuzzlePos(equip_lv, pos);
#if 0
((mt::Equip*)equip_meta)->_movex_position = std::make_shared<std::tuple<float, float, float>>
(
movex,
movey,
movez
);
#endif
}
}
}
}
}