From 2a1d5bc661dcb320434493b9a2ca6e6c81e3f7dd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Sep 2022 14:29:51 +0800 Subject: [PATCH] 1 --- server/gameserver/creature.cc | 180 +++++++++++++++++----------------- server/gameserver/metadata.cc | 6 ++ server/gameserver/metadata.h | 7 +- server/gameserver/metamgr.cc | 24 ++--- 4 files changed, 106 insertions(+), 111 deletions(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index d185fa40..cb6a1147 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -142,6 +142,95 @@ static void InternalCreateBullet(BulletInfo& bullet_info) } } +static void CalcGunMuzzlePosition(Creature* c, + MetaData::Equip* weapon_meta, + MetaData::HeroShotAnimation* shot_animi, + glm::vec4& gun_muzzle_position, + int bulletIdx, + int bulletNum) +{ + if (shot_animi) { + if (weapon_meta->i->shootfire() == DOUBLE_GUN_ANIMATION && + bulletIdx > (int)(bulletNum / 2)) { + gun_muzzle_position += + glm::vec4( + shot_animi->l_x, + shot_animi->l_y, + shot_animi->l_z, + 0 + ); + } else { + if (c->IsCar() && weapon_meta->i->shootfire() != DOUBLE_GUN_ANIMATION) { + switch (c->shot_hole) { + case 1: + { + gun_muzzle_position += + glm::vec4( + shot_animi->p3_x, + shot_animi->p3_y, + shot_animi->p3_z, + 0 + ); + } + break; + case 2: + { + gun_muzzle_position += + glm::vec4( + shot_animi->p4_x, + shot_animi->p4_y, + shot_animi->p4_z, + 0 + ); + } + break; + case 3: + { + gun_muzzle_position += + glm::vec4( + shot_animi->p5_x, + shot_animi->p5_y, + shot_animi->p5_z, + 0 + ); + } + break; + default: + { + } + break; + } + } else { + gun_muzzle_position += + glm::vec4( + shot_animi->r_x, + shot_animi->r_y, + shot_animi->r_z, + 0 + ); + } + } + }//end if + if (weapon_meta->gun_muzzle_position) { + gun_muzzle_position += + glm::vec4( + std::get<0>(*weapon_meta->gun_muzzle_position.get()), + std::get<1>(*weapon_meta->gun_muzzle_position.get()), + std::get<2>(*weapon_meta->gun_muzzle_position.get()), + 0 + ); + } + if (weapon_meta->movex_position) { + gun_muzzle_position += + glm::vec4( + std::get<0>(*weapon_meta->movex_position.get()), + std::get<1>(*weapon_meta->movex_position.get()), + std::get<2>(*weapon_meta->movex_position.get()), + 0 + ); + } +} + void InternalShot(Creature* c, MetaData::Equip* weapon_meta, MetaData::Equip* bullet_meta, @@ -206,6 +295,8 @@ void InternalShot(Creature* c, c->room->xtimer.ModifyTimer(buff->remover_timer, weapon_meta->i->cast_time() / FRAME_RATE_MS); } } + MetaData::HeroShotAnimation* shot_animi = c->GetHeroMeta() ? + c->GetHeroMeta()->GetShotAnimi(weapon_meta->i->shootfire()) : nullptr; int i = 0; int num = weapon_meta->bullet_born_offset.size(); for (auto& tuple : weapon_meta->bullet_born_offset) { @@ -221,7 +312,6 @@ void InternalShot(Creature* c, } } bullet_dir.Rotate(bullet_angle / 180.0f); - #if 1 { bool is_player = c->IsPlayer(); bool is_car = c->IsCar(); @@ -236,92 +326,7 @@ void InternalShot(Creature* c, bullet_born_angle * A8_PI, glm::vec3(0.0, 1.0, 0.0)); glm::vec4 gun_muzzle_position(0.0, 0.0, 0.0, 0.0); - if (weapon_meta->i->shootfire()) { - MetaData::Player* hero_meta = c->GetHeroMeta(); - if (hero_meta) { - auto itr = hero_meta->shot_animations.find(weapon_meta->i->shootfire()); - if (itr != hero_meta->shot_animations.end()) { - if (weapon_meta->i->shootfire() == DOUBLE_GUN_ANIMATION && - i > (int)(num / 2)) { - gun_muzzle_position += - glm::vec4( - itr->second.l_x, - itr->second.l_y, - itr->second.l_z, - 0 - ); - } else { - if (c->IsCar() && weapon_meta->i->shootfire() != DOUBLE_GUN_ANIMATION) { - switch (c->shot_hole) { - case 1: - { - gun_muzzle_position += - glm::vec4( - itr->second.p3_x, - itr->second.p3_y, - itr->second.p3_z, - 0 - ); - } - break; - case 2: - { - gun_muzzle_position += - glm::vec4( - itr->second.p4_x, - itr->second.p4_y, - itr->second.p4_z, - 0 - ); - } - break; - case 3: - { - gun_muzzle_position += - glm::vec4( - itr->second.p5_x, - itr->second.p5_y, - itr->second.p5_z, - 0 - ); - } - break; - default: - { - } - break; - } - } else { - gun_muzzle_position += - glm::vec4( - itr->second.r_x, - itr->second.r_y, - itr->second.r_z, - 0 - ); - } - } - } - } - } - if (weapon_meta->gun_muzzle_position) { - gun_muzzle_position += - glm::vec4( - std::get<0>(*weapon_meta->gun_muzzle_position.get()), - std::get<1>(*weapon_meta->gun_muzzle_position.get()), - std::get<2>(*weapon_meta->gun_muzzle_position.get()), - 0 - ); - } - if (weapon_meta->movex_position) { - gun_muzzle_position += - glm::vec4( - std::get<0>(*weapon_meta->movex_position.get()), - std::get<1>(*weapon_meta->movex_position.get()), - std::get<2>(*weapon_meta->movex_position.get()), - 0 - ); - } + CalcGunMuzzlePosition(c, weapon_meta, shot_animi, gun_muzzle_position, i, num); glm::vec4 v = transform * gun_muzzle_position; bullet_born_offset = a8::Vec2(v.z *10*1, v.x*10*-1); bullet_born_pos = c->GetPos() + bullet_born_offset; @@ -348,7 +353,6 @@ void InternalShot(Creature* c, #endif } } - #endif { BulletInfo bullet_info; bullet_info.c = c->GetWeakPtrRef(); diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index 1098a32e..d491c086 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -646,6 +646,12 @@ namespace MetaData return 0; } + HeroShotAnimation* Player::GetShotAnimi(int shotfire) + { + auto itr = shot_animations.find(shotfire); + return itr != shot_animations.end() ? &itr->second : nullptr; + } + void Robot::Init() { { diff --git a/server/gameserver/metadata.h b/server/gameserver/metadata.h index e54a0259..e7709b9f 100644 --- a/server/gameserver/metadata.h +++ b/server/gameserver/metadata.h @@ -124,28 +124,24 @@ namespace MetaData struct HeroShotAnimation { int id = 0; + int t = 0; - float r_t = 0; float r_x = 0; float r_y = 0; float r_z = 0; - float l_t = 0; float l_x = 0; float l_y = 0; float l_z = 0; - float p3_t = 0; float p3_x = 0; float p3_y = 0; float p3_z = 0; - float p4_t = 0; float p4_x = 0; float p4_y = 0; float p4_z = 0; - float p5_t = 0; float p5_x = 0; float p5_y = 0; float p5_z = 0; @@ -166,6 +162,7 @@ namespace MetaData void Init(); int RandDrop(); + HeroShotAnimation* GetShotAnimi(int shotfire); }; struct NpcStandard diff --git a/server/gameserver/metamgr.cc b/server/gameserver/metamgr.cc index 02f8c0a1..05e07adb 100644 --- a/server/gameserver/metamgr.cc +++ b/server/gameserver/metamgr.cc @@ -583,56 +583,49 @@ private: for (auto& key2 : keys2) { auto anim_xobj = hero_xobj->At(key2); int id = a8::XValue(key2); - float r_t = 0; + 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_t = anim_xobj->At("t")->AsXValue().GetDouble(); 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_t = 0; float l_x = 0; float l_y = 0; float l_z = 0; if (anim_xobj->At("l") && anim_xobj->At("l")->IsObject()) { - l_t = anim_xobj->At("t")->AsXValue().GetDouble(); 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_t = 0; float p3_x = 0; float p3_y = 0; float p3_z = 0; if (anim_xobj->At("p3") && anim_xobj->At("p3")->IsObject()) { - p3_t = anim_xobj->At("t")->AsXValue().GetDouble(); 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_t = 0; float p4_x = 0; float p4_y = 0; float p4_z = 0; if (anim_xobj->At("p4") && anim_xobj->At("p4")->IsObject()) { - p4_t = anim_xobj->At("t")->AsXValue().GetDouble(); + 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_t = 0; float p5_x = 0; float p5_y = 0; float p5_z = 0; if (anim_xobj->At("p5") && anim_xobj->At("p5")->IsObject()) { - p5_t = anim_xobj->At("t")->AsXValue().GetDouble(); 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(); @@ -643,28 +636,24 @@ private: if (hero_meta) { MetaData::HeroShotAnimation anim; anim.id = id; + anim.t = t; - anim.r_t = r_t; anim.r_x = r_x; anim.r_y = r_y; anim.r_z = r_z; - anim.l_t = l_t; anim.l_x = l_x; anim.l_y = l_y; anim.l_z = l_z; - anim.p3_t = p3_t; anim.p3_x = p3_x; anim.p3_y = p3_y; anim.p3_z = p3_z; - anim.p4_t = p4_t; anim.p4_x = p4_x; anim.p4_y = p4_y; anim.p4_z = p4_z; - anim.p5_t = p5_t; anim.p5_x = p5_x; anim.p5_y = p5_y; anim.p5_z = p5_z; @@ -673,15 +662,14 @@ private: } } a8::UdpLog::Instance()->Info - ("shot animation hero_id:%d anim_id:%d r_t:%f r_x:%f r_y:%f r_z:%f l_t:%f l_x:%f l_y:%f l_z:%f", + ("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, - r_t, + t, r_x, r_y, r_z, - l_t, l_x, l_y, l_z