Exemplo n.º 1
0
        /// <summary>
        /// Add a set of cuffs to an existing CuffedComponent.
        /// </summary>
        /// <param name="prototype"></param>
        public void AddNewCuffs(IEntity handcuff)
        {
            if (!handcuff.HasComponent <HandcuffComponent>())
            {
                Logger.Warning($"Handcuffs being applied to player are missing a {nameof(HandcuffComponent)}!");
                return;
            }

            if (!EntitySystem.Get <SharedInteractionSystem>().InRangeUnobstructed(
                    handcuff.Transform.MapPosition,
                    Owner.Transform.MapPosition,
                    _interactRange,
                    ignoredEnt: Owner))
            {
                Logger.Warning("Handcuffs being applied to player are obstructed or too far away! This should not happen!");
                return;
            }

            _container.Insert(handcuff);
            CanStillInteract = _hands.Hands.Count() > CuffedHandCount;

            OnCuffedStateChanged.Invoke();
            UpdateStatusEffect();
            UpdateHeldItems();
            Dirty();
        }
        public bool TryAddNewCuffs(IEntity user, IEntity handcuff)
        {
            if (!handcuff.HasComponent <HandcuffComponent>())
            {
                Logger.Warning($"Handcuffs being applied to player are missing a {nameof(HandcuffComponent)}!");
                return(false);
            }

            if (!handcuff.InRangeUnobstructed(Owner))
            {
                Logger.Warning("Handcuffs being applied to player are obstructed or too far away! This should not happen!");
                return(true);
            }

            // Success!
            if (user.TryGetComponent(out HandsComponent? handsComponent) && handsComponent.IsHolding(handcuff))
            {
                // Good lord handscomponent is scuffed, I hope some smug person will fix it someday
                handsComponent.Drop(handcuff);
            }

            _container.Insert(handcuff);
            CanStillInteract = Owner.TryGetComponent(out HandsComponent? ownerHands) && ownerHands.Hands.Count() > CuffedHandCount;

            OnCuffedStateChanged?.Invoke();
            UpdateAlert();
            UpdateHeldItems();
            Dirty();
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check the current amount of hands the owner has, and if there's less hands than active cuffs we remove some cuffs.
        /// </summary>
        private void UpdateHandCount()
        {
            var dirty     = false;
            var handCount = _hands.Hands.Count();

            while (CuffedHandCount > handCount && CuffedHandCount > 0)
            {
                dirty = true;

                var entity = _container.ContainedEntities[_container.ContainedEntities.Count - 1];
                _container.Remove(entity);
                entity.Transform.WorldPosition = Owner.Transform.GridPosition.Position;
            }

            if (dirty)
            {
                CanStillInteract = handCount > CuffedHandCount;
                OnCuffedStateChanged.Invoke();
                Dirty();
            }
        }
        private void UpdateHandCount()
        {
            var dirty     = false;
            var handCount = Owner.TryGetComponent(out HandsComponent? handsComponent) ? handsComponent.Hands.Count() : 0;

            while (CuffedHandCount > handCount && CuffedHandCount > 0)
            {
                dirty = true;

                var entity = _container.ContainedEntities[_container.ContainedEntities.Count - 1];
                _container.Remove(entity);
                entity.Transform.WorldPosition = Owner.Transform.Coordinates.Position;
            }

            if (dirty)
            {
                CanStillInteract = handCount > CuffedHandCount;
                OnCuffedStateChanged?.Invoke();
                Dirty();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a set of cuffs to an existing CuffedComponent.
        /// </summary>
        /// <param name="prototype"></param>
        public void AddNewCuffs(IEntity handcuff)
        {
            if (!handcuff.HasComponent <HandcuffComponent>())
            {
                Logger.Warning($"Handcuffs being applied to player are missing a {nameof(HandcuffComponent)}!");
                return;
            }

            if (!handcuff.InRangeUnobstructed(Owner, _interactRange))
            {
                Logger.Warning("Handcuffs being applied to player are obstructed or too far away! This should not happen!");
                return;
            }

            _container.Insert(handcuff);
            CanStillInteract = _hands.Hands.Count() > CuffedHandCount;

            OnCuffedStateChanged?.Invoke();
            UpdateAlert();
            UpdateHeldItems();
            Dirty();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attempt to uncuff a cuffed entity. Can be called by the cuffed entity, or another entity trying to help uncuff them.
        /// If the uncuffing succeeds, the cuffs will drop on the floor.
        /// </summary>
        /// <param name="user">The cuffed entity</param>
        /// <param name="cuffsToRemove">Optional param for the handcuff entity to remove from the cuffed entity. If null, uses the most recently added handcuff entity.</param>
        public async void TryUncuff(IEntity user, IEntity cuffsToRemove = null)
        {
            var isOwner = user == Owner;

            if (cuffsToRemove == null)
            {
                cuffsToRemove = LastAddedCuffs;
            }
            else
            {
                if (!_container.ContainedEntities.Contains(cuffsToRemove))
                {
                    Logger.Warning("A user is trying to remove handcuffs that aren't in the owner's container. This should never happen!");
                }
            }

            if (!cuffsToRemove.TryGetComponent <HandcuffComponent>(out var cuff))
            {
                Logger.Warning($"A user is trying to remove handcuffs without a {nameof(HandcuffComponent)}. This should never happen!");
                return;
            }

            if (!isOwner && !ActionBlockerSystem.CanInteract(user))
            {
                user.PopupMessage(user, Loc.GetString("You can't do that!"));
                return;
            }

            if (!isOwner && user.InRangeUnobstructed(Owner, _interactRange))
            {
                user.PopupMessage(user, Loc.GetString("You are too far away to remove the cuffs."));
                return;
            }

            if (!cuffsToRemove.InRangeUnobstructed(Owner, _interactRange))
            {
                Logger.Warning("Handcuffs being removed from player are obstructed or too far away! This should not happen!");
                return;
            }

            user.PopupMessage(user, Loc.GetString("You start removing the cuffs."));

            var audio = EntitySystem.Get <AudioSystem>();

            audio.PlayFromEntity(isOwner ? cuff.StartBreakoutSound : cuff.StartUncuffSound, Owner);

            var uncuffTime       = isOwner ? cuff.BreakoutTime : cuff.UncuffTime;
            var doAfterEventArgs = new DoAfterEventArgs(user, uncuffTime)
            {
                BreakOnUserMove = true,
                BreakOnDamage   = true,
                BreakOnStun     = true,
                NeedHand        = true
            };

            var doAfterSystem = EntitySystem.Get <DoAfterSystem>();
            var result        = await doAfterSystem.DoAfter(doAfterEventArgs);

            if (result != DoAfterStatus.Cancelled)
            {
                audio.PlayFromEntity(cuff.EndUncuffSound, Owner);

                _container.ForceRemove(cuffsToRemove);
                cuffsToRemove.Transform.AttachToGridOrMap();
                cuffsToRemove.Transform.WorldPosition = Owner.Transform.WorldPosition;

                if (cuff.BreakOnRemove)
                {
                    cuff.Broken = true;

                    cuffsToRemove.Name        = cuff.BrokenName;
                    cuffsToRemove.Description = cuff.BrokenDesc;

                    if (cuffsToRemove.TryGetComponent <SpriteComponent>(out var sprite))
                    {
                        sprite.LayerSetState(0, cuff.BrokenState); // TODO: safety check to see if RSI contains the state?
                    }
                }

                CanStillInteract = _hands.Hands.Count() > CuffedHandCount;
                OnCuffedStateChanged.Invoke();
                UpdateStatusEffect();
                Dirty();

                if (CuffedHandCount == 0)
                {
                    _notifyManager.PopupMessage(user, user, Loc.GetString("You successfully remove the cuffs."));

                    if (!isOwner)
                    {
                        _notifyManager.PopupMessage(user, Owner, Loc.GetString("{0:theName} uncuffs your hands.", user));
                    }
                }
                else
                {
                    if (!isOwner)
                    {
                        _notifyManager.PopupMessage(user, user, Loc.GetString("You successfully remove the cuffs. {0} of {1:theName}'s hands remain cuffed.", CuffedHandCount, user));
                        _notifyManager.PopupMessage(user, Owner, Loc.GetString("{0:theName} removes your cuffs. {1} of your hands remain cuffed.", user, CuffedHandCount));
                    }
                    else
                    {
                        _notifyManager.PopupMessage(user, user, Loc.GetString("You successfully remove the cuffs. {0} of your hands remain cuffed.", CuffedHandCount));
                    }
                }
            }
            else
            {
                _notifyManager.PopupMessage(user, user, Loc.GetString("You fail to remove the cuffs."));
            }

            return;
        }