From 3323a17b3d3f5830e8e7a6c6418019c373b9d017 Mon Sep 17 00:00:00 2001 From: MarkerWicker Date: Mon, 18 Aug 2025 17:49:25 -0600 Subject: [PATCH] predict StackSystem GetVerbsEvent (#39741) --- Content.Server/Stack/StackSystem.cs | 41 +---------------- Content.Shared/Stacks/SharedStackSystem.cs | 53 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index a24cb2df42..aac5a23902 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -16,13 +16,9 @@ namespace Content.Server.Stack { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - public static readonly int[] DefaultSplitAmounts = { 1, 5, 10, 20, 30, 50 }; - public override void Initialize() { base.Initialize(); - - SubscribeLocalEvent>(OnStackAlternativeInteract); } public override void SetCount(EntityUid uid, int amount, StackComponent? component = null) @@ -165,42 +161,7 @@ namespace Content.Server.Stack return amounts; } - private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetVerbsEvent args) - { - if (!args.CanAccess || !args.CanInteract || args.Hands == null || stack.Count == 1) - return; - - AlternativeVerb halve = new() - { - Text = Loc.GetString("comp-stack-split-halve"), - Category = VerbCategory.Split, - Act = () => UserSplit(uid, args.User, stack.Count / 2, stack), - Priority = 1 - }; - args.Verbs.Add(halve); - - var priority = 0; - foreach (var amount in DefaultSplitAmounts) - { - if (amount >= stack.Count) - continue; - - AlternativeVerb verb = new() - { - Text = amount.ToString(), - Category = VerbCategory.Split, - Act = () => UserSplit(uid, args.User, amount, stack), - // we want to sort by size, not alphabetically by the verb text. - Priority = priority - }; - - priority--; - - args.Verbs.Add(verb); - } - } - - private void UserSplit(EntityUid uid, EntityUid userUid, int amount, + protected override void UserSplit(EntityUid uid, EntityUid userUid, int amount, StackComponent? stack = null, TransformComponent? userTransform = null) { diff --git a/Content.Shared/Stacks/SharedStackSystem.cs b/Content.Shared/Stacks/SharedStackSystem.cs index 60b93a8da8..b3de1870fe 100644 --- a/Content.Shared/Stacks/SharedStackSystem.cs +++ b/Content.Shared/Stacks/SharedStackSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Interaction; using Content.Shared.Nutrition; using Content.Shared.Popups; using Content.Shared.Storage.EntitySystems; +using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Shared.GameStates; using Robust.Shared.Physics.Systems; @@ -29,6 +30,8 @@ namespace Content.Shared.Stacks [Dependency] protected readonly SharedPopupSystem Popup = default!; [Dependency] private readonly SharedStorageSystem _storage = default!; + public static readonly int[] DefaultSplitAmounts = { 1, 5, 10, 20, 30, 50 }; + public override void Initialize() { base.Initialize(); @@ -40,6 +43,7 @@ namespace Content.Shared.Stacks SubscribeLocalEvent(OnStackInteractUsing); SubscribeLocalEvent(OnBeforeEaten); SubscribeLocalEvent(OnEaten); + SubscribeLocalEvent>(OnStackAlternativeInteract); _vvm.GetTypeHandler() .AddPath(nameof(StackComponent.Count), (_, comp) => comp.Count, SetCount); @@ -432,6 +436,55 @@ namespace Content.Shared.Stacks // Here to tell the food system to do destroy stuff. args.Destroy = true; } + + private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetVerbsEvent args) + { + if (!args.CanAccess || !args.CanInteract || args.Hands == null || stack.Count == 1) + return; + + AlternativeVerb halve = new() + { + Text = Loc.GetString("comp-stack-split-halve"), + Category = VerbCategory.Split, + Act = () => UserSplit(uid, args.User, stack.Count / 2, stack), + Priority = 1 + }; + args.Verbs.Add(halve); + + var priority = 0; + foreach (var amount in DefaultSplitAmounts) + { + if (amount >= stack.Count) + continue; + + AlternativeVerb verb = new() + { + Text = amount.ToString(), + Category = VerbCategory.Split, + Act = () => UserSplit(uid, args.User, amount, stack), + // we want to sort by size, not alphabetically by the verb text. + Priority = priority + }; + + priority--; + + args.Verbs.Add(verb); + } + } + + /// + /// OnStackAlternativeInteract() was moved to shared in order to faciliate prediction of stack splitting verbs. + /// However, prediction of interacitons with spawned entities is non-functional (or so i'm told) + /// So, UserSplit() and Split() should remain on the server for the time being. + /// This empty virtual method allows for UserSplit() to be called on the server from the client. + /// When prediction is improved, those two methods should be moved to shared, in order to predict the splitting itself (not just the verbs) + /// + protected virtual void UserSplit(EntityUid uid, EntityUid userUid, int amount, + StackComponent? stack = null, + TransformComponent? userTransform = null) + { + + } } /// -- 2.51.2