v0.11.0.9
This commit is contained in:
@@ -26,6 +26,8 @@ namespace Barotrauma
|
||||
public readonly Submarine Submarine;
|
||||
public readonly float Condition;
|
||||
|
||||
public bool SpawnIfInventoryFull = true;
|
||||
|
||||
private readonly Action<Item> onSpawned;
|
||||
|
||||
public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition, Action<Item> onSpawned, float? condition = null)
|
||||
@@ -62,6 +64,10 @@ namespace Barotrauma
|
||||
Item spawnedItem;
|
||||
if (Inventory?.Owner != null)
|
||||
{
|
||||
if (!SpawnIfInventoryFull && !Inventory.Items.Any(it => it == null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
spawnedItem = new Item(Prefab, Vector2.Zero, null);
|
||||
if (!Inventory.Owner.Removed && !Inventory.TryPutItem(spawnedItem, null, spawnedItem.AllowedSlots))
|
||||
{
|
||||
@@ -123,6 +129,36 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
class SubmarineSpawnInfo : IEntitySpawnInfo
|
||||
{
|
||||
public readonly string Name;
|
||||
|
||||
public readonly Vector2 Position;
|
||||
|
||||
private readonly Action<Character> onSpawned;
|
||||
|
||||
public SubmarineSpawnInfo(string name, Vector2 worldPosition, Action<Character> onSpawn = null)
|
||||
{
|
||||
this.Name = name ?? throw new ArgumentException("ItemSpawnInfo prefab cannot be null.");
|
||||
Position = worldPosition;
|
||||
this.onSpawned = onSpawn;
|
||||
}
|
||||
|
||||
|
||||
public Entity Spawn()
|
||||
{
|
||||
var submarine = string.IsNullOrEmpty(Name) ? null :
|
||||
new Submarine(SubmarineInfo.SavedSubmarines.First(s => s.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)));
|
||||
return submarine;
|
||||
}
|
||||
|
||||
public void OnSpawned(Entity spawnedCharacter)
|
||||
{
|
||||
if (!(spawnedCharacter is Character character)) { throw new ArgumentException($"The entity passed to CharacterSpawnInfo.OnSpawned must be a Character (value was {spawnedCharacter?.ToString() ?? "null"})."); }
|
||||
onSpawned?.Invoke(character);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Queue<IEntitySpawnInfo> spawnQueue;
|
||||
private readonly Queue<Entity> removeQueue;
|
||||
|
||||
@@ -136,6 +172,14 @@ namespace Barotrauma
|
||||
|
||||
public readonly bool Remove = false;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return
|
||||
(Remove ? "Remove" : "Spawn") + "(" +
|
||||
((Entity as MapEntity)?.Name ?? "[NULL]") +
|
||||
$", {OriginalID}, {OriginalInventoryID})";
|
||||
}
|
||||
|
||||
public SpawnOrRemove(Entity entity, bool remove)
|
||||
{
|
||||
Entity = entity;
|
||||
@@ -163,7 +207,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public EntitySpawner()
|
||||
: base(null)
|
||||
: base(null, Entity.EntitySpawnerID)
|
||||
{
|
||||
spawnQueue = new Queue<IEntitySpawnInfo>();
|
||||
removeQueue = new Queue<Entity>();
|
||||
@@ -200,7 +244,7 @@ namespace Barotrauma
|
||||
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub, onSpawned, condition));
|
||||
}
|
||||
|
||||
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null, Action<Item> onSpawned = null)
|
||||
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null, Action<Item> onSpawned = null, bool spawnIfInventoryFull = true)
|
||||
{
|
||||
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
|
||||
if (itemPrefab == null)
|
||||
@@ -210,7 +254,7 @@ namespace Barotrauma
|
||||
GameAnalyticsManager.AddErrorEventOnce("EntitySpawner.AddToSpawnQueue3:ItemPrefabNull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
return;
|
||||
}
|
||||
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, onSpawned, condition));
|
||||
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, onSpawned, condition) { SpawnIfInventoryFull = spawnIfInventoryFull });
|
||||
}
|
||||
|
||||
public void AddToSpawnQueue(string speciesName, Vector2 worldPosition, Action<Character> onSpawn = null)
|
||||
@@ -253,7 +297,7 @@ namespace Barotrauma
|
||||
if (client != null) GameMain.Server.SetClientCharacter(client, null);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
removeQueue.Enqueue(entity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user