From 0bbf83d6a324b4fe4ea9a18f85462e02abbca8f6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 4 Jun 2021 15:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=209.=E6=9C=BA=E7=94=B2?= =?UTF-8?q?=EF=BC=8C=E5=B0=84=E6=9D=80=E6=95=8C=E4=BA=BA=E6=9C=AA=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=87=BB=E6=9D=80=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/bullet.h | 1 + server/gameserver/creature.cc | 1 + server/gameserver/creature.h | 1 + server/gameserver/human.cc | 15 +++++++++++---- server/gameserver/player.cc | 3 +++ server/gameserver/room.cc | 4 ++++ server/gameserver/room.h | 1 + 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/gameserver/bullet.h b/server/gameserver/bullet.h index dc0b032..b853bff 100644 --- a/server/gameserver/bullet.h +++ b/server/gameserver/bullet.h @@ -23,6 +23,7 @@ class Bullet : public MoveableEntity MetaData::EquipUpgrade* gun_upgrade_meta = nullptr; MetaData::Equip* meta = nullptr; CreatureWeakPtr sender; + CreatureWeakPtr passenger; a8::Vec2 dir; a8::Vec2 born_pos; a8::Vec2 born_dir; diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 61c4acb..4e285e8 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -68,6 +68,7 @@ void InternalShot(Creature* c, (c->room->GetGasData().gas_mode == GasJump && !c->HasBuffEffect(kBET_Jump))) { c->room->CreateBullet(c, + c->shot_passenger, weapon_meta, weapon_upgrade_meta, bullet_meta, diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 938df6c..2aca8d7 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -44,6 +44,7 @@ class Creature : public MoveableEntity long long aiming_frameno = 0; a8::Vec2 shoot_offset; int shot_hole = 0; + Creature* shot_passenger = nullptr; HumanAbility ability; a8::Vec2 target_pos; std::function on_move_collision; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 58509a8..5d55d60 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -3693,10 +3693,17 @@ void Human::OnBulletHit(Bullet* bullet) if (bullet->meta->buff_meta) { MustBeAddBuff(this, bullet->meta->i->buffid()); } - DecHP(finaly_dmg, - bullet->sender.Get()->GetEntityUniId(), - bullet->sender.Get()->GetName(), - bullet->gun_meta->i->id()); + if (bullet->sender.Get() && bullet->sender.Get()->IsCar() && bullet->passenger.Get()) { + DecHP(finaly_dmg, + bullet->passenger.Get()->GetEntityUniId(), + bullet->passenger.Get()->GetName(), + bullet->gun_meta->i->id()); + } else { + DecHP(finaly_dmg, + bullet->sender.Get()->GetEntityUniId(), + bullet->sender.Get()->GetName(), + bullet->gun_meta->i->id()); + } #ifdef DEBUG bullet->sender.Get()->SendDebugMsg (a8::Format("bullet weapon_id:%d atk:%f", diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 36b6e23..e3a191f 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -200,9 +200,11 @@ void Player::UpdateShot() a8::Vec2 target_dir = GetAttackDir(); a8::Vec2 old_car_shoot_offset = GetCar()->shoot_offset; a8::Vec2 old_car_attack_dir = GetCar()->GetAttackDir(); + Creature* old_car_shot_passenger = GetCar()->shot_passenger; int old_car_shot_hole = GetCar()->shot_hole; GetCar()->shoot_offset = shoot_offset; GetCar()->shot_hole = GetSeat(); + GetCar()->shot_passenger = this; GetCar()->SetAttackDir(GetAttackDir()); GetCar()->Shot(target_dir, shot_ok, fly_distance); if (!moving && GetCar()->IsDriver(this)) { @@ -213,6 +215,7 @@ void Player::UpdateShot() } GetCar()->shot_hole = old_car_shot_hole; GetCar()->shoot_offset = old_car_shoot_offset; + GetCar()->shot_passenger = old_car_shot_passenger; } shot_start = false; return; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index a869168..d49530e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -547,6 +547,7 @@ int Room::CreateLootEx(int equip_id, a8::Vec2 born_pos, a8::Vec2 pos, int count, } void Room::CreateBullet(Creature* sender, + Creature* passenger, MetaData::Equip* weapon_meta, MetaData::EquipUpgrade* weapon_upgrade_meta, MetaData::Equip* bullet_meta, @@ -558,6 +559,9 @@ void Room::CreateBullet(Creature* sender, if (grid_service->CanAdd(pos.x, pos.y)) { Bullet* bullet = EntityFactory::Instance()->MakeBullet(AllocUniid()); bullet->sender.Attach(sender); + if (passenger) { + bullet->passenger.Attach(passenger); + } bullet->room = this; bullet->gun_meta = weapon_meta; bullet->gun_upgrade_meta = weapon_upgrade_meta; diff --git a/server/gameserver/room.h b/server/gameserver/room.h index bcf09bb..fa8b66a 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -110,6 +110,7 @@ public: int CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv); int CreateLootEx(int equip_id, a8::Vec2 born_pos, a8::Vec2 pos, int count, int equip_lv, bool show_anim); void CreateBullet(Creature* sender, + Creature* passenger, MetaData::Equip* weapon_meta, MetaData::EquipUpgrade* weapon_upgrade_meta, MetaData::Equip* bullet_meta,