Refactor stacks to not use method events (#4177)
This commit is contained in:
committed by
GitHub
parent
ca4e665296
commit
0093a961bc
@@ -16,14 +16,14 @@ namespace Content.Server.Construction.Completions
|
||||
[DataDefinition]
|
||||
public class SetStackCount : IGraphAction
|
||||
{
|
||||
[DataField("amount")] public int Amount { get; private set; } = 1;
|
||||
[DataField("amount")] public int Amount { get; } = 1;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
if (entity.Deleted) return;
|
||||
if(!entity.HasComponent<StackComponent>()) return;
|
||||
if(!entity.TryGetComponent<StackComponent>(out var stack)) return;
|
||||
|
||||
entity.EntityManager.EventBus.RaiseLocalEvent(entity.Uid, new StackChangeCountEvent(Amount), false);
|
||||
EntitySystem.Get<StackSystem>().SetCount(entity.Uid, stack, Amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ namespace Content.Server.Construction.Completions
|
||||
|
||||
if (EntityPrototypeHelpers.HasComponent<StackComponent>(Prototype))
|
||||
{
|
||||
var stack = entityManager.SpawnEntity(Prototype, coordinates);
|
||||
stack.EntityManager.EventBus.RaiseLocalEvent(stack.Uid, new StackChangeCountEvent(Amount), false);
|
||||
var stackEnt = entityManager.SpawnEntity(Prototype, coordinates);
|
||||
var stack = stackEnt.GetComponent<StackComponent>();
|
||||
EntitySystem.Get<StackSystem>().SetCount(stackEnt.Uid, stack, Amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -269,12 +269,11 @@ namespace Content.Server.Construction.Components
|
||||
if (materialStep.EntityValid(eventArgs.Using, out var stack)
|
||||
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
|
||||
{
|
||||
var splitStack = new StackSplitEvent() {Amount = materialStep.Amount, SpawnPosition = eventArgs.User.Transform.Coordinates};
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(stack.Owner.Uid, splitStack);
|
||||
var splitStack = EntitySystem.Get<StackSystem>().Split(eventArgs.Using.Uid, stack, materialStep.Amount, eventArgs.User.Transform.Coordinates);
|
||||
|
||||
if (splitStack.Result != null)
|
||||
if (splitStack != null)
|
||||
{
|
||||
entityUsing = splitStack.Result;
|
||||
entityUsing = splitStack;
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,16 +86,12 @@ namespace Content.Server.Construction.Components
|
||||
|
||||
foreach (var (stackType, amount) in machineBoard.MaterialRequirements)
|
||||
{
|
||||
var stackSpawn = new StackTypeSpawnEvent()
|
||||
{Amount = amount, StackType = stackType, SpawnPosition = Owner.Transform.Coordinates};
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, stackSpawn);
|
||||
var stack = EntitySystem.Get<StackSystem>().Spawn(amount, stackType, Owner.Transform.Coordinates);
|
||||
|
||||
var s = stackSpawn.Result;
|
||||
|
||||
if (s == null)
|
||||
if (stack == null)
|
||||
throw new Exception($"Couldn't spawn stack of type {stackType}!");
|
||||
|
||||
if (!partContainer.Insert(s))
|
||||
if (!partContainer.Insert(stack))
|
||||
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
|
||||
}
|
||||
|
||||
|
||||
@@ -313,14 +313,12 @@ namespace Content.Server.Construction.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
var splitStack = new StackSplitEvent()
|
||||
{Amount = needed, SpawnPosition = Owner.Transform.Coordinates};
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(stack.Owner.Uid, splitStack);
|
||||
var splitStack = EntitySystem.Get<StackSystem>().Split(eventArgs.Using.Uid, stack, needed, Owner.Transform.Coordinates);
|
||||
|
||||
if (splitStack.Result == null)
|
||||
if (splitStack == null)
|
||||
return false;
|
||||
|
||||
if(!_partContainer.Insert(splitStack.Result))
|
||||
if(!_partContainer.Insert(splitStack))
|
||||
return false;
|
||||
|
||||
_materialProgress[type] += needed;
|
||||
|
||||
@@ -52,15 +52,15 @@ namespace Content.Server.Construction.Components
|
||||
var resultPosition = Owner.Transform.Coordinates;
|
||||
Owner.Delete();
|
||||
|
||||
// spawn each result afrer refine
|
||||
// spawn each result after refine
|
||||
foreach (var result in _refineResult!)
|
||||
{
|
||||
var droppedEnt = Owner.EntityManager.SpawnEntity(result, resultPosition);
|
||||
|
||||
// TODO: If something has a stack... Just use a prototype with a single thing in the stack.
|
||||
// This is not a good way to do it.
|
||||
if (droppedEnt.HasComponent<StackComponent>())
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(droppedEnt.Uid, new StackChangeCountEvent(1), false);
|
||||
if (droppedEnt.TryGetComponent<StackComponent>(out var stack))
|
||||
EntitySystem.Get<StackSystem>().SetCount(droppedEnt.Uid, stack, 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -170,19 +170,17 @@ namespace Content.Server.Construction
|
||||
if (!materialStep.EntityValid(entity, out var stack))
|
||||
continue;
|
||||
|
||||
var splitStack = new StackSplitEvent()
|
||||
{Amount = materialStep.Amount, SpawnPosition = user.ToCoordinates()};
|
||||
RaiseLocalEvent(entity.Uid, splitStack);
|
||||
var splitStack = Get<StackSystem>().Split(entity.Uid, stack, materialStep.Amount, user.ToCoordinates());
|
||||
|
||||
if (splitStack.Result == null)
|
||||
if (splitStack == null)
|
||||
continue;
|
||||
|
||||
if (string.IsNullOrEmpty(materialStep.Store))
|
||||
{
|
||||
if (!container.Insert(splitStack.Result))
|
||||
if (!container.Insert(splitStack))
|
||||
continue;
|
||||
}
|
||||
else if (!GetContainer(materialStep.Store).Insert(splitStack.Result))
|
||||
else if (!GetContainer(materialStep.Store).Insert(splitStack))
|
||||
continue;
|
||||
|
||||
handled = true;
|
||||
|
||||
Reference in New Issue
Block a user