-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add partial GunComponent with drop chance,
make FireOnDropSystem shared, use drop chance per component instead of a hardcoded value
- Loading branch information
1 parent
b0c1c1b
commit d4c4d0c
Showing
3 changed files
with
37 additions
and
35 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
Content.Server/SimpleStation14/Weapons/Ranged/Systems/FireOnDropSystem.cs
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Content.Shared/SimpleStation14/Weapons/Ranged/Components/GunComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
29 changes: 29 additions & 0 deletions
29
Content.Shared/SimpleStation14/Weapons/Ranged/Systems/FireOnDropSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |