* Create BuckleableComponent.cs * Add strap component and keybind to buckle targeted entity * Remove buckle keybind, turn it into a verb * Add moving and attaching the buckled entity to the strap * Fix reality collapsing when clicking on a buckled entity * Add strap position to buckle a mob in the standing or down position * Add new default strap position that makes no change to the mob's standing state * Add Strap component to office chairs and stools * Add Strap component to the pilot chair * Add buckled status effect icon * Add status effect click behaviour * Add buckling and unbuckling sounds * Change Buckle verb to only appear when an entity can be currently buckled * Rotate buckled entity in the direction of the seat * Disable entity rotation when buckled * Fix buckle rotation on beds * Buckling now finds the closest strap to the buckleable entity * Fix rotation when unbuckling an entity * Move buckle verb to StrapComponent * Added buckled entity unbuckle verb, range and interaction checks * Add checks for currently occupied straps * Add unbuckling entity if its respective strap component is removed * Add Clickable, InteractionOutline and Collidable components to bed * Add rotation property to strap component * Rename Buckleable to Buckle * Add Buckle and Strap sizes to buckle multiple entities in the same strap * Remove out of range popup message from strap verb GetData * Move BuckledTo setter logic to its methods * Fix Strap BuckledEntities being public * Fix not updating status when Buckle component is removed * Change BuckleComponent.BuckledTo to be of type StrapComponent * Fix NRE when unbuckling * Add buckle perspective messages * Fix not equals comparison in strap verb * Add added check to Strap TryAdd * Change buckle.ogg and unbuckle.ogg from stereo to mono * Remove -2f volume on buckle and unbuckle sounds * Add summary to Strap TryAdd and Remove methods * Make buckled entities unable to fall * Fix default strap position not rotating the buckled entity * Add downing after unbuckling an entity if it is knocked down * Prevent an entity from buckling onto itself Fixes stack overflow error * Disable recursive buckling * Add buckling onto straps by clicking them with an empty hand * Add recursive buckle check to the trybuckle method as well * Fix being able to click on a different strap to unbuckle from the current one * Merge TryUnbuckle and ForceUnbuckle with a force argument * Remove explicit unimplemented status effect clicking cases * Add documentation to EffectBlockerSystem and ActionBlockerSystem
325 lines
10 KiB
C#
325 lines
10 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Content.Server.GameObjects.EntitySystems;
|
|
using Content.Server.Mobs;
|
|
using Content.Shared.Audio;
|
|
using Content.Shared.GameObjects.Components.Mobs;
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.Timing;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
using Timer = Robust.Shared.Timers.Timer;
|
|
using Content.Shared.GameObjects.Components.Movement;
|
|
using Math = CannyFastMath.Math;
|
|
using MathF = CannyFastMath.MathF;
|
|
|
|
namespace Content.Server.GameObjects.Components.Mobs
|
|
{
|
|
[RegisterComponent]
|
|
[ComponentReference(typeof(SharedStunnableComponent))]
|
|
public class StunnableComponent : SharedStunnableComponent, IInteractHand
|
|
{
|
|
#pragma warning disable 649
|
|
[Dependency] private IGameTiming _gameTiming;
|
|
#pragma warning restore 649
|
|
|
|
private TimeSpan? _lastStun;
|
|
|
|
[ViewVariables] public TimeSpan? StunStart => _lastStun;
|
|
|
|
[ViewVariables]
|
|
public TimeSpan? StunEnd => _lastStun == null
|
|
? (TimeSpan?) null
|
|
: _gameTiming.CurTime +
|
|
(TimeSpan.FromSeconds(Math.Max(_stunnedTimer, Math.Max(_knockdownTimer, _slowdownTimer))));
|
|
|
|
private const int StunLevels = 8;
|
|
|
|
private bool _canHelp = true;
|
|
private float _stunCap = 20f;
|
|
private float _knockdownCap = 20f;
|
|
private float _slowdownCap = 20f;
|
|
private float _helpKnockdownRemove = 1f;
|
|
private float _helpInterval = 1f;
|
|
|
|
private float _stunnedTimer = 0f;
|
|
private float _knockdownTimer = 0f;
|
|
private float _slowdownTimer = 0f;
|
|
|
|
private string _stunTexture;
|
|
private CancellationTokenSource _statusRemoveCancellation = new CancellationTokenSource();
|
|
|
|
[ViewVariables] public override bool Stunned => _stunnedTimer > 0f;
|
|
[ViewVariables] public override bool KnockedDown => _knockdownTimer > 0f;
|
|
[ViewVariables] public override bool SlowedDown => _slowdownTimer > 0f;
|
|
[ViewVariables] public float StunCap => _stunCap;
|
|
[ViewVariables] public float KnockdownCap => _knockdownCap;
|
|
[ViewVariables] public float SlowdownCap => _slowdownCap;
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
serializer.DataField(ref _stunCap, "stunCap", 20f);
|
|
serializer.DataField(ref _knockdownCap, "knockdownCap", 20f);
|
|
serializer.DataField(ref _slowdownCap, "slowdownCap", 20f);
|
|
serializer.DataField(ref _helpInterval, "helpInterval", 1f);
|
|
serializer.DataField(ref _helpKnockdownRemove, "helpKnockdownRemove", 1f);
|
|
serializer.DataField(ref _stunTexture, "stunTexture",
|
|
"/Textures/Objects/Melee/stunbaton.rsi/stunbaton_off.png");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stuns the entity, disallowing it from doing many interactions temporarily.
|
|
/// </summary>
|
|
/// <param name="seconds">How many seconds the mob will stay stunned</param>
|
|
public void Stun(float seconds)
|
|
{
|
|
seconds = MathF.Min(_stunnedTimer + (seconds * StunTimeModifier), _stunCap);
|
|
|
|
if (seconds <= 0f)
|
|
return;
|
|
|
|
StandingStateHelper.DropAllItemsInHands(Owner, false);
|
|
|
|
_stunnedTimer = seconds;
|
|
_lastStun = _gameTiming.CurTime;
|
|
|
|
SetStatusEffect();
|
|
Dirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Knocks down the mob, making it fall to the ground.
|
|
/// </summary>
|
|
/// <param name="seconds">How many seconds the mob will stay on the ground</param>
|
|
public void Knockdown(float seconds)
|
|
{
|
|
seconds = MathF.Min(_knockdownTimer + (seconds * KnockdownTimeModifier), _knockdownCap);
|
|
|
|
if (seconds <= 0f)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StandingStateHelper.Down(Owner);
|
|
|
|
_knockdownTimer = seconds;
|
|
_lastStun = _gameTiming.CurTime;
|
|
|
|
SetStatusEffect();
|
|
Dirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applies knockdown and stun to the mob temporarily
|
|
/// </summary>
|
|
/// <param name="seconds">How many seconds the mob will be paralyzed</param>
|
|
public void Paralyze(float seconds)
|
|
{
|
|
Stun(seconds);
|
|
Knockdown(seconds);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Slows down the mob's walking/running speed temporarily
|
|
/// </summary>
|
|
/// <param name="seconds">How many seconds the mob will be slowed down</param>
|
|
/// <param name="walkModifierOverride">Walk speed modifier. Set to 0 or negative for default value. (0.5f)</param>
|
|
/// <param name="runModifierOverride">Run speed modifier. Set to 0 or negative for default value. (0.5f)</param>
|
|
public void Slowdown(float seconds, float walkModifierOverride = 0f, float runModifierOverride = 0f)
|
|
{
|
|
seconds = MathF.Min(_slowdownTimer + (seconds * SlowdownTimeModifier), _slowdownCap);
|
|
|
|
if (seconds <= 0f)
|
|
return;
|
|
|
|
WalkModifierOverride = walkModifierOverride;
|
|
RunModifierOverride = runModifierOverride;
|
|
|
|
_slowdownTimer = seconds;
|
|
_lastStun = _gameTiming.CurTime;
|
|
|
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
|
movement.RefreshMovementSpeedModifiers();
|
|
|
|
SetStatusEffect();
|
|
Dirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Used when
|
|
/// </summary>
|
|
public void CancelAll()
|
|
{
|
|
_knockdownTimer = 0f;
|
|
_stunnedTimer = 0f;
|
|
Dirty();
|
|
}
|
|
|
|
public bool InteractHand(InteractHandEventArgs eventArgs)
|
|
{
|
|
if (!_canHelp || !KnockedDown)
|
|
return false;
|
|
|
|
_canHelp = false;
|
|
Timer.Spawn(((int) _helpInterval * 1000), () => _canHelp = true);
|
|
|
|
EntitySystem.Get<AudioSystem>()
|
|
.PlayFromEntity("/Audio/effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.25f));
|
|
|
|
_knockdownTimer -= _helpKnockdownRemove;
|
|
|
|
SetStatusEffect();
|
|
|
|
Dirty();
|
|
return true;
|
|
}
|
|
|
|
private void SetStatusEffect()
|
|
{
|
|
if (!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
|
return;
|
|
|
|
status.ChangeStatusEffect(StatusEffect.Stun, _stunTexture,
|
|
(StunStart == null || StunEnd == null) ? default : (StunStart.Value, StunEnd.Value));
|
|
_statusRemoveCancellation.Cancel();
|
|
_statusRemoveCancellation = new CancellationTokenSource();
|
|
}
|
|
|
|
public void ResetStuns()
|
|
{
|
|
_stunnedTimer = 0f;
|
|
_slowdownTimer = 0f;
|
|
|
|
if (KnockedDown)
|
|
StandingStateHelper.Standing(Owner);
|
|
|
|
_knockdownTimer = 0f;
|
|
}
|
|
|
|
public void Update(float delta)
|
|
{
|
|
if (Stunned)
|
|
{
|
|
_stunnedTimer -= delta;
|
|
|
|
if (_stunnedTimer <= 0)
|
|
{
|
|
_stunnedTimer = 0f;
|
|
Dirty();
|
|
}
|
|
}
|
|
|
|
if (KnockedDown)
|
|
{
|
|
_knockdownTimer -= delta;
|
|
|
|
if (_knockdownTimer <= 0f)
|
|
{
|
|
StandingStateHelper.Standing(Owner);
|
|
|
|
_knockdownTimer = 0f;
|
|
Dirty();
|
|
}
|
|
}
|
|
|
|
if (SlowedDown)
|
|
{
|
|
_slowdownTimer -= delta;
|
|
|
|
if (_slowdownTimer <= 0f)
|
|
{
|
|
_slowdownTimer = 0f;
|
|
|
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
|
movement.RefreshMovementSpeedModifiers();
|
|
Dirty();
|
|
}
|
|
}
|
|
|
|
if (!StunStart.HasValue || !StunEnd.HasValue ||
|
|
!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
|
return;
|
|
|
|
var start = StunStart.Value;
|
|
var end = StunEnd.Value;
|
|
|
|
var length = (end - start).TotalSeconds;
|
|
var progress = (_gameTiming.CurTime - start).TotalSeconds;
|
|
|
|
if (progress >= length)
|
|
{
|
|
Timer.Spawn(250, () => status.RemoveStatusEffect(StatusEffect.Stun), _statusRemoveCancellation.Token);
|
|
_lastStun = null;
|
|
}
|
|
}
|
|
|
|
public float StunTimeModifier
|
|
{
|
|
get
|
|
{
|
|
var modifier = 1.0f;
|
|
var components = Owner.GetAllComponents<IStunModifier>();
|
|
|
|
foreach (var component in components)
|
|
{
|
|
modifier *= component.StunTimeModifier;
|
|
}
|
|
|
|
return modifier;
|
|
}
|
|
}
|
|
|
|
public float KnockdownTimeModifier
|
|
{
|
|
get
|
|
{
|
|
var modifier = 1.0f;
|
|
var components = Owner.GetAllComponents<IStunModifier>();
|
|
|
|
foreach (var component in components)
|
|
{
|
|
modifier *= component.KnockdownTimeModifier;
|
|
}
|
|
|
|
return modifier;
|
|
}
|
|
}
|
|
|
|
public float SlowdownTimeModifier
|
|
{
|
|
get
|
|
{
|
|
var modifier = 1.0f;
|
|
var components = Owner.GetAllComponents<IStunModifier>();
|
|
|
|
foreach (var component in components)
|
|
{
|
|
modifier *= component.SlowdownTimeModifier;
|
|
}
|
|
|
|
return modifier;
|
|
}
|
|
}
|
|
|
|
public override ComponentState GetComponentState()
|
|
{
|
|
return new StunnableComponentState(Stunned, KnockedDown, SlowedDown, WalkModifierOverride,
|
|
RunModifierOverride);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This interface allows components to multiply the time in seconds of various stuns by a number.
|
|
/// </summary>
|
|
public interface IStunModifier
|
|
{
|
|
float StunTimeModifier => 1.0f;
|
|
float KnockdownTimeModifier => 1.0f;
|
|
float SlowdownTimeModifier => 1.0f;
|
|
}
|
|
}
|