diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index 1b4bb1b028..f849c79b9e 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -47,16 +47,16 @@ namespace Content.Server.Stack // Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked... var prototype = _prototypeManager.TryIndex(stack.StackTypeId, out var stackType) ? stackType.Spawn - : EntityManager.GetComponent(stack.Owner).EntityPrototype?.ID; + : Prototype(stack.Owner)?.ID; // Try to remove the amount of things we want to split from the original stack... if (!Use(uid, amount, stack)) return default; // Set the output parameter in the event instance to the newly split stack. - var entity = EntityManager.SpawnEntity(prototype, spawnPosition); + var entity = Spawn(prototype, spawnPosition); - if (EntityManager.TryGetComponent(entity, out SharedStackComponent? stackComp)) + if (TryComp(entity, out SharedStackComponent? stackComp)) { // Set the split stack's count. SetCount(entity, amount, stackComp); @@ -73,8 +73,8 @@ namespace Content.Server.Stack 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); + var entity = Spawn(prototype.Spawn, spawnPosition); + var stack = Comp(entity); // And finally, set the correct amount! SetCount(entity, amount, stack); @@ -86,7 +86,7 @@ namespace Content.Server.Stack if (args.Handled) return; - if (!EntityManager.TryGetComponent(args.Used, out var otherStack)) + if (!TryComp(args.Used, out var otherStack)) return; if (!otherStack.StackTypeId.Equals(stack.StackTypeId)) @@ -100,7 +100,7 @@ namespace Content.Server.Stack if (!popupPos.IsValid(EntityManager)) { - popupPos = EntityManager.GetComponent(args.User).Coordinates; + popupPos = Transform(args.User).Coordinates; } var filter = Filter.Entities(args.User); @@ -131,11 +131,13 @@ namespace Content.Server.Stack if (!args.CanAccess || !args.CanInteract) return; - Verb halve = new(); - halve.Text = Loc.GetString("comp-stack-split-halve"); - halve.Category = VerbCategory.Split; - halve.Act = () => UserSplit(uid, args.User, stack.Count / 2, stack); - halve.Priority = 1; + Verb halve = new() + { + Text = Loc.GetString("comp-stack-split-halve"), + Category = VerbCategory.Split, + Act = () => UserSplit(uid, args.User, stack.Count / 2, stack), + Priority = 1 + }; args.Verbs.Add(halve); var priority = 0; @@ -144,13 +146,15 @@ namespace Content.Server.Stack if (amount >= stack.Count) continue; - Verb verb = new(); - verb.Text = amount.ToString(); - verb.Category = VerbCategory.Split; - verb.Act = () => UserSplit(uid, args.User, amount, stack); + Verb verb = new() + { + Text = amount.ToString(), + Category = VerbCategory.Split, + Act = () => UserSplit(uid, args.User, amount, stack), + // we want to sort by size, not alphabetically by the verb text. + Priority = priority + }; - // we want to sort by size, not alphabetically by the verb text. - verb.Priority = priority; priority--; args.Verbs.Add(verb); @@ -173,22 +177,10 @@ namespace Content.Server.Stack return; } - if (EntityManager.TryGetComponent(userUid, out var hands)) - { - if (hands.TryGetActiveHeldEntity(out var heldItem) && heldItem != stack.Owner) - { - return; - } - } - else - { - return; - } - - if (Split(uid, amount, userTransform.Coordinates, stack) is not {Valid: true} split) + if (Split(uid, amount, userTransform.Coordinates, stack) is not {} split) return; - if (EntityManager.TryGetComponent(split, out var item)) + if (TryComp(userUid, out var hands) && TryComp(split, out var item)) { hands.PutInHandOrDrop(item); } diff --git a/Content.Shared/Stacks/SharedStackSystem.cs b/Content.Shared/Stacks/SharedStackSystem.cs index 0993b077a7..a1c6a55e13 100644 --- a/Content.Shared/Stacks/SharedStackSystem.cs +++ b/Content.Shared/Stacks/SharedStackSystem.cs @@ -48,10 +48,10 @@ namespace Content.Shared.Stacks // Queue delete stack if count reaches zero. if(component.Count <= 0) - EntityManager.QueueDeleteEntity(uid); + QueueDel(uid); // Change appearance data. - if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) + if (TryComp(uid, out AppearanceComponent? appearance)) appearance.SetData(StackVisuals.Actual, component.Count); RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count), false); @@ -83,7 +83,7 @@ namespace Content.Shared.Stacks private void OnStackStarted(EntityUid uid, SharedStackComponent component, ComponentStartup args) { - if (!EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) + if (!TryComp(uid, out AppearanceComponent? appearance)) return; appearance.SetData(StackVisuals.Actual, component.Count);