Files
tbd-station-14/Content.Server/GameObjects/Components/Mobs/ClumsyComponent.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

39 lines
1.2 KiB
C#

using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Random;
#nullable enable
namespace Content.Server.GameObjects.Components.Mobs
{
/// <summary>
/// A simple clumsy tag-component.
/// </summary>
[RegisterComponent]
public class ClumsyComponent : Component
{
[Dependency] private readonly IRobustRandom _random = default!;
public override string Name => "Clumsy";
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(IEntity entity, float chance)
{
return entity.TryGetComponent(out ClumsyComponent? clumsy)
&& clumsy.RollClumsy(chance);
}
}
}