2022-02-16 08:24:38 -06:00
|
|
|
using Content.Shared.Damage;
|
2020-07-26 14:08:09 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-01-23 17:54:58 +01:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Interaction.Components
|
2020-07-26 14:08:09 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A simple clumsy tag-component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ClumsyComponent : Component
|
2020-07-26 14:08:09 +02:00
|
|
|
{
|
2021-01-23 17:54:58 +01:00
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
|
2022-02-16 08:24:38 -06:00
|
|
|
[DataField("clumsyDamage", required: true)]
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public DamageSpecifier ClumsyDamage = default!;
|
2021-01-23 17:54:58 +01:00
|
|
|
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>
|
2021-12-05 18:09:01 +01:00
|
|
|
public static bool TryRollClumsy(EntityUid entity, float chance)
|
2021-01-23 17:54:58 +01:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
return IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClumsyComponent? clumsy)
|
2021-01-23 17:54:58 +01:00
|
|
|
&& clumsy.RollClumsy(chance);
|
|
|
|
|
}
|
2020-07-26 14:08:09 +02:00
|
|
|
}
|
|
|
|
|
}
|