Fix the ability to shoot out of crates (#28961)
* Fix the ability to shoot out of crates * Makes it check what inventory the player is in * use IsEntityOrParentInContainer * Fix Issues Github had * gaahhh... Prevents lasers from being shot out of crates * gaahhh... Prevents lasers from being shot out of crates * Fix laser? * hmmm... this is better looking I think? * Uncook indentation * Rerun tests?
This commit is contained in:
@@ -24,6 +24,7 @@ using Robust.Shared.Physics;
|
|||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
|
|
||||||
namespace Content.Server.Weapons.Ranged.Systems;
|
namespace Content.Server.Weapons.Ranged.Systems;
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
[Dependency] private readonly StaminaSystem _stamina = default!;
|
[Dependency] private readonly StaminaSystem _stamina = default!;
|
||||||
[Dependency] private readonly StunSystem _stun = default!;
|
[Dependency] private readonly StunSystem _stun = default!;
|
||||||
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||||
|
|
||||||
private const float DamagePitchVariation = 0.05f;
|
private const float DamagePitchVariation = 0.05f;
|
||||||
public const float GunClumsyChance = 0.5f;
|
public const float GunClumsyChance = 0.5f;
|
||||||
@@ -204,17 +206,21 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
|
|
||||||
var result = rayCastResults[0];
|
var result = rayCastResults[0];
|
||||||
|
|
||||||
// Checks if the laser should pass over unless targeted by its user
|
// Check if laser is shot from in a container
|
||||||
foreach (var collide in rayCastResults)
|
if (!_container.IsEntityOrParentInContainer(lastUser))
|
||||||
{
|
{
|
||||||
if (collide.HitEntity != gun.Target &&
|
// Checks if the laser should pass over unless targeted by its user
|
||||||
CompOrNull<RequireProjectileTargetComponent>(collide.HitEntity)?.Active == true)
|
foreach (var collide in rayCastResults)
|
||||||
{
|
{
|
||||||
continue;
|
if (collide.HitEntity != gun.Target &&
|
||||||
}
|
CompOrNull<RequireProjectileTargetComponent>(collide.HitEntity)?.Active == true)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
result = collide;
|
result = collide;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hit = result.HitEntity;
|
var hit = result.HitEntity;
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ using Content.Shared.Projectiles;
|
|||||||
using Content.Shared.Weapons.Ranged.Components;
|
using Content.Shared.Weapons.Ranged.Components;
|
||||||
using Content.Shared.Standing;
|
using Content.Shared.Standing;
|
||||||
using Robust.Shared.Physics.Events;
|
using Robust.Shared.Physics.Events;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
|
|
||||||
namespace Content.Shared.Damage.Components;
|
namespace Content.Shared.Damage.Components;
|
||||||
|
|
||||||
public sealed class RequireProjectileTargetSystem : EntitySystem
|
public sealed class RequireProjectileTargetSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<RequireProjectileTargetComponent, PreventCollideEvent>(PreventCollide);
|
SubscribeLocalEvent<RequireProjectileTargetComponent, PreventCollideEvent>(PreventCollide);
|
||||||
@@ -23,10 +26,16 @@ public sealed class RequireProjectileTargetSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var other = args.OtherEntity;
|
var other = args.OtherEntity;
|
||||||
if (HasComp<ProjectileComponent>(other) &&
|
if (TryComp(other, out ProjectileComponent? projectile) &&
|
||||||
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
|
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
|
||||||
{
|
{
|
||||||
args.Cancelled = true;
|
// Prevents shooting out of while inside of crates
|
||||||
|
var shooter = projectile.Shooter;
|
||||||
|
if (!shooter.HasValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_container.IsEntityOrParentInContainer(shooter.Value))
|
||||||
|
args.Cancelled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user