Follower fixes (#15348)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Shared.Follower.Components;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
@@ -25,8 +26,9 @@ public sealed class EyeLerpingSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<EyeComponent, ComponentStartup>(OnEyeStartup);
|
SubscribeLocalEvent<EyeComponent, ComponentStartup>(OnEyeStartup);
|
||||||
SubscribeLocalEvent<EyeComponent, ComponentShutdown>(OnEyeShutdown);
|
SubscribeLocalEvent<EyeComponent, ComponentShutdown>(OnEyeShutdown);
|
||||||
SubscribeLocalEvent<LerpingEyeComponent, EntParentChangedMessage>(HandleMapChange);
|
|
||||||
SubscribeLocalEvent<EyeComponent, PlayerAttachedEvent>(OnAttached);
|
SubscribeLocalEvent<EyeComponent, PlayerAttachedEvent>(OnAttached);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<LerpingEyeComponent, EntParentChangedMessage>(HandleMapChange);
|
||||||
SubscribeLocalEvent<LerpingEyeComponent, PlayerDetachedEvent>(OnDetached);
|
SubscribeLocalEvent<LerpingEyeComponent, PlayerDetachedEvent>(OnDetached);
|
||||||
|
|
||||||
UpdatesAfter.Add(typeof(TransformSystem));
|
UpdatesAfter.Add(typeof(TransformSystem));
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ namespace Content.Shared.Follower.Components;
|
|||||||
/// Attached to entities that are currently being followed by a ghost.
|
/// Attached to entities that are currently being followed by a ghost.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, Access(typeof(FollowerSystem))]
|
[RegisterComponent, Access(typeof(FollowerSystem))]
|
||||||
[NetworkedComponent]
|
[NetworkedComponent, AutoGenerateComponentState]
|
||||||
public sealed class FollowedComponent : Component
|
public sealed partial class FollowedComponent : Component
|
||||||
{
|
{
|
||||||
|
[AutoNetworkedField(true), DataField("following")]
|
||||||
public HashSet<EntityUid> Following = new();
|
public HashSet<EntityUid> Following = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ namespace Content.Shared.Follower.Components;
|
|||||||
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[Access(typeof(FollowerSystem))]
|
[Access(typeof(FollowerSystem))]
|
||||||
[NetworkedComponent]
|
[NetworkedComponent, AutoGenerateComponentState]
|
||||||
public sealed class FollowerComponent : Component
|
public sealed partial class FollowerComponent : Component
|
||||||
{
|
{
|
||||||
|
[AutoNetworkedField, DataField("following")]
|
||||||
public EntityUid Following;
|
public EntityUid Following;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Content.Shared.Database;
|
|||||||
using Content.Shared.Follower.Components;
|
using Content.Shared.Follower.Components;
|
||||||
using Content.Shared.Ghost;
|
using Content.Shared.Ghost;
|
||||||
using Content.Shared.Movement.Events;
|
using Content.Shared.Movement.Events;
|
||||||
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
@@ -71,12 +72,12 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
followerComp.Following = entity;
|
followerComp.Following = entity;
|
||||||
|
|
||||||
var followedComp = EnsureComp<FollowedComponent>(entity);
|
var followedComp = EnsureComp<FollowedComponent>(entity);
|
||||||
followedComp.Following.Add(follower);
|
|
||||||
|
if (!followedComp.Following.Add(follower))
|
||||||
|
return;
|
||||||
|
|
||||||
var xform = Transform(follower);
|
var xform = Transform(follower);
|
||||||
_transform.SetParent(follower, xform, entity);
|
_transform.SetCoordinates(follower, xform, new EntityCoordinates(entity, Vector2.Zero), Angle.Zero);
|
||||||
xform.LocalPosition = Vector2.Zero;
|
|
||||||
xform.LocalRotation = Angle.Zero;
|
|
||||||
|
|
||||||
EnsureComp<OrbitVisualsComponent>(follower);
|
EnsureComp<OrbitVisualsComponent>(follower);
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
|
|
||||||
RaiseLocalEvent(follower, followerEv, true);
|
RaiseLocalEvent(follower, followerEv, true);
|
||||||
RaiseLocalEvent(entity, entityEv, false);
|
RaiseLocalEvent(entity, entityEv, false);
|
||||||
|
Dirty(followedComp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -105,10 +107,10 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
RemComp<FollowerComponent>(uid);
|
RemComp<FollowerComponent>(uid);
|
||||||
|
|
||||||
var xform = Transform(uid);
|
var xform = Transform(uid);
|
||||||
xform.AttachToGridOrMap();
|
_transform.AttachToGridOrMap(uid, xform);
|
||||||
if (xform.MapID == MapId.Nullspace)
|
if (xform.MapID == MapId.Nullspace)
|
||||||
{
|
{
|
||||||
Del(uid);
|
QueueDel(uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +121,7 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
|
|
||||||
RaiseLocalEvent(uid, uidEv, true);
|
RaiseLocalEvent(uid, uidEv, true);
|
||||||
RaiseLocalEvent(target, targetEv, false);
|
RaiseLocalEvent(target, targetEv, false);
|
||||||
|
Dirty(followed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
|
using Content.Shared.Follower.Components;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Content.Shared.Movement.Events;
|
using Content.Shared.Movement.Events;
|
||||||
@@ -51,6 +52,8 @@ namespace Content.Shared.Movement.Systems
|
|||||||
SubscribeLocalEvent<InputMoverComponent, ComponentHandleState>(OnInputHandleState);
|
SubscribeLocalEvent<InputMoverComponent, ComponentHandleState>(OnInputHandleState);
|
||||||
SubscribeLocalEvent<InputMoverComponent, EntParentChangedMessage>(OnInputParentChange);
|
SubscribeLocalEvent<InputMoverComponent, EntParentChangedMessage>(OnInputParentChange);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<FollowedComponent, EntParentChangedMessage>(OnFollowedParentChange);
|
||||||
|
|
||||||
_configManager.OnValueChanged(CCVars.CameraRotationLocked, SetCameraRotationLocked, true);
|
_configManager.OnValueChanged(CCVars.CameraRotationLocked, SetCameraRotationLocked, true);
|
||||||
_configManager.OnValueChanged(CCVars.GameDiagonalMovement, SetDiagonalMovement, true);
|
_configManager.OnValueChanged(CCVars.GameDiagonalMovement, SetDiagonalMovement, true);
|
||||||
}
|
}
|
||||||
@@ -145,6 +148,21 @@ namespace Content.Shared.Movement.Systems
|
|||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnFollowedParentChange(EntityUid uid, FollowedComponent component, ref EntParentChangedMessage args)
|
||||||
|
{
|
||||||
|
var moverQuery = GetEntityQuery<InputMoverComponent>();
|
||||||
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
|
foreach (var foll in component.Following)
|
||||||
|
{
|
||||||
|
if (!moverQuery.TryGetComponent(foll, out var mover))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var ev = new EntParentChangedMessage(foll, null, args.OldMapId, xformQuery.GetComponent(foll));
|
||||||
|
OnInputParentChange(foll, mover, ref ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnInputParentChange(EntityUid uid, InputMoverComponent component, ref EntParentChangedMessage args)
|
private void OnInputParentChange(EntityUid uid, InputMoverComponent component, ref EntParentChangedMessage args)
|
||||||
{
|
{
|
||||||
// If we change our grid / map then delay updating our LastGridAngle.
|
// If we change our grid / map then delay updating our LastGridAngle.
|
||||||
|
|||||||
Reference in New Issue
Block a user