Fixed crashing if the server attempts to spawn extra cargo that doesn't spawn in a container.
This commit is contained in:
@@ -111,24 +111,24 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Dictionary<ItemContainer, int> availableContainers = new Dictionary<ItemContainer, int>();
|
Dictionary<ItemContainer, int> availableContainers = new Dictionary<ItemContainer, int>();
|
||||||
ItemPrefab containerPrefab = null;
|
ItemPrefab containerPrefab = null;
|
||||||
foreach (PurchasedItem Pi in itemsToSpawn)
|
foreach (PurchasedItem pi in itemsToSpawn)
|
||||||
{
|
{
|
||||||
Vector2 position = new Vector2(
|
Vector2 position = new Vector2(
|
||||||
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
|
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
|
||||||
cargoRoom.Rect.Y - cargoRoom.Rect.Height + Pi.itemPrefab.Size.Y / 2);
|
cargoRoom.Rect.Y - cargoRoom.Rect.Height + pi.itemPrefab.Size.Y / 2);
|
||||||
|
|
||||||
ItemContainer itemContainer = null;
|
ItemContainer itemContainer = null;
|
||||||
if (!string.IsNullOrEmpty(Pi.itemPrefab.CargoContainerName))
|
if (!string.IsNullOrEmpty(pi.itemPrefab.CargoContainerName))
|
||||||
{
|
{
|
||||||
itemContainer = availableContainers.Keys.ToList().Find(ac =>
|
itemContainer = availableContainers.Keys.ToList().Find(ac =>
|
||||||
ac.Item.Prefab.NameMatches(Pi.itemPrefab.CargoContainerName) ||
|
ac.Item.Prefab.NameMatches(pi.itemPrefab.CargoContainerName) ||
|
||||||
ac.Item.Prefab.Tags.Contains(Pi.itemPrefab.CargoContainerName.ToLowerInvariant()));
|
ac.Item.Prefab.Tags.Contains(pi.itemPrefab.CargoContainerName.ToLowerInvariant()));
|
||||||
|
|
||||||
if (itemContainer == null)
|
if (itemContainer == null)
|
||||||
{
|
{
|
||||||
containerPrefab = MapEntityPrefab.List.Find(ep =>
|
containerPrefab = MapEntityPrefab.List.Find(ep =>
|
||||||
ep.NameMatches(Pi.itemPrefab.CargoContainerName) ||
|
ep.NameMatches(pi.itemPrefab.CargoContainerName) ||
|
||||||
(ep.Tags != null && ep.Tags.Contains(Pi.itemPrefab.CargoContainerName.ToLowerInvariant()))) as ItemPrefab;
|
(ep.Tags != null && ep.Tags.Contains(pi.itemPrefab.CargoContainerName.ToLowerInvariant()))) as ItemPrefab;
|
||||||
|
|
||||||
if (containerPrefab == null)
|
if (containerPrefab == null)
|
||||||
{
|
{
|
||||||
@@ -150,8 +150,21 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < Pi.quantity; i++)
|
for (int i = 0; i < pi.quantity; i++)
|
||||||
{
|
{
|
||||||
|
if (itemContainer == null)
|
||||||
|
{
|
||||||
|
//no container, place at the waypoint
|
||||||
|
if (GameMain.Server != null)
|
||||||
|
{
|
||||||
|
Entity.Spawner.AddToSpawnQueue(pi.itemPrefab, position, wp.Submarine);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new Item(pi.itemPrefab, position, wp.Submarine);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//if the intial container has been removed due to it running out of space, add a new container
|
//if the intial container has been removed due to it running out of space, add a new container
|
||||||
//of the same type and begin filling it
|
//of the same type and begin filling it
|
||||||
if (!availableContainers.ContainsKey(itemContainer))
|
if (!availableContainers.ContainsKey(itemContainer))
|
||||||
@@ -165,41 +178,26 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemContainer == null)
|
//place in the container
|
||||||
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
//no container, place at the waypoint
|
Entity.Spawner.AddToSpawnQueue(pi.itemPrefab, itemContainer.Inventory);
|
||||||
if (GameMain.Server != null)
|
|
||||||
{
|
|
||||||
Entity.Spawner.AddToSpawnQueue(Pi.itemPrefab, position, wp.Submarine);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
new Item(Pi.itemPrefab, position, wp.Submarine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//place in the container
|
var item = new Item(pi.itemPrefab, position, wp.Submarine);
|
||||||
if (GameMain.Server != null)
|
itemContainer.Inventory.TryPutItem(item, null);
|
||||||
{
|
}
|
||||||
Entity.Spawner.AddToSpawnQueue(Pi.itemPrefab, itemContainer.Inventory);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var item = new Item(Pi.itemPrefab, position, wp.Submarine);
|
|
||||||
itemContainer.Inventory.TryPutItem(item, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
//reduce the number of available slots in the container
|
//reduce the number of available slots in the container
|
||||||
//if there is a container
|
//if there is a container
|
||||||
if (availableContainers.ContainsKey(itemContainer))
|
if (availableContainers.ContainsKey(itemContainer))
|
||||||
{
|
{
|
||||||
availableContainers[itemContainer]--;
|
availableContainers[itemContainer]--;
|
||||||
}
|
}
|
||||||
if (availableContainers.ContainsKey(itemContainer) && availableContainers[itemContainer] <= 0)
|
if (availableContainers.ContainsKey(itemContainer) && availableContainers[itemContainer] <= 0)
|
||||||
{
|
{
|
||||||
availableContainers.Remove(itemContainer);
|
availableContainers.Remove(itemContainer);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user