Exemplo n.º 1
0
    void CmdMoveFigure(NetworkIdentity identity, int fromZ_Board, int fromX_Board, int toZ_World, int toX_World)
    {
        if (NetworkServer.connections.Count != 2 || !board.GameIsRunning())
        {
            return;
        }

        Chessman identityChessman = identity.GetComponent <Chessman>();

        int boardToX = board.GetBoardPos(toX_World),
            boardToZ = board.GetBoardPos(toZ_World);

        List <Move> allValidMoves  = identityChessman.GetValidMoves();
        int         validMoveIndex = allValidMoves.FindIndex(move => move.x == boardToX && move.z == boardToZ);

        if (validMoveIndex == -1)
        {
            Debug.LogError("NOT LEGIT MOVE");
            return;
        }

        King kingComponent = identityChessman as King;
        bool isKing        = kingComponent != null;
        bool pawnGotToEnd  = false;

        if (allValidMoves[validMoveIndex].isKill)
        {
            Debug.Log("Entered is kill");

            NetworkIdentity toKill = board.GetComponentInChessman <NetworkIdentity>(allValidMoves[validMoveIndex].z, allValidMoves[validMoveIndex].x);
            NetworkServer.Destroy(NetworkServer.FindLocalObject(toKill.netId));
        }

        if (identityChessman is Pawn)
        {
            pawnGotToEnd = identityChessman.isWhite ? board.GetBoardPos(toZ_World) == 7 : board.GetBoardPos(toZ_World) == 0;
            if (pawnGotToEnd)
            {
                ServerTurnPawnIntoQueen(fromZ_Board, fromX_Board, toZ_World, toX_World, identityChessman);
            }
        }

        else if (allValidMoves[validMoveIndex].isCastle)
        {
            SetRookPositionInCastle(toX_World, kingComponent);
        }

        board.SwapPlayer();

        if (!pawnGotToEnd)
        {
            RpcMoveFigure(identity, fromZ_Board, fromX_Board, toZ_World, toX_World, identityChessman.isWhite, isKing);
        }
    }
Exemplo n.º 2
0
    void CheckSelection()
    {
        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }

        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, LayerMask.GetMask("Chessmen")))
        {
            Chessman chessmanComponent = hit.collider.GetComponent <Chessman>();

            if (chessmanComponent == null)
            {
                Debug.LogError("CheckSelection:: ChessmanComponent is null");
            }

            else if (selectedChessman == chessmanComponent)
            {
                selectedChessman = null;
                selectedChessman_NetworkIdentity = null;

                board.HideHighlighters();
            }

            else if ((isServer == PlayerColorHandler.Instance.ServerPlaysAsWhite) == chessmanComponent.isWhite)
            {
                board.HideHighlighters();

                selectedChessman = chessmanComponent;
                selectedChessman_NetworkIdentity = hit.collider.GetComponent <NetworkIdentity>();

                board.DisplayHighlighters(chessmanComponent.GetValidMoves());
            }
        }
    }