Exemple #1
0
    void OnMouseDown()
    {
        GameObject go = GameObject.Find("SocketIO");

        socket = go.GetComponent <SocketIOComponent>();
        Text txt = FindTextFiel.find();

        MakeRequestResponse command = new MakeRequestResponse();

        command.gameId       = LoginScript.CurrentUserGameId;
        command.playerId     = LoginScript.CurrentUserGEId;
        command.intersection = int.Parse(piece.name);
        RequestJson req = new RequestJson();

        RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/buyCity", command).Then(Response =>
        {
            req.code   = Response.code;
            req.status = Response.status;
            if (req.code == 200)
            {
                JSONObject json_message = new JSONObject();
                json_message.AddField("lobbyid", LoginScript.CurrentUserLobbyId);
                json_message.AddField("username", LoginScript.CurrentUser);
                json_message.AddField("intersection", command.intersection);
                socket.Emit("buyCity", json_message);
                allPieces.SetActive(false);
                if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser)
                {
                    AfiseazaDrum.afiseaza(newPieceO1, piece);
                }
                else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser)
                {
                    AfiseazaDrum.afiseaza(newPieceO2, piece);
                }
                else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser)
                {
                    AfiseazaDrum.afiseaza(newPieceO3, piece);
                }
                else if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser)
                {
                    AfiseazaDrum.afiseaza(newPieceO4, piece);
                }
            }
            Debug.Log(req.code);
            Debug.Log(req.status);

            txt.text = req.status;
        }).Catch(err => { Debug.Log(err); });
        allPieces.SetActive(false);
    }
Exemple #2
0
    public void setupEvents()
    {
        socket.On("wantToTrade", (E) =>
        {
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                if (E.data[3].str == "false")
                {
                    trade--;
                }
                else
                {
                    trade += 10;
                }
                if (trade > 0)
                {
                    trade = 0;
                    TradePlayerJson command = new TradePlayerJson();
                    command.gameId          = LoginScript.CurrentUserGameId;
                    command.playerId        = LoginScript.CurrentUserGEId;
                    RequestJson req         = new RequestJson();
                    RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/sendPartners", command).Then(Response =>
                    {
                        Debug.Log("SendParteners " + Response.code);
                        Debug.Log("Send Parteners " + Response.status);
                        Debug.Log("Send Partenets " + Response.arguments.player_0);
                        SelectedPartener commandSelect = new SelectedPartener();
                        commandSelect.gameId           = LoginScript.CurrentUserGameId;
                        commandSelect.playerId         = LoginScript.CurrentUserGEId;
                        commandSelect.player           = Response.arguments.player_0;
                        Debug.Log("Playerul este: " + commandSelect.player);
                        RequestJson request = new RequestJson();
                        RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/selectPartner", commandSelect).Then(Response2 =>
                        {
                            Debug.Log("SelectPartener " + Response2.code);
                            Debug.Log("SelectPartener " + Response2.status);

                            Text txt = FindTextFiel.find();
                            txt.text = Response2.status;

                            if (Response2.code == 200)
                            {
                                JSONObject json_message = new JSONObject();
                                json_message.AddField("lobbyid", LoginScript.CurrentUserLobbyId);
                                socket.Emit("UpdateResource", json_message);


                                MakeRequestResponse command1 = new MakeRequestResponse();
                                command1.gameId   = LoginScript.CurrentUserGameId;
                                command1.playerId = LoginScript.CurrentUserGEId;
                                RequestJson req1  = new RequestJson();
                                RestClient.Post <UpdateJson>("https://catan-connectivity.herokuapp.com/game/update", command1).Then(Response1 =>
                                {
                                    Debug.Log("Update code " + Response1.code);
                                    Debug.Log("Update status " + Response1.status);
                                    Debug.Log("Update arguments lumber " + Response1.arguments.lumber);

                                    lumber.text = Response1.arguments.lumber.ToString();
                                    ore.text    = Response1.arguments.ore.ToString();
                                    grain.text  = Response1.arguments.grain.ToString();
                                    brick.text  = Response1.arguments.brick.ToString();
                                    wool.text   = Response1.arguments.wool.ToString();
                                }).Catch(err => { Debug.Log(err); });
                            }
                        }).Catch(err => { Debug.Log(err); });
                    }).Catch(err => { Debug.Log(err); });
                }
                if (trade == -3)
                {
                    trade = 0;
                    TradePlayerJson command = new TradePlayerJson();
                    command.gameId          = LoginScript.CurrentUserGameId;
                    command.playerId        = LoginScript.CurrentUserGEId;
                    // command.arguments = null;
                    RequestJson req = new RequestJson();
                    RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/sendPartners", command).Then(Response =>
                    {
                        Debug.Log("SendParteners " + Response.code);
                        Debug.Log("Send Parteners " + Response.status);
                        Debug.Log("Send Partenets " + Response.arguments.player_0);
                        SelectedPartener commandSelect = new SelectedPartener();
                        commandSelect.gameId           = LoginScript.CurrentUserGameId;
                        commandSelect.playerId         = LoginScript.CurrentUserGEId;
                        commandSelect.player           = null;
                        RequestJson request            = new RequestJson();
                        RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/selectPartner", commandSelect).Then(Response2 =>
                        {
                            Debug.Log("Nu a selectat nimeni");
                            Debug.Log(Response2.status);
                        }).Catch(err => { Debug.Log(err); });
                    }).Catch(err => { Debug.Log(err); });
                }
            }
        });
        socket.On("buildsettlement", (E) =>
        {
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                Debug.Log("builtsettelment");
                string user_who_built_settelment = E.data[1].str;
                string intesection = E.data[2].ToString();
                casute.SetActive(true);
                inter = GameObject.Find(intesection);
                print(inter.name);

                if (user_who_built_settelment == LoginScript.CurrentLobby.master)
                {
                    AfiseazaDrum.afiseaza(newPiece1, inter);
                }

                else if (user_who_built_settelment == LoginScript.CurrentLobby.first)
                {
                    AfiseazaDrum.afiseaza(newPiece2, inter);
                }
                else if (user_who_built_settelment == LoginScript.CurrentLobby.second)
                {
                    AfiseazaDrum.afiseaza(newPiece3, inter);
                }
                else if (user_who_built_settelment == LoginScript.CurrentLobby.third)
                {
                    AfiseazaDrum.afiseaza(newPiece4, inter);
                }
                casute.SetActive(false);
            }
        });
        socket.On("buildroad", (E) =>
        {
            turn++;
            Debug.Log("buildroad");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                Debug.Log("buildroad227711");
                string user_who_built_road = E.data[1].str;
                string start = E.data[2].ToString();
                string end   = E.data[3].ToString();
                drumuri.SetActive(true);
                inter  = GameObject.Find(start + " " + end);
                inter1 = GameObject.Find(end + " " + start);
                if (inter == null)
                {
                    inter = GameObject.Find(end + " " + start);
                }

                if (user_who_built_road == LoginScript.CurrentLobby.master && ver.text == "0")
                {
                    AfiseazaDrum.afiseaza(newPieceR1, inter);
                    player1.SetActive(false);
                    player2.SetActive(true);
                    player3.SetActive(false);
                    player4.SetActive(false);
                }

                else if (user_who_built_road == LoginScript.CurrentLobby.first && ver.text == "0")
                {
                    AfiseazaDrum.afiseaza(newPieceR2, inter);
                    player2.SetActive(false);
                    player3.SetActive(true);
                    player1.SetActive(false);
                    player4.SetActive(false);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.second && ver.text == "0")
                {
                    AfiseazaDrum.afiseaza(newPieceR3, inter);
                    player3.SetActive(false);
                    player4.SetActive(true);
                    player1.SetActive(false);
                    player2.SetActive(false);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.third && ver.text == "0")
                {
                    AfiseazaDrum.afiseaza(newPieceR4, inter);
                    player4.SetActive(true);
                    player1.SetActive(false);
                    player3.SetActive(false);
                    player2.SetActive(false);
                    //ok1 = true;
                    ver.text = "1";
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.third && ver.text == "1")
                {
                    AfiseazaDrum.afiseaza(newPieceR4, inter);
                    player4.SetActive(false);
                    player1.SetActive(false);
                    player3.SetActive(true);
                    player2.SetActive(false);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.second && ver.text == "1")
                {
                    AfiseazaDrum.afiseaza(newPieceR3, inter);
                    player4.SetActive(false);
                    player1.SetActive(false);
                    player3.SetActive(false);
                    player2.SetActive(true);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.first && ver.text == "1")
                {
                    AfiseazaDrum.afiseaza(newPieceR2, inter);
                    player4.SetActive(false);
                    player1.SetActive(true);
                    player3.SetActive(false);
                    player2.SetActive(false);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.master && ver.text == "1")
                {
                    AfiseazaDrum.afiseaza(newPieceR1, inter);
                    player4.SetActive(false);
                    player1.SetActive(true);
                    player3.SetActive(false);
                    player2.SetActive(false);
                    ver.text = "2";
                }
                if (user_who_built_road == LoginScript.CurrentLobby.master && ver.text == "2")
                {
                    AfiseazaDrum.afiseaza(newPieceR1, inter);
                }

                else if (user_who_built_road == LoginScript.CurrentLobby.first && ver.text == "2")
                {
                    AfiseazaDrum.afiseaza(newPieceR2, inter);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.second && ver.text == "2")
                {
                    AfiseazaDrum.afiseaza(newPieceR3, inter);
                }
                else if (user_who_built_road == LoginScript.CurrentLobby.third && ver.text == "2")
                {
                    AfiseazaDrum.afiseaza(newPieceR4, inter);
                }
                drumuri.SetActive(false);
            }
        });
        socket.On("RollDice", (E) =>
        {
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                print("dice roll info");
                for (int i = 0; i <= 27; i++)
                {
                    print(E.data[i].ToString());
                }

                if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser)
                {
                    lumber.text = (int.Parse(lumber.text) + int.Parse(E.data[23].ToString())).ToString();
                    ore.text    = (int.Parse(ore.text) + int.Parse(E.data[27].ToString())).ToString();
                    grain.text  = (int.Parse(grain.text) + int.Parse(E.data[25].ToString())).ToString();
                    brick.text  = (int.Parse(brick.text) + int.Parse(E.data[26].ToString())).ToString();
                    wool.text   = (int.Parse(wool.text) + int.Parse(E.data[24].ToString())).ToString();
                }
                else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser)
                {
                    lumber.text = (int.Parse(lumber.text) + int.Parse(E.data[17].ToString())).ToString();
                    ore.text    = (int.Parse(ore.text) + int.Parse(E.data[21].ToString())).ToString();
                    grain.text  = (int.Parse(grain.text) + int.Parse(E.data[19].ToString())).ToString();
                    brick.text  = (int.Parse(brick.text) + int.Parse(E.data[20].ToString())).ToString();
                    wool.text   = (int.Parse(wool.text) + int.Parse(E.data[18].ToString())).ToString();
                }
                else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser)
                {
                    lumber.text = (int.Parse(lumber.text) + int.Parse(E.data[11].ToString())).ToString();
                    ore.text    = (int.Parse(ore.text) + int.Parse(E.data[15].ToString())).ToString();
                    grain.text  = (int.Parse(grain.text) + int.Parse(E.data[13].ToString())).ToString();
                    brick.text  = (int.Parse(brick.text) + int.Parse(E.data[14].ToString())).ToString();
                    wool.text   = (int.Parse(wool.text) + int.Parse(E.data[12].ToString())).ToString();
                }
                else if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser)
                {
                    lumber.text = (int.Parse(lumber.text) + int.Parse(E.data[5].ToString())).ToString();
                    ore.text    = (int.Parse(ore.text) + int.Parse(E.data[9].ToString())).ToString();
                    grain.text  = (int.Parse(grain.text) + int.Parse(E.data[7].ToString())).ToString();
                    brick.text  = (int.Parse(brick.text) + int.Parse(E.data[8].ToString())).ToString();
                    wool.text   = (int.Parse(wool.text) + int.Parse(E.data[6].ToString())).ToString();
                }

                string dice_1 = E.data[2].ToString();
                string dice_2 = E.data[3].ToString();
                switch (dice_1)
                {
                case "1":
                    side1.SetActive(true);
                    side2.SetActive(false);
                    side3.SetActive(false);
                    side4.SetActive(false);
                    side5.SetActive(false);
                    side6.SetActive(false);

                    break;

                case "2":
                    side1.SetActive(false);
                    side2.SetActive(true);
                    side3.SetActive(false);
                    side4.SetActive(false);
                    side5.SetActive(false);
                    side6.SetActive(false);

                    break;

                case "3":
                    side1.SetActive(false);
                    side2.SetActive(false);
                    side3.SetActive(true);
                    side4.SetActive(false);
                    side5.SetActive(false);
                    side6.SetActive(false);

                    break;

                case "4":
                    side1.SetActive(false);
                    side2.SetActive(false);
                    side3.SetActive(false);
                    side4.SetActive(true);
                    side5.SetActive(false);
                    side6.SetActive(false);

                    break;

                case "5":
                    side1.SetActive(false);
                    side2.SetActive(false);
                    side3.SetActive(false);
                    side4.SetActive(false);
                    side5.SetActive(true);
                    side6.SetActive(false);

                    break;

                case "6":
                    side1.SetActive(false);
                    side2.SetActive(false);
                    side3.SetActive(false);
                    side4.SetActive(false);
                    side5.SetActive(false);
                    side6.SetActive(true);

                    break;
                }

                switch (dice_2)
                {
                case "1":
                    sside1.SetActive(true);
                    sside2.SetActive(false);
                    sside3.SetActive(false);
                    sside4.SetActive(false);
                    sside5.SetActive(false);
                    sside6.SetActive(false);

                    break;

                case "2":
                    sside1.SetActive(false);
                    sside2.SetActive(true);
                    sside3.SetActive(false);
                    sside4.SetActive(false);
                    sside5.SetActive(false);
                    sside6.SetActive(false);
                    break;

                case "3":
                    sside1.SetActive(false);
                    sside2.SetActive(false);
                    sside3.SetActive(true);
                    sside4.SetActive(false);
                    sside5.SetActive(false);
                    sside6.SetActive(false);
                    break;

                case "4":
                    sside1.SetActive(false);
                    sside2.SetActive(false);
                    sside3.SetActive(false);
                    sside4.SetActive(true);
                    sside5.SetActive(false);
                    sside6.SetActive(false);
                    break;

                case "5":
                    sside1.SetActive(false);
                    sside2.SetActive(false);
                    sside3.SetActive(false);
                    sside4.SetActive(false);
                    sside5.SetActive(true);
                    sside6.SetActive(false);
                    break;

                case "6":
                    sside1.SetActive(false);
                    sside2.SetActive(false);
                    sside3.SetActive(false);
                    sside4.SetActive(false);
                    sside5.SetActive(false);
                    sside6.SetActive(true);
                    break;
                }
                Debug.Log(dice_1);
                Debug.Log(dice_2);
                if (int.Parse(dice_1) + int.Parse(dice_2) == 7)
                {
                    int player_0_sum = int.Parse(lumber.text) + int.Parse(brick.text) + int.Parse(ore.text) + int.Parse(wool.text) + int.Parse(grain.text);

                    if (player_0_sum > 7)
                    {
                        player_0_sum       = player_0_sum / 2;
                        DiscardAmount.text = "You have to discard " + player_0_sum.ToString() + " of your cards";
                        tataPanel.SetActive(true);
                        tataPanel.SetActive(true);
                        ibirck.text  = "";
                        iore.text    = "";
                        ilumber.text = "";
                        igrain.text  = "";
                        iwool.text   = "";
                    }
                }
            }
        });


        socket.On("endturn", (E) =>
        {
            Debug.Log("endturn");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                string user_who_end_turn = E.data[1].str;
                if (LoginScript.CurrentLobby.master == user_who_end_turn)
                {
                    player1.SetActive(false);
                    player2.SetActive(true);
                    player3.SetActive(false);
                    player4.SetActive(false);
                }
                else if (LoginScript.CurrentLobby.first == user_who_end_turn)
                {
                    player2.SetActive(false);
                    player3.SetActive(true);
                    player1.SetActive(false);
                    player4.SetActive(false);
                }
                else if (LoginScript.CurrentLobby.second == user_who_end_turn)
                {
                    player3.SetActive(false);
                    player4.SetActive(true);
                    player1.SetActive(false);
                    player2.SetActive(false);
                }
                else if (LoginScript.CurrentLobby.third == user_who_end_turn)
                {
                    player4.SetActive(false);
                    player1.SetActive(true);
                    player3.SetActive(false);
                    player2.SetActive(false);
                }
            }
            MakeRequestResponse command1 = new MakeRequestResponse();
            command1.gameId   = LoginScript.CurrentUserGameId;
            command1.playerId = LoginScript.CurrentUserGEId;
            RequestJson req1  = new RequestJson();
            RestClient.Post <UpdateJson>("https://catan-connectivity.herokuapp.com/game/update", command1).Then(Response1 =>
            {
                Debug.Log("Update code " + Response1.code);
                Debug.Log("Update status " + Response1.status);
                Debug.Log("Update arguments lumber " + Response1.arguments.lumber);

                print("end turn info");
                print(Response1.arguments.lumber.ToString());
                print(Response1.arguments.ore.ToString());
                print(Response1.arguments.grain.ToString());
                print(Response1.arguments.brick.ToString());
                print(Response1.arguments.wool.ToString());

                lumber.text = Response1.arguments.lumber.ToString();
                ore.text    = Response1.arguments.ore.ToString();
                grain.text  = Response1.arguments.grain.ToString();
                brick.text  = Response1.arguments.brick.ToString();
                wool.text   = Response1.arguments.wool.ToString();
            }).Catch(err => { Debug.Log(err); });
        });
        socket.On("buyCity", (E) =>
        {
            Debug.Log("buyCity");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                Debug.Log("buyCity");
                string user_who_built_settelment = E.data[1].str;
                string intesection = E.data[2].ToString();
                casute.SetActive(true);
                interO = GameObject.Find(intesection);
                ///Debug.Log(intesection);

                if (user_who_built_settelment == LoginScript.CurrentLobby.master)
                {
                    AfiseazaDrum.afiseaza(newPieceO1, interO);
                }

                else if (user_who_built_settelment == LoginScript.CurrentLobby.first)
                {
                    AfiseazaDrum.afiseaza(newPieceO2, interO);
                }
                else if (user_who_built_settelment == LoginScript.CurrentLobby.second)
                {
                    AfiseazaDrum.afiseaza(newPieceO3, interO);
                }
                else if (user_who_built_settelment == LoginScript.CurrentLobby.third)
                {
                    AfiseazaDrum.afiseaza(newPieceO4, interO);
                }

                casute.SetActive(false);
            }
        });
        socket.On("playerTrade", (E) =>
        {
            Debug.Log("playerTrade");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                tradePanel.SetActive(true);
                playerName.text = "Player " + E.data[1].str + " want to trade";
                print(E.data[2].ToString());
                print(E.data[3].ToString());
                print(E.data[4].ToString());
                print(E.data[5].ToString());
                print(E.data[6].ToString());
                print(E.data[7].ToString());
                print(E.data[8].ToString());
                print(E.data[9].ToString());
                print(E.data[10].ToString());
                print(E.data[11].ToString());
                of1.text = "" + E.data[2].ToString();
                of2.text = "" + E.data[3].ToString();
                of3.text = "" + E.data[4].ToString();
                of4.text = "" + E.data[5].ToString();
                of5.text = "" + E.data[6].ToString();

                rq1.text = "" + E.data[7].ToString();
                rq2.text = "" + E.data[8].ToString();
                rq3.text = "" + E.data[9].ToString();
                rq4.text = "" + E.data[10].ToString();
                rq5.text = "" + E.data[11].ToString();
            }
        });

        socket.On("UpdateResource", (E) =>
        {
            Debug.Log("playerTrade");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                MakeRequestResponse command1 = new MakeRequestResponse();
                command1.gameId   = LoginScript.CurrentUserGameId;
                command1.playerId = LoginScript.CurrentUserGEId;
                RequestJson req1  = new RequestJson();
                RestClient.Post <UpdateJson>("https://catan-connectivity.herokuapp.com/game/update", command1).Then(Response1 =>
                {
                    Debug.Log("Update code " + Response1.code);
                    Debug.Log("Update status " + Response1.status);
                    print(Response1.arguments.lumber.ToString());
                    print(Response1.arguments.ore.ToString());
                    print(Response1.arguments.grain.ToString());
                    print(Response1.arguments.brick.ToString());
                    print(Response1.arguments.wool.ToString());

                    lumber.text = Response1.arguments.lumber.ToString();
                    ore.text    = Response1.arguments.ore.ToString();
                    grain.text  = Response1.arguments.grain.ToString();
                    brick.text  = Response1.arguments.brick.ToString();
                    wool.text   = Response1.arguments.wool.ToString();
                }).Catch(err => { Debug.Log(err); });
            }
        });
        socket.On("placeRobber", (E) =>
        {
            Debug.Log("placeRobber");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                tataHot.SetActive(true);
                GameObject rob = GameObject.Find("0" + E.data[1].str);
                GameObject x   = GameObject.Find("Robber777(Clone)");

                Destroy(x);
                AfiseazaDrum.afiseaza(Robbler, rob);
                //Instantiate(Robler, rob.position, rob.rotation);
                //Rober.SetActive(false);
                tataHot.SetActive(false);
            }
        });

        socket.On("Stolen", (E) =>
        {
            Debug.Log("Stolen");
            if (E.data[0].str == LoginScript.CurrentUserLobbyId)
            {
                MakeRequestResponse command1 = new MakeRequestResponse();
                command1.gameId   = LoginScript.CurrentUserGameId;
                command1.playerId = LoginScript.CurrentUserGEId;
                RequestJson req1  = new RequestJson();
                RestClient.Post <UpdateJson>("https://catan-connectivity.herokuapp.com/game/update", command1).Then(Response1 =>
                {
                    Debug.Log("Update code " + Response1.code);
                    Debug.Log("Update status " + Response1.status);
                    print(Response1.arguments.lumber.ToString());
                    print(Response1.arguments.ore.ToString());
                    print(Response1.arguments.grain.ToString());
                    print(Response1.arguments.brick.ToString());
                    print(Response1.arguments.wool.ToString());

                    lumber.text = Response1.arguments.lumber.ToString();
                    ore.text    = Response1.arguments.ore.ToString();
                    grain.text  = Response1.arguments.grain.ToString();
                    brick.text  = Response1.arguments.brick.ToString();
                    wool.text   = Response1.arguments.wool.ToString();
                }).Catch(err => { Debug.Log(err); });
            }
        });
    }
Exemple #3
0
    void OnMouseDown()
    {
        GameObject go = GameObject.Find("SocketIO");

        socket = go.GetComponent <SocketIOComponent>();
        Text txt = FindTextFiel.find();

        if (numar != -1)
        {
            if (ver.text == "2")
            {
                MakeRequestResponse command = new MakeRequestResponse();
                command.gameId       = LoginScript.CurrentUserGameId;
                command.playerId     = LoginScript.CurrentUserGEId;
                command.intersection = numar;
                RequestJson req = new RequestJson();

                RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/buySettlement", command).Then(Response =>
                {
                    req.code   = Response.code;
                    req.status = Response.status;
                    if (req.code == 200)
                    {
                        JSONObject json_message = new JSONObject();
                        json_message.AddField("lobbyid", LoginScript.CurrentUserLobbyId);
                        json_message.AddField("username", LoginScript.CurrentUser);
                        json_message.AddField("intersection", command.intersection);
                        print(command.intersection);
                        socket.Emit("buildsettlement", json_message);


                        if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece1, piece);
                        }
                        else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece2, piece);
                        }
                        else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece3, piece);
                        }
                        else if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece4, piece);
                        }

                        allPieces.SetActive(false);
                        int x       = int.Parse(lumber.text) - 1;
                        lumber.text = x.ToString();
                        x           = int.Parse(brick.text) - 1;
                        brick.text  = x.ToString();
                        x           = int.Parse(grain.text) - 1;
                        grain.text  = x.ToString();
                        x           = int.Parse(wool.text) - 1;
                        wool.text   = x.ToString();
                    }

                    Debug.Log(req.code);
                    Debug.Log(req.status);

                    txt.text = req.status;
                }).Catch(err => { Debug.Log(err); });
            }
            else
            {
                MakeRequestResponse command = new MakeRequestResponse();
                command.gameId       = LoginScript.CurrentUserGameId;
                command.playerId     = LoginScript.CurrentUserGEId;
                command.intersection = numar;
                RequestJson req = new RequestJson();

                RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/buildSettlement", command).Then(Response =>
                {
                    req.code   = Response.code;
                    req.status = Response.status;
                    if (req.code == 200)
                    {
                        JSONObject json_message = new JSONObject();
                        json_message.AddField("lobbyid", LoginScript.CurrentUserLobbyId);
                        json_message.AddField("username", LoginScript.CurrentUser);
                        json_message.AddField("intersection", command.intersection);
                        print(command.intersection);
                        socket.Emit("buildsettlement", json_message);


                        if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece1, piece);
                        }
                        else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece2, piece);
                        }
                        else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece3, piece);
                        }
                        else if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece4, piece);
                        }
                    }
                    allPieces.SetActive(false);
                    Debug.Log(req.code);
                    Debug.Log(req.status);

                    txt.text = req.status;
                    if (ver.text == "1")
                    {
                        MakeRequestResponse command1 = new MakeRequestResponse();
                        command1.gameId   = LoginScript.CurrentUserGameId;
                        command1.playerId = LoginScript.CurrentUserGEId;
                        RequestJson req1  = new RequestJson();
                        RestClient.Post <UpdateJson>("https://catan-connectivity.herokuapp.com/game/update", command1).Then(Response1 =>
                        {
                            Debug.Log("Update code " + Response1.code);
                            Debug.Log("Update status " + Response1.status);
                            Debug.Log("Update arguments lumber " + Response1.arguments.lumber);
                            lumber.text = Response1.arguments.lumber.ToString();
                            ore.text    = Response1.arguments.ore.ToString();
                            grain.text  = Response1.arguments.grain.ToString();
                            brick.text  = Response1.arguments.brick.ToString();
                            wool.text   = Response1.arguments.wool.ToString();
                        }).Catch(err => { Debug.Log(err); });
                    }
                }).Catch(err => { Debug.Log(err); });
            }
        }
        else
        {
            if (ver.text == "2")
            {
                MakeRequestResponse command = new MakeRequestResponse();
                command.gameId       = LoginScript.CurrentUserGameId;
                command.playerId     = LoginScript.CurrentUserGEId;
                command.intersection = 0;
                command.start        = capat1;
                command.end          = capat2;
                //Debug.Log(CurrentUserGame);
                //Debug.Log(CurrentUserId);
                RequestJson req = new RequestJson();


                RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/buyRoad", command).Then(Response =>
                {
                    req.code   = Response.code;
                    req.status = Response.status;
                    if (req.code == 200)
                    {
                        JSONObject json_message = new JSONObject();
                        json_message.AddField("lobbyid", LoginScript.CurrentUserLobbyId);
                        json_message.AddField("username", LoginScript.CurrentUser);
                        json_message.AddField("start", command.start);
                        json_message.AddField("end", command.end);
                        socket.Emit("buildroad", json_message);
                        allPieces.SetActive(false);
                        if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece1, piece);
                        }
                        else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece2, piece);
                        }
                        else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece3, piece);
                        }
                        else if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser)
                        {
                            AfiseazaDrum.afiseaza(newPiece4, piece);
                        }

                        int x       = int.Parse(lumber.text) - 1;
                        lumber.text = x.ToString();
                        x           = int.Parse(brick.text) - 1;
                        brick.text  = x.ToString();
                    }
                    Debug.Log(req.code);
                    Debug.Log(req.status);

                    txt.text = req.status;
                }).Catch(err => { Debug.Log(err); });
                allPieces.SetActive(false);
            }

            else
            {
                MakeRequestResponse command = new MakeRequestResponse();
                command.gameId       = LoginScript.CurrentUserGameId;
                command.playerId     = LoginScript.CurrentUserGEId;
                command.intersection = 0;
                command.start        = capat1;
                command.end          = capat2;
                //Debug.Log(CurrentUserGame);
                //Debug.Log(CurrentUserId);
                RequestJson req = new RequestJson();


                RestClient.Post <RequestJson>("https://catan-connectivity.herokuapp.com/game/buildRoad", command).Then(Response =>
                {
                    req.code   = Response.code;
                    req.status = Response.status;
                    if (req.code == 200)
                    {
                        JSONObject json_message = new JSONObject();
                        json_message.AddField("lobbyid", LoginScript.CurrentUserLobbyId);
                        json_message.AddField("username", LoginScript.CurrentUser);
                        json_message.AddField("start", command.start);
                        json_message.AddField("end", command.end);
                        socket.Emit("buildroad", json_message);
                        allPieces.SetActive(false);
                        if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser && ver.text == "0")
                        {
                            AfiseazaDrum.afiseaza(newPiece1, piece);
                            player1.SetActive(false);
                            player2.SetActive(true);
                            player3.SetActive(false);
                            player4.SetActive(false);
                        }
                        else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser && ver.text == "0")
                        {
                            AfiseazaDrum.afiseaza(newPiece2, piece);

                            player2.SetActive(false);
                            player3.SetActive(true);
                            player1.SetActive(false);
                            player4.SetActive(false);
                        }
                        else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser && ver.text == "0")
                        {
                            AfiseazaDrum.afiseaza(newPiece3, piece);

                            player3.SetActive(false);
                            player4.SetActive(true);
                            player1.SetActive(false);
                            player2.SetActive(false);
                        }
                        else if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser && ver.text == "0")
                        {
                            AfiseazaDrum.afiseaza(newPiece4, piece);

                            player4.SetActive(true);
                            player1.SetActive(false);
                            player3.SetActive(false);
                            player2.SetActive(false);
                            //  ok = true;
                            ver.text = "1";
                        }
                        else if (LoginScript.CurrentLobby.third == LoginScript.CurrentUser && ver.text == "1")
                        {
                            AfiseazaDrum.afiseaza(newPiece4, piece);
                            player4.SetActive(false);
                            player1.SetActive(false);
                            player3.SetActive(true);
                            player2.SetActive(false);
                        }
                        else if (LoginScript.CurrentLobby.second == LoginScript.CurrentUser && ver.text == "1")
                        {
                            AfiseazaDrum.afiseaza(newPiece3, piece);
                            player4.SetActive(false);
                            player1.SetActive(false);
                            player3.SetActive(false);
                            player2.SetActive(true);
                        }
                        else if (LoginScript.CurrentLobby.first == LoginScript.CurrentUser && ver.text == "1")
                        {
                            AfiseazaDrum.afiseaza(newPiece2, piece);
                            player4.SetActive(false);
                            player1.SetActive(true);
                            player3.SetActive(false);
                            player2.SetActive(false);
                        }
                        else if (LoginScript.CurrentLobby.master == LoginScript.CurrentUser && ver.text == "1")
                        {
                            AfiseazaDrum.afiseaza(newPiece1, piece);
                            player4.SetActive(false);
                            player1.SetActive(true);
                            player3.SetActive(false);
                            player2.SetActive(false);
                            ver.text = "2";
                        }
                    }
                    Debug.Log(req.code);
                    Debug.Log(req.status);
                    txt.text = req.status;
                }).Catch(err => { Debug.Log(err); });
            }


            allPieces.SetActive(false);
        }
    }