Accidental Discharges (#3869)

* why does this keep crashing

* its real

* 12.5% -> 10%

* dependencyops

* commentops

* changeops
This commit is contained in:
KOTOB
2025-06-01 06:55:56 +00:00
committed by GitHub
parent af66ff5f98
commit b7c3da08dd
3 changed files with 43 additions and 0 deletions
@@ -0,0 +1,11 @@
namespace Content.Server._DV.Weapons.Ranged.Components;
[RegisterComponent]
public sealed partial class FireOnLandComponent : Component
{
/// <summary>
/// Chance to trigger.
/// </summary>
[DataField]
public float Probability = 0.1f;
}
@@ -0,0 +1,31 @@
using System.Numerics;
using Content.Server._DV.Weapons.Ranged.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Map;
using Robust.Shared.Random;
namespace Content.Server._DV.Weapons.Ranged.Systems;
public sealed class FireOnLandSystem : EntitySystem
{
[Dependency] private readonly GunSystem _gunSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FireOnLandComponent, LandEvent>(FireOnLand);
}
private void FireOnLand(Entity<FireOnLandComponent> ent, ref LandEvent args)
{
if (!_random.Prob(ent.Comp.Probability) || !TryComp(ent, out GunComponent? gc))
return;
var dir = gc.DefaultDirection;
dir = new Vector2(-dir.Y, dir.X); // 90 degrees counter-clockwise, guns shoot down by default
_gunSystem.AttemptShoot(ent, ent, gc, new EntityCoordinates(ent, dir));
}
}
@@ -68,6 +68,7 @@
- type: Appearance
- type: StaticPrice
price: 500
- type: FireOnLand # DeltaV - gun safety
- type: entity
name: viper