diff --git a/server/gameserver/human.h b/server/gameserver/human.h index ccb179ff..f7042166 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -71,6 +71,8 @@ class Human : public Creature std::shared_ptr throw_bomb; std::map> pending_throw_bomb; std::shared_ptr sand_table_target_pos; + std::shared_ptr shot_target_pos; + std::shared_ptr shot_client_pos; std::string name; std::string avatar_url; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 2f6bb02d..626fddae 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -3,6 +3,9 @@ #include #include #include + +#include + #include #include @@ -621,7 +624,20 @@ void Player::Shot() target_dir = attack_dir; } } - Creature::Shot(target_dir, shot_ok, fly_distance, target_uniid); + if (shot_target_pos && shot_client_pos) { + glm::vec3 old_attack_dir = GetAttackDir(); + if (std::fabs(shot_client_pos->x - GetPos().GetX()) < 60.0f && + std::fabs(shot_client_pos->y - GetPos().GetY()) < 5.0f && + std::fabs(shot_client_pos->y - GetPos().GetZ()) < 60.0f) { + glm::vec3 new_attack_dir = *shot_target_pos - GetPos().ToGlmVec3(); + GlmHelper::Normalize(new_attack_dir); + SetAttackDir(new_attack_dir); + } + Creature::Shot(target_dir, shot_ok, fly_distance, target_uniid); + SetAttackDir(old_attack_dir); + } else { + Creature::Shot(target_dir, shot_ok, fly_distance, target_uniid); + } } void Player::ProcInteraction() @@ -1130,6 +1146,20 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg) GetMovement()->CalcTargetPos(distance); } } + if (msg.has_shot_target_pos() && + msg.has_shot_client_pos()) { + if (!shot_target_pos) { + shot_target_pos = std::make_shared(0.0f, 0.0f, 0.0f); + } + if (!shot_client_pos) { + shot_client_pos = std::make_shared(0.0f, 0.0f, 0.0f); + } + TypeConvert::FromPb(*shot_target_pos, &msg.shot_target_pos()); + TypeConvert::FromPb(*shot_client_pos, &msg.shot_client_pos()); + } else { + shot_target_pos = nullptr; + shot_client_pos = nullptr; + } last_cmmove_frameno = room->GetFrameNo(); trace_target_uniid = msg.trace_target_uniid(); #ifdef DEBUG1