Convert ItemSize to prototypes (#21481)
* item sizes are prototypes * eek
This commit is contained in:
@@ -19,21 +19,23 @@ using Content.Shared.Timing;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Storage.EntitySystems;
|
||||
|
||||
public abstract class SharedStorageSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] protected readonly IRobustRandom Random = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!;
|
||||
[Dependency] protected readonly SharedEntityStorageSystem EntityStorage = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _sharedInteractionSystem = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
||||
@@ -46,7 +48,8 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
private EntityQuery<StackComponent> _stackQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
public const ItemSize DefaultStorageMaxItemSize = ItemSize.Normal;
|
||||
[ValidatePrototypeId<ItemSizePrototype>]
|
||||
public const string DefaultStorageMaxItemSize = "Normal";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
@@ -474,14 +477,15 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
|
||||
if (!_stackQuery.TryGetComponent(insertEnt, out var stack) || !HasSpaceInStacks(uid, stack.StackTypeId))
|
||||
{
|
||||
if (item.Size > GetMaxItemSize((uid, storageComp)))
|
||||
var maxSize = _item.GetSizePrototype(GetMaxItemSize((uid, storageComp)));
|
||||
if (_item.GetSizePrototype(item.Size) > maxSize)
|
||||
{
|
||||
reason = "comp-storage-too-big";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryComp<StorageComponent>(insertEnt, out var insertStorage)
|
||||
&& GetMaxItemSize((insertEnt, insertStorage)) >= GetMaxItemSize((uid, storageComp)))
|
||||
&& _item.GetSizePrototype(GetMaxItemSize((insertEnt, insertStorage))) >= maxSize)
|
||||
{
|
||||
reason = "comp-storage-too-big";
|
||||
return false;
|
||||
@@ -495,7 +499,7 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (SharedItemSystem.GetItemSizeWeight(item.Size) + GetCumulativeItemSizes(uid, storageComp) > storageComp.MaxTotalWeight)
|
||||
else if (_item.GetItemSizeWeight(item.Size) + GetCumulativeItemSizes(uid, storageComp) > storageComp.MaxTotalWeight)
|
||||
{
|
||||
reason = "comp-storage-insufficient-capacity";
|
||||
return false;
|
||||
@@ -643,7 +647,7 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
/// <returns>true if inserted, false otherwise</returns>
|
||||
public bool PlayerInsertEntityInWorld(Entity<StorageComponent?> uid, EntityUid player, EntityUid toInsert)
|
||||
{
|
||||
if (!Resolve(uid, ref uid.Comp) || !_sharedInteractionSystem.InRangeUnobstructed(player, uid))
|
||||
if (!Resolve(uid, ref uid.Comp) || !_interactionSystem.InRangeUnobstructed(player, uid))
|
||||
return false;
|
||||
|
||||
if (!Insert(uid, toInsert, out _, user: player, uid.Comp))
|
||||
@@ -706,13 +710,13 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
{
|
||||
if (!_itemQuery.TryGetComponent(item, out var itemComp))
|
||||
continue;
|
||||
sum += SharedItemSystem.GetItemSizeWeight(itemComp.Size);
|
||||
sum += _item.GetItemSizeWeight(itemComp.Size);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public ItemSize GetMaxItemSize(Entity<StorageComponent?> uid)
|
||||
public ProtoId<ItemSizePrototype> GetMaxItemSize(Entity<StorageComponent?> uid)
|
||||
{
|
||||
if (!Resolve(uid, ref uid.Comp))
|
||||
return DefaultStorageMaxItemSize;
|
||||
@@ -723,12 +727,14 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
|
||||
if (!_itemQuery.TryGetComponent(uid, out var item))
|
||||
return DefaultStorageMaxItemSize;
|
||||
var size = _item.GetSizePrototype(item.Size);
|
||||
|
||||
// if there is no max item size specified, the value used
|
||||
// is one below the item size of the storage entity, clamped at ItemSize.Tiny
|
||||
var sizes = Enum.GetValues<ItemSize>().ToList();
|
||||
var currentSizeIndex = sizes.IndexOf(item.Size);
|
||||
return sizes[Math.Max(currentSizeIndex - 1, 0)];
|
||||
var sizes = _prototype.EnumeratePrototypes<ItemSizePrototype>().ToList();
|
||||
sizes.Sort();
|
||||
var currentSizeIndex = sizes.IndexOf(size);
|
||||
return sizes[Math.Max(currentSizeIndex - 1, 0)].ID;
|
||||
}
|
||||
|
||||
public FixedPoint2 GetStorageFillPercentage(Entity<StorageComponent?> uid)
|
||||
|
||||
Reference in New Issue
Block a user