解决换阵营子弹碰撞问题
This commit is contained in:
parent
84a0b1d608
commit
ff7712db8f
|
@ -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)
|
||||
|
|
|
@ -6,8 +6,8 @@ public interface IHurt
|
|||
/// <summary>
|
||||
/// 返回是否可以造成伤害
|
||||
/// </summary>
|
||||
/// <param name="target">触发伤害的对象, 为 null 表示不存在对象或者对象已经被销毁</param>
|
||||
bool CanHurt(ActivityObject target);
|
||||
/// <param name="targetCamp">攻击目标所属层级</param>
|
||||
bool CanHurt(CampEnum targetCamp);
|
||||
|
||||
/// <summary>
|
||||
/// 受到伤害
|
||||
|
|
|
@ -29,6 +29,11 @@ public partial class Explode : Area2D, IPoolItem
|
|||
/// 产生爆炸的子弹数据
|
||||
/// </summary>
|
||||
public BulletData BulletData { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属阵营
|
||||
/// </summary>
|
||||
public CampEnum Camp { get; private set; }
|
||||
|
||||
private bool _init = false;
|
||||
private float _hitRadius;
|
||||
|
@ -56,11 +61,12 @@ public partial class Explode : Area2D, IPoolItem
|
|||
/// 初始化爆炸数据
|
||||
/// </summary>
|
||||
/// <param name="bulletData">产生爆炸的子弹数据</param>
|
||||
/// <param name="camp">所属阵营</param>
|
||||
/// <param name="hitRadius">伤害半径</param>
|
||||
/// <param name="harm">造成的伤害</param>
|
||||
/// <param name="repelledRadius">击退半径</param>
|
||||
/// <param name="maxRepelled">最大击退速度</param>
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -189,8 +189,7 @@ public partial class Bullet : ActivityObject, IBullet
|
|||
/// </summary>
|
||||
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);
|
||||
|
||||
//穿透次数
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
//计算子弹造成的伤害
|
||||
|
|
Loading…
Reference in New Issue
Block a user