(99fb00391) Don't allow deconstructing items that don't give anything when deconstructed. Closes #690

This commit is contained in:
Joonas Rikkonen
2019-04-18 12:03:22 +03:00
parent fdacc4534b
commit c85cf63494
2 changed files with 12 additions and 7 deletions
@@ -71,8 +71,10 @@ namespace Barotrauma.Items.Components
var targetItem = inputContainer.Inventory.Items.LastOrDefault(i => i != null); var targetItem = inputContainer.Inventory.Items.LastOrDefault(i => i != null);
if (targetItem == null) { return; } if (targetItem == null) { return; }
progressState = Math.Min(progressTimer / targetItem.Prefab.DeconstructTime, 1.0f); float deconstructTime = targetItem.Prefab.DeconstructItems.Any() ? targetItem.Prefab.DeconstructTime : 1.0f;
if (progressTimer > targetItem.Prefab.DeconstructTime)
progressState = Math.Min(progressTimer / deconstructTime, 1.0f);
if (progressTimer > deconstructTime)
{ {
foreach (DeconstructItem deconstructProduct in targetItem.Prefab.DeconstructItems) foreach (DeconstructItem deconstructProduct in targetItem.Prefab.DeconstructItems)
{ {
@@ -100,10 +102,13 @@ namespace Barotrauma.Items.Components
} }
} }
inputContainer.Inventory.RemoveItem(targetItem); if (targetItem.Prefab.DeconstructItems.Any())
Entity.Spawner.AddToRemoveQueue(targetItem); {
MoveInputQueue(); inputContainer.Inventory.RemoveItem(targetItem);
PutItemsToLinkedContainer(); Entity.Spawner.AddToRemoveQueue(targetItem);
MoveInputQueue();
PutItemsToLinkedContainer();
}
if (inputContainer.Inventory.Items.Any(i => i != null)) if (inputContainer.Inventory.Items.Any(i => i != null))
{ {
@@ -566,7 +566,7 @@ namespace Barotrauma
break; break;
#endif #endif
case "deconstruct": case "deconstruct":
DeconstructTime = subElement.GetAttributeFloat("time", 10.0f); DeconstructTime = subElement.GetAttributeFloat("time", 1.0f);
foreach (XElement deconstructItem in subElement.Elements()) foreach (XElement deconstructItem in subElement.Elements())
{ {