Add events for GunComponent values, muzzle flashes and cartridge spread (#24077)

* Add a modifier event for GunComponent values

* Add docs

* Add VV readwrite to modified values

* Add more docs

* More docs

* Add Gun parameter to GunRefreshModifiersEvent

* Add another event for handling cartridge spread

* Fix pneumatic speed
This commit is contained in:
DrSmugleaf
2024-01-28 15:32:42 -08:00
committed by GitHub
parent 556545e324
commit 4e8b1fb0d3
16 changed files with 284 additions and 90 deletions

View File

@@ -10,7 +10,6 @@ using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction.Components;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Melee;
@@ -19,11 +18,9 @@ using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Content.Shared.Weapons.Reflect;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
@@ -156,8 +153,11 @@ public sealed partial class GunSystem : SharedGunSystem
}
if (cartridge.Count > 1)
{
var angles = LinearSpread(mapAngle - cartridge.Spread / 2,
mapAngle + cartridge.Spread / 2, cartridge.Count);
var ev = new GunGetAmmoSpreadEvent(cartridge.Spread);
RaiseLocalEvent(gunUid, ref ev);
var angles = LinearSpread(mapAngle - ev.Spread / 2,
mapAngle + ev.Spread / 2, cartridge.Count);
for (var i = 0; i < cartridge.Count; i++)
{
@@ -180,7 +180,7 @@ public sealed partial class GunSystem : SharedGunSystem
SetCartridgeSpent(ent.Value, cartridge, true);
MuzzleFlash(gunUid, cartridge, user);
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
if (cartridge.DeleteOnSpawn)
Del(ent.Value);
@@ -201,7 +201,7 @@ public sealed partial class GunSystem : SharedGunSystem
case AmmoComponent newAmmo:
shotProjectiles.Add(ent!.Value);
MuzzleFlash(gunUid, newAmmo, user);
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
ShootOrThrow(ent.Value, mapDirection, gunVelocity, gun, gunUid, user);
break;
case HitscanPrototype hitscan:
@@ -288,7 +288,7 @@ public sealed partial class GunSystem : SharedGunSystem
FireEffects(fromEffect, hitscan.MaxLength, dir.ToAngle(), hitscan);
}
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
break;
default:
throw new ArgumentOutOfRangeException();
@@ -308,11 +308,11 @@ public sealed partial class GunSystem : SharedGunSystem
{
RemoveShootable(uid);
// TODO: Someone can probably yeet this a billion miles so need to pre-validate input somewhere up the call stack.
ThrowingSystem.TryThrow(uid, mapDirection, gun.ProjectileSpeed, user);
ThrowingSystem.TryThrow(uid, mapDirection, gun.ProjectileSpeedModified, user);
return;
}
ShootProjectile(uid, mapDirection, gunVelocity, gunUid, user, gun.ProjectileSpeed);
ShootProjectile(uid, mapDirection, gunVelocity, gunUid, user, gun.ProjectileSpeedModified);
}
/// <summary>
@@ -337,7 +337,7 @@ public sealed partial class GunSystem : SharedGunSystem
private Angle GetRecoilAngle(TimeSpan curTime, GunComponent component, Angle direction)
{
var timeSinceLastFire = (curTime - component.LastFire).TotalSeconds;
var newTheta = MathHelper.Clamp(component.CurrentAngle.Theta + component.AngleIncrease.Theta - component.AngleDecay.Theta * timeSinceLastFire, component.MinAngle.Theta, component.MaxAngle.Theta);
var newTheta = MathHelper.Clamp(component.CurrentAngle.Theta + component.AngleIncreaseModified.Theta - component.AngleDecayModified.Theta * timeSinceLastFire, component.MinAngleModified.Theta, component.MaxAngleModified.Theta);
component.CurrentAngle = new Angle(newTheta);
component.LastFire = component.NextFire;
@@ -345,7 +345,7 @@ public sealed partial class GunSystem : SharedGunSystem
var random = Random.NextFloat(-0.5f, 0.5f);
var spread = component.CurrentAngle.Theta * random;
var angle = new Angle(direction.Theta + component.CurrentAngle.Theta * random);
DebugTools.Assert(spread <= component.MaxAngle.Theta);
DebugTools.Assert(spread <= component.MaxAngleModified.Theta);
return angle;
}