Refactors stacks to be fully ECS. (#4046)

This commit is contained in:
Vera Aguilera Puerto
2021-05-26 10:20:57 +02:00
committed by GitHub
parent 0f8e330a3d
commit 33fa208214
18 changed files with 494 additions and 249 deletions

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Shared.Construction;
using Content.Shared.GameObjects.Components.Interactable;
@@ -264,11 +265,17 @@ namespace Content.Server.GameObjects.Components.Construction
break;
case MaterialConstructionGraphStep materialStep:
if (materialStep.EntityValid(eventArgs.Using, out var sharedStack)
if (materialStep.EntityValid(eventArgs.Using, out var stack)
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
{
var stack = (StackComponent) sharedStack;
valid = stack.Split(materialStep.Amount, eventArgs.User.Transform.Coordinates, out entityUsing);
var splitStack = new StackSplitEvent() {Amount = materialStep.Amount, SpawnPosition = eventArgs.User.Transform.Coordinates};
Owner.EntityManager.EventBus.RaiseLocalEvent(stack.Owner.Uid, splitStack);
if (splitStack.Result != null)
{
entityUsing = splitStack.Result;
valid = true;
}
}
break;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Content.Server.Construction;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
@@ -87,7 +88,14 @@ namespace Content.Server.GameObjects.Components.Construction
foreach (var (stackType, amount) in machineBoard.MaterialRequirements)
{
var s = StackHelpers.SpawnStack(stackType, amount, Owner.Transform.Coordinates);
var stackSpawn = new StackTypeSpawnEvent()
{Amount = amount, StackType = stackType, SpawnPosition = Owner.Transform.Coordinates};
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, stackSpawn);
var s = stackSpawn.Result;
if (s == null)
throw new Exception($"Couldn't spawn stack of type {stackType}!");
if (!partContainer.Insert(s))
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");

View File

@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Content.Server.Construction;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Components.Construction;
using Content.Shared.GameObjects.Components.Tag;
using Content.Shared.Interfaces.GameObjects.Components;
@@ -314,10 +315,14 @@ namespace Content.Server.GameObjects.Components.Construction
return true;
}
if (!stack.Split(needed, Owner.Transform.Coordinates, out var newStack))
var splitStack = new StackSplitEvent()
{Amount = needed, SpawnPosition = Owner.Transform.Coordinates};
Owner.EntityManager.EventBus.RaiseLocalEvent(stack.Owner.Uid, splitStack);
if (splitStack.Result == null)
return false;
if(!_partContainer.Insert(newStack))
if(!_partContainer.Insert(splitStack.Result))
return false;
_materialProgress[type] += needed;