diff --git a/Content.Server/Construction/AnchorableSystem.cs b/Content.Server/Construction/AnchorableSystem.cs index 0195532bef..2e82c95e55 100644 --- a/Content.Server/Construction/AnchorableSystem.cs +++ b/Content.Server/Construction/AnchorableSystem.cs @@ -30,10 +30,10 @@ namespace Content.Server.Construction return; // If the used entity doesn't have a tool, return early. - if (!EntityManager.TryGetComponent(args.Used.Uid, out ToolComponent? usedTool)) + if (!EntityManager.TryGetComponent(args.UsedUid, out ToolComponent? usedTool)) return; - args.Handled = await TryToggleAnchor(uid, args.User.Uid, args.Used.Uid, anchorable, usingTool:usedTool); + args.Handled = await TryToggleAnchor(uid, args.UserUid, args.UsedUid, anchorable, usingTool:usedTool); } /// diff --git a/Content.Server/Construction/Components/MachineComponent.cs b/Content.Server/Construction/Components/MachineComponent.cs index 503aba03e8..66316c5a6a 100644 --- a/Content.Server/Construction/Components/MachineComponent.cs +++ b/Content.Server/Construction/Components/MachineComponent.cs @@ -91,7 +91,7 @@ namespace Content.Server.Construction.Components if (stack == null) throw new Exception($"Couldn't spawn stack of type {stackType}!"); - if (!partContainer.Insert(stack)) + if (!partContainer.Insert(Owner.EntityManager.GetEntity(stack))) throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}"); } diff --git a/Content.Server/Construction/Components/MachineFrameComponent.cs b/Content.Server/Construction/Components/MachineFrameComponent.cs index 2d9a57636d..73c8c7217f 100644 --- a/Content.Server/Construction/Components/MachineFrameComponent.cs +++ b/Content.Server/Construction/Components/MachineFrameComponent.cs @@ -319,7 +319,7 @@ namespace Content.Server.Construction.Components if (splitStack == null) return false; - if(!_partContainer.Insert(splitStack)) + if(!_partContainer.Insert(Owner.EntityManager.GetEntity(splitStack.Value))) return false; _materialProgress[type] += needed; diff --git a/Content.Server/Construction/ConstructionSystem.Initial.cs b/Content.Server/Construction/ConstructionSystem.Initial.cs index 1b1bf6d632..3da7c15098 100644 --- a/Content.Server/Construction/ConstructionSystem.Initial.cs +++ b/Content.Server/Construction/ConstructionSystem.Initial.cs @@ -171,10 +171,10 @@ namespace Content.Server.Construction if (string.IsNullOrEmpty(materialStep.Store)) { - if (!container.Insert(splitStack)) + if (!container.Insert(EntityManager.GetEntity(splitStack.Value))) continue; } - else if (!GetContainer(materialStep.Store).Insert(splitStack)) + else if (!GetContainer(materialStep.Store).Insert(EntityManager.GetEntity(splitStack.Value))) continue; handled = true; @@ -186,7 +186,7 @@ namespace Content.Server.Construction case ArbitraryInsertConstructionGraphStep arbitraryStep: foreach (var entity in EnumerateNearby(user)) { - if (!arbitraryStep.EntityValid(entity)) + if (!arbitraryStep.EntityValid(entity.Uid, EntityManager)) continue; if (string.IsNullOrEmpty(arbitraryStep.Store)) @@ -430,7 +430,7 @@ namespace Content.Server.Construction switch (step) { case EntityInsertConstructionGraphStep entityInsert: - if (entityInsert.EntityValid(holding)) + if (entityInsert.EntityValid(holding.Uid, EntityManager)) valid = true; break; case ToolConstructionGraphStep _: diff --git a/Content.Server/Construction/ConstructionSystem.Interactions.cs b/Content.Server/Construction/ConstructionSystem.Interactions.cs index 76c5aebf59..30a95d9d81 100644 --- a/Content.Server/Construction/ConstructionSystem.Interactions.cs +++ b/Content.Server/Construction/ConstructionSystem.Interactions.cs @@ -273,11 +273,11 @@ namespace Content.Server.Construction if (doAfterState == DoAfterState.Cancelled) return HandleResult.False; - var insert = interactUsing.Used; + var insert = interactUsing.UsedUid; // Since many things inherit this step, we delegate the "is this entity valid?" logic to them. // While this is very OOP and I find it icky, I must admit that it simplifies the code here a lot. - if(!insertStep.EntityValid(insert)) + if(!insertStep.EntityValid(insert, EntityManager)) return HandleResult.False; // If we're only testing whether this step would be handled by the given event, then we're done. @@ -312,7 +312,7 @@ namespace Content.Server.Construction // we split the stack in two and insert the split stack. if (insertStep is MaterialConstructionGraphStep materialInsertStep) { - if (_stackSystem.Split(insert.Uid, materialInsertStep.Amount, interactUsing.User.Transform.Coordinates) is not { } stack) + if (_stackSystem.Split(insert, materialInsertStep.Amount, EntityManager.GetComponent(interactUsing.UserUid).Coordinates) is not {} stack) return HandleResult.False; insert = stack; @@ -330,12 +330,12 @@ namespace Content.Server.Construction // The container doesn't necessarily need to exist, so we ensure it. _containerSystem.EnsureContainer(uid, store) - .Insert(insert); + .Insert(EntityManager.GetEntity(insert)); } else { // If we don't store the item in a container on the entity, we just delete it right away. - insert.Delete(); + EntityManager.DeleteEntity(insert); } // Step has been handled correctly, so we signal this. diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index 47b7638f1c..df33833923 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -245,7 +245,7 @@ namespace Content.Server.Hands.Systems if (splitStack == null) return false; - throwEnt = splitStack; + throwEnt = EntityManager.GetEntity(splitStack.Value); } else if (!hands.Drop(throwEnt)) return false; diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index 402eb65bea..576d0c6cf7 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using Content.Server.Hands.Components; using Content.Server.Items; using Content.Server.Popups; @@ -28,7 +29,7 @@ namespace Content.Server.Stack [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; - public static readonly List DefaultSplitAmounts = new() { 1, 5, 10, 20, 30, 50 }; + public static readonly int[] DefaultSplitAmounts = { 1, 5, 10, 20, 30, 50 }; public override void Initialize() { @@ -41,7 +42,7 @@ namespace Content.Server.Stack /// /// Try to split this stack into two. Returns a non-null if successful. /// - public IEntity? Split(EntityUid uid, int amount, EntityCoordinates spawnPosition, SharedStackComponent? stack = null) + public EntityUid? Split(EntityUid uid, int amount, EntityCoordinates spawnPosition, SharedStackComponent? stack = null) { if (!Resolve(uid, ref stack)) return null; @@ -56,12 +57,12 @@ namespace Content.Server.Stack return null; // Set the output parameter in the event instance to the newly split stack. - var entity = EntityManager.SpawnEntity(prototype, spawnPosition); + var entity = EntityManager.SpawnEntity(prototype, spawnPosition).Uid; - if (EntityManager.TryGetComponent(entity.Uid, out SharedStackComponent? stackComp)) + if (EntityManager.TryGetComponent(entity, out SharedStackComponent? stackComp)) { // Set the split stack's count. - SetCount(entity.Uid, amount, stackComp); + SetCount(entity, amount, stackComp); // Don't let people dupe unlimited stacks stackComp.Unlimited = false; } @@ -72,14 +73,14 @@ namespace Content.Server.Stack /// /// Spawns a stack of a certain stack type. See . /// - public IEntity Spawn(int amount, StackPrototype prototype, EntityCoordinates spawnPosition) + public EntityUid Spawn(int amount, StackPrototype prototype, EntityCoordinates spawnPosition) { // Set the output result parameter to the new stack entity... - var entity = EntityManager.SpawnEntity(prototype.Spawn, spawnPosition); - var stack = EntityManager.GetComponent(entity.Uid); + var entity = EntityManager.SpawnEntity(prototype.Spawn, spawnPosition).Uid; + var stack = EntityManager.GetComponent(entity); // And finally, set the correct amount! - SetCount(entity.Uid, amount, stack); + SetCount(entity, amount, stack); return entity; } @@ -136,7 +137,7 @@ namespace Content.Server.Stack Verb halve = new(); halve.Text = Loc.GetString("comp-stack-split-halve"); halve.Category = VerbCategory.Split; - halve.Act = () => UserSplit(args.User, stack, stack.Count / 2); + halve.Act = () => UserSplit(uid, args.User.Uid, stack.Count / 2, stack); halve.Priority = 1; args.Verbs.Add(halve); @@ -149,7 +150,7 @@ namespace Content.Server.Stack Verb verb = new(); verb.Text = amount.ToString(); verb.Category = VerbCategory.Split; - verb.Act = () => UserSplit(args.User, stack, amount); + verb.Act = () => UserSplit(uid, args.User.Uid, amount, stack); // we want to sort by size, not alphabetically by the verb text. verb.Priority = priority; @@ -159,15 +160,23 @@ namespace Content.Server.Stack } } - private void UserSplit(IEntity user, StackComponent stack, int amount) + private void UserSplit(EntityUid uid, EntityUid userUid, int amount, + StackComponent? stack = null, + TransformComponent? userTransform = null) { + if (!Resolve(uid, ref stack)) + return; + + if (!Resolve(userUid, ref userTransform)) + return; + if (amount <= 0) { - user.PopupMessage(Loc.GetString("comp-stack-split-too-small")); + _popupSystem.PopupCursor(Loc.GetString("comp-stack-split-too-small"), Filter.Entities(userUid)); return; } - if (user.TryGetComponent(out var hands)) + if (EntityManager.TryGetComponent(userUid, out var hands)) { if (hands.TryGetActiveHeldEntity(out var heldItem) && heldItem != stack.Owner) { @@ -179,12 +188,15 @@ namespace Content.Server.Stack return; } - var secondStack = Split(stack.Owner.Uid, amount, user.Transform.Coordinates, stack); - user.PopupMessage(Loc.GetString("comp-stack-split")); - if (secondStack is not null && secondStack.TryGetComponent(out var itemComponent)) + if(Split(uid, amount, userTransform.Coordinates, stack) is not {} splitStack) + return; + + if (EntityManager.TryGetComponent(splitStack, out var item)) { - hands.PutInHandOrDrop(itemComponent); + hands.PutInHandOrDrop(item); } + + _popupSystem.PopupCursor(Loc.GetString("comp-stack-split"), Filter.Entities(userUid)); } } } diff --git a/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs b/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs index 139c790162..179f8b1fb2 100644 --- a/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs @@ -10,9 +10,9 @@ namespace Content.Shared.Construction.Steps { [DataField("component")] public string Component { get; } = string.Empty; - public override bool EntityValid(IEntity entity) + public override bool EntityValid(EntityUid uid, IEntityManager entityManager) { - foreach (var component in entity.GetAllComponents()) + foreach (var component in entityManager.GetComponents(uid)) { if (component.Name == Component) return true; diff --git a/Content.Shared/Construction/Steps/EntityInsertConstructionGraphStep.cs b/Content.Shared/Construction/Steps/EntityInsertConstructionGraphStep.cs index e77f4de32f..45680b5d2d 100644 --- a/Content.Shared/Construction/Steps/EntityInsertConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/EntityInsertConstructionGraphStep.cs @@ -8,6 +8,6 @@ namespace Content.Shared.Construction.Steps { [DataField("store")] public string Store { get; } = string.Empty; - public abstract bool EntityValid(IEntity entity); + public abstract bool EntityValid(EntityUid uid, IEntityManager entityManager); } } diff --git a/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs b/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs index e799bdc87e..90c4f8a982 100644 --- a/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs @@ -27,9 +27,9 @@ namespace Content.Shared.Construction.Steps examinedEvent.Message.AddMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", material.Name))); } - public override bool EntityValid(IEntity entity) + public override bool EntityValid(EntityUid uid, IEntityManager entityManager) { - return entity.TryGetComponent(out SharedStackComponent? stack) && stack.StackTypeId.Equals(MaterialPrototypeId) && stack.Count >= Amount; + return entityManager.TryGetComponent(uid, out SharedStackComponent? stack) && stack.StackTypeId.Equals(MaterialPrototypeId) && stack.Count >= Amount; } public bool EntityValid(IEntity entity, [NotNullWhen(true)] out SharedStackComponent? stack) diff --git a/Content.Shared/Construction/Steps/MultipleTagsConstructionGraphStep.cs b/Content.Shared/Construction/Steps/MultipleTagsConstructionGraphStep.cs index 8d79712774..d7c27e3d6e 100644 --- a/Content.Shared/Construction/Steps/MultipleTagsConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/MultipleTagsConstructionGraphStep.cs @@ -18,16 +18,20 @@ namespace Content.Shared.Construction.Steps return list == null || list.Count == 0; } - public override bool EntityValid(IEntity entity) + public override bool EntityValid(EntityUid uid, IEntityManager entityManager) { // This step can only happen if either list has tags. if (IsNullOrEmpty(_allTags) && IsNullOrEmpty(_anyTags)) return false; // Step is somehow invalid, we return. - if (_allTags != null && !entity.HasAllTags(_allTags)) + // No tags at all. + if (!entityManager.TryGetComponent(uid, out TagComponent? tags)) + return false; + + if (_allTags != null && !tags.HasAllTags(_allTags)) return false; // We don't have all the tags needed. - if (_anyTags != null && !entity.HasAnyTag(_anyTags)) + if (_anyTags != null && !tags.HasAnyTag(_anyTags)) return false; // We don't have any of the tags needed. // This entity is valid! diff --git a/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs b/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs index 2a86c46ecf..317ac8ab6f 100644 --- a/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs @@ -10,9 +10,9 @@ namespace Content.Shared.Construction.Steps { [DataField("prototype")] public string Prototype { get; } = string.Empty; - public override bool EntityValid(IEntity entity) + public override bool EntityValid(EntityUid uid, IEntityManager entityManager) { - return entity.Prototype?.ID == Prototype; + return entityManager.GetComponent(uid).EntityPrototype?.ID == Prototype; } public override void DoExamine(ExaminedEvent examinedEvent) diff --git a/Content.Shared/Construction/Steps/TagConstructionGraphStep.cs b/Content.Shared/Construction/Steps/TagConstructionGraphStep.cs index c8880764ff..3a4fb6495f 100644 --- a/Content.Shared/Construction/Steps/TagConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/TagConstructionGraphStep.cs @@ -10,9 +10,9 @@ namespace Content.Shared.Construction.Steps [DataField("tag")] private string? _tag = null; - public override bool EntityValid(IEntity entity) + public override bool EntityValid(EntityUid uid, IEntityManager entityManager) { - return !string.IsNullOrEmpty(_tag) && entity.HasTag(_tag); + return !string.IsNullOrEmpty(_tag) && entityManager.TryGetComponent(uid, out TagComponent? tags) && tags.HasTag(_tag); } } }