예제 #1
0
    private void OnQuestInterracted(IInteractible interactible)
    {
        quests[_currentQuestIndex].StartQuest();

        switch (quests[_currentQuestIndex].questGoal.goalType)
        {
        case QuestGoal.GoalType.Read:
            Debug.Log("Read item" + _currentQuestIndex);
            quests[_currentQuestIndex].CompleteQuest();
            TriggerNextQuestOrFinishGame();
            break;

        case QuestGoal.GoalType.Pickup:
            Debug.Log("Pickedup item" + _currentQuestIndex);
            quests[_currentQuestIndex].CompleteQuest();
            TriggerNextQuestOrFinishGame();
            _hasKey = true;
            break;

        case QuestGoal.GoalType.Use:
            if (_hasKey)
            {
                Debug.Log("Used item" + _currentQuestIndex);
                quests[_currentQuestIndex].CompleteQuest();
                TriggerNextQuestOrFinishGame();
                _hasKey = false;
            }
            else
            {
                Debug.LogWarning("Tried to open door without quest item" + _currentQuestIndex);
            }
            break;
        }
    }
예제 #2
0
파일: Quest.cs 프로젝트: TheSica/Borobel
 protected virtual void OnQuestInterracted(IInteractible interactible)
 {
     // Make a temporary copy of the event to avoid possibility of
     // a race condition if the last subscriber unsubscribes
     // immediately after the null check and before the event is raised.
     QuestInterracted?.Invoke(interactible);
 }
    public void InteractAttempt(ItemHandler handler)
    {
        closestInteraction = UpdateInteractibles();
        if (closestInteraction == null)
        {
            InteractionsInRange = new List <GameObject>();
            return;
        }

        else
        {
            if (closestInteraction.CanAct() == false)
            {
                return;
            }
            //closestInteraction.LeaveRange(this);
            if (handler.currentItem != null && closestInteraction.CanReceiveItem())
            {
                InteractWithItem(closestInteraction, handler);
                OnUseItem.Invoke(handler.currentItem);
            }

            else
            {
                InteractWithoutItem(closestInteraction);
            }
        }
    }
예제 #4
0
    public void OnObjectInteracted(IPlaceable placeable)
    {
        // If on placeable already placed item, then call "OnObjectInteracted" for that item.
        if (placeable.HavePlacedItem())
        {
            IInteractible interactible = placeable.GetPlacedItem().GetComponent <IInteractible>();
            OnObjectInteracted(interactible);
            return;
        }

        ItemType selectedItemType = UIManager.Instance.GetSelectedItemType();

        if (selectedItemType == ItemType.None)
        {
            return;
        }

        InventoryItem invItem = inventory.GetItem(selectedItemType);

        if (invItem.count == 0)
        {
            return;
        }

        invItem.count--;
        Vector3 pos  = placeable.GetItemPlacePos();
        Item    item = gameMap.SpawnItem(selectedItemType, pos);

        item.isInteractible = true;
        placeable.SetPlacedItem(item);
        UIManager.Instance.UpdateHUD(inventory);
    }
예제 #5
0
 private void OtherInput()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         invPanel.SetActive(!invPanel.activeSelf);
     }
     if (Input.GetKeyDown(KeyCode.R))
     {
         body.velocity = new Vector2(0, body.velocity.y);
         canMove       = false;
         anim.SetTrigger("Attack");
     }
     if (Input.GetKeyDown(KeyCode.F))
     {
         Collider2D[] col = Physics2D.OverlapBoxAll(transform.position, Vector2.one, 0);
         foreach (var item in col)
         {
             IInteractible interactible = item.gameObject.GetComponent <IInteractible>();
             if (interactible != null)
             {
                 interactible.Interact(character);
             }
         }
     }
 }
예제 #6
0
    public void AddInteractible(IInteractible interactible, Vector2 worldPosition)
    {
        Vector2 tileIndices = WorldToMap(worldPosition);

        if (!interactibleMap.ContainsKey(tileIndices) || interactibleMap[tileIndices] == null)
        {
            interactibleMap[tileIndices] = new System.Collections.Generic.List <IInteractible>();
        }
        interactibleMap[tileIndices].Add(interactible);
    }
예제 #7
0
 public override void Interact(IInteractible other)
 {
     if (other as Structure)
     {
         (other as Structure).Destruct();
     }
     else
     {
         Debug.Log("Nothing to combust");
     }
 }
        public void Cancel()
        {
            Collider      closestInteractee = GetClosestInteractee();
            IInteractible interactible      = closestInteractee?.GetComponent <IInteractible>();

            if (interactible != null)
            {
                interactionHandler.OnCancelled(interactible.InteractibleType, interactible.Transform);
                interactible.Cancel(transform);
            }
        }
예제 #9
0
    public void RemoveInteractible(IInteractible interactible, Vector2 worldPosition)
    {
        Vector2 tileIndices = WorldToMap(worldPosition);

        if (interactibleMap.ContainsKey(tileIndices) &&
            interactibleMap[tileIndices] != null &&
            interactibleMap[tileIndices].Contains(interactible))
        {
            interactibleMap[tileIndices].Remove(interactible);
        }
    }
예제 #10
0
        public void Cancel(OnCancelled onCancelled = null)
        {
            Collider2D    closestInteractee = GetClosestInteractee();
            IInteractible interactible      = closestInteractee?.GetComponent <IInteractible>();

            if (interactible != null)
            {
                onCancelled?.Invoke(interactible.InteractibleType, interactible.Transform);
                interactible.Cancel(INTERACTIBLE_TYPE.USER, transform);
            }
        }
예제 #11
0
 public override void Interact(IInteractible other)
 {
     if (other as Weapon)
     {
         Unit.activeUnit.EquipAction(other as Weapon);
         Unit.activeUnit.curSlot.DetachPickupFromSlot();
     }
     else
     {
         Debug.Log("Nothing to pick");
     }
 }
예제 #12
0
 protected virtual void Update()
 {
     if (Input.GetButtonDown("Activate"))
     {
         foreach (var x in proximityProbe.GetCloseObjects())
         {
             IInteractible interactible = x.GetComponent <IInteractible>();
             if (interactible != null)
             {
                 interactible.AcceptBob(this);
             }
         }
     }
 }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (InteractionsInRange.Contains(other.gameObject))
        {
            InteractionsInRange.Remove(other.gameObject);
            other.GetComponent <IInteractible>().LeaveRange(this);
            closestInteraction = UpdateInteractibles();
        }

        if (closestInteraction != null)
        {
            closestInteraction.OnRange(this);
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.GetComponent <IInteractible>() != null)
        {
            InteractionsInRange.Add(other.gameObject);
            //other.GetComponent<IInteractible>().OnBroadcastDestroy += RemoveObject(gameObject);
            closestInteraction = UpdateInteractibles();
        }

        if (closestInteraction != null)
        {
            closestInteraction.OnRange(this);
        }
    }
예제 #15
0
    private void Interact()
    {
        List <GameObject> collidingWith = Detector.GetCurrentOverlapping();

        if (collidingWith.Count > 0)
        {
            IInteractible firstCollided = collidingWith.FirstOrDefault()
                                          .GetComponent <IInteractible>();

            if (firstCollided != null)
            {
                firstCollided.Use(ReferenceCollider);
            }
        }
    }
예제 #16
0
    public void AcceptBob(Bob source)
    {
        if (enabled)
        {
            IInteractible realTarget = target != null?target.GetComponent <IInteractible>() : null;

            if (realTarget != null)
            {
                realTarget.AcceptBob(source);
            }
            else
            {
                Debug.LogWarning("No target available to relay the call.");
            }
        }
    }
예제 #17
0
        private void OnTriggerEnter(Collider other)
        {
            var col = other.transform.GetComponent <ICollectable>();

            if (col != null)
            {
                col.Collect(this);
            }

            var intreactible = other.transform.GetComponent <IInteractible>();

            if (intreactible != null)
            {
                _currentIntreactible = intreactible;
                _canClear            = false;
            }
        }
예제 #18
0
    protected override bool CanActivate(out string errorMessage)
    {
        errorMessage = "";//none

        IInteractible interactible = GameController.Instance.nearbyInteractible;

        if (interactible == null)
        {
            errorMessage = "Error, nothing to interact with\n";
        }
        else if (!interactible.CanInteract())
        {
            errorMessage = interactible.GetErrorMessage();
        }

        return(HaveControl && interactible != null && interactible.CanInteract());
    }
예제 #19
0
    private void FixedUpdate()
    {
        if (UISystem.MenuPresence || m_CurrentSelection != null && m_CurrentSelection.KeepInteractability)
        {
            return;
        }

        Ray ray;

        if (InputHandler.PCLayout)
        {
            ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
        }
        else
        {
            ray = new Ray(transform.position + m_PlayerCenter, transform.forward);
        }

        if (Physics.Raycast(ray, out hit, 3.0f, 1 << layerMask, QueryTriggerInteraction.Ignore))
        {
            IInteractible interactible = hit.transform.GetComponent <IInteractible>();

            if (interactible != null)
            {
                if (interactible != m_CurrentSelection)
                {
                    if (m_CurrentSelection != null)
                    {
                        m_CurrentSelection.OnStopBeingInteractible();
                    }

                    m_CurrentSelection = interactible;
                    interactible.OnBeingInteractible();
                }
            }
        }
        else if (m_CurrentSelection != null && !m_CurrentSelection.KeepInteractability)
        {
            if (m_CurrentSelection != null)
            {
                m_CurrentSelection.OnStopBeingInteractible();
            }

            m_CurrentSelection = null;
        }
    }
예제 #20
0
            /// <summary>
            /// Checks if the mouse is touching an interactible object.
            /// </summary>
            /// <param name="screenPosition">The position of the cursor on the screen.</param>
            /// <returns>The hit interactible objetc, null if none was hit.</returns>
            public IInteractible CheckForInteractibleObject(Vector3 screenPosition)
            {
                Ray mouseRay = mainCamera.ScreenPointToRay(screenPosition);

                RaycastHit[] hits = Physics.RaycastAll(mouseRay);

                foreach (RaycastHit hit in hits)
                {
                    IInteractible interactible = hit.collider.gameObject.GetComponent <IInteractible>();

                    if (interactible != null)
                    {
                        return(interactible);
                    }
                }

                return(null);
            }
예제 #21
0
        private void TestUnderCursor()
        {
            RaycastHit hit;

            Physics.Raycast(transform.position, transform.forward, out hit, 10000, mask);

            if (currentTransform != hit.transform)
            {
                currentTransform = hit.transform;
                if (currentTransform != null)
                {
                    currentInteractible = currentTransform.GetComponent <IInteractible>();

                    if (currentInteractible != null)
                    {
                        interactionData.Value.InteractionText = currentInteractible.InteractionText;
                        isInteractible = true;
                    }
                    else
                    {
                        isInteractible = false;
                    }
                }
                else
                {
                    isInteractible = false;
                }
            }
            if (isInteractible)
            {
                if ((transform.position - hit.point).sqrMagnitude < Mathf.Pow(interactionDistance * currentInteractible.InteractionDistanceMultiplier, 2))
                {
                    inRange = true;
                }
                else
                {
                    inRange = false;
                }
            }
            else
            {
                inRange = false;
            }
        }
예제 #22
0
            private void Update()
            {
                IInteractible interactible = inputManager.CheckForInteractibleObject(Input.mousePosition);

                if (Input.GetMouseButtonDown(0) && gravityHandler.CheckForOnGround(transform.position, gravityCheckersPositions) && currentDashCooldown == 0)
                {
                    if (interactible == null)
                    {
                        Debug.Log("may be dash");
                        if (currentPriestDashDuration == 0 && inputManager.GetMouseDirection(Input.mousePosition, transform.position) != PlayerDirection.None)
                        {
                            StartDash();
                        }
                    }
                    else
                    {
                        interactible.Interact();
                    }
                }

                if (currentDashCooldown > 0)
                {
                    currentDashCooldown -= Time.deltaTime;
                }
                else if (currentDashCooldown < 0)
                {
                    currentDashCooldown = 0;
                }

                if (dashing)
                {
                    priestRenderer.material.color = Color.cyan;
                }
                else if (currentDashCooldown > 0)
                {
                    priestRenderer.material.color = Color.red;
                }
                else
                {
                    priestRenderer.material.color = Color.green;
                }
            }
예제 #23
0
    void Interact()
    {
        Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, maxReach))
        {
            //Debug.DrawLine(ray.origin, hit.point, Color.red, 10);

            IInteractible interactible = hit.transform.gameObject.GetComponent <IInteractible>();
            IPickUp       iPickUp      = hit.transform.gameObject.GetComponent <IPickUp>();

            if (interactible != null)
            {
                interactible.Interact();
            }
            else if (iPickUp != null)
            {
                iPickUp.Interact(this);
            }
        }
    }
예제 #24
0
    public void OnObjectInteracted(IInteractible interactible)
    {
        if (!interactible.IsInteractible())
        {
            return;
        }

        ItemType selectedItemType = UIManager.Instance.GetSelectedItemType();

        if (selectedItemType == ItemType.None)
        {
            ItemType removedItemType = interactible.GetItemType();
            interactible.RemoveItem();
            InventoryItem invItem = inventory.GetItem(removedItemType);
            invItem.count++;
            UIManager.Instance.UpdateHUD(inventory);
        }
        else
        {
            interactible.RotateItem();
        }
    }
예제 #25
0
        public void Interact()
        {
            if (IsBusy)
            {
                return;
            }

            // Use interactibles first, whether we're holding an item or not.
            // If that fails, try and use the held item if we're holding one.
            currentInteractible = GetInteractible();
            if (currentInteractible != null)
            {
                var type = currentInteractible.Use(this);

                if (type != InteractionTypes.None)
                {
                    actor.Animator.ApplyInteractionAnimation(type);
                    state = States.UsingInteractible;
                    return;
                }
            }

            // No interactibles were used
            if (CurrentItem != null)
            {
                var type = CurrentItem.CanUse(this);
                if (type != InteractionTypes.None)
                {
                    actor.Animator.ApplyInteractionAnimation(type);
                    state = States.UsingItem;
                    return;
                }
            }

            state = States.None;
        }
예제 #26
0
    private void Update()
    {
        // Resetting the outline
        if (_interactingObject != null)
        {
            //Debug.Log("Resetting");
            _interactingObject.GetComponentInChildren <Outline>().enabled = false;
            _interactingObject = null;
        }
        RaycastHit hit;
        Outline    targetOutline = null;

        // Chehcking raycast
        if (Physics.Raycast(transform.position, transform.forward, out hit, interactDistance, interactLayer))
        {
            //Debug.Log("hit");
            Transform interactingObject = hit.transform;
            if (!targetOutline)
            {
                targetOutline = interactingObject.GetComponentInChildren <Outline>();
            }
            // enable the outline
            targetOutline.enabled = true;
            // wait for interaction input
            if (Input.GetButtonDown("Interact"))
            {
                IInteractible interactible = hit.collider.GetComponent <IInteractible>();
                if (interactible != null)
                {
                    SoundyManager.Play("General", "Grab");
                    interactible.Interact();
                }
            }
            _interactingObject = interactingObject;
        }
    }
예제 #27
0
 internal static bool smethod_0(IInteractible iinteractible_0, ref GClass116.< > c__DisplayClass12_0 <> c__DisplayClass12_0_0)
 void InteractWithItem(IInteractible interactible, ItemHandler handler)
 {
     interactible.UseItemOnStation(this, handler.currentItem);
     handler.currentItem.OnUseWithStation(handler);
     handler.AttemptUseItem();
 }
 void InteractWithoutItem(IInteractible interactible)
 {
     interactible.Interact(this);
 }
예제 #30
0
 public override void Interact(IInteractible other)
 {
     PlayerFlag.m.StartTwoStepAttack(unitSource, atkId);
 }