Make item size scale with stack size (#17623)

* Make stack count affect item size

* and the test, too

* readd this check

* vwoom

* huh

* if you ever read this commit message ping me on discord in #contributors

* changerinos
This commit is contained in:
Nemanja
2023-06-25 11:44:37 -04:00
committed by GitHub
parent 0d086df2e5
commit 5c60a27c7c
39 changed files with 399 additions and 81 deletions

View File

@@ -1,16 +1,18 @@
using Content.Shared.CombatMode;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
using Content.Shared.Stacks;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Item;
public abstract class SharedItemSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
[Dependency] protected readonly SharedContainerSystem Container = default!;
@@ -20,6 +22,7 @@ public abstract class SharedItemSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<ItemComponent, GetVerbsEvent<InteractionVerb>>(AddPickupVerb);
SubscribeLocalEvent<ItemComponent, InteractHandEvent>(OnHandInteract);
SubscribeLocalEvent<ItemComponent, StackCountChangedEvent>(OnStackCountChanged);
SubscribeLocalEvent<ItemComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<ItemComponent, ComponentHandleState>(OnHandleState);
@@ -29,7 +32,7 @@ public abstract class SharedItemSystem : EntitySystem
public void SetSize(EntityUid uid, int size, ItemComponent? component = null)
{
if (!Resolve(uid, ref component))
if (!Resolve(uid, ref component, false))
return;
component.Size = size;
@@ -75,6 +78,18 @@ public abstract class SharedItemSystem : EntitySystem
args.Handled = _handsSystem.TryPickup(args.User, uid, animateUser: false);
}
private void OnStackCountChanged(EntityUid uid, ItemComponent component, StackCountChangedEvent args)
{
if (!TryComp<StackComponent>(uid, out var stack))
return;
if (!_prototype.TryIndex<StackPrototype>(stack.StackTypeId, out var stackProto) ||
stackProto.ItemSize is not { } size)
return;
SetSize(uid, args.NewCount * size, component);
}
private void OnHandleState(EntityUid uid, ItemComponent component, ref ComponentHandleState args)
{
if (args.Current is not ItemComponentState state)