mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
Accidental Discharges (#3869)
* why does this keep crashing * its real * 12.5% -> 10% * dependencyops * commentops * changeops
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user