Fix lathe queue bug (#7883)
This commit is contained in:
@@ -74,7 +74,7 @@ namespace Content.Server.Lathe
|
|||||||
}
|
}
|
||||||
lathe.ProducingAccumulator = 0;
|
lathe.ProducingAccumulator = 0;
|
||||||
|
|
||||||
FinishProducing(lathe.ProducingRecipe, lathe);
|
FinishProducing(lathe.ProducingRecipe, lathe, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ namespace Content.Server.Lathe
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnInteractUsing(EntityUid uid, LatheComponent component, InteractUsingEvent args)
|
private void OnInteractUsing(EntityUid uid, LatheComponent component, InteractUsingEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<MaterialStorageComponent>(uid, out var storage)
|
if (!TryComp<MaterialStorageComponent>(uid, out var storage)
|
||||||
|| !TryComp<MaterialComponent>(args.Used, out var material)
|
|| !TryComp<MaterialComponent>(args.Used, out var material)
|
||||||
|| component.LatheWhitelist?.IsValid(args.Used) == false)
|
|| component.LatheWhitelist?.IsValid(args.Used) == false)
|
||||||
return;
|
return;
|
||||||
@@ -131,13 +131,13 @@ namespace Content.Server.Lathe
|
|||||||
storage.InsertMaterial(mat, vol * multiplier);
|
storage.InsertMaterial(mat, vol * multiplier);
|
||||||
lastMat = mat;
|
lastMat = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Play a sound when inserting, if any
|
// Play a sound when inserting, if any
|
||||||
if (component.InsertingSound != null)
|
if (component.InsertingSound != null)
|
||||||
{
|
{
|
||||||
SoundSystem.Play(Filter.Pvs(component.Owner, entityManager: EntityManager), component.InsertingSound.GetSound(), component.Owner);
|
SoundSystem.Play(Filter.Pvs(component.Owner, entityManager: EntityManager), component.InsertingSound.GetSound(), component.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need the prototype to get the color
|
// We need the prototype to get the color
|
||||||
_prototypeManager.TryIndex(lastMat, out MaterialPrototype? matProto);
|
_prototypeManager.TryIndex(lastMat, out MaterialPrototype? matProto);
|
||||||
|
|
||||||
@@ -156,17 +156,26 @@ namespace Content.Server.Lathe
|
|||||||
/// This handles the checks to start producing an item, and
|
/// This handles the checks to start producing an item, and
|
||||||
/// starts up the sound and visuals
|
/// starts up the sound and visuals
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool Produce(LatheComponent component, LatheRecipePrototype recipe, bool SkipCheck = false)
|
private void Produce(LatheComponent component, LatheRecipePrototype recipe, bool SkipCheck = false)
|
||||||
{
|
{
|
||||||
if (!component.CanProduce(recipe)
|
if (!component.CanProduce(recipe)
|
||||||
|| !TryComp(component.Owner, out MaterialStorageComponent? storage))
|
|| !TryComp(component.Owner, out MaterialStorageComponent? storage))
|
||||||
return false;
|
{
|
||||||
|
FinishProducing(recipe, component, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SkipCheck && HasComp<LatheProducingComponent>(component.Owner))
|
if (!SkipCheck && HasComp<LatheProducingComponent>(component.Owner))
|
||||||
return false;
|
{
|
||||||
|
FinishProducing(recipe, component, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (TryComp<ApcPowerReceiverComponent>(component.Owner, out var receiver) && !receiver.Powered)
|
if (TryComp<ApcPowerReceiverComponent>(component.Owner, out var receiver) && !receiver.Powered)
|
||||||
return false;
|
{
|
||||||
|
FinishProducing(recipe, component, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
component.UserInterface?.SendMessage(new LatheFullQueueMessage(GetIdQueue(component)));
|
component.UserInterface?.SendMessage(new LatheFullQueueMessage(GetIdQueue(component)));
|
||||||
|
|
||||||
@@ -185,17 +194,17 @@ namespace Content.Server.Lathe
|
|||||||
}
|
}
|
||||||
UpdateRunningAppearance(component.Owner, true);
|
UpdateRunningAppearance(component.Owner, true);
|
||||||
ProducingAddQueue.Enqueue(component.Owner);
|
ProducingAddQueue.Enqueue(component.Owner);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// After the production timer is up, this spawns the recipe and
|
/// If we were able to produce the recipe,
|
||||||
/// either cleans up or continues to the next item in the queue
|
/// spawn it and cleanup. If we weren't, just do cleanup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void FinishProducing(LatheRecipePrototype recipe, LatheComponent component)
|
private void FinishProducing(LatheRecipePrototype recipe, LatheComponent component, bool productionSucceeded = true)
|
||||||
{
|
{
|
||||||
component.ProducingRecipe = null;
|
component.ProducingRecipe = null;
|
||||||
EntityManager.SpawnEntity(recipe.Result, Comp<TransformComponent>(component.Owner).Coordinates);
|
if (productionSucceeded)
|
||||||
|
EntityManager.SpawnEntity(recipe.Result, Comp<TransformComponent>(component.Owner).Coordinates);
|
||||||
component.UserInterface?.SendMessage(new LatheStoppedProducingRecipeMessage());
|
component.UserInterface?.SendMessage(new LatheStoppedProducingRecipeMessage());
|
||||||
// Continue to next in queue if there are items left
|
// Continue to next in queue if there are items left
|
||||||
if (component.Queue.Count > 0)
|
if (component.Queue.Count > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user