Add Buckling (#1155)
* 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
This commit is contained in:
321
Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs
Normal file
321
Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
using Content.Server.GameObjects.Components.Strap;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Strap;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Mobs
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class BuckleComponent : SharedBuckleComponent, IActionBlocker, IInteractHand, IEffectBlocker
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystem;
|
||||
[Dependency] private readonly IServerNotifyManager _notifyManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private int _size;
|
||||
|
||||
[ViewVariables, CanBeNull]
|
||||
public StrapComponent BuckledTo { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public int Size => _size;
|
||||
|
||||
private void BuckleStatus()
|
||||
{
|
||||
if (Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
{
|
||||
status.ChangeStatusEffectIcon(StatusEffect.Buckled,
|
||||
BuckledTo == null
|
||||
? "/Textures/Mob/UI/Buckle/unbuckled.png"
|
||||
: "/Textures/Mob/UI/Buckle/buckled.png");
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryBuckle(IEntity user, IEntity to)
|
||||
{
|
||||
if (user == null || user == to)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
_notifyManager.PopupMessage(user, user,
|
||||
Loc.GetString("You can't do that!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var strapPosition = Owner.Transform.MapPosition;
|
||||
var range = SharedInteractionSystem.InteractionRange / 2;
|
||||
|
||||
if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range))
|
||||
{
|
||||
_notifyManager.PopupMessage(user, user,
|
||||
Loc.GetString("You can't reach there!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent hands))
|
||||
{
|
||||
_notifyManager.PopupMessage(user, user,
|
||||
Loc.GetString("You don't have hands!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hands.GetActiveHand != null)
|
||||
{
|
||||
_notifyManager.PopupMessage(user, user,
|
||||
Loc.GetString("Your hand isn't free!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BuckledTo != null)
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, user,
|
||||
Loc.GetString(Owner == user
|
||||
? "You are already buckled in!"
|
||||
: "{0:They} are already buckled in!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!to.TryGetComponent(out StrapComponent strap))
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, user,
|
||||
Loc.GetString(Owner == user
|
||||
? "You can't buckle yourself there!"
|
||||
: "You can't buckle {0:them} there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
var parent = to.Transform.Parent;
|
||||
while (parent != null)
|
||||
{
|
||||
if (parent == user.Transform)
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, user,
|
||||
Loc.GetString(Owner == user
|
||||
? "You can't buckle yourself there!"
|
||||
: "You can't buckle {0:them} there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
parent = parent.Parent;
|
||||
}
|
||||
|
||||
if (!strap.HasSpace(this))
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, user,
|
||||
Loc.GetString(Owner == user
|
||||
? "You can't fit there!"
|
||||
: "{0:They} can't fit there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
_entitySystem.GetEntitySystem<AudioSystem>()
|
||||
.PlayFromEntity(strap.BuckleSound, Owner);
|
||||
|
||||
if (!strap.TryAdd(this))
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, user,
|
||||
Loc.GetString(Owner == user
|
||||
? "You can't buckle yourself there!"
|
||||
: "You can't buckle {0:them} there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
BuckledTo = strap;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(BuckleVisuals.Buckled, true);
|
||||
}
|
||||
|
||||
var ownTransform = Owner.Transform;
|
||||
var strapTransform = strap.Owner.Transform;
|
||||
|
||||
ownTransform.GridPosition = strapTransform.GridPosition;
|
||||
ownTransform.AttachParent(strapTransform);
|
||||
|
||||
switch (strap.Position)
|
||||
{
|
||||
case StrapPosition.None:
|
||||
ownTransform.WorldRotation = strapTransform.WorldRotation;
|
||||
break;
|
||||
case StrapPosition.Stand:
|
||||
StandingStateHelper.Standing(Owner);
|
||||
ownTransform.WorldRotation = strapTransform.WorldRotation;
|
||||
break;
|
||||
case StrapPosition.Down:
|
||||
StandingStateHelper.Down(Owner);
|
||||
ownTransform.WorldRotation = Angle.South;
|
||||
break;
|
||||
}
|
||||
|
||||
BuckleStatus();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryUnbuckle(IEntity user, bool force = false)
|
||||
{
|
||||
if (BuckledTo == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!force)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
_notifyManager.PopupMessage(user, user,
|
||||
Loc.GetString("You can't do that!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var strapPosition = Owner.Transform.MapPosition;
|
||||
var range = SharedInteractionSystem.InteractionRange / 2;
|
||||
|
||||
if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range))
|
||||
{
|
||||
_notifyManager.PopupMessage(user, user,
|
||||
Loc.GetString("You can't reach there!"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (BuckledTo.Owner.TryGetComponent(out StrapComponent strap))
|
||||
{
|
||||
strap.Remove(this);
|
||||
_entitySystem.GetEntitySystem<AudioSystem>()
|
||||
.PlayFromEntity(strap.UnbuckleSound, Owner);
|
||||
}
|
||||
|
||||
Owner.Transform.DetachParent();
|
||||
Owner.Transform.WorldRotation = BuckledTo.Owner.Transform.WorldRotation;
|
||||
BuckledTo = null;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(BuckleVisuals.Buckled, false);
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out StunnableComponent stunnable) && stunnable.KnockedDown)
|
||||
{
|
||||
StandingStateHelper.Down(Owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
StandingStateHelper.Standing(Owner);
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out SpeciesComponent species))
|
||||
{
|
||||
species.CurrentDamageState.EnterState(Owner);
|
||||
}
|
||||
|
||||
BuckleStatus();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ToggleBuckle(IEntity user, IEntity to)
|
||||
{
|
||||
if (BuckledTo == null)
|
||||
{
|
||||
return TryBuckle(user, to);
|
||||
}
|
||||
else if (BuckledTo.Owner == to)
|
||||
{
|
||||
return TryUnbuckle(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _size, "size", 100);
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
BuckleStatus();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
if (BuckledTo != null && BuckledTo.Owner.TryGetComponent(out StrapComponent strap))
|
||||
{
|
||||
strap.Remove(this);
|
||||
}
|
||||
|
||||
BuckledTo = null;
|
||||
BuckleStatus();
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
return TryUnbuckle(eventArgs.User);
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanMove()
|
||||
{
|
||||
return BuckledTo == null;
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanChangeDirection()
|
||||
{
|
||||
return BuckledTo == null;
|
||||
}
|
||||
|
||||
bool IEffectBlocker.CanFall()
|
||||
{
|
||||
return BuckledTo == null;
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class BuckleVerb : Verb<BuckleComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, BuckleComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
component.BuckledTo == null)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Unbuckle");
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, BuckleComponent component)
|
||||
{
|
||||
component.TryUnbuckle(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user