Cleanup ExecutionSystem (#24382)
* Creat Execution Component and add to sharp items * Kill Server ExecutionSystem. Create ExecutionSystem in shared. Create ActiveExecution Component. Transferred the Execution system into shared. Heavily re-wrote the system in order to reduce duplication, and remove gun code from the system. The melee weapon modifier which was dependant on swing rate was removed. The ActiveExecutionComponent was created in order to apply the damage modifier to the shot from a gun execution. It is added just before the gun fires and removed after an attempt is made. * Fix bugs The execution completed text will now only show up if the gun fires. The client also no longer crashes because I forgot to network the component. * Remove clumsy text * Make BaseSword abstract * Add ExecutionComponent to every weapon * Fix bug * Remove execution comp from battery weapons Currently the gun system does not have a way to alter hitscan damage like it does with projectiles. * Cleanup * Revert "Remove clumsy text" This reverts commit a46da6448d5d179a4e936f9213d5622bedb58a16. * Actually fix the ExecutionSystem Everything about the shot goes through the gun system now. The Damage multiplier is only applied when a projectile impacts the target so people that get in the way don't get hit with 9 times damage for no reason. In order to make suicides work I needed to create fake EntityCoordinates because the gun system and the projectile system do not play well with a projectile that has the same start and end position. * Make launchers able to execute * Fix prediction bug The OnAmmoShotEvent is only raised on the server. * Readd ability for clowns to accidentally shoot themselves while executing * Cleanup * Reset melee cooldown to initial value * Address reviews fix bug Addressed reviews on overriding messages. Now I actually mark doafters as handled. Return normal cooldown to some meleeweapons I forgot on the previous commit. * Address Reviews Remove duplication * Exorcise codebase Remove evil null coercion that I was sure I removed a while ago * Address reviews again * Remove melee weapon attack logic and rely on the system. Remove gun and melee checks. * Make system functional again and cleanup * Remove code I forgot to remove * Cleanup * stalled * Selectively revert gun penetration The collision layer check doesn't work and I don't have time to fix it. * Fixes --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ using Content.Server.Administration.Logs;
|
||||
using Content.Server.Cargo.Systems;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Projectiles;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Weapons.Ranged.Components;
|
||||
using Content.Shared.Damage;
|
||||
@@ -29,13 +30,13 @@ namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed partial class GunSystem : SharedGunSystem
|
||||
{
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
[Dependency] private readonly BatterySystem _battery = default!;
|
||||
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
|
||||
[Dependency] private readonly InteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly PricingSystem _pricing = default!;
|
||||
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
|
||||
[Dependency] private readonly ProjectileSystem _projectile = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly StaminaSystem _stamina = default!;
|
||||
[Dependency] private readonly StunSystem _stun = default!;
|
||||
@@ -65,6 +66,137 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
args.Price += price * component.UnspawnedCount;
|
||||
}
|
||||
|
||||
protected override bool ShootDirect(EntityUid gunUid, GunComponent gun, EntityUid target, List<(EntityUid? Entity, IShootable Shootable)> ammo, EntityUid user)
|
||||
{
|
||||
var result = false;
|
||||
|
||||
// TODO: This is dogshit. I just want to get executions slightly better.
|
||||
// Ideally you'd pull out cartridge + ammo to separate handling functions and re-use it here, then hitscan you need to bypass entirely.
|
||||
// You should also make shooting into a struct of args given how many there are now.
|
||||
var fromCoordinates = Transform(gunUid).Coordinates;
|
||||
var toCoordinates = Transform(target).Coordinates;
|
||||
|
||||
var fromMap = fromCoordinates.ToMap(EntityManager, TransformSystem);
|
||||
var toMap = toCoordinates.ToMapPos(EntityManager, TransformSystem);
|
||||
var mapDirection = toMap - fromMap.Position;
|
||||
var angle = GetRecoilAngle(Timing.CurTime, gun, mapDirection.ToAngle());
|
||||
|
||||
// If applicable, this ensures the projectile is parented to grid on spawn, instead of the map.
|
||||
var fromEnt = MapManager.TryFindGridAt(fromMap, out var gridUid, out _)
|
||||
? fromCoordinates.WithEntityId(gridUid, EntityManager)
|
||||
: new EntityCoordinates(MapManager.GetMapEntityId(fromMap.MapId), fromMap.Position);
|
||||
|
||||
// I must be high because this was getting tripped even when true.
|
||||
// DebugTools.Assert(direction != Vector2.Zero);
|
||||
var shotProjectiles = new List<EntityUid>(ammo.Count);
|
||||
var cartridgeBullets = new List<EntityUid>();
|
||||
|
||||
foreach (var (ent, shootable) in ammo)
|
||||
{
|
||||
switch (shootable)
|
||||
{
|
||||
// Cartridge shoots something else
|
||||
case CartridgeAmmoComponent cartridge:
|
||||
if (!cartridge.Spent)
|
||||
{
|
||||
for (var i = 0; i < cartridge.Count; i++)
|
||||
{
|
||||
var uid = Spawn(cartridge.Prototype, fromEnt);
|
||||
cartridgeBullets.Add(uid);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(ent!.Value, new AmmoShotEvent()
|
||||
{
|
||||
FiredProjectiles = cartridgeBullets,
|
||||
});
|
||||
|
||||
shotProjectiles.AddRange(cartridgeBullets);
|
||||
cartridgeBullets.Clear();
|
||||
SetCartridgeSpent(ent.Value, cartridge, true);
|
||||
MuzzleFlash(gunUid, cartridge, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
|
||||
if (cartridge.DeleteOnSpawn)
|
||||
Del(ent.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Audio.PlayPredicted(gun.SoundEmpty, gunUid, user);
|
||||
}
|
||||
|
||||
// Something like ballistic might want to leave it in the container still
|
||||
if (!cartridge.DeleteOnSpawn && !Containers.IsEntityInContainer(ent!.Value))
|
||||
EjectCartridge(ent.Value, angle);
|
||||
|
||||
result = true;
|
||||
Dirty(ent!.Value, cartridge);
|
||||
break;
|
||||
// Ammo shoots itself
|
||||
case AmmoComponent newAmmo:
|
||||
result = true;
|
||||
shotProjectiles.Add(ent!.Value);
|
||||
MuzzleFlash(gunUid, newAmmo, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
break;
|
||||
case HitscanPrototype hitscan:
|
||||
result = true;
|
||||
var hitEntity = target;
|
||||
if (hitscan.StaminaDamage > 0f)
|
||||
_stamina.TakeStaminaDamage(hitEntity, hitscan.StaminaDamage, source: user);
|
||||
|
||||
var dmg = hitscan.Damage;
|
||||
|
||||
var hitName = ToPrettyString(hitEntity);
|
||||
if (dmg != null)
|
||||
dmg = Damageable.TryChangeDamage(hitEntity, dmg, origin: user);
|
||||
|
||||
// check null again, as TryChangeDamage returns modified damage values
|
||||
if (dmg != null)
|
||||
{
|
||||
if (!Deleted(hitEntity))
|
||||
{
|
||||
if (dmg.Any())
|
||||
{
|
||||
_color.RaiseEffect(Color.Red, new List<EntityUid>() { hitEntity }, Filter.Pvs(hitEntity, entityManager: EntityManager));
|
||||
}
|
||||
|
||||
// TODO get fallback position for playing hit sound.
|
||||
PlayImpactSound(hitEntity, dmg, hitscan.Sound, hitscan.ForceSound);
|
||||
}
|
||||
|
||||
Logs.Add(LogType.HitScanHit,
|
||||
$"{ToPrettyString(user):user} hit {hitName:target} using hitscan and dealt {dmg.GetTotal():damage} damage");
|
||||
}
|
||||
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var ammoUid in shotProjectiles)
|
||||
{
|
||||
// TODO: Handle this shit
|
||||
if (!TryComp(ammoUid, out ProjectileComponent? projectileComponent))
|
||||
{
|
||||
QueueDel(ammoUid);
|
||||
continue;
|
||||
}
|
||||
|
||||
_projectile.TryHandleProjectile(target, (ammoUid, projectileComponent));
|
||||
// Even this deletion handling is mega sussy.
|
||||
Del(ammoUid);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(gunUid, new AmmoShotEvent()
|
||||
{
|
||||
FiredProjectiles = shotProjectiles,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid? Entity, IShootable Shootable)> ammo,
|
||||
EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, out bool userImpulse, EntityUid? user = null, bool throwItems = false)
|
||||
{
|
||||
@@ -72,7 +204,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
|
||||
// Try a clumsy roll
|
||||
// TODO: Who put this here
|
||||
if (TryComp<ClumsyComponent>(user, out var clumsy) && gun.ClumsyProof == false)
|
||||
if (TryComp<ClumsyComponent>(user, out var clumsy) && !gun.ClumsyProof)
|
||||
{
|
||||
for (var i = 0; i < ammo.Count; i++)
|
||||
{
|
||||
@@ -93,6 +225,8 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
}
|
||||
}
|
||||
|
||||
// As the above message wasn't obvious stop putting stuff here and use events
|
||||
|
||||
var fromMap = fromCoordinates.ToMap(EntityManager, TransformSystem);
|
||||
var toMap = toCoordinates.ToMapPos(EntityManager, TransformSystem);
|
||||
var mapDirection = toMap - fromMap.Position;
|
||||
@@ -100,7 +234,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
var angle = GetRecoilAngle(Timing.CurTime, gun, mapDirection.ToAngle());
|
||||
|
||||
// If applicable, this ensures the projectile is parented to grid on spawn, instead of the map.
|
||||
var fromEnt = MapManager.TryFindGridAt(fromMap, out var gridUid, out var grid)
|
||||
var fromEnt = MapManager.TryFindGridAt(fromMap, out var gridUid, out _)
|
||||
? fromCoordinates.WithEntityId(gridUid, EntityManager)
|
||||
: new EntityCoordinates(MapManager.GetMapEntityId(fromMap.MapId), fromMap.Position);
|
||||
|
||||
@@ -112,6 +246,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
// I must be high because this was getting tripped even when true.
|
||||
// DebugTools.Assert(direction != Vector2.Zero);
|
||||
var shotProjectiles = new List<EntityUid>(ammo.Count);
|
||||
var cartridgeBullets = new List<EntityUid>();
|
||||
|
||||
foreach (var (ent, shootable) in ammo)
|
||||
{
|
||||
@@ -140,21 +275,23 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
{
|
||||
var uid = Spawn(cartridge.Prototype, fromEnt);
|
||||
ShootOrThrow(uid, angles[i].ToVec(), gunVelocity, gun, gunUid, user);
|
||||
shotProjectiles.Add(uid);
|
||||
cartridgeBullets.Add(uid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var uid = Spawn(cartridge.Prototype, fromEnt);
|
||||
ShootOrThrow(uid, mapDirection, gunVelocity, gun, gunUid, user);
|
||||
shotProjectiles.Add(uid);
|
||||
cartridgeBullets.Add(uid);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(ent!.Value, new AmmoShotEvent()
|
||||
{
|
||||
FiredProjectiles = shotProjectiles,
|
||||
FiredProjectiles = cartridgeBullets,
|
||||
});
|
||||
|
||||
shotProjectiles.AddRange(cartridgeBullets);
|
||||
cartridgeBullets.Clear();
|
||||
SetCartridgeSpent(ent.Value, cartridge, true);
|
||||
MuzzleFlash(gunUid, cartridge, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
|
||||
Reference in New Issue
Block a user