private void OnStackHandleState(EntityUid uid, SharedStackComponent component, ref ComponentHandleState args)
        {
            if (args.Current is not StackComponentState cast)
            {
                return;
            }

            component.MaxCount = cast.MaxCount;
            // This will change the count and call events.
            SetCount(uid, cast.Count, component);
        }
        private void OnStackStarted(EntityUid uid, SharedStackComponent component, ComponentStartup args)
        {
            if (!TryComp(uid, out AppearanceComponent? appearance))
            {
                return;
            }

            appearance.SetData(StackVisuals.Actual, component.Count);
            appearance.SetData(StackVisuals.MaxCount, component.MaxCount);
            appearance.SetData(StackVisuals.Hide, false);
        }
示例#3
0
        /// <summary>
        ///     Try to use an amount of items on this stack. Returns whether this succeeded.
        /// </summary>
        public bool Use(EntityUid uid, SharedStackComponent stack, int amount)
        {
            // Check if we have enough things in the stack for this...
            if (stack.Count < amount)
            {
                // Not enough things in the stack, return false.
                return(false);
            }

            // We do have enough things in the stack, so remove them and change.
            SetCount(uid, stack, stack.Count - amount);
            return(true);
        }
示例#4
0
        private void OnStackInteractUsing(EntityUid uid, SharedStackComponent stack, InteractUsingEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            if (!TryComp(args.Used, out SharedStackComponent? recipientStack))
            {
                return;
            }

            if (!TryMergeStacks(uid, args.Used, out var transfered, stack, recipientStack))
            {
                return;
            }

            args.Handled = true;

            // interaction is done, the rest is just generating a pop-up

            if (!_gameTiming.IsFirstTimePredicted)
            {
                return;
            }

            var popupPos = args.ClickLocation;

            if (!popupPos.IsValid(EntityManager))
            {
                popupPos = Transform(args.User).Coordinates;
            }

            switch (transfered)
            {
            case > 0:
                PopupSystem.PopupCoordinates($"+{transfered}", popupPos, Filter.Local());

                if (recipientStack.AvailableSpace == 0)
                {
                    PopupSystem.PopupCoordinates(Loc.GetString("comp-stack-becomes-full"),
                                                 popupPos.Offset(new Vector2(0, -0.5f)), Filter.Local());
                }

                break;

            case 0 when recipientStack.AvailableSpace == 0:
                PopupSystem.PopupCoordinates(Loc.GetString("comp-stack-already-full"), popupPos, Filter.Local());
                break;
            }
        }
        private void OnStackExamined(EntityUid uid, SharedStackComponent component, ExaminedEvent args)
        {
            if (!args.IsInDetailsRange)
            {
                return;
            }

            args.PushMarkup(
                Loc.GetString("comp-stack-examine-detail-count",
                              ("count", component.Count),
                              ("markupCountColor", "lightgray")
                              )
                );
        }
示例#6
0
        public void SetCount(EntityUid uid, SharedStackComponent component, int amount)
        {
            // Do nothing if amount is already the same.
            if (amount == component.Count)
            {
                return;
            }

            // Store old value for event-raising purposes...
            var old = component.Count;

            // Clamp the value.
            if (amount > component.MaxCount)
            {
                amount = component.MaxCount;
            }

            if (amount < 0)
            {
                amount = 0;
            }

            component.Count = amount;
            component.Dirty();

            // Queue delete stack if count reaches zero.
            if (component.Count <= 0)
            {
                EntityManager.QueueDeleteEntity(uid);
            }

            // Change appearance data.
            if (ComponentManager.TryGetComponent(uid, out SharedAppearanceComponent? appearance))
            {
                appearance.SetData(StackVisuals.Actual, component.Count);
            }

            RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count));
        }
 private void OnStackGetState(EntityUid uid, SharedStackComponent component, ref ComponentGetState args)
 {
     args.State = new StackComponentState(component.Count, component.MaxCount);
 }