예제 #1
0
    public int AttackSquare(Piece selected, Mode mode, Vector3 position)
    {
        // Piece target = board[(int)position.x, (int)position.z].GetPiece();
        Piece target = syncBoard[(int)position.x][(int)position.z].GetPiece();

        if (target)
        {
            if (mode == Mode.ATTACK)
            {
                if (selected.GetComponent <Miner>() != null)
                {
                    selected.Attack();
                    return(selected.GetAttack());
                }
                if (selected.GetComponent <Bishop>() != null)
                {
                    if (selected.GetAOEPattern() == null)
                    {
                        selected.Attack();
                        target.Damaged(-1 * selected.GetAttack());
                    }
                    else
                    {
                        Piece[] tilesToHealArray = GenerateAOETiles(selected, mode, position);
                        for (int i = 0; i < tilesToHealArray.Length; i++)
                        {
                            target = tilesToHealArray[i];
                            target.Damaged(-1 * selected.GetAttack());
                        }
                        selected.Attack();
                    }
                    return(0);
                }
                if (selected.GetAOEPattern() == null)
                {
                    return(AttackPiece(selected, target));
                }
                else
                {
                    Piece[] tilesToAttackArray = GenerateAOETiles(selected, mode, position);
                    int     sum = 0;
                    for (int i = 0; i < tilesToAttackArray.Length; i++)
                    {
                        target = tilesToAttackArray[i];
                        int check = AttackPiece(selected, target);
                        if (check == -1)
                        {
                            return(-1);
                        }
                        sum += check;
                    }
                    return(sum);
                }
            }
        }
        return(0);
    }
    // Update is called once per frame
    void Update()
    {
        if (!dying && !attacking)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3    point  = hit.point;
                Vector2Int gPoint = Geometry.GridFromPoint(point);

                // show path if it's a valid move
                if (attackLocations.Contains(gPoint))
                {
                    attackHighlight.SetActive(true);
                    attackHighlight.transform.position =
                        Geometry.PointFromGrid(gPoint) + new Vector3(0, .01f, 0);
                }
                else // if move is not valid, get out!
                {
                    attackHighlight.SetActive(false);
                    return;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    attacking = true;
                    Piece piece = movingPiece.GetComponent <Piece>();
                    piece.Attack();

                    dyingPoint = gPoint;

                    startTime = Time.time;
                }
            }
            else
            {
                attackHighlight.SetActive(false);
            }
        }
        else  // dying/attacking animation is playing
        {
            if (attacking && Time.time - startTime > 1)
            {
                GameObject dyingPiece = GameManager.instance.PieceAtGrid(dyingPoint);
                Piece      dPiece     = dyingPiece.GetComponent <Piece>();
                dPiece.Die();
                attacking = false;
                dying     = true;
            }
            else if (dying && Time.time - startTime > 2)
            {
                GameManager.instance.KillPieceAt(dyingPoint);
                ExitState();
            }
        }
    }
예제 #3
0
    //-----------------------------------------------------------------------------------------------------

    private void HandleEnemySelection()
    {
        Piece selectedEnemy = selectedObject.GetComponent <Piece>();

        if (selectedEnemy.occupiedField.Available)
        {
            HandlePieceSelection();
            selectedPiece.Attack(selectedEnemy, 10);

            StartCoroutine(DoComputerMove(selectedPiece.moveTime + 1f));
            selectedPiece = null;
        }
    }
예제 #4
0
    //-----------------------------------------------------------------------------------------------------

    // Returns how much time should game wait after move
    private float DoComputerPieceMove(Piece enemy)
    {
        Piece pieceToAttack = enemy.GetComputerPieceToAttack();

        if (pieceToAttack != null && !pieceToAttack.IsDead)
        {
            enemy.Attack(pieceToAttack, 2);
            return(enemy.moveTime + 0.5f);
        }
        else if (!enemy.waitMode)
        {
            enemy.MoveTo(enemy.GetComputerFieldToMove());
            return(enemy.moveTime);
        }
        return(0);
    }
예제 #5
0
    public int AttackPiece(Piece selected, Piece target)
    {
        selected.Attack();
        bool changeIncome = target.GetComponent <Miner>() != null;
        int  player       = selected.GetPlayer();
        bool isDead       = target.Damaged(selected.GetAttack() - target.GetDefense());

        if (isDead)
        {
            if (changeIncome)
            {
                Room.GamePlayers[player].RpcChangeIncome(-1);
            }
            target.Die();
            RpcRemovePiece(target.GetPosition());
            return(target.GetValue());
        }
        return(0);
    }
예제 #6
0
    private IEnumerator MoveQueueCoroutine(Piece piece, Tile[] tiles, int occupantId, bool scored)
    {
        float travelTime = 1f;

        foreach (Tile t in tiles)
        {
            piece.MoveTo(t);

            Tile targetTile = tiles[tiles.Length - 1];

            // If we are going to be overtaking a Tile
            if (opponentTrack != null)
            {
                // If we are at the Tile before the occupied Tile
                if ((tiles.Length == 1) || t == tiles[tiles.Length - 1])
                {
                    piece.FaceTile(targetTile);
                    piece.Attack();

                    // Player attack sound
                    audioSource.PlayOneShot(attackSound);

                    opponentTrack.BumpPiece(occupantId);
                    opponentTrack = null;
                    yield return(new WaitForSeconds(3.5f));

                    piece.MoveTo(t);
                }
            }

            travelTime = Vector3.Distance(piece.transform.position, t.GetObjectPosition()) * 0.3f;
            yield return(new WaitForSeconds(travelTime));
        }

        //if(scored)
        //{
        //    // Set landedOnRosette to false because the last Tile on the board
        //    // is a rosette and gets recorded. In turn, this allows the scoring player
        //    // to roll again, which isn't allowed.
        //    landedOnRosette = false;
        //    NextTurn();
        //}
    }
예제 #7
0
    protected void Select(Vector3 pointerPosition)
    {
        Ray        ray = Camera.main.ScreenPointToRay(pointerPosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            BaseTile s = null;

            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Tiles"))
            {
                s = hit.collider.GetComponentInParent <HexTile>();
            }
            else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Pieces"))
            {
                s = hit.collider.GetComponent <Piece>().Tile;
            }
            else
            {
                throw new Exception("You click something new?!");
            }

            if (selected != null && selected.OcuppiedBy != null)
            {
                Piece p = selected.OcuppiedBy;

                switch (s.State)
                {
                case HexTile.eState.Moveable:
                    Vector3 start = p.transform.position;

                    StartMove(p, p.transform.position, s.transform.position);

                    s.OcuppiedBy        = p;
                    p.Tile              = s;
                    selected.OcuppiedBy = null;
                    ClearSelection();
                    break;

                case HexTile.eState.Atackable:
                    p.Attack(s.OcuppiedBy);
                    ClearSelection();
                    break;

                case HexTile.eState.NotSelected:
                    if (s.OcuppiedBy != null)
                    {
                        SelectTile(s);
                    }
                    else
                    {
                        ClearSelection();
                    }
                    break;
                }
            }
            else if (s.OcuppiedBy != null)
            {
                SelectTile(s);
            }
        }
        else
        {
            ClearSelection();
        }
    }