Build 1.1.4.0

This commit is contained in:
Markus Isberg
2023-03-31 18:40:44 +03:00
parent efba17e0ff
commit 9470edead3
483 changed files with 17487 additions and 8548 deletions
@@ -8,6 +8,8 @@ using System.Linq;
using System.Text;
using System.Xml.Linq;
using Barotrauma.Networking;
using System.Collections;
using System.Collections.Immutable;
#if SERVER
using Barotrauma.Networking;
#endif
@@ -414,14 +416,31 @@ namespace Barotrauma
}
}
#endif
return Submarine.MainSub.GetItems(true).FindAll(item =>
return FindAllSellableItems().Where(it => IsItemSellable(it, confirmedSoldEntities));
}
public static IReadOnlyCollection<Item> FindAllItemsOnPlayerAndSub(Character character)
{
List<Item> allItems = new();
if (character?.Inventory is { } inv)
{
allItems.AddRange(inv.FindAllItems(recursive: true));
}
allItems.AddRange(FindAllSellableItems());
return allItems;
}
public static IEnumerable<Item> FindAllSellableItems()
{
if (Submarine.MainSub is null) { return Enumerable.Empty<Item>(); }
return Submarine.MainSub.GetItems(true).FindAll(static item =>
{
if (!IsItemSellable(item, confirmedSoldEntities)) { return false; }
if (item.GetRootInventoryOwner() is Character) { return false; }
if (!item.Components.All(c => !(c is Holdable h) || !h.Attachable || !h.Attached)) { return false; }
if (!item.Components.All(c => !(c is Wire w) || w.Connections.All(c => c == null))) { return false; }
if (!item.Components.All(static c => c is not Holdable { Attachable: true, Attached: true })) { return false; }
if (!item.Components.All(static c => c is not Wire w || w.Connections.All(static c => c is null))) { return false; }
if (!ItemAndAllContainersInteractable(item)) { return false; }
if (item.GetRootContainer() is Item rootContainer && rootContainer.HasTag("dontsellitems")) { return false; }
if (item.GetRootContainer() is { } rootContainer && rootContainer.HasTag("dontsellitems")) { return false; }
return true;
}).Distinct();
@@ -471,6 +490,21 @@ namespace Barotrauma
return true;
}
public static IEnumerable<Hull> FindCargoRooms(IEnumerable<Submarine> subs) => subs.SelectMany(s => FindCargoRooms(s));
public static IEnumerable<Hull> FindCargoRooms(Submarine sub) => WayPoint.WayPointList
.Where(wp => wp.Submarine == sub && wp.SpawnType == SpawnType.Cargo)
.Select(wp => wp.CurrentHull)
.Distinct();
public static IEnumerable<Item> FilterCargoCrates(IEnumerable<Item> items, Func<Item, bool> conditional = null)
=> items.Where(it => it.HasTag("crate") && !it.NonInteractable && !it.NonPlayerTeamInteractable && !it.HiddenInGame && !it.Removed && (conditional == null || conditional(it)));
public static IEnumerable<ItemContainer> FindReusableCargoContainers(IEnumerable<Submarine> subs, IEnumerable<Hull> cargoRooms = null) =>
FilterCargoCrates(Item.ItemList, it => subs.Contains(it.Submarine) && (cargoRooms == null || cargoRooms.Contains(it.CurrentHull)))
.Select(it => it.GetComponent<ItemContainer>())
.Where(c => c != null);
public static ItemContainer GetOrCreateCargoContainerFor(ItemPrefab item, ISpatialEntity cargoRoomOrSpawnPoint, ref List<ItemContainer> availableContainers)
{
ItemContainer itemContainer = null;
@@ -553,8 +587,8 @@ namespace Barotrauma
}
#endif
}
List<ItemContainer> availableContainers = new List<ItemContainer>();
var connectedSubs = sub.GetConnectedSubs().Where(s => s.Info.Type == SubmarineType.Player);
List<ItemContainer> availableContainers = FindReusableCargoContainers(connectedSubs, FindCargoRooms(connectedSubs)).ToList();
foreach (PurchasedItem pi in itemsToSpawn)
{
Vector2 position = GetCargoPos(cargoRoom, pi.ItemPrefab);