Revert "Revert "Revert "Cleanup ExecutionSystem (#24382)" (#25555)""

This reverts commit 3c9c149b81.

# Conflicts:
#	Content.Server/Projectiles/ProjectileSystem.cs
#	Content.Server/Weapons/Ranged/Systems/GunSystem.cs
#	Content.Shared/Projectiles/SharedProjectileSystem.cs
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml
This commit is contained in:
Remuchi
2024-04-14 12:11:31 +07:00
parent 2b57a5c0e1
commit 8712256194
28 changed files with 54 additions and 1020 deletions

View File

@@ -19,7 +19,7 @@ public record struct ShotAttemptedEvent
public bool Cancelled { get; private set; }
/// <summary>
/// </summary>
/// Prevent the gun from shooting
/// </summary>
public void Cancel()
@@ -27,7 +27,7 @@ public record struct ShotAttemptedEvent
Cancelled = true;
}
/// <summary>
/// </summary>
/// Allow the gun to shoot again, only use if you know what you are doing
/// </summary>
public void Uncancel()

View File

@@ -22,7 +22,6 @@ using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
@@ -142,7 +141,7 @@ public abstract partial class SharedGunSystem : EntitySystem
gun.ShootCoordinates = GetCoordinates(msg.Coordinates);
gun.Target = GetEntity(msg.Target);
Log.Debug($"Set shoot coordinates to {gun.ShootCoordinates}");
AttemptShootInternal(user.Value, ent, gun);
AttemptShoot(user.Value, ent, gun);
}
private void OnStopShootRequest(RequestStopShootEvent ev, EntitySessionEventArgs args)
@@ -206,38 +205,13 @@ public abstract partial class SharedGunSystem : EntitySystem
Dirty(uid, gun);
}
/// <summary>
/// Attempts to shoot the specified target directly.
/// This may bypass projectiles firing etc.
/// </summary>
public bool AttemptDirectShoot(EntityUid user, EntityUid gunUid, EntityUid target, GunComponent gun)
{
// Unique name so people don't think it's "shoot towards" and not "I will teleport a bullet into them".
gun.ShootCoordinates = Transform(target).Coordinates;
if (!TryTakeAmmo(user, gunUid, gun, out _, out _, out var args))
{
gun.ShootCoordinates = null;
return false;
}
var result = ShootDirect(gunUid, gun, target, args.Ammo, user: user);
gun.ShootCoordinates = null;
return result;
}
protected virtual bool ShootDirect(EntityUid gunUid, GunComponent gun, EntityUid target, List<(EntityUid? Entity, IShootable Shootable)> ammo, EntityUid user)
{
return false;
}
/// <summary>
/// Attempts to shoot at the target coordinates. Resets the shot counter after every shot.
/// </summary>
public void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun, EntityCoordinates toCoordinates)
{
gun.ShootCoordinates = toCoordinates;
AttemptShootInternal(user, gunUid, gun);
AttemptShoot(user, gunUid, gun);
gun.ShotCounter = 0;
}
@@ -248,35 +222,20 @@ public abstract partial class SharedGunSystem : EntitySystem
{
var coordinates = new EntityCoordinates(gunUid, new Vector2(0, -1));
gun.ShootCoordinates = coordinates;
AttemptShootInternal(gunUid, gunUid, gun);
AttemptShoot(gunUid, gunUid, gun);
gun.ShotCounter = 0;
}
private void AttemptShootInternal(EntityUid user, EntityUid gunUid, GunComponent gun)
{
if (!TryTakeAmmo(user, gunUid, gun, out var fromCoordinates, out var toCoordinates, out var args))
return;
Shoot(gunUid, gun, args.Ammo, fromCoordinates, toCoordinates, out var userImpulse, user: user);
if (userImpulse && TryComp<PhysicsComponent>(user, out var userPhysics))
{
if (_gravity.IsWeightless(user, userPhysics))
CauseImpulse(fromCoordinates, toCoordinates, user, userPhysics);
}
}
/// <summary>
/// Validates if a gun can currently shoot.
/// </summary>
[Pure]
private bool CanShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
{
if (gun.FireRateModified <= 0f ||
!_actionBlockerSystem.CanAttack(user))
{
return false;
}
return;
var toCoordinates = gun.ShootCoordinates;
if (toCoordinates == null)
return;
var curTime = Timing.CurTime;
@@ -288,42 +247,17 @@ public abstract partial class SharedGunSystem : EntitySystem
};
RaiseLocalEvent(gunUid, ref prevention);
if (prevention.Cancelled)
return false;
return;
RaiseLocalEvent(user, ref prevention);
if (prevention.Cancelled)
return false;
return;
// Need to do this to play the clicking sound for empty automatic weapons
// but not play anything for burst fire.
if (gun.NextFire > curTime)
return false;
return;
return true;
}
/// <summary>
/// Tries to return ammo prepped for shooting if a gun is available to shoot.
/// </summary>
private bool TryTakeAmmo(
EntityUid user,
EntityUid gunUid, GunComponent gun,
out EntityCoordinates fromCoordinates,
out EntityCoordinates toCoordinates,
[NotNullWhen(true)] out TakeAmmoEvent? args)
{
toCoordinates = EntityCoordinates.Invalid;
fromCoordinates = EntityCoordinates.Invalid;
args = null;
if (!CanShoot(user, gunUid, gun))
return false;
if (gun.ShootCoordinates == null)
return false;
toCoordinates = gun.ShootCoordinates.Value;
var curTime = Timing.CurTime;
var fireRate = TimeSpan.FromSeconds(1f / gun.FireRateModified);
// First shot
@@ -375,11 +309,10 @@ public abstract partial class SharedGunSystem : EntitySystem
}
gun.NextFire = TimeSpan.FromSeconds(Math.Max(lastFire.TotalSeconds + SafetyNextFire, gun.NextFire.TotalSeconds));
return false;
return;
}
fromCoordinates = Transform(user).Coordinates;
var fromCoordinates = Transform(user).Coordinates;
// Remove ammo
var ev = new TakeAmmoEvent(shots, new List<(EntityUid? Entity, IShootable Shootable)>(), fromCoordinates, user);
@@ -414,18 +347,24 @@ public abstract partial class SharedGunSystem : EntitySystem
// May cause prediction issues? Needs more tweaking
gun.NextFire = TimeSpan.FromSeconds(Math.Max(lastFire.TotalSeconds + SafetyNextFire, gun.NextFire.TotalSeconds));
Audio.PlayPredicted(gun.SoundEmpty, gunUid, user);
return false;
return;
}
return false;
return;
}
// Shoot confirmed - sounds also played here in case it's invalid (e.g. cartridge already spent).
Shoot(gunUid, gun, ev.Ammo, fromCoordinates, toCoordinates.Value, out var userImpulse, user, throwItems: attemptEv.ThrowItems);
var shotEv = new GunShotEvent(user, ev.Ammo);
RaiseLocalEvent(gunUid, ref shotEv);
args = ev;
return true;
if (userImpulse && TryComp<PhysicsComponent>(user, out var userPhysics))
{
if (_gravity.IsWeightless(user, userPhysics))
CauseImpulse(fromCoordinates, toCoordinates.Value, user, userPhysics);
}
Dirty(gunUid, gun);
}
public void Shoot(