Fix invalid followers being saved in maps (#16146)
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Maps;
|
using Robust.Server.Maps;
|
||||||
using Robust.Shared.ContentPack;
|
using Robust.Shared.ContentPack;
|
||||||
|
using Robust.Shared.Map.Events;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization.Markdown;
|
using Robust.Shared.Serialization.Markdown;
|
||||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Movement.Events;
|
|||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Map.Events;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Follower;
|
namespace Content.Shared.Follower;
|
||||||
@@ -20,6 +21,25 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<GetVerbsEvent<AlternativeVerb>>(OnGetAlternativeVerbs);
|
SubscribeLocalEvent<GetVerbsEvent<AlternativeVerb>>(OnGetAlternativeVerbs);
|
||||||
SubscribeLocalEvent<FollowerComponent, MoveInputEvent>(OnFollowerMove);
|
SubscribeLocalEvent<FollowerComponent, MoveInputEvent>(OnFollowerMove);
|
||||||
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
|
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
|
||||||
|
SubscribeLocalEvent<BeforeSaveEvent>(OnBeforeSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBeforeSave(BeforeSaveEvent ev)
|
||||||
|
{
|
||||||
|
// Some followers will not be map savable. This ensures that maps don't get saved with empty/invalid
|
||||||
|
// followers, but just stopping any following on the map being saved.
|
||||||
|
|
||||||
|
var query = AllEntityQuery<FollowerComponent, TransformComponent, MetaDataComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var follower, out var xform, out var meta))
|
||||||
|
{
|
||||||
|
if (meta.EntityPrototype == null || meta.EntityPrototype.MapSavable)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (xform.MapUid != ev.Map)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
StopFollowingEntity(uid, follower.Following);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetAlternativeVerbs(GetVerbsEvent<AlternativeVerb> ev)
|
private void OnGetAlternativeVerbs(GetVerbsEvent<AlternativeVerb> ev)
|
||||||
|
|||||||
Reference in New Issue
Block a user