diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs index 63176af8a..fb3aebc16 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs @@ -111,9 +111,9 @@ namespace Barotrauma.Items.Components if (!inadequateSkills.Any()) { text = "Required items:\n"; - foreach (Tuple ip in targetItem.RequiredItems) + foreach (Tuple ip in targetItem.RequiredItems) { - text += " - " + ip.Item1.Name + " x" + ip.Item2 + "\n"; + text += " - " + ip.Item1.Name + " x" + ip.Item2 + (ip.Item3 < 1.0f ? ", " + ip.Item3 * 100 + "% condition\n" : "\n"); } text += "Required time: " + targetItem.RequiredTime + " s"; } diff --git a/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml b/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml index 747b3abde..05256665b 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml @@ -134,8 +134,9 @@ - + + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Electricity/signalitems.xml b/Barotrauma/BarotraumaShared/Content/Items/Electricity/signalitems.xml index bdd85ce4f..b7cd52e1c 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Electricity/signalitems.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Electricity/signalitems.xml @@ -99,6 +99,11 @@ price="100" description="Field-programmable gate array - a multi-purpose circuit which can be reconfigured for use in a large variety of electrical devices."> + + + + + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Fabricators/fabricators.xml b/Barotrauma/BarotraumaShared/Content/Items/Fabricators/fabricators.xml index ed7d3591c..d67bcf896 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Fabricators/fabricators.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Fabricators/fabricators.xml @@ -15,16 +15,22 @@ - + + - - - + + - + + + + + + + @@ -33,13 +39,23 @@ + + + + + + - + + + + + @@ -62,25 +78,42 @@ - - - - - - + + - + + + + + + + + + + + + + - + + + + + + + + + + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml index 8ba8c006e..26ac6fc54 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml @@ -4,7 +4,9 @@ category="Equipment" tags="smallitem" - description="Allows remote communication between the crew."> + description="Allows remote communication between the crew." + + price="10"> diff --git a/Barotrauma/BarotraumaShared/Content/Items/Reactor/reactor.xml b/Barotrauma/BarotraumaShared/Content/Items/Reactor/reactor.xml index 255bf051f..fea88d421 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Reactor/reactor.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Reactor/reactor.xml @@ -61,7 +61,9 @@ - + + + @@ -79,7 +81,7 @@ - + @@ -93,7 +95,7 @@ + price="50"> diff --git a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml index 1c05f3b14..359b48473 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml @@ -271,8 +271,10 @@ tags="smallitem"> - - + + + + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml b/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml index 1719f6aa1..d393a601a 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml @@ -144,6 +144,12 @@ price="200" tags="smallitem,weapon"> + + + + + + @@ -161,6 +167,12 @@ category="Equipment" tags="smallitem,weapon"> + + + + + + @@ -222,8 +234,8 @@ - - + + @@ -242,8 +254,8 @@ - - + + diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs index 96b285ea4..40ef6463c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs @@ -57,7 +57,8 @@ namespace Barotrauma.Items.Components foreach (DeconstructItem deconstructProduct in targetItem.Prefab.DeconstructItems) { - if (deconstructProduct.RequireFullCondition && targetItem.Condition < targetItem.Prefab.Health) continue; + float percentageHealth = targetItem.Condition / targetItem.Prefab.Health; + if (percentageHealth <= deconstructProduct.MinCondition || percentageHealth > deconstructProduct.MaxCondition) continue; var itemPrefab = MapEntityPrefab.Find(deconstructProduct.ItemPrefabName) as ItemPrefab; if (itemPrefab == null) @@ -69,11 +70,11 @@ namespace Barotrauma.Items.Components //container full, drop the items outside the deconstructor if (containers[1].Inventory.Items.All(i => i != null)) { - Entity.Spawner.AddToSpawnQueue(itemPrefab, item.Position, item.Submarine); + Entity.Spawner.AddToSpawnQueue(itemPrefab, item.Position, item.Submarine, itemPrefab.Health * deconstructProduct.OutCondition); } else { - Entity.Spawner.AddToSpawnQueue(itemPrefab, containers[1].Inventory); + Entity.Spawner.AddToSpawnQueue(itemPrefab, containers[1].Inventory, itemPrefab.Health * deconstructProduct.OutCondition); } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs index 9857fb052..9c838ebce 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs @@ -12,10 +12,12 @@ namespace Barotrauma.Items.Components { public readonly ItemPrefab TargetItem; - public readonly List> RequiredItems; + public readonly List> RequiredItems; public readonly float RequiredTime; + public readonly float OutCondition; //Percentage-based from 0 to 1 + public readonly List RequiredSkills; public FabricableItem(XElement element) @@ -31,8 +33,9 @@ namespace Barotrauma.Items.Components RequiredSkills = new List(); RequiredTime = element.GetAttributeFloat("requiredtime", 1.0f); - RequiredItems = new List>(); - + OutCondition = element.GetAttributeFloat("outcondition", 1.0f); + RequiredItems = new List>(); + //Backwards compatibility for string lists string[] requiredItemNames = element.GetAttributeString("requireditems", "").Split(','); foreach (string requiredItemName in requiredItemNames) { @@ -48,12 +51,12 @@ namespace Barotrauma.Items.Components var existing = RequiredItems.Find(r => r.Item1 == requiredItem); if (existing == null) { - RequiredItems.Add(new Tuple(requiredItem, 1)); + RequiredItems.Add(new Tuple(requiredItem, 1, 1.0f, false)); } else { RequiredItems.Remove(existing); - RequiredItems.Add(new Tuple(requiredItem, existing.Item2 + 1)); + RequiredItems.Add(new Tuple(requiredItem, existing.Item2 + 1, 1.0f, false)); } } @@ -66,6 +69,34 @@ namespace Barotrauma.Items.Components subElement.GetAttributeString("name", ""), subElement.GetAttributeInt("level", 0))); break; + case "item": //New system allowing for setting minimal item condition + string requiredItemName = subElement.GetAttributeString("name", ""); + float minCondition = subElement.GetAttributeFloat("mincondition", 1.0f); + //Substract mincondition from required item's condition or delete it regardless? + bool useCondition = subElement.GetAttributeBool("usecondition", false); + int count = subElement.GetAttributeInt("count", 1); + + if (string.IsNullOrWhiteSpace(requiredItemName)) continue; + + ItemPrefab requiredItem = MapEntityPrefab.Find(requiredItemName.Trim()) as ItemPrefab; + if (requiredItem == null) + { + DebugConsole.ThrowError("Error in fabricable item " + name + "! Required item \"" + requiredItemName + "\" not found."); + continue; + } + + var existing = RequiredItems.Find(r => r.Item1 == requiredItem); + if (existing == null) + { + RequiredItems.Add(new Tuple(requiredItem, count, minCondition, useCondition)); + } + else + { + RequiredItems.Remove(existing); + RequiredItems.Add(new Tuple(requiredItem, existing.Item2 + count, minCondition, useCondition)); + } + + break; } } @@ -236,25 +267,32 @@ namespace Barotrauma.Items.Components return; } - foreach (Tuple ip in fabricatedItem.RequiredItems) + foreach (Tuple ip in fabricatedItem.RequiredItems) { for (int i = 0; i < ip.Item2; i++) { - var requiredItem = containers[0].Inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ip.Item1); + var requiredItem = containers[0].Inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ip.Item1 && it.Condition >= ip.Item1.Health * ip.Item3); if (requiredItem == null) continue; - + + //Item4 = use condition bool + if (ip.Item4 && requiredItem.Condition - ip.Item1.Health * ip.Item3 > 0.0f) //Leave it behind with reduced condition if it has enough to stay above 0 + { + requiredItem.Condition -= ip.Item1.Health * ip.Item3; + continue; + } Entity.Spawner.AddToRemoveQueue(requiredItem); containers[0].Inventory.RemoveItem(requiredItem); } } + //TODO: apply OutCondition if (containers[1].Inventory.Items.All(i => i != null)) { - Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine); + Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition); } else { - Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, containers[1].Inventory); + Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, containers[1].Inventory, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition); } CancelFabricating(null); @@ -269,11 +307,10 @@ namespace Barotrauma.Items.Components { return false; } - ItemContainer container = item.GetComponent(); - foreach (Tuple ip in fabricableItem.RequiredItems) + foreach (Tuple ip in fabricableItem.RequiredItems) { - if (Array.FindAll(container.Inventory.Items, it => it != null && it.Prefab == ip.Item1).Length < ip.Item2) return false; + if (Array.FindAll(container.Inventory.Items, it => it != null && it.Prefab == ip.Item1 && it.Condition >= ip.Item1.Health * ip.Item3).Length < ip.Item2) return false; } return true; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 8964c050f..44d05981d 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -335,18 +335,18 @@ namespace Barotrauma } } - public Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine) + public Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine, float? spawnCondition = null) : this(new Rectangle( (int)(position.X - itemPrefab.sprite.size.X / 2), (int)(position.Y + itemPrefab.sprite.size.Y / 2), (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), - itemPrefab, submarine) + itemPrefab, submarine, spawnCondition) { } - public Item(Rectangle newRect, ItemPrefab itemPrefab, Submarine submarine) + public Item(Rectangle newRect, ItemPrefab itemPrefab, Submarine submarine, float? spawnCondition = null) : base(itemPrefab, submarine) { prefab = itemPrefab; @@ -361,8 +361,8 @@ namespace Barotrauma rect = newRect; - condition = prefab.Health; - lastSentCondition = prefab.Health; + condition = (float)(spawnCondition ?? prefab.Health); + lastSentCondition = condition; XElement element = prefab.ConfigElement; if (element == null) return; diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index dba9dfd98..bf19c6c0a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -10,12 +10,16 @@ namespace Barotrauma struct DeconstructItem { public readonly string ItemPrefabName; - public readonly bool RequireFullCondition; + public readonly float MinCondition; + public readonly float MaxCondition; + public readonly float OutCondition; - public DeconstructItem(string itemPrefabName, bool requireFullCondition) + public DeconstructItem(string itemPrefabName, float minCondition, float maxCondition, float outCondition) { ItemPrefabName = itemPrefabName; - RequireFullCondition = requireFullCondition; + MinCondition = minCondition; + MaxCondition = maxCondition; + OutCondition = outCondition; } } @@ -301,9 +305,14 @@ namespace Barotrauma { string deconstructItemName = deconstructItem.GetAttributeString("name", "not found"); - bool requireFullCondition = deconstructItem.GetAttributeBool("requirefullcondition", false); + //minCondition does <= check, meaning that below or equeal to min condition will be skipped. + float minCondition = deconstructItem.GetAttributeFloat("mincondition", -0.1f); + //maxCondition does > check, meaning that above this max the deconstruct item will be skipped. + float maxCondition = deconstructItem.GetAttributeFloat("maxcondition", 1.0f); + //Condition of item on creation + float outCondition = deconstructItem.GetAttributeFloat("outcondition", 1.0f); - DeconstructItems.Add(new DeconstructItem(deconstructItemName, requireFullCondition)); + DeconstructItems.Add(new DeconstructItem(deconstructItemName, minCondition, maxCondition, outCondition)); } diff --git a/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs b/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs index 3ad1322c8..448cbd819 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs @@ -22,24 +22,28 @@ namespace Barotrauma public readonly Vector2 Position; public readonly Inventory Inventory; public readonly Submarine Submarine; + public readonly float Condition; - public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition) + public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition, float? condition = null) { Prefab = prefab; Position = worldPosition; + Condition = (float)(condition ?? prefab.Health); } - public ItemSpawnInfo(ItemPrefab prefab, Vector2 position, Submarine sub) + public ItemSpawnInfo(ItemPrefab prefab, Vector2 position, Submarine sub, float? condition = null) { Prefab = prefab; Position = position; Submarine = sub; + Condition = (float)(condition ?? prefab.Health); } - public ItemSpawnInfo(ItemPrefab prefab, Inventory inventory) + public ItemSpawnInfo(ItemPrefab prefab, Inventory inventory, float? condition = null) { Prefab = prefab; Inventory = inventory; + Condition = (float)(condition ?? prefab.Health); } public Entity Spawn() @@ -48,12 +52,12 @@ namespace Barotrauma if (Inventory != null) { - spawnedItem = new Item(Prefab, Vector2.Zero, null); + spawnedItem = new Item(Prefab, Vector2.Zero, null, Condition); Inventory.TryPutItem(spawnedItem, null, spawnedItem.AllowedSlots); } else { - spawnedItem = new Item(Prefab, Position, Submarine); + spawnedItem = new Item(Prefab, Position, Submarine, Condition); } return spawnedItem; @@ -83,25 +87,25 @@ namespace Barotrauma removeQueue = new Queue(); } - public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 worldPosition) + public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 worldPosition, float? condition = null) { if (GameMain.Client != null) return; - spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, worldPosition)); + spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, worldPosition, condition)); } - public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, Submarine sub) + public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, Submarine sub, float? condition = null) { if (GameMain.Client != null) return; - spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub)); + spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub, condition)); } - public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory) + public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null) { if (GameMain.Client != null) return; - spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory)); + spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, condition)); } public void AddToRemoveQueue(Entity entity)