Refactor stacks to not use method events (#4177)

This commit is contained in:
Vera Aguilera Puerto
2021-06-12 11:24:34 +02:00
committed by GitHub
parent ca4e665296
commit 0093a961bc
17 changed files with 79 additions and 248 deletions

View File

@@ -5,6 +5,7 @@ using Content.Server.Engineering.Components;
using Content.Server.Stack;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Stacks;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -65,20 +66,15 @@ namespace Content.Server.Engineering.EntitySystems
if (component.Deleted || component.Owner.Deleted)
return;
var hasStack = component.Owner.HasComponent<StackComponent>();
if (hasStack && component.RemoveOnInteract)
if (component.Owner.TryGetComponent<SharedStackComponent>(out var stackComp)
&& component.RemoveOnInteract && !Get<StackSystem>().Use(uid, stackComp, 1))
{
var stackUse = new StackUseEvent() {Amount = 1};
RaiseLocalEvent(component.Owner.Uid, stackUse);
if (!stackUse.Result)
return;
return;
}
EntityManager.SpawnEntity(component.Prototype, args.ClickLocation.SnapToGrid(grid));
if (component.RemoveOnInteract && !hasStack && !component.Owner.Deleted)
if (component.RemoveOnInteract && stackComp == null && !component.Owner.Deleted)
component.Owner.Delete();
}
}