Remove FoodContainer, add whitelists, replace with SpawnItemsOnUse (#4358)
This commit is contained in:
@@ -15,6 +15,7 @@ using Content.Shared.Item;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -47,10 +48,16 @@ namespace Content.Server.Storage.Components
|
||||
|
||||
[DataField("occludesLight")]
|
||||
private bool _occludesLight = true;
|
||||
|
||||
[DataField("quickInsert")]
|
||||
private bool _quickInsert; //Can insert storables by "attacking" them with the storage entity
|
||||
private bool _quickInsert = false; // Can insert storables by "attacking" them with the storage entity
|
||||
|
||||
[DataField("areaInsert")]
|
||||
private bool _areaInsert; //"Attacking" with the storage entity causes it to insert all nearby storables after a delay
|
||||
private bool _areaInsert = false; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay
|
||||
|
||||
[DataField("whitelist")]
|
||||
private EntityWhitelist? _whitelist = null;
|
||||
|
||||
private bool _storageInitialCalculated;
|
||||
private int _storageUsed;
|
||||
[DataField("capacity")]
|
||||
@@ -123,6 +130,11 @@ namespace Content.Server.Storage.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_whitelist != null && !_whitelist.IsValid(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Storage.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Spawns items when used in hand.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class SpawnItemsOnUseComponent : Component
|
||||
{
|
||||
public override string Name => "SpawnItemsOnUse";
|
||||
|
||||
/// <summary>
|
||||
/// The list of entities to spawn, with amounts and orGroups.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DataField("items", required: true)]
|
||||
public List<EntitySpawnEntry> Items = new List<EntitySpawnEntry>();
|
||||
|
||||
/// <summary>
|
||||
/// A sound to play when the items are spawned. For example, gift boxes being unwrapped.
|
||||
/// </summary>
|
||||
[DataField("sound")]
|
||||
public SoundSpecifier? Sound = null;
|
||||
|
||||
/// <summary>
|
||||
/// How many uses before the item should delete itself.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DataField("uses")]
|
||||
public int Uses = 1;
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,9 @@ namespace Content.Server.Storage.Components
|
||||
{
|
||||
public override string Name => "StorageFill";
|
||||
|
||||
[DataField("contents")] private List<StorageFillEntry> _contents = new();
|
||||
[DataField("contents")] private List<EntitySpawnEntry> _contents = new();
|
||||
|
||||
public IReadOnlyList<StorageFillEntry> Contents => _contents;
|
||||
public IReadOnlyList<EntitySpawnEntry> Contents => _contents;
|
||||
|
||||
void IMapInit.MapInit()
|
||||
{
|
||||
@@ -39,7 +39,6 @@ namespace Content.Server.Storage.Components
|
||||
var alreadySpawnedGroups = new List<string>();
|
||||
foreach (var storageItem in _contents)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageItem.PrototypeId)) continue;
|
||||
if (!string.IsNullOrEmpty(storageItem.GroupId) &&
|
||||
alreadySpawnedGroups.Contains(storageItem.GroupId)) continue;
|
||||
|
||||
@@ -58,50 +57,5 @@ namespace Content.Server.Storage.Components
|
||||
if (!string.IsNullOrEmpty(storageItem.GroupId)) alreadySpawnedGroups.Add(storageItem.GroupId);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataDefinition]
|
||||
public struct StorageFillEntry : IPopulateDefaultValues
|
||||
{
|
||||
[DataField("id", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? PrototypeId;
|
||||
|
||||
[DataField("prob")] public float SpawnProbability;
|
||||
|
||||
/// <summary>
|
||||
/// The probability that an item will spawn. Takes decimal form so 0.05 is 5%, 0.50 is 50% etc.
|
||||
/// </summary>
|
||||
[DataField("orGroup")] public string GroupId;
|
||||
|
||||
/// <summary>
|
||||
/// orGroup signifies to pick between entities designated with an ID.
|
||||
///
|
||||
/// <example>
|
||||
/// <para>To define an orGroup in a StorageFill component you
|
||||
/// need to add it to the entities you want to choose between and
|
||||
/// add a prob field. In this example there is a 50% chance the storage
|
||||
/// spawns with Y or Z.
|
||||
///
|
||||
/// </para>
|
||||
/// <code>
|
||||
/// - type: StorageFill
|
||||
/// contents:
|
||||
/// - name: X
|
||||
/// - name: Y
|
||||
/// prob: 0.50
|
||||
/// orGroup: YOrZ
|
||||
/// - name: Z
|
||||
/// orGroup: YOrZ
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
[DataField("amount")] public int Amount;
|
||||
|
||||
public void PopulateDefaultValues()
|
||||
{
|
||||
Amount = 1;
|
||||
SpawnProbability = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user