Fix invalid followers being saved in maps (#16146)

This commit is contained in:
Leon Friedrich
2023-05-07 11:38:56 +12:00
committed by GitHub
parent d3efc9fdec
commit 9c8ee0c6c9
2 changed files with 21 additions and 0 deletions

View File

@@ -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;

View File

@@ -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)