Added mapped storage for things like crayon belts and tools (#4201)
* Added mapped storage for things like crayon belts and tools * Attempt to get StorageFillEvent to work * Managed to get it working with Visualizer logi * Improved PR and did some light refactoring of components * Update Content.Client/Storage/Visualizers/MappedItemVisualizer.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Removed event, went with stateful ApperanceData * Removed ids in favor of whitelist * Refactor YAML, Moved functionality to Shared and renamed it. * Changed so insert/remove always send full state. * Move logic to component * Fix some issues on MappedVisualizer and few nitpicks - Fix mapped visualizer only doing init or update layers - Fixed naming of systems - Fixed sort of crayons * Forgot to apply Vera's suggestion * Fix the data to be more strict and to avoid unnecessary clearing Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Tag;
|
||||
@@ -21,6 +22,7 @@ namespace Content.Server.Storage.Components
|
||||
/// amount: 6 # Note: this field can be omitted
|
||||
/// countTag: Cigarette # Note: field doesn't point to entity Id, but its tag
|
||||
/// </code>
|
||||
[Obsolete("Should be deprecated in favor of SharedItemCounterSystem")]
|
||||
[RegisterComponent]
|
||||
public class StorageCounterComponent : Component, ISerializationHooks
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
@@ -16,8 +17,7 @@ namespace Content.Server.Storage.Components
|
||||
{
|
||||
public override string Name => "StorageFill";
|
||||
|
||||
[DataField("contents")]
|
||||
private List<StorageFillEntry> _contents = new();
|
||||
[DataField("contents")] private List<StorageFillEntry> _contents = new();
|
||||
|
||||
public IReadOnlyList<StorageFillEntry> Contents => _contents;
|
||||
|
||||
@@ -40,7 +40,8 @@ namespace Content.Server.Storage.Components
|
||||
foreach (var storageItem in _contents)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageItem.PrototypeId)) continue;
|
||||
if (!string.IsNullOrEmpty(storageItem.GroupId) && alreadySpawnedGroups.Contains(storageItem.GroupId)) continue;
|
||||
if (!string.IsNullOrEmpty(storageItem.GroupId) &&
|
||||
alreadySpawnedGroups.Contains(storageItem.GroupId)) continue;
|
||||
|
||||
if (storageItem.SpawnProbability != 1f &&
|
||||
!random.Prob(storageItem.SpawnProbability))
|
||||
@@ -50,8 +51,10 @@ namespace Content.Server.Storage.Components
|
||||
|
||||
for (var i = 0; i < storageItem.Amount; i++)
|
||||
{
|
||||
storage.Insert(Owner.EntityManager.SpawnEntity(storageItem.PrototypeId, Owner.Transform.Coordinates));
|
||||
storage.Insert(
|
||||
Owner.EntityManager.SpawnEntity(storageItem.PrototypeId, Owner.Transform.Coordinates));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(storageItem.GroupId)) alreadySpawnedGroups.Add(storageItem.GroupId);
|
||||
}
|
||||
}
|
||||
@@ -63,13 +66,13 @@ namespace Content.Server.Storage.Components
|
||||
[DataField("id", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? PrototypeId;
|
||||
|
||||
[DataField("prob")]
|
||||
public float SpawnProbability;
|
||||
[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;
|
||||
[DataField("orGroup")] public string GroupId;
|
||||
|
||||
/// <summary>
|
||||
/// orGroup signifies to pick between entities designated with an ID.
|
||||
///
|
||||
@@ -92,8 +95,7 @@ namespace Content.Server.Storage.Components
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
[DataField("amount")]
|
||||
public int Amount;
|
||||
[DataField("amount")] public int Amount;
|
||||
|
||||
public void PopulateDefaultValues()
|
||||
{
|
||||
|
||||
41
Content.Server/Storage/ItemCounterSystem.cs
Normal file
41
Content.Server/Storage/ItemCounterSystem.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Storage.ItemCounter;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Storage
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ItemCounterSystem : SharedItemCounterSystem
|
||||
{
|
||||
protected override bool TryGetContainer(ContainerModifiedMessage msg,
|
||||
ItemCounterComponent itemCounter,
|
||||
out IReadOnlyList<string> showLayers)
|
||||
{
|
||||
if (msg.Container.Owner.TryGetComponent(out ServerStorageComponent? component))
|
||||
{
|
||||
var containedLayers = component.StoredEntities ?? new List<IEntity>();
|
||||
var list = new List<string>();
|
||||
foreach (var mapLayerData in itemCounter.MapLayers.Values)
|
||||
{
|
||||
foreach (var entity in containedLayers)
|
||||
{
|
||||
if (mapLayerData.Whitelist.IsValid(entity))
|
||||
{
|
||||
list.Add(mapLayerData.Layer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showLayers = list;
|
||||
return true;
|
||||
}
|
||||
|
||||
showLayers = new List<string>();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user