/// <summary>
        ///     Places item in user's active hand in one of the entity's hands.
        /// </summary>
        private async void PlaceActiveHandItemInHands(EntityUid user, string handName)
        {
            var hands     = _entities.GetComponent <HandsComponent>(Owner);
            var userHands = _entities.GetComponent <HandsComponent>(user);
            var sys       = _sysMan.GetEntitySystem <SharedHandsSystem>();

            bool Check()
            {
                if (userHands.ActiveHandEntity == null)
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-not-holding-anything"));
                    return(false);
                }

                if (!sys.CanDropHeld(user, userHands.ActiveHand !))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop"));
                    return(false);
                }

                if (!hands.Hands.TryGetValue(handName, out var hand) ||
                    !sys.CanPickupToHand(Owner, userHands.ActiveHandEntity.Value, hand, checkActionBlocker: false, hands))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-put-message", ("owner", Owner)));
                    return(false);
                }

                return(true);
            }

            var doAfterSystem = _sysMan.GetEntitySystem <DoAfterSystem>();

            var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
            {
                ExtraCheck        = Check,
                BreakOnStun       = true,
                BreakOnDamage     = true,
                BreakOnTargetMove = true,
                BreakOnUserMove   = true,
                NeedHand          = true,
            };

            var result = await doAfterSystem.WaitDoAfter(doAfterArgs);

            if (result != DoAfterStatus.Finished)
            {
                return;
            }

            if (userHands.ActiveHandEntity is not EntityUid held)
            {
                return;
            }

            sys.TryDrop(user, checkActionBlocker: false, handsComp: userHands);
            sys.TryPickup(Owner, held, handName, checkActionBlocker: false, animateUser: true, handsComp: hands);
            // hand update will trigger strippable update
        }
Пример #2
0
        private bool InteractUI(EntityUid user, ActivatableUIComponent aui)
        {
            if (!EntityManager.TryGetComponent(user, out ActorComponent? actor))
            {
                return(false);
            }

            if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession))
            {
                return(false);
            }

            if (!_actionBlockerSystem.CanInteract(user))
            {
                user.PopupMessageCursor(Loc.GetString("base-computer-ui-component-cannot-interact"));
                return(true);
            }

            var ui = aui.UserInterface;

            if (ui == null)
            {
                return(false);
            }

            if (aui.SingleUser && (aui.CurrentSingleUser != null) && (actor.PlayerSession != aui.CurrentSingleUser))
            {
                // If we get here, supposedly, the object is in use.
                // Check with BUI that it's ACTUALLY in use just in case.
                // Since this could brick the object if it goes wrong.
                if (ui.SubscribedSessions.Count != 0)
                {
                    return(false);
                }
            }

            // If we've gotten this far, fire a cancellable event that indicates someone is about to activate this.
            // This is so that stuff can require further conditions (like power).
            var oae = new ActivatableUIOpenAttemptEvent(user);

            RaiseLocalEvent((aui).Owner, oae, false);
            if (oae.Cancelled)
            {
                return(false);
            }

            SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui);
            ui.Toggle(actor.PlayerSession);
            return(true);
        }
        private void TryCreatePackage(EntityUid user, UiAction action, string label, int pillAmount, int bottleAmount)
        {
            if (BufferSolution.TotalVolume == 0)
            {
                user.PopupMessageCursor(Loc.GetString("chem-master-window-buffer-empty-text"));
                return;
            }

            if (action == UiAction.CreateBottles)
            {
                var individualVolume = BufferSolution.TotalVolume / FixedPoint2.New(bottleAmount);
                if (individualVolume < FixedPoint2.New(1))
                {
                    user.PopupMessageCursor(Loc.GetString("chem-master-window-buffer-low-text"));
                    return;
                }

                var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(30));
                for (int i = 0; i < bottleAmount; i++)
                {
                    var bottle = _entities.SpawnEntity("ChemistryEmptyBottle01", _entities.GetComponent <TransformComponent>(Owner).Coordinates);

                    //Adding label
                    LabelComponent labelComponent = bottle.EnsureComponent <LabelComponent>();
                    labelComponent.OriginalName = _entities.GetComponent <MetaDataComponent>(bottle).EntityName;
                    string val = _entities.GetComponent <MetaDataComponent>(bottle).EntityName + $" ({label})";
                    _entities.GetComponent <MetaDataComponent>(bottle).EntityName = val;
                    labelComponent.CurrentLabel = label;

                    var bufferSolution = BufferSolution.SplitSolution(actualVolume);
                    var bottleSolution = EntitySystem.Get <SolutionContainerSystem>().EnsureSolution(bottle, "drink");

                    EntitySystem.Get <SolutionContainerSystem>().TryAddSolution(bottle, bottleSolution, bufferSolution);

                    //Try to give them the bottle
                    if (_entities.TryGetComponent <HandsComponent?>(user, out var hands) &&
                        _entities.TryGetComponent <SharedItemComponent?>(bottle, out var item))
                    {
                        if (hands.CanPutInHand(item))
                        {
                            hands.PutInHand(item);
                            continue;
                        }
                    }

                    //Put it on the floor
                    _entities.GetComponent <TransformComponent>(bottle).Coordinates = _entities.GetComponent <TransformComponent>(user).Coordinates;
                    //Give it an offset
                    bottle.RandomOffset(0.2f);
                }
            }
            else //Pills
            {
                var individualVolume = BufferSolution.TotalVolume / FixedPoint2.New(pillAmount);
                if (individualVolume < FixedPoint2.New(1))
                {
                    user.PopupMessageCursor(Loc.GetString("chem-master-window-buffer-low-text"));
                    return;
                }

                var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(50));
                for (int i = 0; i < pillAmount; i++)
                {
                    var pill = _entities.SpawnEntity("pill", _entities.GetComponent <TransformComponent>(Owner).Coordinates);

                    //Adding label
                    LabelComponent labelComponent = pill.EnsureComponent <LabelComponent>();
                    labelComponent.OriginalName = _entities.GetComponent <MetaDataComponent>(pill).EntityName;
                    string val = _entities.GetComponent <MetaDataComponent>(pill).EntityName + $" ({label})";
                    _entities.GetComponent <MetaDataComponent>(pill).EntityName = val;
                    labelComponent.CurrentLabel = label;

                    var bufferSolution = BufferSolution.SplitSolution(actualVolume);
                    var pillSolution   = EntitySystem.Get <SolutionContainerSystem>().EnsureSolution(pill, "food");
                    EntitySystem.Get <SolutionContainerSystem>().TryAddSolution(pill, pillSolution, bufferSolution);

                    //Change pill Sprite component state
                    if (!_entities.TryGetComponent(pill, out SpriteComponent? sprite))
                    {
                        return;
                    }
                    sprite?.LayerSetState(0, "pill" + _pillType);

                    //Try to give them the bottle
                    if (_entities.TryGetComponent <HandsComponent?>(user, out var hands) &&
                        _entities.TryGetComponent <SharedItemComponent?>(pill, out var item))
                    {
                        if (hands.CanPutInHand(item))
                        {
                            hands.PutInHand(item);
                            continue;
                        }
                    }

                    //Put it on the floor
                    _entities.GetComponent <TransformComponent>(pill).Coordinates = _entities.GetComponent <TransformComponent>(user).Coordinates;
                    //Give it an offset
                    pill.RandomOffset(0.2f);
                }
            }

            if (_bufferSolution?.Contents.Count == 0)
            {
                _label = "";
            }

            UpdateUserInterface();
        }
        public bool TryDoInject(EntityUid?target, EntityUid user)
        {
            if (!EligibleEntity(target, _entMan))
            {
                return(false);
            }

            string?msgFormat = null;

            if (target == user)
            {
                msgFormat = "hypospray-component-inject-self-message";
            }
            else if (EligibleEntity(user, _entMan) && ClumsyComponent.TryRollClumsy(user, ClumsyFailChance))
            {
                msgFormat = "hypospray-component-inject-self-clumsy-message";
                target    = user;
            }

            var solutionsSys = EntitySystem.Get <SolutionContainerSystem>();

            solutionsSys.TryGetSolution(Owner, SolutionName, out var hypoSpraySolution);

            if (hypoSpraySolution == null || hypoSpraySolution.CurrentVolume == 0)
            {
                user.PopupMessageCursor(Loc.GetString("hypospray-component-empty-message"));
                return(true);
            }

            if (!solutionsSys.TryGetInjectableSolution(target.Value, out var targetSolution))
            {
                user.PopupMessage(user,
                                  Loc.GetString("hypospray-cant-inject", ("target", Identity.Entity(target.Value, _entMan))));
                return(false);
            }

            user.PopupMessage(Loc.GetString(msgFormat ?? "hypospray-component-inject-other-message",
                                            ("other", target)));
            if (target != user)
            {
                target.Value.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message"));
                var meleeSys = EntitySystem.Get <MeleeWeaponSystem>();
                var angle    = Angle.FromWorldVec(_entMan.GetComponent <TransformComponent>(target.Value).WorldPosition - _entMan.GetComponent <TransformComponent>(user).WorldPosition);
                meleeSys.SendLunge(angle, user);
            }

            SoundSystem.Play(_injectSound.GetSound(), Filter.Pvs(user), user);

            // Get transfer amount. May be smaller than _transferAmount if not enough room
            var realTransferAmount = FixedPoint2.Min(TransferAmount, targetSolution.AvailableVolume);

            if (realTransferAmount <= 0)
            {
                user.PopupMessage(user,
                                  Loc.GetString("hypospray-component-transfer-already-full-message",
                                                ("owner", target)));
                return(true);
            }

            // Move units from attackSolution to targetSolution
            var removedSolution =
                EntitySystem.Get <SolutionContainerSystem>()
                .SplitSolution(Owner, hypoSpraySolution, realTransferAmount);

            if (!targetSolution.CanAddSolution(removedSolution))
            {
                return(true);
            }

            removedSolution.DoEntityReaction(target.Value, ReactionMethod.Injection);

            EntitySystem.Get <SolutionContainerSystem>().TryAddSolution(target.Value, targetSolution, removedSolution);
Пример #5
0
        /// <summary>
        ///     Places item in user's active hand to an inventory slot.
        /// </summary>
        private async void PlaceActiveHandItemInInventory(EntityUid user, string slot)
        {
            var userHands = _entities.GetComponent <HandsComponent>(user);
            var item      = userHands.GetActiveHand;
            var invSystem = EntitySystem.Get <InventorySystem>();

            bool Check()
            {
                if (!EntitySystem.Get <ActionBlockerSystem>().CanInteract(user))
                {
                    return(false);
                }

                if (item == null)
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-not-holding-anything"));
                    return(false);
                }

                if (!userHands.CanDrop(userHands.ActiveHand !))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop"));
                    return(false);
                }

                if (!invSystem.HasSlot(Owner, slot))
                {
                    return(false);
                }

                if (invSystem.TryGetSlotEntity(Owner, slot, out _))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied", ("owner", Owner)));
                    return(false);
                }

                if (!invSystem.CanEquip(user, Owner, item.Owner, slot, out _))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-equip-message", ("owner", Owner)));
                    return(false);
                }

                return(true);
            }

            var doAfterSystem = EntitySystem.Get <DoAfterSystem>();

            var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
            {
                ExtraCheck        = Check,
                BreakOnStun       = true,
                BreakOnDamage     = true,
                BreakOnTargetMove = true,
                BreakOnUserMove   = true,
                NeedHand          = true,
            };

            var result = await doAfterSystem.WaitDoAfter(doAfterArgs);

            if (result != DoAfterStatus.Finished)
            {
                return;
            }

            userHands.Drop(item !.Owner, false);
            invSystem.TryEquip(user, Owner, item.Owner, slot);

            UpdateState();
        }
        /// <summary>
        ///     Places item in user's active hand in one of the entity's hands.
        /// </summary>
        private async void PlaceActiveHandItemInHands(EntityUid user, string hand)
        {
            var hands     = _entities.GetComponent <HandsComponent>(Owner);
            var userHands = _entities.GetComponent <HandsComponent>(user);
            var item      = userHands.GetActiveHandItem;

            bool Check()
            {
                if (item == null)
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-not-holding-anything"));
                    return(false);
                }

                if (!userHands.CanDrop(userHands.ActiveHand !))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop"));
                    return(false);
                }

                if (!hands.HasHand(hand))
                {
                    return(false);
                }

                if (hands.TryGetItem(hand, out var _))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied-message", ("owner", Owner)));
                    return(false);
                }

                if (!hands.CanPickupEntity(hand, item.Owner, checkActionBlocker: false))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-put-message", ("owner", Owner)));
                    return(false);
                }

                return(true);
            }

            var doAfterSystem = EntitySystem.Get <DoAfterSystem>();

            var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
            {
                ExtraCheck        = Check,
                BreakOnStun       = true,
                BreakOnDamage     = true,
                BreakOnTargetMove = true,
                BreakOnUserMove   = true,
                NeedHand          = true,
            };

            var result = await doAfterSystem.WaitDoAfter(doAfterArgs);

            if (result != DoAfterStatus.Finished)
            {
                return;
            }

            userHands.Drop(hand);
            hands.TryPickupEntity(hand, item !.Owner, checkActionBlocker: false, animateUser: true);
            // hand update will trigger strippable update
        }
        /// <summary>
        ///     Places item in user's active hand to an inventory slot.
        /// </summary>
        private async void PlaceActiveHandItemInInventory(EntityUid user, string slot)
        {
            var userHands = _entities.GetComponent <HandsComponent>(user);
            var invSystem = _sysMan.GetEntitySystem <InventorySystem>();
            var handSys   = _sysMan.GetEntitySystem <SharedHandsSystem>();

            bool Check()
            {
                if (userHands.ActiveHand?.HeldEntity is not EntityUid held)
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-not-holding-anything"));
                    return(false);
                }

                if (!handSys.CanDropHeld(user, userHands.ActiveHand))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop"));
                    return(false);
                }

                if (!invSystem.HasSlot(Owner, slot))
                {
                    return(false);
                }

                if (invSystem.TryGetSlotEntity(Owner, slot, out _))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied", ("owner", Owner)));
                    return(false);
                }

                if (!invSystem.CanEquip(user, Owner, held, slot, out _))
                {
                    user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-equip-message", ("owner", Owner)));
                    return(false);
                }

                return(true);
            }

            var doAfterSystem = EntitySystem.Get <DoAfterSystem>();

            var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
            {
                ExtraCheck        = Check,
                BreakOnStun       = true,
                BreakOnDamage     = true,
                BreakOnTargetMove = true,
                BreakOnUserMove   = true,
                NeedHand          = true,
            };

            var result = await doAfterSystem.WaitDoAfter(doAfterArgs);

            if (result != DoAfterStatus.Finished)
            {
                return;
            }

            if (userHands.ActiveHand?.HeldEntity is EntityUid held &&
                handSys.TryDrop(user, userHands.ActiveHand, handsComp: userHands))
            {
                invSystem.TryEquip(user, Owner, held, slot);
            }

            UpdateState();
        }