* 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
158 lines
5.2 KiB
C#
158 lines
5.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Content.Client.UserInterface;
|
|
using Content.Client.Utility;
|
|
using Content.Shared.GameObjects.Components.Mobs;
|
|
using Content.Shared.Input;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Interfaces.ResourceManagement;
|
|
using Robust.Client.Interfaces.UserInterface;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Input;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Interfaces.Network;
|
|
using Robust.Shared.Interfaces.Timing;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Players;
|
|
|
|
namespace Content.Client.GameObjects.Components.Mobs
|
|
{
|
|
/// <inheritdoc/>
|
|
[RegisterComponent]
|
|
public sealed class ClientStatusEffectsComponent : SharedStatusEffectsComponent
|
|
{
|
|
#pragma warning disable 649
|
|
[Dependency] private readonly IPlayerManager _playerManager;
|
|
[Dependency] private readonly IResourceCache _resourceCache;
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager;
|
|
[Dependency] private readonly IGameTiming _gameTiming;
|
|
#pragma warning restore 649
|
|
|
|
private StatusEffectsUI _ui;
|
|
private Dictionary<StatusEffect, StatusEffectStatus> _status = new Dictionary<StatusEffect, StatusEffectStatus>();
|
|
private Dictionary<StatusEffect, CooldownGraphic> _cooldown = new Dictionary<StatusEffect, CooldownGraphic>();
|
|
|
|
/// <summary>
|
|
/// Allows calculating if we need to act due to this component being controlled by the current mob
|
|
/// </summary>
|
|
private bool CurrentlyControlled => _playerManager.LocalPlayer != null && _playerManager.LocalPlayer.ControlledEntity == Owner;
|
|
|
|
protected override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
PlayerDetached();
|
|
}
|
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent component)
|
|
{
|
|
base.HandleMessage(message, component);
|
|
switch (message)
|
|
{
|
|
case PlayerAttachedMsg _:
|
|
PlayerAttached();
|
|
break;
|
|
case PlayerDetachedMsg _:
|
|
PlayerDetached();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
|
{
|
|
base.HandleComponentState(curState, nextState);
|
|
if (!(curState is StatusEffectComponentState state) || _status == state.StatusEffects) return;
|
|
_status = state.StatusEffects;
|
|
UpdateStatusEffects();
|
|
}
|
|
|
|
private void PlayerAttached()
|
|
{
|
|
if (!CurrentlyControlled || _ui != null)
|
|
{
|
|
return;
|
|
}
|
|
_ui = new StatusEffectsUI();
|
|
_userInterfaceManager.StateRoot.AddChild(_ui);
|
|
UpdateStatusEffects();
|
|
}
|
|
|
|
private void PlayerDetached()
|
|
{
|
|
_ui?.Dispose();
|
|
_ui = null;
|
|
}
|
|
|
|
public void UpdateStatusEffects()
|
|
{
|
|
if (!CurrentlyControlled || _ui == null)
|
|
{
|
|
return;
|
|
}
|
|
_cooldown.Clear();
|
|
_ui.VBox.DisposeAllChildren();
|
|
|
|
foreach (var (key, effect) in _status.OrderBy(x => (int) x.Key))
|
|
{
|
|
var texture = _resourceCache.GetTexture(effect.Icon);
|
|
var status = new StatusControl(key, texture);
|
|
|
|
if (effect.Cooldown.HasValue)
|
|
{
|
|
var cooldown = new CooldownGraphic();
|
|
status.Children.Add(cooldown);
|
|
_cooldown[key] = cooldown;
|
|
}
|
|
|
|
status.OnPressed += args => StatusPressed(args, status);
|
|
|
|
_ui.VBox.AddChild(status);
|
|
}
|
|
}
|
|
|
|
private void StatusPressed(BaseButton.ButtonEventArgs args, StatusControl status)
|
|
{
|
|
if (args.Event.Function != EngineKeyFunctions.UIClick)
|
|
{
|
|
return;
|
|
}
|
|
|
|
SendNetworkMessage(new ClickStatusMessage(status.Effect));
|
|
}
|
|
|
|
public void RemoveStatusEffect(StatusEffect name)
|
|
{
|
|
_status.Remove(name);
|
|
UpdateStatusEffects();
|
|
}
|
|
|
|
public void FrameUpdate(float frameTime)
|
|
{
|
|
foreach (var (effect, cooldownGraphic) in _cooldown)
|
|
{
|
|
var status = _status[effect];
|
|
if (!status.Cooldown.HasValue)
|
|
{
|
|
cooldownGraphic.Progress = 0;
|
|
cooldownGraphic.Visible = false;
|
|
continue;
|
|
}
|
|
|
|
var start = status.Cooldown.Value.Item1;
|
|
var end = status.Cooldown.Value.Item2;
|
|
|
|
var length = (end - start).TotalSeconds;
|
|
var progress = (_gameTiming.CurTime - start).TotalSeconds / length;
|
|
var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5);
|
|
|
|
cooldownGraphic.Progress = (float)ratio.Clamp(-1, 1);
|
|
cooldownGraphic.Visible = ratio > -1f;
|
|
}
|
|
}
|
|
}
|
|
}
|