The real movement refactor (#9645)

* The real movement refactor

* ref events

* Jetpack cleanup

* a

* Vehicles partially working

* Balance tweaks

* Restore some shitcode

* AAAAAAAA

* Even more prediction

* ECS compstate trying to fix this

* yml

* vehicles kill me

* Don't lock keys

* a

* Fix problem

* Fix sounds

* shuttle inputs

* Shuttle controls

* space brakes

* Keybinds

* Fix merge

* Handle shutdown

* Fix keys

* Bump friction

* fix buckle offset

* Fix relay and friction

* Fix jetpack turning

* contexts amirite
This commit is contained in:
metalgearsloth
2022-07-16 13:51:52 +10:00
committed by GitHub
parent e0b7b48cae
commit b9e876ca92
109 changed files with 1752 additions and 1584 deletions

View File

@@ -68,7 +68,7 @@ namespace Content.Server.Buckle.Components
_buckledTo = value;
_buckleTime = _gameTiming.CurTime;
_sysMan.GetEntitySystem<ActionBlockerSystem>().UpdateCanMove(Owner);
Dirty(_entMan);
Dirty(EntMan);
}
}
@@ -99,33 +99,6 @@ namespace Content.Server.Buckle.Components
}
}
/// <summary>
/// Reattaches this entity to the strap, modifying its position and rotation.
/// </summary>
/// <param name="strap">The strap to reattach to.</param>
public void ReAttach(StrapComponent strap)
{
var ownTransform = _entMan.GetComponent<TransformComponent>(Owner);
var strapTransform = _entMan.GetComponent<TransformComponent>(strap.Owner);
ownTransform.AttachParent(strapTransform);
ownTransform.LocalRotation = Angle.Zero;
switch (strap.Position)
{
case StrapPosition.None:
break;
case StrapPosition.Stand:
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
break;
case StrapPosition.Down:
EntitySystem.Get<StandingStateSystem>().Down(Owner, false, false);
break;
}
ownTransform.LocalPosition = strap.BuckleOffset;
}
public bool CanBuckle(EntityUid user, EntityUid to, [NotNullWhen(true)] out StrapComponent? strap)
{
var popupSystem = EntitySystem.Get<SharedPopupSystem>();
@@ -136,7 +109,7 @@ namespace Content.Server.Buckle.Components
return false;
}
if (!_entMan.TryGetComponent(to, out strap))
if (!EntMan.TryGetComponent(to, out strap))
{
return false;
}
@@ -160,7 +133,7 @@ namespace Content.Server.Buckle.Components
}
}
if (!_entMan.HasComponent<HandsComponent>(user))
if (!EntMan.HasComponent<HandsComponent>(user))
{
popupSystem.PopupEntity(Loc.GetString("buckle-component-no-hands-message"), user, Filter.Entities(user));
return false;
@@ -176,10 +149,10 @@ namespace Content.Server.Buckle.Components
return false;
}
var parent = _entMan.GetComponent<TransformComponent>(to).Parent;
var parent = EntMan.GetComponent<TransformComponent>(to).Parent;
while (parent != null)
{
if (parent == _entMan.GetComponent<TransformComponent>(user))
if (parent == EntMan.GetComponent<TransformComponent>(user))
{
var message = Loc.GetString(Owner == user
? "buckle-component-cannot-buckle-message"
@@ -224,7 +197,7 @@ namespace Content.Server.Buckle.Components
return false;
}
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
if(EntMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
appearance.SetData(BuckleVisuals.Buckled, true);
ReAttach(strap);
@@ -236,10 +209,10 @@ namespace Content.Server.Buckle.Components
UpdateBuckleStatus();
var ev = new BuckleChangeEvent() { Buckling = true, Strap = BuckledTo.Owner, BuckledEntity = Owner };
_entMan.EventBus.RaiseLocalEvent(ev.BuckledEntity, ev, false);
_entMan.EventBus.RaiseLocalEvent(ev.Strap, ev, false);
EntMan.EventBus.RaiseLocalEvent(ev.BuckledEntity, ev, false);
EntMan.EventBus.RaiseLocalEvent(ev.Strap, ev, false);
if (_entMan.TryGetComponent(Owner, out SharedPullableComponent? ownerPullable))
if (EntMan.TryGetComponent(Owner, out SharedPullableComponent? ownerPullable))
{
if (ownerPullable.Puller != null)
{
@@ -247,7 +220,7 @@ namespace Content.Server.Buckle.Components
}
}
if (_entMan.TryGetComponent(to, out SharedPullableComponent? toPullable))
if (EntMan.TryGetComponent(to, out SharedPullableComponent? toPullable))
{
if (toPullable.Puller == Owner)
{
@@ -292,7 +265,7 @@ namespace Content.Server.Buckle.Components
return false;
}
// If the strap is a vehicle and the rider is not the person unbuckling, return.
if (_entMan.TryGetComponent<VehicleComponent>(oldBuckledTo.Owner, out var vehicle) &&
if (EntMan.TryGetComponent<VehicleComponent>(oldBuckledTo.Owner, out var vehicle) &&
vehicle.Rider != user)
return false;
}
@@ -312,11 +285,11 @@ namespace Content.Server.Buckle.Components
xform.Coordinates = oldBuckledXform.Coordinates.Offset(oldBuckledTo.UnbuckleOffset);
}
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
if(EntMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
appearance.SetData(BuckleVisuals.Buckled, false);
if (_entMan.HasComponent<KnockedDownComponent>(Owner)
| (_entMan.TryGetComponent<MobStateComponent>(Owner, out var mobState) && mobState.IsIncapacitated()))
if (EntMan.HasComponent<KnockedDownComponent>(Owner)
| (EntMan.TryGetComponent<MobStateComponent>(Owner, out var mobState) && mobState.IsIncapacitated()))
{
EntitySystem.Get<StandingStateSystem>().Down(Owner);
}
@@ -334,8 +307,8 @@ namespace Content.Server.Buckle.Components
SoundSystem.Play(oldBuckledTo.UnbuckleSound.GetSound(), Filter.Pvs(Owner), Owner);
var ev = new BuckleChangeEvent() { Buckling = false, Strap = oldBuckledTo.Owner, BuckledEntity = Owner };
_entMan.EventBus.RaiseLocalEvent(Owner, ev, false);
_entMan.EventBus.RaiseLocalEvent(oldBuckledTo.Owner, ev, false);
EntMan.EventBus.RaiseLocalEvent(Owner, ev, false);
EntMan.EventBus.RaiseLocalEvent(oldBuckledTo.Owner, ev, false);
return true;
}
@@ -386,8 +359,8 @@ namespace Content.Server.Buckle.Components
int? drawDepth = null;
if (BuckledTo != null &&
_entMan.GetComponent<TransformComponent>(BuckledTo.Owner).LocalRotation.GetCardinalDir() == Direction.North &&
_entMan.TryGetComponent<SpriteComponent>(BuckledTo.Owner, out var spriteComponent))
EntMan.GetComponent<TransformComponent>(BuckledTo.Owner).LocalRotation.GetCardinalDir() == Direction.North &&
EntMan.TryGetComponent<SpriteComponent>(BuckledTo.Owner, out var spriteComponent))
{
drawDepth = spriteComponent.DrawDepth - 1;
}

View File

@@ -10,12 +10,10 @@ namespace Content.Server.Buckle.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedStrapComponent))]
public sealed class StrapComponent : SharedStrapComponent, ISerializationHooks
public sealed class StrapComponent : SharedStrapComponent
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly HashSet<EntityUid> _buckledEntities = new();
/// <summary>
/// The angle in degrees to rotate the player by when they get strapped
/// </summary>
@@ -28,13 +26,6 @@ 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)]
public Vector2 BuckleOffsetUnclamped = Vector2.Zero;
private bool _enabled = true;
/// <summary>
@@ -51,38 +42,11 @@ namespace Content.Server.Buckle.Components
}
}
/// <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 = 0.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(
BuckleOffsetUnclamped,
Vector2.One * -MaxBuckleDistance,
Vector2.One * MaxBuckleDistance);
/// <summary>
/// The entity that is currently buckled here, synced from <see cref="BuckleComponent.BuckledTo"/>
/// </summary>
public IReadOnlyCollection<EntityUid> BuckledEntities => _buckledEntities;
/// <summary>
/// The change in position to the strapped mob
/// </summary>
[DataField("position")]
public StrapPosition Position { get; } = StrapPosition.None;
/// <summary>
/// The sound to be played when a mob is buckled
/// </summary>
@@ -138,7 +102,7 @@ namespace Content.Server.Buckle.Components
return false;
}
if (!_buckledEntities.Add(buckle.Owner))
if (!BuckledEntities.Add(buckle.Owner))
{
return false;
}
@@ -154,6 +118,7 @@ namespace Content.Server.Buckle.Components
appearance.SetData("StrapState", true);
}
Dirty();
return true;
}
@@ -164,7 +129,7 @@ namespace Content.Server.Buckle.Components
/// <param name="buckle">The component to remove</param>
public void Remove(BuckleComponent buckle)
{
if (_buckledEntities.Remove(buckle.Owner))
if (BuckledEntities.Remove(buckle.Owner))
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent>(Owner, out var appearance))
{
@@ -172,6 +137,7 @@ namespace Content.Server.Buckle.Components
}
_occupiedSize -= buckle.Size;
Dirty();
}
}
@@ -186,7 +152,7 @@ namespace Content.Server.Buckle.Components
{
var entManager = IoCManager.Resolve<IEntityManager>();
foreach (var entity in _buckledEntities.ToArray())
foreach (var entity in BuckledEntities.ToArray())
{
if (entManager.TryGetComponent<BuckleComponent>(entity, out var buckle))
{
@@ -194,13 +160,9 @@ namespace Content.Server.Buckle.Components
}
}
_buckledEntities.Clear();
BuckledEntities.Clear();
_occupiedSize = 0;
}
public override ComponentState GetComponentState()
{
return new StrapComponentState(Position);
Dirty();
}
public override bool DragDropOn(DragDropEvent eventArgs)

View File

@@ -2,11 +2,13 @@ using Content.Server.Buckle.Components;
using Content.Server.Interaction;
using Content.Server.Storage.Components;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.Interaction;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
namespace Content.Server.Buckle.Systems
{
@@ -20,20 +22,21 @@ namespace Content.Server.Buckle.Systems
UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem));
SubscribeLocalEvent<BuckleComponent, MoveEvent>(MoveEvent);
SubscribeLocalEvent<StrapComponent, RotateEvent>(RotateEvent);
SubscribeLocalEvent<StrapComponent, ComponentGetState>(OnStrapGetState);
SubscribeLocalEvent<StrapComponent, EntInsertedIntoContainerMessage>(ContainerModifiedStrap);
SubscribeLocalEvent<StrapComponent, EntRemovedFromContainerMessage>(ContainerModifiedStrap);
SubscribeLocalEvent<BuckleComponent, MoveEvent>(MoveEvent);
SubscribeLocalEvent<BuckleComponent, InteractHandEvent>(HandleInteractHand);
SubscribeLocalEvent<BuckleComponent, GetVerbsEvent<InteractionVerb>>(AddUnbuckleVerb);
SubscribeLocalEvent<BuckleComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
}
private void OnStrapGetState(EntityUid uid, StrapComponent component, ref ComponentGetState args)
{
args.State = new StrapComponentState(component.Position, component.BuckleOffset, component.BuckledEntities, component.MaxBuckleDistance);
}
private void AddUnbuckleVerb(EntityUid uid, BuckleComponent component, GetVerbsEvent<InteractionVerb> args)
{
if (!args.CanAccess || !args.CanInteract || !component.Buckled)
@@ -80,21 +83,6 @@ namespace Content.Server.Buckle.Systems
buckle.TryUnbuckle(buckle.Owner, true);
}
private void RotateEvent(EntityUid uid, StrapComponent strap, ref RotateEvent ev)
{
// On rotation of a strap, reattach all buckled entities.
// This fixes buckle offsets and draw depths.
foreach (var buckledEntity in strap.BuckledEntities)
{
if (!EntityManager.TryGetComponent(buckledEntity, out BuckleComponent? buckled))
{
continue;
}
buckled.ReAttach(strap);
Dirty(buckled);
}
}
private void ContainerModifiedStrap(EntityUid uid, StrapComponent strap, ContainerModifiedMessage message)
{
foreach (var buckledEntity in strap.BuckledEntities)