diff --git a/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs b/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs
index 7b8b7a00..b83bd6b4 100644
--- a/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs
+++ b/DungeonShooting_Godot/src/framework/activity/hurt/HurtArea.cs
@@ -21,19 +21,15 @@ public partial class HurtArea : Area2D, IHurt
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 3c3686d7..da56662e 100644
--- a/DungeonShooting_Godot/src/framework/activity/hurt/IHurt.cs
+++ b/DungeonShooting_Godot/src/framework/activity/hurt/IHurt.cs
@@ -6,8 +6,8 @@ public interface IHurt
///
/// 返回是否可以造成伤害
///
- /// 触发伤害的对象, 为 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 c74d1896..52af65a4 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 partial class Explode : Area2D, IPoolItem
/// 产生爆炸的子弹数据
///
public BulletData BulletData { get; private set; }
+
+ ///
+ /// 所属阵营
+ ///
+ public CampEnum Camp { get; private set; }
private bool _init = false;
private float _hitRadius;
@@ -56,11 +61,12 @@ public partial class Explode : Area2D, IPoolItem
/// 初始化爆炸数据
///
/// 产生爆炸的子弹数据
+ /// 所属阵营
/// 伤害半径
/// 造成的伤害
/// 击退半径
/// 最大击退速度
- 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 @@ public partial class Explode : Area2D, IPoolItem
BodyEntered += OnBodyEntered;
}
+ Camp = camp;
BulletData = bulletData;
_hitRadius = hitRadius;
_harm = harm;
@@ -159,9 +166,9 @@ public partial class Explode : Area2D, IPoolItem
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 6870c121..af0a9c4b 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 @@ public partial class Laser : Area2D, IBullet
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 @@ public partial class Laser : Area2D, IBullet
}
//造成伤害
+ 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 e2ea57e4..9da59f66 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 @@ public partial class BoomBullet : Bullet
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 c74ee7af..d96b193c 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 partial class Bullet : ActivityObject, IBullet
///
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 @@ public partial class Bullet : ActivityObject, IBullet
}
//造成伤害
+ 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 f9d0d165..f49703d4 100644
--- a/DungeonShooting_Godot/src/game/activity/item/ObstacleObject.cs
+++ b/DungeonShooting_Godot/src/game/activity/item/ObstacleObject.cs
@@ -7,7 +7,7 @@ using Godot;
[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 246dafc6..17670148 100644
--- a/DungeonShooting_Godot/src/game/activity/role/Role.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs
@@ -1422,7 +1422,7 @@ public abstract partial class Role : ActivityObject
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 33e39caf..b051ad67 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 @@ public partial class Player : Role
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 aae6cb95..dffce05d 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 @@ public partial class Knife : Weapon
private void HandlerCollision(IHurt hurt)
{
- if (hurt.CanHurt(TriggerRole))
+ if (TriggerRole == null || hurt.CanHurt(TriggerRole.Camp))
{
var damage = Utils.Random.RandomConfigRange(Attribute.Bullet.HarmRange);
//计算子弹造成的伤害