Files
tbd-station-14/Content.Server/Interaction/Components/ClumsyComponent.cs
Ephememory 8b1a711843 Fix clown not being clumsy (#5208)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2022-02-17 01:24:38 +11:00

39 lines
1.4 KiB
C#

using Content.Shared.Damage;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.Interaction.Components
{
/// <summary>
/// A simple clumsy tag-component.
/// </summary>
[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);
}
}
}