Exemplo n.º 1
0
    private void CheckInteraction()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // Crear un rayo hacia el mundo 3D desde la posicion del mouse
            Ray ray = _mouseScreenRayProvider.CreateRay(_camera);

            // Revisar si el jugador hizo click sobre una moneda
            var selectedCoin = _coinSelector.Check(ray);

            // Si hizo click, recolectar esa moneda y dejar verificar interacción con otras cosas
            if (selectedCoin != null)
            {
                // Seleccionar la moneda
                selectedCoin.Collect();
                return;
            }

            // Revisar si el jugador hizo click sobre el piso
            if (Physics.Raycast(ray, out RaycastHit hit, _layerMaskGround))
            {
                // Indicar cual es el nuevo objetivo del jugador
                _navMeshAgent.SetDestination(hit.point);

                // Iniciar animación de correr
                _animator.SetBool("Running", true);
            }
        }
    }
Exemplo n.º 2
0
        private void Update()
        {
            UpdatePower();

            if (Input.GetMouseButtonDown(0))
            {
                OnLeftClick();

                if (_currentClickSelection != null)
                {
                    OnDrag();
                }
            }

            if (Input.GetMouseButton(0))
            {
                OnDrag();
            }

            if (Input.GetMouseButtonUp(0))
            {
                OnLMB_Up();
            }

            if (Input.GetMouseButtonDown(1))
            {
                OnRightClick();
            }

            //HighlightCraftingMaterials();

            _selector.Check(_rayProvider.CreateRay());
        }
    // Update is called once per frame
    void Update()
    {
        //deselection  response
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }


        _selector.Check(_rayProvider.CreateRay());

        _currentSelection = _selector.GetSelection();;

        //selection response
        if (_currentSelection != null)
        {
            //if object has prerequisite and is not complete, do nothing
            if (_currentSelection.GetComponent <Prerequisite>() && !_currentSelection.GetComponent <Prerequisite>().Complete)
            {
                return;
            }


            _selectionResponse.OnSelect(_currentSelection);
        }
    }
Exemplo n.º 4
0
    void Shooting()
    {
        timer.GetDeltaTime(Time.deltaTime);
        timer.TimeMultiplication(shootingSpeed.Value);

        if (Input.GetMouseButton(0) && timer.time > 1f && ammo.HasAmmoInMag())
        {
            Debug.Log(name + " is shooting");
            selector.Check(rayProvider.CreateRay());
            ammo.Shot();


            if (selector.GetSelection() != null)
            {
                selector.GetSelection().GetComponent <Idamageable>().GetDamaged(damage.Value);
            }

            timer.ResetTime(0);
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            Debug.Log(name + " Reloaded");
            ammo.Reload();
        }
        else if (!ammo.HasAmmoInMag())
        {
            return;
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        // Set ray variable to camera center, in FPS controller the mouse is always at the screen center
        // Cast a ray into the distance, if an object is hit, the hit variable will return true
        // Get the location of the object that was hit and then get the object
        // Ensure the object is selectable

        if (Input.touchCount > 0)
        {
            if (Input.touches[0].phase == TouchPhase.Began)
            {
                Debug.Log("Touch Pressed");
                TouchTime = Time.time;
                //print(TouchTime);
                _selector.Check(_rayProvider.CreateRay());
                _initialSelection = _selector.GetSelection();
            }

            if (Input.touches[0].phase == TouchPhase.Ended)
            {
                //print(TouchTime);
                _selector.Check(_rayProvider.CreateRay());
                _currentSelection = _selector.GetSelection();

                Debug.Log("Touch Lifted/Released");
                if (_currentSelection != null && _initialSelection == _currentSelection)
                {
                    var ObjTags = _currentSelection.GetComponent <Tags>();
                    if (ObjTags.hasTag("Combinable"))
                    {
                        updateSelections(_currentSelection);
                    }

                    if (Time.time - TouchTime > 1.0)
                    {
                        //print("QUACK");
                        print(_selector.GetSelection().name);
                        _currentLongSelection = _selector.GetSelection();
                    }
                }
            }
        }
    }
    private void Update()
    {
        if (_currentselection != null)
            _selectionResponse.OnDeselect(_currentselection);

        _selector.Check(_rayProvider.CreateRay());
        _currentselection = _selector.GetSelection();

        if (_currentselection != null)
            _selectionResponse.OnSelect(_currentselection);
    }
 private void ClickDestination()
 {
     selector.Check(rayProvider.CreateRay());
     if (selector.GetSelection() != null)
     {
         hitInfo = selector.GetHitInfo();
         SetDestination(hitInfo.point);
         SetWaypoint();
         SetSelected(false);
         animator.SetBool("IsWalking", true);
     }
 }
        // Update is called once per frame
        private void Update()
        {
            if (currectSelection != null)
            {
                selectionResponse.OnDeselect(currectSelection);
            }

            selector.Check(rayProvider.CreateRay());
            currectSelection = selector.GetSelection();

            if (currectSelection != null)
            {
                selectionResponse.OnSelect(currectSelection);
            }
        }
Exemplo n.º 9
0
    void LateUpdate()
    {
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }

        _selector.Check(_rayProvider.CreateRay());
        _currentSelection = _selector.GetSelection();

        if (_currentSelection != null)
        {
            _selectionResponse.OnHover(_currentSelection);
        }
    }
Exemplo n.º 10
0
        // Select the targets satifying the predicate.
        // predicate shall extend std.unary_function<Unit*, bool>
        public List <Unit> SelectTargetList(ISelector selector, uint maxTargets, SelectAggroTarget targetType)
        {
            var targetList = new List <Unit>();

            var threatlist = GetThreatManager().getThreatList();

            if (threatlist.Empty())
            {
                return(targetList);
            }

            foreach (var hostileRef in threatlist)
            {
                if (selector.Check(hostileRef.getTarget()))
                {
                    targetList.Add(hostileRef.getTarget());
                }
            }

            if (targetList.Count < maxTargets)
            {
                return(targetList);
            }

            if (targetType == SelectAggroTarget.Nearest || targetType == SelectAggroTarget.Farthest)
            {
                SortByDistanceTo(me, targetList);
            }

            if (targetType == SelectAggroTarget.Farthest || targetType == SelectAggroTarget.BottomAggro)
            {
                targetList.Reverse();
            }

            if (targetType == SelectAggroTarget.Random)
            {
                targetList = targetList.SelectRandom(maxTargets).ToList();
            }
            else
            {
                targetList.Resize(maxTargets);
            }

            return(targetList);
        }
Exemplo n.º 11
0
    void Update()
    {
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }

        var        ray = _rayProvider.CreateRay();
        RaycastHit hit;

        _selector.Check(ray);

        _currentSelection = _selector.GetSelection();
        if (_currentSelection != null)
        {
            _selectionResponse.OnSelect(_currentSelection);
        }
    }
Exemplo n.º 12
0
    private void Update()
    {
        //selection
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }

        //determineSeelection
        _selector.Check(_rayProvider.CreateRay());
        _currentSelection = _selector.GetSelection();

        //selection
        if (_currentSelection != null)
        {
            _selectionResponse.OnSelect(_currentSelection);
        }
    }
    private void Update()
    {
        #region Raycast & Select
        _selector.Check(_rayProvider.CreateRay());
        var selection = _selector.GetSelection();
        #endregion
        if (IsNewSelection(selection))
        {
            if (_currentSelection != null)
            {
                _selectionResponse.OnDeselect(_currentSelection);
            }
            if (selection != null)
            {
                _selectionResponse.OnSelect(selection);
            }
        }

        _currentSelection = selection;
    }
Exemplo n.º 14
0
    private void Update()
    {
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
            _hoverResponse.OnDeselect(_currentSelection);
        }

        _selector.Check(_rayProvider.CreateRay());
        _currentSelection = _selector.GetSelection();

        if (_currentSelection != null)
        {
            _selectionResponse.OnSelect(_currentSelection);
            if (_currentSelection.CompareTag("Selectable"))
            {
                if (pointer != null)
                {
                    pointer.GetComponent <Image>().enabled = true;

                    //When click, execute the action on IClickResponse
                    if (Input.GetKeyDown(action))
                    {
                        _clickResponse.OnClick(_currentSelection);
                    }
                }
            }
            else if (_currentSelection.CompareTag("Hoverable"))
            {
                _hoverResponse.OnSelect(_currentSelection);
            }
        }
        else
        {
            if (pointer != null)
            {
                pointer.GetComponent <Image>().enabled = false;
            }
        }
    }
Exemplo n.º 15
0
    public void OnMouseClick()
    {
        //CREATING THE RAY
        var ray = _rayProvider.CreateRay();

        //SHOTING THE RAY
        //shooting a raycast to get the tile that the player clicked
        if (_selector.Check(ray))
        {
            TileField tile;
            _physicsCache.TryGetTileField(_selector.GetSelection(), out tile);
            if (_phaseManager.GetCurrentPhase() == Phase.MOVEMENT)
            {
                //Two possibilities: the field can or not have a piece
                if (tile.Piece != null)
                {
                    // One possibility: If its a piece from the current turn, we try to highlight
                    if (ValidateHighlight(tile.Piece))
                    {
                        // Three possibilities:
                        // If the clicked tile is the current highlighted, we only dehighlight
                        // If the highlighted tile is null, we only highlight
                        // If the clicked tile isn't the current highlighted, we dehighlight and highlight the clicked one
                        if (tile == m_HighlightedTile)
                        {
                            Deselect();
                        }
                        else if (m_HighlightedTile == null)
                        {
                            TrySelectEmptyAdjacents(tile);
                        }
                        else if (tile != m_HighlightedTile)
                        {
                            Deselect();
                            TrySelectEmptyAdjacents(tile);
                        }
                    }
                }
                else
                {
                    //One possibilities: if there is not a piece on the field we clicked, and we already have a highlighted field, we try to move
                    if (m_HighlightedTile != null)
                    {
                        //MOVE PIECE
                        if (tile.IsHighlighting)
                        {
                            //If this tile is highlighted, we can move to this tile.
                            m_HighlightedTile.MovePieceTo(tile);
                            UpdateBoard(tile, m_HighlightedTile);
                            Deselect();
                            _turnManager.NextTurn();
                        }
                    }
                }
            }
            else if (_phaseManager.GetCurrentPhase() == Phase.POSITIONING)
            {
                //One Possibility: There's no piece on the field, we can only move to an empty space
                if (tile.Piece == null)
                {
                    //No piece can be put in the middle on the positioning phase
                    if (tile.Coordinates.x == 2 && tile.Coordinates.y == 2)
                    {
                        return;
                    }

                    if (_turnManager.IsWhiteTurn())
                    {
                        tile.SetPiece(_pieceProvider.GetNonPlacedWhitePiece());
                    }
                    else
                    {
                        tile.SetPiece(_pieceProvider.GetNonPlacedBlackPiece());
                    }

                    _turnIndex++;

                    // Each player places 2 pieces before the next turn
                    if (_turnIndex % 2 == 0)
                    {
                        _turnManager.NextTurn();
                    }

                    //when all pieces are placed
                    if (_turnIndex == 24)
                    {
                        _phaseManager.StartMovementPhase();
                    }
                }
            }
        }
    }
Exemplo n.º 16
0
        /// <summary>
        /// Select the best (up to) <num> targets (in <targetType> order) satisfying <predicate> from the threat list and stores them in <targetList> (which is cleared first).
        /// If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped.
        /// </summary>
        public List <Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset, ISelector selector)
        {
            var targetList = new List <Unit>();

            ThreatManager mgr = GetThreatManager();

            // shortcut: we're gonna ignore the first <offset> elements, and there's at most <offset> elements, so we ignore them all - nothing to do here
            if (mgr.GetThreatListSize() <= offset)
            {
                return(targetList);
            }

            if (targetType == SelectAggroTarget.MaxDistance || targetType == SelectAggroTarget.MinDistance)
            {
                foreach (HostileReference refe in mgr.GetThreatList())
                {
                    if (!refe.IsOnline())
                    {
                        continue;
                    }

                    targetList.Add(refe.GetTarget());
                }
            }
            else
            {
                Unit currentVictim = mgr.GetCurrentVictim();
                if (currentVictim != null)
                {
                    targetList.Add(currentVictim);
                }

                foreach (HostileReference refe in mgr.GetThreatList())
                {
                    if (!refe.IsOnline())
                    {
                        continue;
                    }

                    Unit thisTarget = refe.GetTarget();
                    if (thisTarget != currentVictim)
                    {
                        targetList.Add(thisTarget);
                    }
                }
            }

            // shortcut: the list isn't gonna get any larger
            if (targetList.Count <= offset)
            {
                targetList.Clear();
                return(targetList);
            }

            // right now, list is unsorted for DISTANCE types - re-sort by MAXDISTANCE
            if (targetType == SelectAggroTarget.MaxDistance || targetType == SelectAggroTarget.MinDistance)
            {
                SortByDistance(targetList, targetType == SelectAggroTarget.MinDistance);
            }

            // now the list is MAX sorted, reverse for MIN types
            if (targetType == SelectAggroTarget.MinThreat)
            {
                targetList.Reverse();
            }

            // ignore the first <offset> elements
            while (offset != 0)
            {
                targetList.RemoveAt(0);
                --offset;
            }

            // then finally filter by predicate
            targetList.RemoveAll(target => { return(!selector.Check(target)); });

            if (targetList.Count <= num)
            {
                return(targetList);
            }

            if (targetType == SelectAggroTarget.Random)
            {
                targetList = targetList.SelectRandom(num).ToList();
            }
            else
            {
                targetList.Resize(num);
            }

            return(targetList);
        }
Exemplo n.º 17
0
        // Select the targets satifying the predicate.
        public Unit SelectTarget(SelectAggroTarget targetType, uint position, ISelector selector)
        {
            var threatlist = GetThreatManager().getThreatList();

            if (position >= threatlist.Count)
            {
                return(null);
            }

            List <Unit> targetList    = new List <Unit>();
            Unit        currentVictim = null;

            var currentVictimReference = GetThreatManager().getCurrentVictim();

            if (currentVictimReference != null)
            {
                currentVictim = currentVictimReference.getTarget();

                // Current victim always goes first
                if (currentVictim && selector.Check(currentVictim))
                {
                    targetList.Add(currentVictim);
                }
            }

            foreach (var hostileRef in threatlist)
            {
                if (currentVictim != null && hostileRef.getTarget() != currentVictim && selector.Check(hostileRef.getTarget()))
                {
                    targetList.Add(hostileRef.getTarget());
                }
                else if (currentVictim == null && selector.Check(hostileRef.getTarget()))
                {
                    targetList.Add(hostileRef.getTarget());
                }
            }

            if (position >= targetList.Count)
            {
                return(null);
            }

            if (targetType == SelectAggroTarget.Nearest || targetType == SelectAggroTarget.Farthest)
            {
                SortByDistanceTo(me, targetList);
            }

            switch (targetType)
            {
            case SelectAggroTarget.Nearest:
            case SelectAggroTarget.TopAggro:
            {
                return(targetList.First());
            }

            case SelectAggroTarget.Farthest:
            case SelectAggroTarget.BottomAggro:
            {
                return(targetList.Last());
            }

            case SelectAggroTarget.Random:
            {
                return(targetList.SelectRandom());
            }

            default:
                break;
            }

            return(null);
        }