Skip to content

Commit

Permalink
add partial GunComponent with drop chance,
Browse files Browse the repository at this point in the history
make FireOnDropSystem shared,
use drop chance per component instead of a hardcoded value
  • Loading branch information
DEATHB4DEFEAT committed Nov 4, 2023
1 parent b0c1c1b commit d4c4d0c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ReSharper disable once CheckNamespace // Extending the GunComponent to add a variable
namespace Content.Shared.Weapons.Ranged.Components;

public partial class GunComponent
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float FireOnDropChance = 0.1f;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared.Throwing;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Random;

namespace Content.Shared.SimpleStation14.Weapons.Ranged.Systems;

public sealed class FireOnDropSystem : EntitySystem
{
[Dependency] private readonly SharedGunSystem _gun = default!;
[Dependency] private readonly IRobustRandom _random = default!;


public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<GunComponent, LandEvent>(HandleLand);
}


private void HandleLand(EntityUid uid, GunComponent component, ref LandEvent args)
{
if (_random.Prob(component.FireOnDropChance))
// The gun fires itself (weird), with the target being its own position offset by its rotation as a point vector.
// The result being that it will always fire the direction that all gun sprites point in.
_gun.AttemptShoot(uid, uid, component, Transform(uid).Coordinates.Offset(Transform(uid).LocalRotation.ToVec()));
}
}

0 comments on commit d4c4d0c

Please sign in to comment.