From 29c46c5e2797a7edf7aa64f38a0ff6ed36d382a5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 24 May 2021 18:31:30 +0800 Subject: [PATCH] 1 --- server/gameserver/car.cc | 14 ++++++++++++++ server/gameserver/car.h | 2 ++ server/gameserver/player.cc | 22 ++++++++++++---------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/server/gameserver/car.cc b/server/gameserver/car.cc index 90011e8..4d06919 100644 --- a/server/gameserver/car.cc +++ b/server/gameserver/car.cc @@ -169,6 +169,15 @@ void Car::GetOn(Human* passenger) SyncAroundPlayers(__FILE__, __LINE__, __func__); } +bool Car::CanShot(Human* passenger) +{ + if (!IsPassenger(passenger)) { + return false; + } + return passenger->GetSeat() < meta->shoot_offsets.size() && + std::get<0>(meta->shoot_offsets[passenger->GetSeat()]); +} + int Car::AllocSeat() { int seat = -1; @@ -349,3 +358,8 @@ void Car::SendDebugMsg(const std::string& debug_msg) passenger->SendDebugMsg("载具debugmsg: " + debug_msg); } } + +bool Car::IsPassenger(Human* hum) +{ + return passengers_.find(hum) != passengers_.end(); +} diff --git a/server/gameserver/car.h b/server/gameserver/car.h index c366a3f..39abf96 100644 --- a/server/gameserver/car.h +++ b/server/gameserver/car.h @@ -30,6 +30,7 @@ class Car : public Creature bool IsDriver(Human* hum) { return driver_ == hum && driver_; } void GetDown(Human* passenger); void GetOn(Human* passenger); + bool CanShot(Human* passenger); void SyncPos(); virtual float GetRadius() override; virtual float GetSpeed() override; @@ -40,6 +41,7 @@ class Car : public Creature int AllocSeat(); void BeKill(int killer_id, const std::string& killer_name, int weapon_id); void Explosion(int team_id); + bool IsPassenger(Human* hum); private: long long born_frameno_ = 0; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 3eb4bef..fdc48eb 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -190,17 +190,19 @@ void Player::UpdateShot() if (HasBuffEffect(kBET_Vertigo)) { return; } - if (GetCar() && GetCar()->IsDriver(this)) { - bool shot_ok = false; - a8::Vec2 target_dir = GetAttackDir(); - a8::Vec2 old_car_shoot_offset = GetCar()->shoot_offset; - GetCar()->shoot_offset = shoot_offset; - GetCar()->SetAttackDir(GetAttackDir()); - GetCar()->Shot(target_dir, shot_ok, fly_distance); - if (!moving) { - GetCar()->SetMoveDir(GetAttackDir()); + if (GetCar()) { + if (GetCar()->CanShot(this)) { + bool shot_ok = false; + a8::Vec2 target_dir = GetAttackDir(); + a8::Vec2 old_car_shoot_offset = GetCar()->shoot_offset; + GetCar()->shoot_offset = shoot_offset; + GetCar()->SetAttackDir(GetAttackDir()); + GetCar()->Shot(target_dir, shot_ok, fly_distance); + if (!moving) { + GetCar()->SetMoveDir(GetAttackDir()); + } + GetCar()->shoot_offset = old_car_shoot_offset; } - GetCar()->shoot_offset = old_car_shoot_offset; shot_start = false; return; } else {