Fix gun clumsy (#11246)

This commit is contained in:
metalgearsloth
2022-09-13 23:52:36 +10:00
committed by GitHub
parent 6596534390
commit fed0c0c108
7 changed files with 64 additions and 29 deletions

View File

@@ -1,5 +1,4 @@
using Content.Shared.Damage;
using Robust.Shared.Random;
namespace Content.Server.Interaction.Components
{
@@ -9,28 +8,8 @@ namespace Content.Server.Interaction.Components
[RegisterComponent]
public sealed class ClumsyComponent : Component
{
[Dependency] private readonly IRobustRandom _random = default!;
[DataField("clumsyDamage", required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier ClumsyDamage = default!;
public bool RollClumsy(float chance)
{
return Running && _random.Prob(chance);
}
/// <summary>
/// Rolls a probability chance for a "bad action" if the target entity is clumsy.
/// </summary>
/// <param name="entity">The entity that the clumsy check is happening for.</param>
/// <param name="chance">
/// The chance that a "bad action" happens if the user is clumsy, between 0 and 1 inclusive.
/// </param>
/// <returns>True if a "bad action" happened, false if the normal action should happen.</returns>
public static bool TryRollClumsy(EntityUid entity, float chance)
{
return IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClumsyComponent? clumsy)
&& clumsy.RollClumsy(chance);
}
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.Interaction.Components;
using Robust.Shared.Random;
namespace Content.Server.Interaction;
public sealed partial class InteractionSystem
{
public bool RollClumsy(ClumsyComponent component, float chance)
{
return component.Running && _random.Prob(chance);
}
/// <summary>
/// Rolls a probability chance for a "bad action" if the target entity is clumsy.
/// </summary>
/// <param name="entity">The entity that the clumsy check is happening for.</param>
/// <param name="chance">
/// The chance that a "bad action" happens if the user is clumsy, between 0 and 1 inclusive.
/// </param>
/// <returns>True if a "bad action" happened, false if the normal action should happen.</returns>
public bool TryRollClumsy(EntityUid entity, float chance, ClumsyComponent? component = null)
{
return Resolve(entity, ref component, false) && RollClumsy(component, chance);
}
}

View File

@@ -19,6 +19,7 @@ using Robust.Shared.Containers;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Players;
using Robust.Shared.Random;
using static Content.Shared.Storage.SharedStorageComponent;
namespace Content.Server.Interaction
@@ -27,11 +28,12 @@ namespace Content.Server.Interaction
/// Governs interactions during clicking on entities
/// </summary>
[UsedImplicitly]
public sealed class InteractionSystem : SharedInteractionSystem
public sealed partial class InteractionSystem : SharedInteractionSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly PullingSystem _pullSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!;