Beispiel #1
0
    public void SendResult(char miss, int att)
    {
        //miss = M //attack = N
        if (miss == 'M')
        {
            reState = resultState.Win;
            animBattle.instance.isMiss = 0;
        }
        else
        {
            reState = resultState.Win;
            animBattle.instance.isMiss = 1;
            GameObject p_obj1 = GameObject.Find("Player1");
            GameObject p_obj2 = GameObject.Find("Player2");

            if (myPlayer == 0)
            {
                PlayerControl p1 = p_obj2.GetComponent <PlayerControl> ();
                p1.mHp = p1.mHp - att;
                if (p1.mHp <= 0)
                {
                    p1.mHp    = 0;
                    rankState = "Win";
                }
            }
            else
            {
                PlayerControl p1 = p_obj1.GetComponent <PlayerControl> ();
                p1.mHp = p1.mHp - att;
                if (p1.mHp <= 0)
                {
                    p1.mHp    = 0;
                    rankState = "Win";
                }
            }
        }

        byte[] packet = new byte[3];
        packet [0] = (byte)'r';
        packet [1] = (byte)miss;
        packet [2] = (byte)att;

        PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, packet);
    }
Beispiel #2
0
 public void setReState()
 {
     reState = resultState.Wait;
 }
Beispiel #3
0
 public void animState()
 {
     reState = resultState.WaitAnim;
 }
Beispiel #4
0
    //byte[] result = new byte[1];
    public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
    {
        char state = (char)data [0];

        if (state == 'c')
        {
            /* case press h,s,p */
            char temp   = (char)data [1];
            char fPress = (char)data [2];
            char mPress = 'f';

            //Debug.Log ("ooooJinoooo choose : " + temp); // temp is character type

            for (int i = 0; i < PlayName.Length; i++)
            {
                GameObject    play = GameObject.Find(PlayName [i]);
                PlayerControl p    = play.GetComponent <PlayerControl> ();
                if (!p.Blink)
                {
                    //p.setTurn();
                    p.setPress(fPress);
                }
                else
                {
                    mPress = p.mPrees;
                }
            }

            if (mPress == fPress)
            {
                if (temp == myChoose)
                {
                    /* draw case*/

                    friendManager.instance.draw.gameObject.SetActive(true);
                    if (temp == 'H')
                    {
                        friendManager.instance.H_p2.gameObject.SetActive(true);
                        friendManager.instance.H_p1.gameObject.SetActive(true);
                        friendManager.instance.S_p2.gameObject.SetActive(false);
                        friendManager.instance.S_p1.gameObject.SetActive(false);
                        friendManager.instance.P_p2.gameObject.SetActive(false);
                        friendManager.instance.P_p1.gameObject.SetActive(false);
                    }
                    else if (temp == 'P')
                    {
                        friendManager.instance.P_p2.gameObject.SetActive(true);
                        friendManager.instance.P_p1.gameObject.SetActive(true);
                        friendManager.instance.H_p2.gameObject.SetActive(false);
                        friendManager.instance.H_p1.gameObject.SetActive(false);
                        friendManager.instance.S_p2.gameObject.SetActive(false);
                        friendManager.instance.S_p1.gameObject.SetActive(false);
                    }
                    else if (temp == 'S')
                    {
                        friendManager.instance.S_p2.gameObject.SetActive(true);
                        friendManager.instance.S_p1.gameObject.SetActive(true);
                        friendManager.instance.H_p2.gameObject.SetActive(false);
                        friendManager.instance.H_p1.gameObject.SetActive(false);
                        friendManager.instance.P_p2.gameObject.SetActive(false);
                        friendManager.instance.P_p1.gameObject.SetActive(false);
                    }
                    reState = resultState.Draw;
                }
                else
                {
                    reState = resultState.WinWait;

                    float atk;
                    float ang = 0.0f;
                    float def;
                    float att;

                    float op;
                    float spdA;
                    float spdB;

                    int        ran;
                    char       m;
                    GameObject p_obj1 = GameObject.Find("Player1");
                    GameObject p_obj2 = GameObject.Find("Player2");

                    if (myPlayer == 0)
                    {
                        PlayerControl p1 = p_obj1.GetComponent <PlayerControl> ();
                        atk = p1.mAtk;
                        PlayerControl p2 = p_obj2.GetComponent <PlayerControl> ();
                        def = p2.mDef;

                        att = (atk + (atk * 10.0f / 100.0f) * (ang / 3.0f)) - def;
                        if (att <= 0.0f)
                        {
                            att = 1.0f;
                        }

                        spdA = p1.mSpd;
                        spdB = p2.mSpd;

                        if (spdA > spdB)
                        {
                            ran = Random.Range(1, 100);
                            if (ran > 15)
                            {
                                m = 'N';
                            }
                            else
                            {
                                m = 'M';
                            }
                        }
                        else
                        {
                            ran = Random.Range(1, 100);
                            if (ran > 40)
                            {
                                m = 'N';
                            }
                            else
                            {
                                m = 'M';
                            }
                        }
                    }
                    else
                    {
                        PlayerControl p1 = p_obj2.GetComponent <PlayerControl> ();
                        atk = p1.mAtk;
                        PlayerControl p2 = p_obj1.GetComponent <PlayerControl> ();
                        def = p2.mDef;

                        att = (atk + (atk * 10.0f / 100.0f) * (ang / 3.0f)) - def;
                        if (att <= 0.0f)
                        {
                            att = 1.0f;
                        }

                        spdA = p1.mSpd;
                        spdB = p2.mSpd;

                        if (spdA > spdB)
                        {
                            ran = Random.Range(1, 100);
                            if (ran > 15)
                            {
                                m = 'N';
                            }
                            else
                            {
                                m = 'M';
                            }
                        }
                        else
                        {
                            ran = Random.Range(1, 100);
                            if (ran > 40)
                            {
                                m = 'N';
                            }
                            else
                            {
                                m = 'M';
                            }
                        }
                    }


                    if (temp == 'H' && myChoose == 'P')
                    {
                        //reState = resultState.Win;
                        friendManager.instance.H_p2.gameObject.SetActive(true);
                        friendManager.instance.P_p1.gameObject.SetActive(true);

                        friendManager.instance.P_p2.gameObject.SetActive(false);
                        friendManager.instance.H_p1.gameObject.SetActive(false);
                        friendManager.instance.S_p2.gameObject.SetActive(false);
                        friendManager.instance.S_p1.gameObject.SetActive(false);

                        SendResult(m, Mathf.FloorToInt(att));
                    }
                    if (temp == 'H' && myChoose == 'S')
                    {
                        friendManager.instance.H_p2.gameObject.SetActive(true);
                        friendManager.instance.S_p1.gameObject.SetActive(true);

                        friendManager.instance.S_p2.gameObject.SetActive(false);
                        friendManager.instance.H_p1.gameObject.SetActive(false);
                        friendManager.instance.P_p2.gameObject.SetActive(false);
                        friendManager.instance.P_p1.gameObject.SetActive(false);
                        //reState = resultState.Lose;
                    }
                    if (temp == 'P' && myChoose == 'H')
                    {
                        //reState = resultState.Lose;
                        friendManager.instance.P_p2.gameObject.SetActive(true);
                        friendManager.instance.H_p1.gameObject.SetActive(true);

                        friendManager.instance.H_p2.gameObject.SetActive(false);
                        friendManager.instance.P_p1.gameObject.SetActive(false);
                        friendManager.instance.S_p2.gameObject.SetActive(false);
                        friendManager.instance.S_p1.gameObject.SetActive(false);
                    }
                    if (temp == 'P' && myChoose == 'S')
                    {
                        //reState = resultState.Win;friendManager.instance.H_p2.gameObject.SetActive(true);
                        friendManager.instance.P_p2.gameObject.SetActive(true);
                        friendManager.instance.S_p1.gameObject.SetActive(true);

                        friendManager.instance.P_p1.gameObject.SetActive(false);
                        friendManager.instance.S_p2.gameObject.SetActive(false);
                        friendManager.instance.H_p1.gameObject.SetActive(false);
                        friendManager.instance.H_p2.gameObject.SetActive(false);

                        SendResult(m, Mathf.FloorToInt(att));
                    }
                    if (temp == 'S' && myChoose == 'H')
                    {
                        //reState = resultState.Win;
                        friendManager.instance.S_p2.gameObject.SetActive(true);
                        friendManager.instance.H_p1.gameObject.SetActive(true);

                        friendManager.instance.S_p1.gameObject.SetActive(false);
                        friendManager.instance.H_p2.gameObject.SetActive(false);
                        friendManager.instance.P_p1.gameObject.SetActive(false);
                        friendManager.instance.P_p2.gameObject.SetActive(false);

                        SendResult(m, Mathf.FloorToInt(att));
                    }
                    if (temp == 'S' && myChoose == 'P')
                    {
                        friendManager.instance.S_p2.gameObject.SetActive(true);
                        friendManager.instance.P_p1.gameObject.SetActive(true);

                        friendManager.instance.S_p1.gameObject.SetActive(false);
                        friendManager.instance.P_p2.gameObject.SetActive(false);
                        friendManager.instance.H_p1.gameObject.SetActive(false);
                        friendManager.instance.H_p2.gameObject.SetActive(false);
                        //reState = resultState.Lose;
                    }
                }

                stateWait = 0;
                for (int i = 0; i < PlayName.Length; i++)
                {
                    GameObject    play = GameObject.Find(PlayName [i]);
                    PlayerControl p    = play.GetComponent <PlayerControl> ();
                    p.setPress('f');
                }
            }
        }
        else if (state == 'i')
        {
            /* case send data */
            friendManager.instance.haveFriend = true;
            friendManager.instance.load.gameObject.SetActive(false);
            char[] chars = new char[data.Length / sizeof(char)];
            System.Buffer.BlockCopy(data, 0, chars, 0, data.Length);
            //return new string (chars);
            string temp = new string (chars);
            //Debug.Log ("ooooJinoooo temp is " + temp);
            string[] tempArray = temp.Split('-');

            Participant        self    = GetSelf();
            List <Participant> players = GetPlayers();


            int i;
            for (i = 0; i < PlayName.Length; i++)
            {
                GameObject    play = GameObject.Find(PlayName [i]);
                PlayerControl p    = play.GetComponent <PlayerControl> ();
                //Debug.Log ("ooooJinoooo show id : " + p.ParticipantId);
                if (p.ParticipantId == senderId)
                {
                    p.setDataInfo(tempArray [1], int.Parse(tempArray [2]), int.Parse(tempArray [3]),
                                  int.Parse(tempArray [4]), int.Parse(tempArray [5]), int.Parse(tempArray [6]), tempArray [7]); // store data in my controler

                    //NPChangeTex.instance.change(tempArray[7]);
                    Debug.Log("ooooJinoooo friend Texture is " + tempArray[7]);
                }
                Debug.Log("ooooJinoooo Texture : " + p.mTexture + " and i is " + i);
            }
        }
        else if (state == 'r')
        {
            char s = (char)data[1];
            int  a = (int)data[2];

            if (s == 'M')
            {
                reState = resultState.Lose;
                animBattle.instance.isMiss = 0;
                animBattle.instance.isLose = true;
            }
            else
            {
                /* have to minus hp */
                reState = resultState.Lose;
                animBattle.instance.isMiss = 1;
                animBattle.instance.isLose = true;
                GameObject p_obj1 = GameObject.Find("Player1");
                GameObject p_obj2 = GameObject.Find("Player2");

                if (myPlayer == 0)
                {
                    PlayerControl p1 = p_obj1.GetComponent <PlayerControl> ();
                    p1.mHp = p1.mHp - a;
                    if (p1.mHp <= 0)
                    {
                        p1.mHp    = 0;
                        rankState = "Lose";
                    }
                }
                else
                {
                    PlayerControl p1 = p_obj2.GetComponent <PlayerControl> ();
                    p1.mHp = p1.mHp - a;
                    if (p1.mHp <= 0)
                    {
                        p1.mHp    = 0;
                        rankState = "Lose";
                    }
                }
            }
        }
    }