diff --git a/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs b/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs index 7b8b7a0..b83bd6b 100644 --- a/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs +++ b/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs @@ -21,19 +21,15 @@ Monitoring = false; } - public bool CanHurt(ActivityObject target) + public bool CanHurt(CampEnum targetCamp) { //无敌状态 if (Master.Invincible) { return true; } - - if (target is Role role) - { - return Master.IsEnemy(role); - } - return true; + + return Master.IsEnemy(targetCamp); } public void Hurt(ActivityObject target, int damage, float angle) diff --git a/DungeonShooting_Godot/src/framework/activity/hurt/IHurt.cs b/DungeonShooting_Godot/src/framework/activity/hurt/IHurt.cs index 3c3686d..da56662 100644 --- a/DungeonShooting_Godot/src/framework/activity/hurt/IHurt.cs +++ b/DungeonShooting_Godot/src/framework/activity/hurt/IHurt.cs @@ -6,8 +6,8 @@ /// /// 返回是否可以造成伤害 /// - /// 触发伤害的对象, 为 null 表示不存在对象或者对象已经被销毁 - bool CanHurt(ActivityObject target); + /// 攻击目标所属层级 + bool CanHurt(CampEnum targetCamp); /// /// 受到伤害 diff --git a/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs b/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs index c74d189..52af65a 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs @@ -29,6 +29,11 @@ /// 产生爆炸的子弹数据 /// public BulletData BulletData { get; private set; } + + /// + /// 所属阵营 + /// + public CampEnum Camp { get; private set; } private bool _init = false; private float _hitRadius; @@ -56,11 +61,12 @@ /// 初始化爆炸数据 /// /// 产生爆炸的子弹数据 + /// 所属阵营 /// 伤害半径 /// 造成的伤害 /// 击退半径 /// 最大击退速度 - public void Init(BulletData bulletData, float hitRadius, int harm, float repelledRadius, float maxRepelled) + public void Init(BulletData bulletData, CampEnum camp, float hitRadius, int harm, float repelledRadius, float maxRepelled) { if (!_init) { @@ -73,6 +79,7 @@ BodyEntered += OnBodyEntered; } + Camp = camp; BulletData = bulletData; _hitRadius = hitRadius; _harm = harm; @@ -159,9 +166,9 @@ var len = temp.Length(); var angle = temp.Angle(); - var target = BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole; - if (hurt.CanHurt(target)) + if (hurt.CanHurt(Camp)) { + var target = BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole; if (len <= _hitRadius) //在伤害半径内 { hurt.Hurt(target, _harm, angle); diff --git a/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs b/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs index 6870c12..af0a9c4 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs @@ -215,8 +215,7 @@ private void HandlerCollision(IHurt hurt) { - var target = BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole; - if (hurt.CanHurt(target)) + if (hurt.CanHurt(Camp)) { if (BulletData.Repel != 0) { @@ -228,6 +227,7 @@ } //造成伤害 + var target = BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole; hurt.Hurt(target, BulletData.Harm, Rotation); } } diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/BoomBullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/BoomBullet.cs index e2ea57e..9da59f6 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/BoomBullet.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/BoomBullet.cs @@ -59,7 +59,7 @@ explode.Position = pos; explode.RotationDegrees = Utils.Random.RandomRangeInt(0, 360); explode.AddToActivityRootDeferred(RoomLayerEnum.YSortLayer); - explode.Init(BulletData, 25, BulletData.Harm, 50, BulletData.Repel); + explode.Init(BulletData, Camp, 25, BulletData.Harm, 50, BulletData.Repel); explode.RunPlay(BulletData.TriggerRole); if (AffiliationArea != null) { diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs index c74ee7a..d96b193 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs @@ -189,8 +189,7 @@ /// public virtual void OnCollisionTarget(IHurt hurt) { - var target = BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole; - if (hurt.CanHurt(target)) + if (hurt.CanHurt(Camp)) { OnPlayDisappearEffect(); if (BulletData.Repel != 0) @@ -203,6 +202,7 @@ } //造成伤害 + var target = BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole; hurt.Hurt(target, BulletData.Harm, Rotation); //穿透次数 diff --git a/DungeonShooting_Godot/src/game/activity/item/ObstacleObject.cs b/DungeonShooting_Godot/src/game/activity/item/ObstacleObject.cs index f9d0d16..f49703d 100644 --- a/DungeonShooting_Godot/src/game/activity/item/ObstacleObject.cs +++ b/DungeonShooting_Godot/src/game/activity/item/ObstacleObject.cs @@ -7,7 +7,7 @@ [Tool] public partial class ObstacleObject : ActivityObject, IHurt { - public virtual bool CanHurt(ActivityObject target) + public virtual bool CanHurt(CampEnum targetCamp) { return true; } diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs index 246dafc..1767014 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Role.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs @@ -1422,7 +1422,7 @@ private void HandlerCollision(IHurt hurt, Weapon activeWeapon) { - if (hurt.CanHurt(this)) + if (hurt.CanHurt(Camp)) { var damage = Utils.Random.RandomConfigRange(activeWeapon.Attribute.MeleeAttackHarmRange); damage = RoleState.CalcDamage(damage); diff --git a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs index 33e39ca..b051ad6 100644 --- a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs +++ b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs @@ -225,7 +225,7 @@ foreach (var enemy in enemyList) { var hurt = ((Enemy)enemy).HurtArea; - if (hurt.CanHurt(this)) + if (hurt.CanHurt(Camp)) { hurt.Hurt(this, 1000, 0); } diff --git a/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs b/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs index aae6cb9..dffce05 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs @@ -159,7 +159,7 @@ private void HandlerCollision(IHurt hurt) { - if (hurt.CanHurt(TriggerRole)) + if (TriggerRole == null || hurt.CanHurt(TriggerRole.Camp)) { var damage = Utils.Random.RandomConfigRange(Attribute.Bullet.HarmRange); //计算子弹造成的伤害