Esempio n. 1
0
    // ------------------------------------------ 서버에서 오는 반응 ----------------------------------------------
    #region
    public void handleData(message mes)
    {
        switch (mes.messageText)
        {
        case "homeResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                cSock.Close();
            }
            break;

        case "closeResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                cSock.Close();
                Application.Quit();
            }
            break;

        case "loginResponse":
            Debug.Log("" + mes.getSCObject(0).getBool("response"));
            Debug.Log("The login response returned: " + (mes.getSCObject(0).getBool("response") ? "correct." : "not correct."));

            if (mes.getSCObject(0).getBool("response"))
            {
                existurlcheck(userName, pass);
                //ItemCountCheck(userName, wItem);
            }

            else
            {
                CheckUserInfoObj.SetActive(true);
                LoginPanelObj.SetActive(true);
            }
            break;

        case "registerResponse":

            Debug.Log("" + mes.getSCObject(0).getBool("response"));
            Debug.Log("The register response returned: " + (mes.getSCObject(0).getBool("response") ? "correct." : "not correct."));
            if (mes.getSCObject(0).getBool("response"))
            {
                CreateAccountPanelObj.SetActive(false);
                LoginPanelObj.SetActive(true);
            }
            else
            {
                IdCheckObj.SetActive(true);
            }
            break;

        case "urlResponse":
            Debug.Log("" + mes.getSCObject(0).getBool("response"));
            Debug.Log("The url response returned: " + (mes.getSCObject(0).getBool("response") ? "correct." : "not correct."));
            if (mes.getSCObject(0).getBool("response"))
            {
                Debug.Log("URL 등록 성공");
            }
            else
            {
                Debug.Log("URL 등록 실패");
            }
            break;

        case "ItemCountCheckResponse":

            Debug.Log("server send message ItemCountCheck");
            if (mes.getSCObject(0).getBool("response"))    // 서버에서 ItemCountCheck가 잘 실행되면 각 아이템에 계정에 맞게 아이템 수 저장.
            {
                wGetItem = mes.getSCObject(0).getInt("wItemNum");
                Debug.Log("wGetItem = mes.getSCObject(0).getInt(wItemNum);");
                fGetItem = mes.getSCObject(0).getInt("fItemNum");
                Debug.Log("fGetItem = mes.getSCObject(0).getInt(fItemNum);");
                sGetItem = mes.getSCObject(0).getInt("sItemNum");
                Debug.Log("sGetItem = mes.getSCObject(0).getInt(sItemNum);");
                nGetItem = mes.getSCObject(0).getInt("nItemNum");
                Debug.Log("nGetItem = mes.getSCObject(0).getInt(nItemNum);");
                sfsGetItem = mes.getSCObject(0).getInt("sfsItemNum");
                Debug.Log("sfsGetItem = mes.getSCObject(0).getInt(sfsItemNum);");
                csGetItem = mes.getSCObject(0).getInt("csItemNum");
                Debug.Log("csGetItem = mes.getSCObject(0).getInt(csItemNum);");
                tsGetItem = mes.getSCObject(0).getInt("tsItemNum");
                Debug.Log("tsGetItem = mes.getSCObject(0).getInt(tsItemNum);");
                Debug.Log("ItemCountCheckResponse success.");
            }
            else
            {
                Debug.Log("ItemCountCheckResponse fail");
            }
            break;

        case "UpdatePlantListTableResponse":
            Debug.Log("" + mes.getSCObject(0).getBool("response"));
            Debug.Log("The url response returned: " + (mes.getSCObject(0).getBool("response") ? "correct." : "not correct."));
            if (mes.getSCObject(0).getBool("response"))
            {
                Debug.Log("UpdatePlantListTableResponse Success");
            }
            else
            {
                Debug.Log("UpdatePlantListTableResponse Fail");
            }
            break;

        case "SelectQueryResponse":
            Debug.Log("server send message SelectQueryResponse");
            if (mes.getSCObject(0).getBool("response"))     ///범용성잇게만들려면 여기도 다시
            {
                for (int i = 0; i <= mes.getSCObject(0).getInt("plantListTableCount") - 1; i++)
                {
                    plantName.Add(mes.getSCObject(0).getString("plantName[" + i + "]"));
                    plantPos.Add(mes.getSCObject(0).getInt("plantPos[" + i + "]"));
                    plantID.Add(mes.getSCObject(0).getInt("plantID[" + i + "]"));
                    Lv.Add(mes.getSCObject(0).getInt("Lv[" + i + "]"));
                    waterEXP.Add(mes.getSCObject(0).getFloat("waterEXP[" + i + "]"));
                    sunEXP.Add(mes.getSCObject(0).getFloat("sunEXP[" + i + "]"));
                    fertilizerEXP.Add(mes.getSCObject(0).getFloat("fertilizerEXP[" + i + "]"));
                }     //sendmessage 생각해보자, cloudrecotrackableventhandler
                Debug.Log("SelectQuery success");
                Debug.Log("plantPos[0] = " + plantPos[0] + " & plantPos.count is " + plantPos.Count);
            }
            else
            {
                Debug.Log("loginScript - SelectQueryResponse 실행안됨");
            }
            break;

        case "UpdatePlantExpResponse":
            Debug.Log("server send message UpdatePlantExpResponse");
            if (mes.getSCObject(0).getBool("response"))     ///범용성잇게만들려면 여기도 다시
            {
                Debug.Log("UpdatePlantExpResponse success");
            }
            else
            {
                Debug.Log("loginScript - UpdatePlantExpResponse Error");
            }
            break;

        case "urlcheckResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                LoginPanelObj.SetActive(false);
                SceneManager.LoadScene("PlantInfo");
            }

            else
            {
                LoginPanelObj.SetActive(false);
                SceneManager.LoadScene("SetPlantsBedScene");
                //cSock.Close();
            }
            break;

        case "getItemResponse":     // 서버에서 getItem의 결과를 받아옴
            Debug.Log("" + mes.getSCObject(0).getBool("response"));
            Debug.Log("The getItem response returned: " + (mes.getSCObject(0).getBool("response") ? "correct." : "not correct."));
            if (mes.getSCObject(0).getBool("response"))
            {
                Debug.Log(itemName + "increase OK");
            }
            else
            {
                Debug.Log(itemName + "increase Fali");
                SceneManager.LoadScene("GPSScene");
            }
            break;


        case "UseItemResponse":
            Debug.Log("using OK?");
            if (mes.getSCObject(0).getBool("response"))
            {
                Debug.Log("UseItemResponse - 서버에서 true 값 받아옴.");
                //wGetItem, fGetItem, sGetItem, nGetItem, sfsGetItem, csGetItem, tsGetItem

                /*wGetItem = mes.getSCObject(0).getInt("wItemNum");
                 * fGetItem = mes.getSCObject(0).getInt("fItemNum");
                 * sGetItem = mes.getSCObject(0).getInt("sItemNum");
                 * nGetItem = mes.getSCObject(0).getInt("nItemNum");
                 * sfsGetItem = mes.getSCObject(0).getInt("sfsItemNum");
                 * csGetItem = mes.getSCObject(0).getInt("csItemNum");
                 * tsGetItem = mes.getSCObject(0).getInt("tsItemNum");*/
            }
            else
            {
                Debug.Log("UseItemResponse - 서버에서 false 값 받아옴.");
                SceneManager.LoadScene("PlantInfo");
            }
            break;

        case "TransferIPResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                Debug.Log("TransferIPResponse Working");
                Battle Bt = new Battle();
                Bt.NextScene();
            }

            else
            {
                Debug.Log("Wait");
            }
            break;

        case "GetPlantNameResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                name1 = mes.getSCObject(0).getString("name1");
                name2 = mes.getSCObject(0).getString("name2");
                name3 = mes.getSCObject(0).getString("name3");
                name4 = mes.getSCObject(0).getString("name4");
                Debug.Log("" + name1 + " " + name2 + " " + name3 + " " + name4);
            }
            else
            {
                Debug.Log("Fail to Get PlantName");
            }
            break;

        case "SendipaddressResponse":     //서버에서 보낸 IP주소를 받아와서 클라이언트 ip에 저장.
            userip = mes.getSCObject(0).getString("useripaddress");
            if (mes.getSCObject(0).getBool("response"))
            {
                Debug.Log("PPPPPPPPPPPPPPPPPPPPPP" + userip);
            }
            else
            {
                cSock.Close();
                SceneManager.LoadScene("loginScene");
            }
            break;

        case "servermessageResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                servermessage = mes.getSCObject(0).getString("servermessage");
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "MyCardResponse":     //내가 받는 메세지 //여기 해결 못함 //계속 디버그만 반복됨 ;
            if (mes.getSCObject(0).getBool("response"))
            {
                switch (mes.getSCObject(0).getString("plantname"))
                {
                case "PoisonMushroom_B(Clone)":
                    Battle_DropZone.PoisonMushroom_B();
                    break;

                case "PoisonMushroom_R(Clone)":
                    Battle_DropZone.PoisonMushroom_R();
                    break;

                case "Baby plant(Clone)":
                    Battle_DropZone.Baby_plant();
                    break;

                case "BlowFishORCactus(Clone)":
                    Battle_DropZone.BlowFishORCactus();
                    break;

                case "Cosmos(Clone)":
                    Battle_DropZone.Cosmos();
                    break;

                case "DeliciousMushRoom(Clone)":
                    Battle_DropZone.DeliciousMushRoom();
                    break;

                case "GreenbristleGrass(Clone)":
                    Battle_DropZone.GreenbristleGrass();
                    break;

                case "JustBamboo(Clone)":
                    Battle_DropZone.JustBamboo();
                    break;

                case "NotTreeButRock(Clone)":
                    Battle_DropZone.NotTreeButRock();
                    break;

                case "PoisonMushroom_G(Clone)":
                    Battle_DropZone.PoisonMushroom_G();
                    break;

                case "PurpleFlower(Clone)":
                    Battle_DropZone.PurpleFlower();
                    break;

                case "ShiningFlower(Clone)":
                    Battle_DropZone.ShiningFlower();
                    break;

                case "UnknownOrangeColorFlower(Clone)":
                    Battle_DropZone.UnknownOrangeColorFlower();
                    break;

                case "UselessRock(Clone)":
                    Battle_DropZone.UselessRock();
                    break;

                case "Weed(Clone)":
                    Battle_DropZone.Weed();
                    break;

                case "Yellow Flower(Clone)":
                    Battle_DropZone.Yellow_Flower();
                    break;

                case "YouCantSeeMyFaceFlower(Clone)":
                    Battle_DropZone.YouCantSeeMyFaceFlower();
                    break;
                }
            }
            break;

        case "SendCreateAICardResponse":     //상대가 받는 메세지
            if (mes.getSCObject(0).getBool("response"))
            {
                switch (mes.getSCObject(0).getString("plantname"))
                {
                case "PoisonMushroom_B(Clone)":
                    Battle_DropZone.PoisonMushroom_B_Ai();
                    break;

                case "PoisonMushroom_R(Clone)":
                    Battle_DropZone.PoisonMushroom_R_Ai();
                    break;

                case "Baby plant(Clone)":
                    Battle_DropZone.Baby_plant_Ai();
                    break;

                case "BlowFishORCactus(Clone)":
                    Battle_DropZone.BlowFishORCactus_Ai();
                    break;

                case "Cosmos(Clone)":
                    Battle_DropZone.Cosmos_Ai();
                    break;

                case "DeliciousMushRoom(Clone)":
                    Battle_DropZone.DeliciousMushRoom_Ai();
                    break;

                case "GreenbristleGrass(Clone)":
                    Battle_DropZone.GreenbristleGrass_Ai();
                    break;

                case "JustBamboo(Clone)":
                    Battle_DropZone.JustBamboo_Ai();
                    break;

                case "NotTreeButRock(Clone)":
                    Battle_DropZone.NotTreeButRock_Ai();
                    break;

                case "PoisonMushroom_G(Clone)":
                    Battle_DropZone.PoisonMushroom_G_Ai();
                    break;

                case "PurpleFlower(Clone)":
                    Battle_DropZone.PurpleFlower_Ai();
                    break;

                case "ShiningFlower(Clone)":
                    Battle_DropZone.ShiningFlower_Ai();
                    break;

                case "UnknownOrangeColorFlower(Clone)":
                    Battle_DropZone.UnknownOrangeColorFlower_Ai();
                    break;

                case "UselessRock(Clone)":
                    Battle_DropZone.UselessRock_Ai();
                    break;

                case "Weed(Clone)":
                    Battle_DropZone.Weed_Ai();
                    break;

                case "Yellow Flower(Clone)":
                    Battle_DropZone.Yellow_Flower_Ai();
                    break;

                case "YouCantSeeMyFaceFlower(Clone)":
                    Battle_DropZone.YouCantSeeMyFaceFlower_Ai();
                    break;
                }
            }
            break;

        case "SendDestroyMyObjectResponse":    //나의 오브젝트가 뿌셔졌을때. //여기도 무슨 몬스터가 죽었는지 표시해주면 더 좋아짐.
            if (mes.getSCObject(0).getBool("response"))
            {
                Enemy1_info.Instance.DestroyMyObj();
                Debug.Log("SendDestroyMyObjectResponse");
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "SendDestroyAiObjectResponse":    //AI의 오브젝트가 뿌셔졌을때 ////여기도 무슨 몬스터가 죽었는지 표시해주면 더 좋아짐.
            if (mes.getSCObject(0).getBool("response"))
            {
                Enemy2_info.Instance.DestroyMyObj();
                Debug.Log("SendDestroyAiObjectResponse");
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "SendDestroyMyCastleResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                MyCastle.Instance.DestoryCastle();
                Debug.Log("SendDestroyMyCastleResponse");
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "SendDestroyAiCastleResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                EnemyCastle.Instance.DestoryCastle();
                Debug.Log("SendDestroyAiCastleResponse");
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "SendVictoryResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                addRank();
                StartCoroutine(Victory());
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "SendLoseResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                subtractionRank();
                StartCoroutine(Defeat());
            }
            else
            {
                Debug.Log("NOT OK");
            }
            break;

        case "addRankResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                rankpoint = mes.getSCObject(0).getInt("rankpoint");
                Debug.Log("addRank " + rankpoint);
            }
            else
            {
                Debug.Log("Not OK");
            }
            break;

        case "subtractionRankResponse":
            if (mes.getSCObject(0).getBool("response"))
            {
                rankpoint = mes.getSCObject(0).getInt("rankpoint");
                Debug.Log("subtractionRank " + rankpoint);
            }
            else
            {
                Debug.Log("Not OK");
            }
            break;

        default:
            Debug.Log("The server sent a message: " + mes.messageText);
            break;
        }
    }