Rollerbeds (#5681)

This commit is contained in:
metalgearsloth
2021-12-29 15:57:20 +11:00
committed by GitHub
parent 0bab6ecb71
commit e5e144d99c
40 changed files with 627 additions and 53 deletions

View File

@@ -133,7 +133,7 @@ namespace Content.Server.Buckle.Components
break;
}
ownTransform.LocalPosition = Vector2.Zero + BuckleOffset;
ownTransform.LocalPosition = Vector2.Zero + strap.BuckleOffset;
}
public bool CanBuckle(EntityUid user, EntityUid to, [NotNullWhen(true)] out StrapComponent? strap)
@@ -317,10 +317,17 @@ namespace Content.Server.Buckle.Components
BuckledTo = null;
if (_entMan.GetComponent<TransformComponent>(Owner).Parent == _entMan.GetComponent<TransformComponent>(oldBuckledTo.Owner))
var entManager = IoCManager.Resolve<IEntityManager>();
var xform = entManager.GetComponent<TransformComponent>(Owner);
var oldBuckledXform = entManager.GetComponent<TransformComponent>(oldBuckledTo.Owner);
if (xform.ParentUid == oldBuckledXform.Owner)
{
_entMan.GetComponent<TransformComponent>(Owner).AttachParentToContainerOrGrid();
_entMan.GetComponent<TransformComponent>(Owner).WorldRotation = _entMan.GetComponent<TransformComponent>(oldBuckledTo.Owner).WorldRotation;
xform.AttachParentToContainerOrGrid();
xform.WorldRotation = oldBuckledXform.WorldRotation;
if (oldBuckledTo.UnbuckleOffset != Vector2.Zero)
xform.Coordinates = oldBuckledXform.Coordinates.Offset(oldBuckledTo.UnbuckleOffset);
}
Appearance?.SetData(BuckleVisuals.Buckled, false);

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
using Content.Shared.Alert;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.DragDrop;
using Content.Shared.Interaction;
@@ -9,6 +11,8 @@ using Content.Shared.Sound;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -21,8 +25,6 @@ namespace Content.Server.Buckle.Components
{
[ComponentDependency] public readonly SpriteComponent? SpriteComponent = null;
[Dependency] private readonly IEntityManager _entMan = default!;
private readonly HashSet<EntityUid> _buckledEntities = new();
/// <summary>
@@ -37,6 +39,50 @@ namespace Content.Server.Buckle.Components
[ViewVariables] [DataField("size")] private int _size = 100;
private int _occupiedSize;
/// <summary>
/// The buckled entity will be offset by this amount from the center of the strap object.
/// If this offset it too big, it will be clamped to <see cref="MaxBuckleDistance"/>
/// </summary>
[DataField("buckleOffset", required: false)]
private Vector2 _buckleOffset = Vector2.Zero;
private bool _enabled = true;
/// <summary>
/// If disabled, nothing can be buckled on this object, and it will unbuckle anything that's already buckled
/// </summary>
public bool Enabled
{
get => _enabled;
set
{
_enabled = value;
if (_enabled == value) return;
RemoveAll();
}
}
/// <summary>
/// The distance above which a buckled entity will be automatically unbuckled.
/// Don't change it unless you really have to
/// </summary>
[DataField("maxBuckleDistance", required: false)]
public float MaxBuckleDistance = 1f;
/// <summary>
/// You can specify the offset the entity will have after unbuckling.
/// </summary>
[DataField("unbuckleOffset", required: false)]
public Vector2 UnbuckleOffset = Vector2.Zero;
/// <summary>
/// Gets and clamps the buckle offset to MaxBuckleDistance
/// </summary>
public Vector2 BuckleOffset => Vector2.Clamp(
_buckleOffset,
Vector2.One * -MaxBuckleDistance,
Vector2.One * MaxBuckleDistance);
/// <summary>
/// The entity that is currently buckled here, synced from <see cref="BuckleComponent.BuckledTo"/>
/// </summary>
@@ -96,6 +142,8 @@ namespace Content.Server.Buckle.Components
/// <returns>True if added, false otherwise</returns>
public bool TryAdd(BuckleComponent buckle, bool force = false)
{
if (!Enabled) return false;
if (!force && !HasSpace(buckle))
{
return false;
@@ -110,6 +158,12 @@ namespace Content.Server.Buckle.Components
buckle.Appearance?.SetData(StrapVisuals.RotationAngle, _rotation);
// Update the visuals of the strap object
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent>(Owner, out var appearance))
{
appearance.SetData("StrapState", true);
}
#pragma warning disable 618
SendMessage(new StrapMessage(buckle.Owner, Owner));
#pragma warning restore 618
@@ -126,6 +180,11 @@ namespace Content.Server.Buckle.Components
{
if (_buckledEntities.Remove(buckle.Owner))
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent>(Owner, out var appearance))
{
appearance.SetData("StrapState", false);
}
_occupiedSize -= buckle.Size;
#pragma warning disable 618
SendMessage(new UnStrapMessage(buckle.Owner, Owner));
@@ -147,9 +206,11 @@ namespace Content.Server.Buckle.Components
private void RemoveAll()
{
var entManager = IoCManager.Resolve<IEntityManager>();
foreach (var entity in _buckledEntities.ToArray())
{
if (_entMan.TryGetComponent<BuckleComponent?>(entity, out var buckle))
if (entManager.TryGetComponent<BuckleComponent>(entity, out var buckle))
{
buckle.TryUnbuckle(entity, true);
}
@@ -166,7 +227,9 @@ namespace Content.Server.Buckle.Components
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
if (!_entMan.TryGetComponent<BuckleComponent?>(eventArgs.User, out var buckle))
var entManager = IoCManager.Resolve<IEntityManager>();
if (!entManager.TryGetComponent<BuckleComponent>(eventArgs.User, out var buckle))
{
return false;
}
@@ -176,7 +239,9 @@ namespace Content.Server.Buckle.Components
public override bool DragDropOn(DragDropEvent eventArgs)
{
if (!_entMan.TryGetComponent(eventArgs.Dragged, out BuckleComponent? buckleComponent)) return false;
var entManager = IoCManager.Resolve<IEntityManager>();
if (!entManager.TryGetComponent(eventArgs.Dragged, out BuckleComponent? buckleComponent)) return false;
return buckleComponent.TryBuckle(eventArgs.User, Owner);
}
}

View File

@@ -42,10 +42,12 @@ namespace Content.Server.Buckle.Systems
if (!args.CanAccess || !args.CanInteract || !component.Buckled)
return;
Verb verb = new();
verb.Act = () => component.TryUnbuckle(args.User);
verb.Text = Loc.GetString("verb-categories-unbuckle");
verb.IconTexture = "/Textures/Interface/VerbIcons/unbuckle.svg.192dpi.png";
Verb verb = new()
{
Act = () => component.TryUnbuckle(args.User),
Text = Loc.GetString("verb-categories-unbuckle"),
IconTexture = "/Textures/Interface/VerbIcons/unbuckle.svg.192dpi.png"
};
if (args.Target == args.User && args.Using == null)
{
@@ -81,7 +83,7 @@ namespace Content.Server.Buckle.Systems
var strapPosition = EntityManager.GetComponent<TransformComponent>(strap.Owner).Coordinates.Offset(buckle.BuckleOffset);
if (ev.NewPosition.InRange(EntityManager, strapPosition, 0.2f))
if (ev.NewPosition.InRange(EntityManager, strapPosition, strap.MaxBuckleDistance))
{
return;
}

View File

@@ -27,7 +27,7 @@ namespace Content.Server.Buckle.Systems
private void AddStrapVerbs(EntityUid uid, StrapComponent component, GetInteractionVerbsEvent args)
{
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
if (args.Hands == null || !args.CanAccess || !args.CanInteract || !component.Enabled)
return;
// Note that for whatever bloody reason, buckle component has its own interaction range. Additionally, this
@@ -41,9 +41,12 @@ namespace Content.Server.Buckle.Systems
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target, range: buckledComp.Range))
continue;
Verb verb = new();
verb.Act = () => buckledComp.TryUnbuckle(args.User);
verb.Category = VerbCategory.Unbuckle;
Verb verb = new()
{
Act = () => buckledComp.TryUnbuckle(args.User),
Category = VerbCategory.Unbuckle
};
if (entity == args.User)
verb.Text = Loc.GetString("verb-self-target-pronoun");
else
@@ -64,10 +67,12 @@ namespace Content.Server.Buckle.Systems
component.HasSpace(buckle) &&
_interactionSystem.InRangeUnobstructed(args.User, args.Target, range: buckle.Range))
{
Verb verb = new();
verb.Act = () => buckle.TryBuckle(args.User, args.Target);
verb.Category = VerbCategory.Buckle;
verb.Text = Loc.GetString("verb-self-target-pronoun");
Verb verb = new()
{
Act = () => buckle.TryBuckle(args.User, args.Target),
Category = VerbCategory.Buckle,
Text = Loc.GetString("verb-self-target-pronoun")
};
args.Verbs.Add(verb);
}
@@ -82,14 +87,15 @@ namespace Content.Server.Buckle.Systems
if (!_interactionSystem.InRangeUnobstructed(@using, args.Target, usingBuckle.Range, predicate: Ignored))
return;
Verb verb = new();
verb.Act = () => usingBuckle.TryBuckle(args.User, args.Target);
verb.Category = VerbCategory.Buckle;
verb.Text = EntityManager.GetComponent<MetaDataComponent>(@using).EntityName;
// If the used entity is a person being pulled, prioritize this verb. Conversely, if it is
// just a held object, the user is probably just trying to sit down.
verb.Priority = EntityManager.HasComponent<ActorComponent>(@using) ? 1 : -1;
Verb verb = new()
{
Act = () => usingBuckle.TryBuckle(args.User, args.Target),
Category = VerbCategory.Buckle,
Text = EntityManager.GetComponent<MetaDataComponent>(@using).EntityName,
// just a held object, the user is probably just trying to sit down.
// If the used entity is a person being pulled, prioritize this verb. Conversely, if it is
Priority = EntityManager.HasComponent<ActorComponent>(@using) ? 1 : -1
};
args.Verbs.Add(verb);
}