Пример #1
0
        /// <summary>
        /// Try to fold/unfold
        /// </summary>
        /// <param name="comp"></param>
        /// <param name="state">Folded state we want</param>
        /// <returns>True if successful</returns>
        private bool TrySetFolded(FoldableComponent comp, bool state)
        {
            if (state == comp.IsFolded)
            {
                return(false);
            }

            if (_container.IsEntityInContainer(comp.Owner))
            {
                return(false);
            }

            // First we check if the foldable object has a strap component
            if (EntityManager.TryGetComponent(comp.Owner, out StrapComponent? strap))
            {
                // If an entity is buckled to the object we can't pick it up or fold it
                if (strap.BuckledEntities.Any())
                {
                    return(false);
                }
            }

            SetFolded(comp, state);
            return(true);
        }
 private void OnFoldableOpenAttempt(EntityUid uid, FoldableComponent component, StorageOpenAttemptEvent args)
 {
     if (component.IsFolded)
     {
         args.Cancel();
     }
 }
Пример #3
0
 /// <summary>
 /// Prevents foldable objects to be picked up when unfolded
 /// </summary>
 /// <param name="uid"></param>
 /// <param name="component"></param>
 /// <param name="args"></param>
 private void OnPickedUpAttempt(EntityUid uid, FoldableComponent component, AttemptItemPickupEvent args)
 {
     if (!component.IsFolded)
     {
         args.Cancel();
     }
 }
        public void OnStoreThisAttempt(EntityUid uid, FoldableComponent comp, StoreMobInItemContainerAttemptEvent args)
        {
            args.Handled = true;

            if (comp.IsFolded)
            {
                args.Cancel();
            }
        }
        /// <summary>
        /// Set the folded state of the given <see cref="FoldableComponent"/>
        /// </summary>
        /// <param name="component"></param>
        /// <param name="folded">If true, the component will become folded, else unfolded</param>
        public override void SetFolded(FoldableComponent component, bool folded)
        {
            base.SetFolded(component, folded);

            // You can't buckle an entity to a folded object
            if (TryComp(component.Owner, out StrapComponent? strap))
            {
                strap.Enabled = !component.IsFolded;
            }
        }
        /// <summary>
        /// Try to fold/unfold
        /// </summary>
        /// <param name="comp"></param>
        /// <param name="state">Folded state we want</param>
        /// <returns>True if successful</returns>
        public bool TrySetFolded(FoldableComponent comp, bool state)
        {
            if (state == comp.IsFolded)
            {
                return(false);
            }

            if (!CanToggleFold(comp.Owner, comp))
            {
                return(false);
            }

            SetFolded(comp, state);
            return(true);
        }
Пример #7
0
        /// <summary>
        /// Set the folded state of the given <see cref="FoldableComponent"/>
        /// </summary>
        /// <param name="component"></param>
        /// <param name="folded">If true, the component will become folded, else unfolded</param>
        private void SetFolded(FoldableComponent component, bool folded)
        {
            component.IsFolded    = folded;
            component.CanBeFolded = !_container.IsEntityInContainer(component.Owner);

            // You can't buckle an entity to a folded object
            if (EntityManager.TryGetComponent(component.Owner, out StrapComponent? strap))
            {
                strap.Enabled = !component.IsFolded;
            }

            // Update visuals only if the value has changed
            if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearance))
            {
                appearance.SetData(FoldKey, folded);
            }
        }
        private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetAlternativeVerbsEvent args)
        {
            if (!args.CanAccess || !args.CanInteract || !CanToggleFold(uid, component))
            {
                return;
            }

            Verb verb = new()
            {
                Act         = () => TryToggleFold(component),
                Text        = component.IsFolded ? Loc.GetString("unfold-verb") : Loc.GetString("fold-verb"),
                IconTexture = "/Textures/Interface/VerbIcons/fold.svg.192dpi.png",

                // If the object is unfolded and they click it, they want to fold it, if it's folded, they want to pick it up
                Priority = component.IsFolded ? 0 : 2,
            };

            args.Verbs.Add(verb);
        }
 public bool TryToggleFold(FoldableComponent comp)
 {
     return(TrySetFolded(comp, !comp.IsFolded));
 }
Пример #10
0
 private void OnFoldableInit(EntityUid uid, FoldableComponent component, ComponentInit args)
 {
     SetFolded(component, component.IsFolded);
 }