Adds ClumsyComponent.TryRollClumsy helper method.
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Random;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Mobs
|
namespace Content.Server.GameObjects.Components.Mobs
|
||||||
{
|
{
|
||||||
@@ -8,6 +14,27 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class ClumsyComponent : Component
|
public class ClumsyComponent : Component
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
|
||||||
public override string Name => "Clumsy";
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,9 +161,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
|||||||
|
|
||||||
_lastFireTime = curTime;
|
_lastFireTime = curTime;
|
||||||
|
|
||||||
if (ClumsyCheck &&
|
if (ClumsyCheck && ClumsyComponent.TryRollClumsy(user, ClumsyExplodeChance))
|
||||||
user.HasComponent<ClumsyComponent>() &&
|
|
||||||
_random.Prob(ClumsyExplodeChance))
|
|
||||||
{
|
{
|
||||||
var soundSystem = EntitySystem.Get<AudioSystem>();
|
var soundSystem = EntitySystem.Get<AudioSystem>();
|
||||||
soundSystem.PlayAtCoords("/Audio/Items/bikehorn.ogg",
|
soundSystem.PlayAtCoords("/Audio/Items/bikehorn.ogg",
|
||||||
|
|||||||
Reference in New Issue
Block a user