Merge branch 'final-version' into upupup

This commit is contained in:
Aviu00
2024-02-05 10:24:33 +03:00
1189 changed files with 31542 additions and 354012 deletions

View File

@@ -1,5 +1,6 @@
using System.Numerics;
using Robust.Shared.GameStates;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Weapons.Melee.Components;
@@ -89,6 +90,12 @@ public sealed partial class MeleeThrownComponent : Component
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoNetworkedField]
public TimeSpan MinLifetimeTime;
/// <summary>
/// the status to which the entity will return when the thrown ends
/// </summary>
[DataField]
public BodyStatus PreviousStatus;
}
/// <summary>

View File

@@ -71,6 +71,7 @@ public sealed class MeleeThrowOnHitSystem : EntitySystem
(body.BodyType & (BodyType.Dynamic | BodyType.KinematicController)) == 0x0)
return;
comp.PreviousStatus = body.BodyStatus;
comp.ThrownEndTime = _timing.CurTime + TimeSpan.FromSeconds(comp.Lifetime);
comp.MinLifetimeTime = _timing.CurTime + TimeSpan.FromSeconds(comp.MinLifetime);
_physics.SetBodyStatus(body, BodyStatus.InAir);
@@ -82,7 +83,7 @@ public sealed class MeleeThrowOnHitSystem : EntitySystem
private void OnThrownShutdown(Entity<MeleeThrownComponent> ent, ref ComponentShutdown args)
{
if (TryComp<PhysicsComponent>(ent, out var body))
_physics.SetBodyStatus(body, BodyStatus.OnGround);
_physics.SetBodyStatus(body,ent.Comp.PreviousStatus);
var ev = new MeleeThrowOnHitEndEvent();
RaiseLocalEvent(ent, ref ev);
}

View File

@@ -534,24 +534,10 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
$"{ToPrettyString(user):actor} melee attacked (light) {ToPrettyString(target.Value):subject} using {ToPrettyString(meleeUid):tool} and dealt {damageResult.GetTotal():damage} damage");
}
PlayHitSound(target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
}
else
{
if (hitEvent.HitSoundOverride != null)
{
Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user);
}
else if (!GetDamage(meleeUid, user, component).Any() && component.HitSound != null)
{
Audio.PlayPredicted(component.HitSound, meleeUid, user);
}
else
{
Audio.PlayPredicted(component.NoDamageSound, meleeUid, user);
}
}
PlayHitSound(target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound, component.NoDamageSound);
if (damageResult?.GetTotal() > FixedPoint2.Zero)
{
DoDamageEffect(targets, user, targetXform);
@@ -687,22 +673,8 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (entities.Count != 0)
{
if (appliedDamage.GetTotal() > FixedPoint2.Zero)
{
var target = entities.First();
PlayHitSound(target, user, GetHighestDamageSound(appliedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
}
else
{
if (hitEvent.HitSoundOverride != null)
{
Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user);
}
else
{
Audio.PlayPredicted(component.NoDamageSound, meleeUid, user);
}
}
var target = entities.First();
PlayHitSound(target, user, GetHighestDamageSound(appliedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound, component.NoDamageSound);
}
if (appliedDamage.GetTotal() > FixedPoint2.Zero)
@@ -746,7 +718,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
return true;
}
public void PlayHitSound(EntityUid target, EntityUid? user, string? type, SoundSpecifier? hitSoundOverride, SoundSpecifier? hitSound)
public void PlayHitSound(EntityUid target, EntityUid? user, string? type, SoundSpecifier? hitSoundOverride, SoundSpecifier? hitSound, SoundSpecifier? noDamageSound)
{
var playedSound = false;
@@ -788,6 +760,11 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
Audio.PlayPredicted(hitSound, coords, user, AudioParams.Default.WithVariation(DamagePitchVariation));
playedSound = true;
}
else if (noDamageSound != null)
{
Audio.PlayPredicted(noDamageSound, coords, user, AudioParams.Default.WithVariation(DamagePitchVariation));
playedSound = true;
}
}
// Fallback to generic sounds.

View File

@@ -0,0 +1,45 @@
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// Allows battery weapons to fire different types of projectiles
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(BatteryWeaponFireModesSystem))]
[AutoGenerateComponentState]
public sealed partial class BatteryWeaponFireModesComponent : Component
{
/// <summary>
/// A list of the different firing modes the weapon can switch between
/// </summary>
[DataField(required: true)]
[AutoNetworkedField]
public List<BatteryWeaponFireMode> FireModes = new();
/// <summary>
/// The currently selected firing mode
/// </summary>
[DataField]
[AutoNetworkedField]
public int CurrentFireMode;
}
[DataDefinition, Serializable, NetSerializable]
public sealed partial class BatteryWeaponFireMode
{
/// <summary>
/// The projectile prototype associated with this firing mode
/// </summary>
[DataField("proto", required: true)]
public EntProtoId Prototype = default!;
/// <summary>
/// The battery cost to fire the projectile associated with this firing mode
/// </summary>
[DataField]
public float FireCost = 100;
}

View File

@@ -1,30 +1,41 @@
using Content.Shared.Damage;
using Content.Shared.Tag;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Weapons.Ranged.Components;
[RegisterComponent, NetworkedComponent, Virtual]
[AutoGenerateComponentState]
public partial class GunComponent : Component
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedGunSystem))]
public sealed partial class GunComponent : Component
{
#region Sound
[ViewVariables(VVAccess.ReadWrite), DataField("soundGunshot")]
public SoundSpecifier? SoundGunshot { get; set; } = new SoundPathSpecifier("/Audio/Weapons/Guns/Gunshots/smg.ogg");
/// <summary>
/// The base sound to use when the gun is fired.
/// </summary>
[DataField]
public SoundSpecifier? SoundGunshot = new SoundPathSpecifier("/Audio/Weapons/Guns/Gunshots/smg.ogg");
[ViewVariables(VVAccess.ReadWrite), DataField("soundEmpty")]
/// <summary>
/// The sound to use when the gun is fired.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? SoundGunshotModified;
[DataField]
public SoundSpecifier? SoundEmpty = new SoundPathSpecifier("/Audio/Weapons/Guns/Empty/empty.ogg");
/// <summary>
/// Sound played when toggling the <see cref="SelectedMode"/> for this gun.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("soundMode")]
public SoundSpecifier? SoundModeToggle = new SoundPathSpecifier("/Audio/Weapons/Guns/Misc/selector.ogg");
[DataField]
public SoundSpecifier? SoundMode = new SoundPathSpecifier("/Audio/Weapons/Guns/Misc/selector.ogg");
#endregion
@@ -32,59 +43,94 @@ public partial class GunComponent : Component
// These values are very small for now until we get a debug overlay and fine tune it
/// <summary>
/// The base scalar value applied to the vector governing camera recoil.
/// </summary>
[DataField, AutoNetworkedField]
public float CameraRecoilScalar = 1f;
/// <summary>
/// A scalar value applied to the vector governing camera recoil.
/// If 0, there will be no camera recoil.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[DataField("cameraRecoilScalar"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float CameraRecoilScalar = 1f;
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public float CameraRecoilScalarModified = 1f;
/// <summary>
/// Last time the gun fired.
/// Used for recoil purposes.
/// </summary>
[DataField("lastFire")]
[DataField]
public TimeSpan LastFire = TimeSpan.Zero;
/// <summary>
/// What the current spread is for shooting. This gets changed every time the gun fires.
/// </summary>
[DataField("currentAngle")]
[DataField]
[AutoNetworkedField]
public Angle CurrentAngle;
/// <summary>
/// How much the spread increases every time the gun fires.
/// The base value for how much the spread increases every time the gun fires.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("angleIncrease")]
[DataField]
public Angle AngleIncrease = Angle.FromDegrees(0.5);
/// <summary>
/// How much the <see cref="CurrentAngle"/> decreases per second.
/// How much the spread increases every time the gun fires.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[DataField("angleDecay")]
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public Angle AngleIncreaseModified;
/// <summary>
/// The base value for how much the <see cref="CurrentAngle"/> decreases per second.
/// </summary>
[DataField]
public Angle AngleDecay = Angle.FromDegrees(4);
/// <summary>
/// The maximum angle allowed for <see cref="CurrentAngle"/>
/// How much the <see cref="CurrentAngle"/> decreases per second.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("maxAngle")]
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public Angle AngleDecayModified;
/// <summary>
/// The base value for the maximum angle allowed for <see cref="CurrentAngle"/>
/// </summary>
[DataField]
[AutoNetworkedField]
public Angle MaxAngle = Angle.FromDegrees(2);
/// <summary>
/// The minimum angle allowed for <see cref="CurrentAngle"/>
/// The maximum angle allowed for <see cref="CurrentAngle"/>
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("minAngle")]
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public Angle MaxAngleModified;
/// <summary>
/// The base value for the minimum angle allowed for <see cref="CurrentAngle"/>
/// </summary>
[DataField]
[AutoNetworkedField]
public Angle MinAngle = Angle.FromDegrees(1);
/// <summary>
/// The minimum angle allowed for <see cref="CurrentAngle"/>.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public Angle MinAngleModified;
#endregion
/// <summary>
/// Whether this gun is shot via the use key or the alt-use key.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("useKey"), AutoNetworkedField]
[DataField, AutoNetworkedField]
public bool UseKey = true;
/// <summary>
@@ -93,6 +139,19 @@ public partial class GunComponent : Component
[ViewVariables]
public EntityCoordinates? ShootCoordinates = null;
/// <summary>
/// The base value for how many shots to fire per burst.
/// </summary>
[DataField, AutoNetworkedField]
public int ShotsPerBurst = 3;
/// <summary>
/// How many shots to fire per burst.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public int ShotsPerBurstModified = 3;
/// <summary>
/// Used for tracking semi-auto / burst
/// </summary>
@@ -101,55 +160,57 @@ public partial class GunComponent : Component
public int ShotCounter = 0;
/// <summary>
/// How many times it shoots per second.
/// The base value for how many times it shoots per second.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("fireRate")]
[DataField]
[AutoNetworkedField]
public float FireRate = 8f;
/// <summary>
/// How many times it shoots per second.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public float FireRateModified;
/// <summary>
/// Starts fire cooldown when equipped if true.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("resetOnHandSelected")]
[DataField]
public bool ResetOnHandSelected = true;
/// <summary>
/// Type of ammo the gun can work with
/// The base value for how fast the projectile moves.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("compatibleAmmo")]
public List<ProtoId<TagPrototype>>? CompatibleAmmo;
/// <summary>
/// Damage the gun deals when used with wrong ammo
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("damageOnWrongAmmo")]
public DamageSpecifier? DamageOnWrongAmmo = null;
[DataField]
public float ProjectileSpeed = 25f;
/// <summary>
/// How fast the projectile moves.
/// <seealso cref="GunRefreshModifiersEvent"/>
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("projectileSpeed")]
public float ProjectileSpeed = 25f;
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public float ProjectileSpeedModified;
/// <summary>
/// When the gun is next available to be shot.
/// Can be set multiple times in a single tick due to guns firing faster than a single tick time.
/// </summary>
[DataField("nextFire", customTypeSerializer:typeof(TimeOffsetSerializer))]
[DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
[AutoNetworkedField]
public TimeSpan NextFire = TimeSpan.Zero;
/// <summary>
/// What firemodes can be selected.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("availableModes")]
[DataField]
[AutoNetworkedField]
public SelectiveFire AvailableModes = SelectiveFire.SemiAuto;
/// <summary>
/// What firemode is currently selected.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("selectedMode")]
[DataField]
[AutoNetworkedField]
public SelectiveFire SelectedMode = SelectiveFire.SemiAuto;
@@ -157,14 +218,14 @@ public partial class GunComponent : Component
/// Whether or not information about
/// the gun will be shown on examine.
/// </summary>
[DataField("showExamineText")]
[DataField]
public bool ShowExamineText = true;
/// <summary>
/// Whether or not someone with the
/// clumsy trait can shoot this
/// </summary>
[DataField("clumsyProof"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool ClumsyProof = false;
// WD START

View File

@@ -0,0 +1,8 @@
namespace Content.Shared.Weapons.Ranged.Events;
/// <summary>
/// Raised directed on the gun entity when ammo is shot to calculate its spread.
/// </summary>
/// <param name="Spread">The spread of the ammo, can be changed by handlers.</param>
[ByRefEvent]
public record struct GunGetAmmoSpreadEvent(Angle Spread);

View File

@@ -0,0 +1,8 @@
namespace Content.Shared.Weapons.Ranged.Events;
/// <summary>
/// Raised directed on the gun entity when a muzzle flash is about to happen.
/// </summary>
/// <param name="Cancelled">If set to true, the muzzle flash will not be shown.</param>
[ByRefEvent]
public record struct GunMuzzleFlashAttemptEvent(bool Cancelled);

View File

@@ -0,0 +1,23 @@
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio;
namespace Content.Shared.Weapons.Ranged.Events;
/// <summary>
/// Raised directed on the gun entity when <see cref="SharedGunSystem.RefreshModifiers"/>
/// is called, to update the values of <see cref="GunComponent"/> from other systems.
/// </summary>
[ByRefEvent]
public record struct GunRefreshModifiersEvent(
Entity<GunComponent> Gun,
SoundSpecifier? SoundGunshot,
float CameraRecoilScalar,
Angle AngleIncrease,
Angle AngleDecay,
Angle MaxAngle,
Angle MinAngle,
int ShotsPerBurst,
float FireRate,
float ProjectileSpeed
);

View File

@@ -0,0 +1,113 @@
using System.Linq;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Prototypes;
namespace Content.Shared.Weapons.Ranged.Systems;
public sealed class BatteryWeaponFireModesSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ActivateInWorldEvent>(OnInteractHandEvent);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ExaminedEvent>(OnExamined);
}
private void OnExamined(EntityUid uid, BatteryWeaponFireModesComponent component, ExaminedEvent args)
{
if (component.FireModes.Count < 2)
return;
var fireMode = GetMode(component);
if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var proto))
return;
args.PushMarkup(Loc.GetString("gun-set-fire-mode", ("mode", proto.Name)));
}
private BatteryWeaponFireMode GetMode(BatteryWeaponFireModesComponent component)
{
return component.FireModes[component.CurrentFireMode];
}
private void OnGetVerb(EntityUid uid, BatteryWeaponFireModesComponent component, GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
return;
if (component.FireModes.Count < 2)
return;
for (var i = 0; i < component.FireModes.Count; i++)
{
var fireMode = component.FireModes[i];
var entProto = _prototypeManager.Index<EntityPrototype>(fireMode.Prototype);
var index = i;
var v = new Verb
{
Priority = 1,
Category = VerbCategory.SelectType,
Text = entProto.Name,
Disabled = i == component.CurrentFireMode,
Impact = LogImpact.Low,
DoContactInteraction = true,
Act = () =>
{
SetFireMode(uid, component, index, args.User);
}
};
args.Verbs.Add(v);
}
}
private void OnInteractHandEvent(EntityUid uid, BatteryWeaponFireModesComponent component, ActivateInWorldEvent args)
{
if (component.FireModes.Count < 2)
return;
CycleFireMode(uid, component, args.User);
}
private void CycleFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, EntityUid user)
{
if (component.FireModes.Count < 2)
return;
var index = (component.CurrentFireMode + 1) % component.FireModes.Count;
SetFireMode(uid, component, index, user);
}
private void SetFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, int index, EntityUid? user = null)
{
var fireMode = component.FireModes[index];
component.CurrentFireMode = index;
Dirty(uid, component);
if (TryComp(uid, out ProjectileBatteryAmmoProviderComponent? projectileBatteryAmmoProvider))
{
if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var prototype))
return;
projectileBatteryAmmoProvider.Prototype = fireMode.Prototype;
projectileBatteryAmmoProvider.FireCost = fireMode.FireCost;
if (user != null)
{
_popupSystem.PopupClient(Loc.GetString("gun-set-fire-mode", ("mode", prototype.Name)), uid, user.Value);
}
}
}
}

View File

@@ -195,10 +195,10 @@ public abstract partial class SharedGunSystem
// Reset shotting for cycling
if (Resolve(uid, ref gunComp, false) &&
gunComp is { FireRate: > 0f } &&
gunComp is { FireRateModified: > 0f } &&
!Paused(uid))
{
gunComp.NextFire = Timing.CurTime + TimeSpan.FromSeconds(1 / gunComp.FireRate);
gunComp.NextFire = Timing.CurTime + TimeSpan.FromSeconds(1 / gunComp.FireRateModified);
}
Dirty(uid, component);

View File

@@ -19,7 +19,7 @@ public abstract partial class SharedGunSystem
args.PushMarkup(Loc.GetString("gun-selected-mode-examine", ("color", ModeExamineColor),
("mode", GetLocSelector(component.SelectedMode))));
args.PushMarkup(Loc.GetString("gun-fire-rate-examine", ("color", FireRateExamineColor),
("fireRate", $"{component.FireRate:0.0}")));
("fireRate", $"{component.FireRateModified:0.0}")));
if (!TryComp<TwoModeEnergyAmmoProviderComponent>(uid, out var comp))
return;
@@ -91,7 +91,7 @@ public abstract partial class SharedGunSystem
component.NextFire += cooldown;
}
Audio.PlayPredicted(component.SoundModeToggle, uid, user);
Audio.PlayPredicted(component.SoundMode, uid, user);
Popup(Loc.GetString("gun-selected-mode", ("mode", GetLocSelector(fire))), uid, user);
Dirty(uid, component);
}
@@ -123,7 +123,7 @@ public abstract partial class SharedGunSystem
private void OnGunSelected(EntityUid uid, GunComponent component, HandSelectedEvent args)
{
var fireDelay = 1f / component.FireRate;
var fireDelay = 1f / component.FireRateModified;
if (fireDelay.Equals(0f))
return;

View File

@@ -69,7 +69,7 @@ public abstract partial class SharedGunSystem : EntitySystem
private const float EjectOffset = 0.4f;
protected const string AmmoExamineColor = "yellow";
protected const string FireRateExamineColor = "yellow";
protected const string ModeExamineColor = "cyan";
public const string ModeExamineColor = "cyan";
protected const string TwoModeExamineColor = "red";
public override void Initialize()
@@ -97,18 +97,19 @@ public abstract partial class SharedGunSystem : EntitySystem
SubscribeLocalEvent<GunComponent, CycleModeEvent>(OnCycleMode);
SubscribeLocalEvent<GunComponent, HandSelectedEvent>(OnGunSelected);
SubscribeLocalEvent<GunComponent, EntityUnpausedEvent>(OnGunUnpaused);
#if DEBUG
SubscribeLocalEvent<GunComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(EntityUid uid, GunComponent component, MapInitEvent args)
private void OnMapInit(Entity<GunComponent> gun, ref MapInitEvent args)
{
if (component.NextFire > Timing.CurTime)
Log.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(uid)}");
#if DEBUG
if (gun.Comp.NextFire > Timing.CurTime)
Log.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(gun)}");
DebugTools.Assert((component.AvailableModes & component.SelectedMode) != 0x0);
DebugTools.Assert((gun.Comp.AvailableModes & gun.Comp.SelectedMode) != 0x0);
#endif
RefreshModifiers((gun, gun));
}
private void OnGunMelee(EntityUid uid, GunComponent component, MeleeHitEvent args)
@@ -231,7 +232,7 @@ public abstract partial class SharedGunSystem : EntitySystem
private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
{
if (gun.FireRate <= 0f ||
if (gun.FireRateModified <= 0f ||
!_actionBlockerSystem.CanAttack(user))
return;
@@ -261,7 +262,7 @@ public abstract partial class SharedGunSystem : EntitySystem
if (gun.NextFire > curTime)
return;
var fireRate = TimeSpan.FromSeconds(1f / gun.FireRate);
var fireRate = TimeSpan.FromSeconds(1f / gun.FireRateModified);
// First shot
// Previously we checked shotcounter but in some cases all the bullets got dumped at once
@@ -293,7 +294,7 @@ public abstract partial class SharedGunSystem : EntitySystem
shots = Math.Min(shots, 1 - gun.ShotCounter);
break;
case SelectiveFire.Burst:
shots = Math.Min(shots, 3 - gun.ShotCounter);
shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter);
break;
case SelectiveFire.FullAuto:
break;
@@ -474,6 +475,11 @@ public abstract partial class SharedGunSystem : EntitySystem
protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid? user = null)
{
var attemptEv = new GunMuzzleFlashAttemptEvent();
RaiseLocalEvent(gun, ref attemptEv);
if (attemptEv.Cancelled)
return;
var sprite = component.MuzzleFlash;
if (sprite == null)
@@ -493,6 +499,41 @@ public abstract partial class SharedGunSystem : EntitySystem
var impulseVector = shotDirection * impulseStrength;
Physics.ApplyLinearImpulse(user, -impulseVector, body: userPhysics);
}
public void RefreshModifiers(Entity<GunComponent?> gun)
{
if (!Resolve(gun, ref gun.Comp))
return;
var comp = gun.Comp;
var ev = new GunRefreshModifiersEvent(
(gun, comp),
comp.SoundGunshot,
comp.CameraRecoilScalar,
comp.AngleIncrease,
comp.AngleDecay,
comp.MaxAngle,
comp.MinAngle,
comp.ShotsPerBurst,
comp.FireRate,
comp.ProjectileSpeed
);
RaiseLocalEvent(gun, ref ev);
comp.SoundGunshotModified = ev.SoundGunshot;
comp.CameraRecoilScalarModified = ev.CameraRecoilScalar;
comp.AngleIncreaseModified = ev.AngleIncrease;
comp.AngleDecayModified = ev.AngleDecay;
comp.MaxAngleModified = ev.MaxAngle;
comp.MinAngleModified = ev.MinAngle;
comp.ShotsPerBurstModified = ev.ShotsPerBurst;
comp.FireRateModified = ev.FireRate;
comp.ProjectileSpeedModified = ev.ProjectileSpeed;
Dirty(gun);
}
protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null);
/// <summary>