Esempio n. 1
0
    /// <summary>
    /// Check if item has an interaction with a an item in a slot
    /// If not or if bool returned is true, swap items
    /// </summary>
    public void TryItemInteract(bool swapIfEmpty = true)
    {
        var slotName = itemSlot.SlotIdentifier.NamedSlot;

        // Clicked on another slot other than our own hands
        if (itemSlot != UIManager.Hands.LeftHand.ItemSlot && itemSlot != UIManager.Hands.RightHand.itemSlot)
        {
            // If full, attempt to interact the two, otherwise swap
            if (Item != null)
            {
                //check IF2 InventoryApply interaction - combine the active hand item with this (only if
                //both are occupied)
                if (TryIF2InventoryApply())
                {
                    return;
                }

                if (swapIfEmpty)
                {
                    UIManager.Hands.SwapItem(this);
                }
                return;
            }
            else
            {
                if (swapIfEmpty)
                {
                    UIManager.Hands.SwapItem(this);
                }
                return;
            }
        }
        // If there is an item and the hand is interacting in the same slot
        if (Item != null && UIManager.Hands.CurrentSlot.ItemSlot == itemSlot)
        {
            //check IF2 logic first
            var interactables = Item.GetComponents <IBaseInteractable <HandActivate> >()
                                .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
            var activate = HandActivate.ByLocalPlayer();
            InteractionUtils.ClientCheckAndTrigger(interactables, activate);
        }
        else
        {
            if (UIManager.Hands.CurrentSlot.ItemSlot != itemSlot)
            {
                //Clicked on item with otherslot selected
                if (UIManager.Hands.OtherSlot.Item != null)
                {
                    if (TryIF2InventoryApply())
                    {
                        return;
                    }
                    if (swapIfEmpty)
                    {
                        UIManager.Hands.SwapItem(this);
                    }
                }
            }
        }
    }
Esempio n. 2
0
    private bool TryIF2InventoryApply()
    {
        //check IF2 InventoryApply interaction - apply the active hand item with this (only if
        //target slot is occupied, but it's okay if active hand slot is not occupied)
        if (Item != null)
        {
            var combine = InventoryApply.ByLocalPlayer(itemSlot, UIManager.Hands.CurrentSlot.itemSlot);
            //check interactables in the active hand (if active hand occupied)
            if (UIManager.Hands.CurrentSlot.Item != null)
            {
                var handInteractables = UIManager.Hands.CurrentSlot.Item.GetComponents <IBaseInteractable <InventoryApply> >()
                                        .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
                if (InteractionUtils.ClientCheckAndTrigger(handInteractables, combine) != null)
                {
                    return(true);
                }
            }

            //check interactables in the target
            var targetInteractables = Item.GetComponents <IBaseInteractable <InventoryApply> >()
                                      .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
            if (InteractionUtils.ClientCheckAndTrigger(targetInteractables, combine) != null)
            {
                return(true);
            }
        }

        return(false);
    }
    private bool CheckAimApply(MouseButtonState buttonState)
    {
        ChangeDirection();
        //currently there is nothing for ghosts to interact with, they only can change facing
        if (PlayerManager.LocalPlayerScript.IsGhost)
        {
            return(false);
        }

        //can't do anything if we have no item in hand
        var handObj = UIManager.Hands.CurrentSlot.Item;

        if (handObj == null)
        {
            triggeredAimApply = null;
            secondsSinceLastAimApplyTrigger = 0;
            return(false);
        }

        var aimApplyInfo = AimApply.ByLocalPlayer(buttonState);

        if (buttonState == MouseButtonState.PRESS)
        {
            //it's being clicked down
            triggeredAimApply = null;
            //Checks for aim apply interactions which can trigger
            var comps = handObj.GetComponents <IBaseInteractable <AimApply> >()
                        .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
            var triggered = InteractionUtils.ClientCheckAndTrigger(comps, aimApplyInfo);
            if (triggered != null)
            {
                triggeredAimApply = triggered;
                secondsSinceLastAimApplyTrigger = 0;
                return(true);
            }
        }
        else
        {
            //it's being held
            //if we are already triggering an AimApply, keep triggering it based on the AimApplyInterval
            if (triggeredAimApply != null)
            {
                secondsSinceLastAimApplyTrigger += Time.deltaTime;
                if (secondsSinceLastAimApplyTrigger > AimApplyInterval)
                {
                    if (triggeredAimApply.CheckInteract(aimApplyInfo, NetworkSide.Client))
                    {
                        //only reset timer if it was actually triggered
                        secondsSinceLastAimApplyTrigger = 0;
                        InteractionUtils.RequestInteract(aimApplyInfo, triggeredAimApply);
                    }
                }

                //no matter what the result, we keep trying to trigger it until mouse is released.
                return(true);
            }
        }

        return(false);
    }
Esempio n. 4
0
    private void OnDragEnd()
    {
        UIManager.IsMouseInteractionDisabled = false;
        Destroy(shadowObject);
        shadowObject = null;
        if (lightingSystem.enabled && !lightingSystem.IsScreenPointVisible(CommonInput.mousePosition))
        {
            //do nothing, the point is not visible.
            return;
        }
        //check what we dropped on, which may or may not have mousedrop interaction components
        //can only drop on things that have a RegisterTile
        var dropTargets =
            MouseUtils.GetOrderedObjectsUnderMouse();

        //go through the stack of objects and call any drop components we find
        foreach (GameObject dropTarget in dropTargets)
        {
            MouseDrop info = MouseDrop.ByLocalPlayer(gameObject, dropTarget.gameObject);
            //call this object's mousedrop interaction methods if it has any, for each object we are dropping on
            if (InteractionUtils.ClientCheckAndTrigger(mouseDrops, info) != null)
            {
                return;
            }
            var targetComps = dropTarget.GetComponents <IBaseInteractable <MouseDrop> >()
                              .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
            if (InteractionUtils.ClientCheckAndTrigger(targetComps, info) != null)
            {
                return;
            }
        }
    }
Esempio n. 5
0
        /// <summary>
        ///     Loops over all <see cref="IDisablingInteractionAdvisor" /> <see cref="IFacet" />s and
        ///     returns <c>true</c> only if none disables the member.
        /// </summary>
        public virtual IConsent IsUsable(INakedObjectAdapter target)
        {
            IInteractionContext ic = InteractionContext
                                     .AccessMember(Session, false, target, Identifier);

            return(InteractionUtils.IsUsable(this, ic));
        }
Esempio n. 6
0
 private void ContextMenuOptionClicked(ContextMenuApply interaction)
 {
     if (!AccessRestrictions || AccessRestrictions.CheckAccess(interaction.Performer))
     {
         InteractionUtils.RequestInteract(interaction, this);
     }
     else
     {
         Chat.AddExamineMsg(interaction.Performer, $"Access Denied.");
         // Play sound
         SoundManager.PlayNetworkedAtPos(SingletonSOSounds.Instance.AccessDenied, gameObject.AssumedWorldPosServer(), sourceObj: gameObject);
     }
 }
Esempio n. 7
0
        private void CheckForInteractions(AiActivate.ClickTypes clickType)
        {
            var handApplyTargets = MouseUtils.GetOrderedObjectsUnderMouse();

            //go through the stack of objects and call AiActivate interaction components we find
            foreach (GameObject applyTarget in handApplyTargets)
            {
                var behaviours = applyTarget.GetComponents <IBaseInteractable <AiActivate> >()
                                 .Where(mb => mb != null && (mb as MonoBehaviour).enabled);

                var aiActivate = new AiActivate(gameObject, null, applyTarget, Intent.Help, clickType);
                InteractionUtils.ClientCheckAndTrigger(behaviours, aiActivate);
            }
        }
Esempio n. 8
0
        public IConsent IsValid(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter proposedValue)
        {
            if (proposedValue != null && !proposedValue.Spec.IsOfType(Spec))
            {
                string msg = string.Format(Resources.NakedObjects.TypeMismatchError, Spec.SingularName);
                return(GetConsent(msg));
            }

            var buf = new InteractionBuffer();
            IInteractionContext ic = InteractionContext.ModifyingPropParam(session, false, parentAction.RealTarget(nakedObjectAdapter), Identifier, proposedValue);

            InteractionUtils.IsValid(this, ic, buf);
            return(InteractionUtils.IsValid(buf));
        }
Esempio n. 9
0
    /// <summary>
    /// Check if item has an interaction with a an item in a slot
    /// If not or if bool returned is true, swap items
    /// </summary>
    public void TryItemInteract()
    {
        // Clicked on another slot other than hands
        if (equipSlot != EquipSlot.leftHand && equipSlot != EquipSlot.rightHand)
        {
            // If full, attempt to interact the two, otherwise swap
            if (Item != null)
            {
                //check IF2 InventoryApply interaction - combine the active hand item with this (only if
                //both are occupied)
                if (TryIF2InventoryApply())
                {
                    return;
                }

                UIManager.Hands.SwapItem(this);
                return;
            }
            else
            {
                UIManager.Hands.SwapItem(this);
                return;
            }
        }
        // If there is an item and the hand is interacting in the same slot
        if (Item != null && UIManager.Hands.CurrentSlot.equipSlot == equipSlot)
        {
            //check IF2 logic first
            var interactables = Item.GetComponents <IBaseInteractable <HandActivate> >()
                                .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
            var activate = HandActivate.ByLocalPlayer();
            InteractionUtils.ClientCheckAndTrigger(interactables, activate);
        }
        else
        {
            if (UIManager.Hands.CurrentSlot.equipSlot != equipSlot)
            {
                //Clicked on item with otherslot selected
                if (UIManager.Hands.OtherSlot.Item != null)
                {
                    if (TryIF2InventoryApply())
                    {
                        return;
                    }
                    UIManager.Hands.SwapItem(this);
                }
            }
        }
    }
Esempio n. 10
0
        public void OnDrop(PointerEventData data)
        {
            // something was dropped onto this slot
            if (UIManager.UiDragAndDrop.FromSlotCache != null && UIManager.UiDragAndDrop.DraggedItem != null)
            {
                var fromSlot   = UIManager.UiDragAndDrop.DraggedItem.GetComponent <Pickupable>().ItemSlot;
                var targetItem = itemSlot.ItemSlot.ItemObject;

                if (fromSlot.ItemObject == null || fromSlot.ItemObject == targetItem)
                {
                    return;
                }

                // if there's an item in the target slot, try inventory apply interaction

                if (targetItem != null)
                {
                    var invApply = InventoryApply.ByLocalPlayer(itemSlot.ItemSlot, fromSlot);

                    // check interactables in the fromSlot (if it's occupied)
                    var fromInteractables = fromSlot.ItemObject.GetComponents <IBaseInteractable <InventoryApply> >()
                                            .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
                    if (InteractionUtils.ClientCheckAndTrigger(fromInteractables, invApply) != null)
                    {
                        UIManager.UiDragAndDrop.DropInteracted = true;
                        UIManager.UiDragAndDrop.StopDrag();
                        return;
                    }

                    // check interactables in the target
                    var targetInteractables = targetItem.GetComponents <IBaseInteractable <InventoryApply> >()
                                              .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
                    if (InteractionUtils.ClientCheckAndTrigger(targetInteractables, invApply) != null)
                    {
                        UIManager.UiDragAndDrop.DropInteracted = true;
                        UIManager.UiDragAndDrop.StopDrag();
                        return;
                    }
                }
                else
                {
                    UIManager.UiDragAndDrop.DropInteracted = true;
                    UIManager.UiDragAndDrop.StopDrag();
                    Inventory.ClientRequestTransfer(fromSlot, itemSlot.ItemSlot);
                }
            }
            UIManager.UiDragAndDrop.StopDrag();
        }
Esempio n. 11
0
        protected override IEnumerator CustomUpdateBenchmark(int sampleCount)
        {
            int disableGeneratorPoint = sampleCount / 3;
            int enableGeneratorPoint  = sampleCount * 2 / 3;

            yield return(new WaitWhile(LoopFunction));

            bool LoopFunction()
            {
                sampleCount--;
                if (sampleCount == disableGeneratorPoint || sampleCount == enableGeneratorPoint)
                {
                    var generator = GetAtRelative <PowerGenerator>(Orientation.Right);
                    InteractionUtils.RequestInteract(HandApply.ByLocalPlayer(generator.gameObject), generator);
                }
                return(sampleCount > 0);
            }
        }
Esempio n. 12
0
        public void StopDrag()
        {
            if (!DropInteracted && DraggedItem != null)
            {
                var mouseDrops = DraggedItem.GetComponents <IBaseInteractable <MouseDrop> >();
                // check for MouseDrop interactions in the world if we didn't drop on a UI slot
                // check what we dropped on, which may or may not have mousedrop interaction components
                var dropTargets =
                    MouseUtils.GetOrderedObjectsUnderMouse();

                // go through the stack of objects and call any drop components we find
                foreach (GameObject dropTarget in dropTargets)
                {
                    MouseDrop info = MouseDrop.ByLocalPlayer(DraggedItem, dropTarget.gameObject);
                    // call this object's mousedrop interaction methods if it has any, for each object we are dropping on
                    if (InteractionUtils.ClientCheckAndTrigger(mouseDrops, info) != null)
                    {
                        break;
                    }
                    var targetComps = dropTarget.GetComponents <IBaseInteractable <MouseDrop> >()
                                      .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
                    if (InteractionUtils.ClientCheckAndTrigger(targetComps, info) != null)
                    {
                        break;
                    }
                }
            }
            DropInteracted    = false;
            isDragging        = false;
            dragDummy.enabled = false;
            if (FromSlotCache != null)
            {
                if (FromSlotCache.Item != null)
                {
                    FromSlotCache.RefreshImage();
                }
            }


            FromSlotCache = null;
            DraggedItem   = null;
            ResetInteractable();
        }
Esempio n. 13
0
        /// <summary>
        ///     Checks declarative constraints, and then checks imperatively.
        /// </summary>
        public IConsent IsParameterSetValid(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter[] parameterSet)
        {
            IInteractionContext ic;
            var buf = new InteractionBuffer();

            if (parameterSet != null)
            {
                INakedObjectAdapter[] parms = RealParameters(nakedObjectAdapter, parameterSet);
                for (int i = 0; i < parms.Length; i++)
                {
                    ic = InteractionContext.ModifyingPropParam(Session, false, RealTarget(nakedObjectAdapter), Identifier, parameterSet[i]);
                    InteractionUtils.IsValid(GetParameter(i), ic, buf);
                }
            }
            INakedObjectAdapter target = RealTarget(nakedObjectAdapter);

            ic = InteractionContext.InvokingAction(Session, false, target, Identifier, parameterSet);
            InteractionUtils.IsValid(this, ic, buf);
            return(InteractionUtils.IsValid(buf));
        }
        public virtual IConsent IsAssociationValid(INakedObject inObject, INakedObject reference)
        {
            if (reference != null && !reference.Spec.IsOfType(ReturnSpec))
            {
                return(GetConsent(string.Format(Resources.NakedObjects.TypeMismatchError, ReturnSpec.SingularName)));
            }

            if (!inObject.ResolveState.IsNotPersistent())
            {
                if (reference != null && !reference.Spec.IsParseable && reference.ResolveState.IsNotPersistent())
                {
                    return(GetConsent(Resources.NakedObjects.TransientFieldMessage));
                }
            }

            var buf = new InteractionBuffer();
            InteractionContext ic = InteractionContext.ModifyingPropParam(Session, false, inObject, Identifier, reference);

            InteractionUtils.IsValid(this, ic, buf);
            return(InteractionUtils.IsValid(buf));
        }
    private bool CheckClick()
    {
        ChangeDirection();
        //currently there is nothing for ghosts to interact with, they only can change facing
        if (PlayerManager.LocalPlayerScript.IsGhost)
        {
            return(false);
        }

        bool ctrlClick = KeyboardInputManager.IsControlPressed();

        if (!ctrlClick)
        {
            var handApplyTargets =
                MouseUtils.GetOrderedObjectsUnderMouse();

            //go through the stack of objects and call any interaction components we find
            foreach (GameObject applyTarget in handApplyTargets)
            {
                if (CheckHandApply(applyTarget))
                {
                    return(true);
                }
            }
            //check empty space positional hand apply
            var posHandApply = PositionalHandApply.ByLocalPlayer(null);
            if (posHandApply.HandObject != null)
            {
                var handAppliables = posHandApply.HandObject.GetComponents <IBaseInteractable <PositionalHandApply> >()
                                     .Where(c => c != null && (c as MonoBehaviour).enabled);
                if (InteractionUtils.ClientCheckAndTrigger(handAppliables, posHandApply) != null)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 16
0
        public override IConsent IsUsable(INakedObjectAdapter target)
        {
            IInteractionContext ic = InteractionContext.InvokingAction(Session, false, RealTarget(target), Identifier, new[] { target });

            return(InteractionUtils.IsUsable(this, ic));
        }
Esempio n. 17
0
 private void RightClickInteract()
 {
     InteractionUtils.RequestInteract(MouseDrop.ByLocalPlayer(gameObject, PlayerManager.LocalPlayer), this);
 }
Esempio n. 18
0
        /// <summary>
        ///     Loops over all <see cref="IHidingInteractionAdvisor" /> <see cref="IFacet" />s and
        ///     returns <c>true</c> only if none hide the member.
        /// </summary>
        public virtual bool IsVisible(INakedObjectAdapter target)
        {
            IInteractionContext ic = InteractionContext.AccessMember(Session, false, target, Identifier);

            return(InteractionUtils.IsVisible(this, ic, LifecycleManager, metamodelManager));
        }
Esempio n. 19
0
 private void ContextMenuOptionClicked(ContextMenuApply interaction)
 {
     InteractionUtils.RequestInteract(interaction, this);
 }
Esempio n. 20
0
 private void RightClickInteract()
 {
     InteractionUtils.RequestInteract(HandApply.ByLocalPlayer(gameObject), this);
 }
    private bool CheckHandApply(GameObject target)
    {
        //call the used object's handapply interaction methods if it has any, for each object we are applying to
        var handApply    = HandApply.ByLocalPlayer(target);
        var posHandApply = PositionalHandApply.ByLocalPlayer(target);

        //if handobj is null, then its an empty hand apply so we only need to check the receiving object
        if (handApply.HandObject != null)
        {
            //get all components that can handapply or PositionalHandApply
            var handAppliables = handApply.HandObject.GetComponents <MonoBehaviour>()
                                 .Where(c => c != null && c.enabled && (c is IBaseInteractable <HandApply> || c is IBaseInteractable <PositionalHandApply>));
            Logger.LogTraceFormat("Checking HandApply / PositionalHandApply interactions from {0} targeting {1}",
                                  Category.Interaction, handApply.HandObject.name, target.name);

            foreach (var handAppliable in handAppliables.Reverse())
            {
                var interacted = false;
                if (handAppliable is IBaseInteractable <HandApply> )
                {
                    var hap = handAppliable as IBaseInteractable <HandApply>;
                    if (hap.CheckInteract(handApply, NetworkSide.Client))
                    {
                        InteractionUtils.RequestInteract(handApply, hap);
                        return(true);
                    }
                }
                else
                {
                    var hap = handAppliable as IBaseInteractable <PositionalHandApply>;
                    if (hap.CheckInteract(posHandApply, NetworkSide.Client))
                    {
                        InteractionUtils.RequestInteract(posHandApply, hap);
                        return(true);
                    }
                }
            }
        }

        //call the hand apply interaction methods on the target object if it has any
        var targetHandAppliables = handApply.TargetObject.GetComponents <MonoBehaviour>()
                                   .Where(c => c != null && c.enabled && (c is IBaseInteractable <HandApply> || c is IBaseInteractable <PositionalHandApply>));

        foreach (var targetHandAppliable in targetHandAppliables.Reverse())
        {
            var interacted = false;
            if (targetHandAppliable is IBaseInteractable <HandApply> )
            {
                var hap = targetHandAppliable as IBaseInteractable <HandApply>;
                if (hap.CheckInteract(handApply, NetworkSide.Client))
                {
                    InteractionUtils.RequestInteract(handApply, hap);
                    return(true);
                }
            }
            else
            {
                var hap = targetHandAppliable as IBaseInteractable <PositionalHandApply>;
                if (hap.CheckInteract(posHandApply, NetworkSide.Client))
                {
                    InteractionUtils.RequestInteract(posHandApply, hap);
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 22
0
 private void RightClickInteract()
 {
     //trigger the interaction manually, triggered via the right click menu
     InteractionUtils.RequestInteract(HandApply.ByLocalPlayer(gameObject), this);
 }
Esempio n. 23
0
    /// <summary>
    /// Check if item has an interaction with a an item in a slot
    /// If not or if bool returned is true, swap items
    /// </summary>
    public void TryItemInteract(bool swapIfEmpty = true)
    {
        // Clicked on another slot other than our own hands
        bool IsHandSlots = false;

        foreach (var HadnitemSlot in PlayerManager.LocalPlayerScript.DynamicItemStorage.GetHandSlots())
        {
            if (HadnitemSlot == itemSlot)
            {
                IsHandSlots = true;
            }
        }

        if (IsHandSlots == false)
        {
            // If full, attempt to interact the two, otherwise swap
            if (Item != null)
            {
                //check IF2 InventoryApply interaction - combine the active hand item with this (only if
                //both are occupied)
                if (TryIF2InventoryApply())
                {
                    return;
                }

                if (swapIfEmpty)
                {
                    SwapItem(this);
                }
                return;
            }
            else
            {
                if (swapIfEmpty)
                {
                    SwapItem(this);
                }
                return;
            }
        }

        // If there is an item and the hand is interacting in the same slot
        if (Item != null && PlayerManager.LocalPlayerScript.DynamicItemStorage.GetActiveHandSlot() == itemSlot)
        {
            //check IF2 logic first
            var interactables = Item.GetComponents <IBaseInteractable <HandActivate> >()
                                .Where(mb => mb != null && (mb as MonoBehaviour).enabled);
            var activate = HandActivate.ByLocalPlayer();
            InteractionUtils.ClientCheckAndTrigger(interactables, activate);
        }
        else
        {
            if (PlayerManager.LocalPlayerScript.DynamicItemStorage.GetActiveHandSlot() != itemSlot)
            {
                if (TryIF2InventoryApply())
                {
                    return;
                }
                if (swapIfEmpty)
                {
                    SwapItem(this);
                }
            }
        }
    }