Make projectiles not hit crates unless clicked on (#28072)
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Damage.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prevent the object from getting hit by projetiles unless you target the object.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
[Access(typeof(RequireProjectileTargetSystem))]
|
||||||
|
public sealed partial class RequireProjectileTargetComponent : Component
|
||||||
|
{
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public bool Active = true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using Content.Shared.Projectiles;
|
||||||
|
using Content.Shared.Weapons.Ranged.Components;
|
||||||
|
using Content.Shared.Standing;
|
||||||
|
using Robust.Shared.Physics.Events;
|
||||||
|
|
||||||
|
namespace Content.Shared.Damage.Components;
|
||||||
|
|
||||||
|
public sealed class RequireProjectileTargetSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<RequireProjectileTargetComponent, PreventCollideEvent>(PreventCollide);
|
||||||
|
SubscribeLocalEvent<RequireProjectileTargetComponent, StoodEvent>(StandingBulletHit);
|
||||||
|
SubscribeLocalEvent<RequireProjectileTargetComponent, DownedEvent>(LayingBulletPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PreventCollide(Entity<RequireProjectileTargetComponent> ent, ref PreventCollideEvent args)
|
||||||
|
{
|
||||||
|
if (args.Cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!ent.Comp.Active)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var other = args.OtherEntity;
|
||||||
|
if (HasComp<ProjectileComponent>(other) &&
|
||||||
|
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
|
||||||
|
{
|
||||||
|
args.Cancelled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetActive(Entity<RequireProjectileTargetComponent> ent, bool value)
|
||||||
|
{
|
||||||
|
if (ent.Comp.Active == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ent.Comp.Active = value;
|
||||||
|
Dirty(ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StandingBulletHit(Entity<RequireProjectileTargetComponent> ent, ref StoodEvent args)
|
||||||
|
{
|
||||||
|
SetActive(ent, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LayingBulletPass(Entity<RequireProjectileTargetComponent> ent, ref DownedEvent args)
|
||||||
|
{
|
||||||
|
SetActive(ent, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,6 @@ public partial class MobStateSystem
|
|||||||
SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
|
SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
|
||||||
SubscribeLocalEvent<MobStateComponent, CombatModeShouldHandInteractEvent>(OnCombatModeShouldHandInteract);
|
SubscribeLocalEvent<MobStateComponent, CombatModeShouldHandInteractEvent>(OnCombatModeShouldHandInteract);
|
||||||
SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
|
SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
|
||||||
SubscribeLocalEvent<MobStateComponent, PreventCollideEvent>(OnPreventCollide);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
|
private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
|
||||||
@@ -179,21 +178,5 @@ public partial class MobStateSystem
|
|||||||
args.Cancelled = true;
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# The progenitor. This should only container the most basic components possible.
|
# The progenitor. This should only container the most basic components possible.
|
||||||
# Only put things on here if every mob *must* have it. This includes ghosts.
|
# Only put things on here if every mob *must* have it. This includes ghosts.
|
||||||
- type: entity
|
- type: entity
|
||||||
save: false
|
save: false
|
||||||
@@ -43,6 +43,8 @@
|
|||||||
- type: MovementSpeedModifier
|
- type: MovementSpeedModifier
|
||||||
- type: Polymorphable
|
- type: Polymorphable
|
||||||
- type: StatusIcon
|
- type: StatusIcon
|
||||||
|
- type: RequireProjectileTarget
|
||||||
|
active: False
|
||||||
|
|
||||||
# Used for mobs that have health and can take damage.
|
# Used for mobs that have health and can take damage.
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
node: crategenericsteel
|
node: crategenericsteel
|
||||||
containers:
|
containers:
|
||||||
- entity_storage
|
- entity_storage
|
||||||
|
- type: RequireProjectileTarget
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: CrateGeneric
|
parent: CrateGeneric
|
||||||
|
|||||||
Reference in New Issue
Block a user