private void OnStackInteractUsing(EntityUid uid, StackComponent stack, InteractUsingEvent args) { if (!args.Used.TryGetComponent <StackComponent>(out var otherStack)) { return; } if (!otherStack.StackTypeId.Equals(stack.StackTypeId)) { return; } var toTransfer = Math.Min(stack.Count, otherStack.AvailableSpace); SetCount(uid, stack, stack.Count - toTransfer); SetCount(args.Used.Uid, otherStack, otherStack.Count + toTransfer); var popupPos = args.ClickLocation; if (!popupPos.IsValid(EntityManager)) { popupPos = args.User.Transform.Coordinates; } switch (toTransfer) { case > 0: popupPos.PopupMessage(args.User, $"+{toTransfer}"); if (otherStack.AvailableSpace == 0) { args.Used.SpawnTimer( 300, () => popupPos.PopupMessage( args.User, Loc.GetString("comp-stack-becomes-full") ) ); } break; case 0 when otherStack.AvailableSpace == 0: popupPos.PopupMessage( args.User, Loc.GetString("comp-stack-already-full") ); break; } args.Handled = true; }
private void OnStackInteractUsing(EntityUid uid, StackComponent stack, InteractUsingEvent args) { if (args.Handled) { return; } if (!TryComp <StackComponent>(args.Used, out var otherStack)) { return; } if (!otherStack.StackTypeId.Equals(stack.StackTypeId)) { return; } var toTransfer = Math.Min(stack.Count, otherStack.AvailableSpace); SetCount(uid, stack.Count - toTransfer, stack); SetCount(args.Used, otherStack.Count + toTransfer, otherStack); var popupPos = args.ClickLocation; if (!popupPos.IsValid(EntityManager)) { popupPos = Transform(args.User).Coordinates; } var filter = Filter.Entities(args.User); switch (toTransfer) { case > 0: _popupSystem.PopupCoordinates($"+{toTransfer}", popupPos, filter); if (otherStack.AvailableSpace == 0) { _popupSystem.PopupCoordinates(Loc.GetString("comp-stack-becomes-full"), popupPos.Offset(new Vector2(0, -0.5f)), filter); } break; case 0 when otherStack.AvailableSpace == 0: _popupSystem.PopupCoordinates(Loc.GetString("comp-stack-already-full"), popupPos, filter); break; } args.Handled = true; }
private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetAlternativeVerbsEvent args) { if (!args.CanAccess || !args.CanInteract) { return; } Verb 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; } Verb 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); } }