Make projectiles not hit crit mobs unless clicked on (#27905)
This commit is contained in:
@@ -10,12 +10,15 @@ using Content.Shared.Item;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Pointing;
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Pulling.Events;
|
||||
using Content.Shared.Speech;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Strip.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
|
||||
namespace Content.Shared.Mobs.Systems;
|
||||
|
||||
@@ -43,6 +46,7 @@ public partial class MobStateSystem
|
||||
SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, CombatModeShouldHandInteractEvent>(OnCombatModeShouldHandInteract);
|
||||
SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
|
||||
SubscribeLocalEvent<MobStateComponent, PreventCollideEvent>(OnPreventCollide);
|
||||
}
|
||||
|
||||
private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
|
||||
@@ -175,5 +179,21 @@ public partial class MobStateSystem
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnPreventCollide(Entity<MobStateComponent> ent, ref PreventCollideEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
if (IsAlive(ent, ent))
|
||||
return;
|
||||
|
||||
var other = args.OtherEntity;
|
||||
if (HasComp<ProjectileComponent>(other) &&
|
||||
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent.Owner)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -139,6 +137,12 @@ public sealed partial class GunComponent : Component
|
||||
[ViewVariables]
|
||||
public EntityCoordinates? ShootCoordinates = null;
|
||||
|
||||
/// <summary>
|
||||
/// Who the gun is being requested to shoot at directly.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public EntityUid? Target = null;
|
||||
|
||||
/// <summary>
|
||||
/// The base value for how many shots to fire per burst.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Weapons.Ranged.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(SharedGunSystem))]
|
||||
public sealed partial class TargetedProjectileComponent : Component
|
||||
{
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid Target;
|
||||
}
|
||||
@@ -11,4 +11,5 @@ public sealed class RequestShootEvent : EntityEventArgs
|
||||
{
|
||||
public NetEntity Gun;
|
||||
public NetCoordinates Coordinates;
|
||||
public NetEntity? Target;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
return;
|
||||
|
||||
gun.ShootCoordinates = GetCoordinates(msg.Coordinates);
|
||||
gun.Target = GetEntity(msg.Target);
|
||||
AttemptShoot(user.Value, ent, gun);
|
||||
}
|
||||
|
||||
@@ -196,6 +197,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
|
||||
gun.ShotCounter = 0;
|
||||
gun.ShootCoordinates = null;
|
||||
gun.Target = null;
|
||||
Dirty(uid, gun);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user