Beispiel #1
0
    public void PassBall(bool isSuper = false)
    {
        if (_isKicking && sepakBall.IsInRange(1.5f))
        {
            sepakBall.speed = 3f;
            if (isSuper)
            {
                sepakBall.SetSpecial(true);
            }

            int randIndex = Random.Range(0, MultiplayerGameSession.NumberOfPlayers - 1);

            List <Transform> receivers = new List <Transform>();

            if (transform.parent.name.Contains("player1"))
            {
                int count = PlayerHost.Server.NetworkObjects.transform.childCount;
                for (int i = 0; i < count; i++)
                {
                    Transform t = PlayerHost.Server.NetworkObjects.transform.GetChild(i);
                    if (t.name.Contains("player1ai"))
                    {
                        receivers.Add(t);
                    }
                }
            }
            else
            {
                int count = PlayerHost.Server.NetworkObjects.transform.childCount;
                for (int i = 0; i < count; i++)
                {
                    Transform t = PlayerHost.Server.NetworkObjects.transform.GetChild(i);
                    if (t.name.Contains("player2ai"))
                    {
                        receivers.Add(t);
                    }
                }
            }

            MultiplayerAIController ai = receivers[randIndex].GetComponent <MultiplayerAIController>();
            sepakBall.CreateDestination(ai.transform.position);
            ai.IsKicker = true;
        }
    }
Beispiel #2
0
    public void FindKicker()
    {
        string kickerTerm = (SepakBall.Ball.CurrentDestination.transform.position.y < 0) ?
                            "player1" : "player2";

        Transform kicker       = null;
        float     tempDistance = 0f;

        foreach (Transform i in playersTransform)
        {
            if (i.name.Contains(kickerTerm))
            {
                float dist = Vector3.Distance(i.position, SepakBall.Ball.CurrentDestination.transform.position);


                if (kicker == null)
                {
                    kicker       = i;
                    tempDistance = dist;
                }
                else
                {
                    if (dist < tempDistance)
                    {
                        tempDistance = dist;
                        kicker       = i;
                    }
                }
            }
        }

        MultiplayerAIController ai = kicker.GetComponent <MultiplayerAIController>();

        if (ai != null)
        {
            ai.IsKicker = true;
        }
    }
Beispiel #3
0
    public void SetCanPlayersMove(bool canmove)
    {
        HostPlayerController p1 = BottomServer.GetComponent <HostPlayerController>();

        p1._canmove = canmove; p1.CancelInvoke();

        NetworkClientController p2 = TopServer.GetComponent <NetworkClientController>();

        p2._canmove = canmove; p2.CancelInvoke();

        foreach (Transform ai in playersTransform)
        {
            MultiplayerAIController aiPlayer = ai.GetComponent <MultiplayerAIController>();
            if (aiPlayer != null)
            {
                aiPlayer._canmove = canmove;

                if (!canmove)
                {
                    aiPlayer.IsKicker = false;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if(!string.IsNullOrWhiteSpace(PlayerHost.MultiplayerSession.P1Country) &&
           !string.IsNullOrWhiteSpace(PlayerHost.MultiplayerSession.P2Country))
        {
            // gameObject.SetActive(false);
            transform.parent.gameObject.SetActive(false);
            Debug.Log("both players ready");

            PlayerHost.MultiplayerSession.CountryPl = CountryModel.GetCountryByShortName(PlayerHost.MultiplayerSession.P1Country);
            PlayerHost.MultiplayerSession.CountryP2 = CountryModel.GetCountryByShortName(PlayerHost.MultiplayerSession.P2Country);

            RuntimeAnimatorController player1Controller = PlayerHost.MultiplayerSession.CountryPl.ControllerBottom1;
            RuntimeAnimatorController player2Controller = PlayerHost.MultiplayerSession.CountryP2.ControllerTop1;

            CountryModel p1country = PlayerHost.MultiplayerSession.CountryPl;
            CountryModel p2country = PlayerHost.MultiplayerSession.CountryP2;

            // server.NetworkObjects.transform.Find("player1").GetComponent<Animator>().runtimeAnimatorController = player1Controller;
            //server.NetworkObjects.transform.Find("player2").GetComponent<Animator>().runtimeAnimatorController = player2Controller;
            int count = server.NetworkObjects.transform.childCount;
            for(int i = 0; i < count; i++)
            {
                Transform t = server.NetworkObjects.transform.GetChild(i);

                Animator animator = t.GetComponent<Animator>(); 

                MultiplayerAIController ai = t.GetComponent<MultiplayerAIController>();

                HostPlayerController hplayer = t.GetComponent<HostPlayerController>();
                NetworkClientController cplayer = t.GetComponent<NetworkClientController>();


                if (t.name.Contains("player1"))
                {
                    animator.runtimeAnimatorController = player1Controller;
                    if (ai != null)
                    {
                        ai.SetSpeed(p1country.RawSpeed);
                        ai.SetPower(p1country.RawPower);
                        ai.SetInt(p1country.RawInt);
                    }else if(hplayer != null)
                    {
                        hplayer.SetSpeed(p1country.RawSpeed);
                        hplayer.SetPower(p1country.RawPower);
                        hplayer.SetInt(p1country.RawInt);
                    }

                }
                else if (t.name.Contains("player2"))
                {
                    animator.runtimeAnimatorController = player2Controller;
                    if (ai != null)
                    {
                        ai.SetSpeed(p2country.RawSpeed);
                        ai.SetPower(p2country.RawPower);
                        ai.SetInt(p2country.RawInt);
                    }
                    else if (cplayer != null)
                    {
                        cplayer.SetSpeed(p2country.RawSpeed);
                        cplayer.SetPower(p2country.RawPower);
                        cplayer.SetInt(p2country.RawInt);
                    }

                }
            }

            //server.NetworkObjects.SetActive(true);

            server.MultiplayerUIScript.ShowModal("Loading...");
            server.Send("HOSTACTION|PICKINGSDONE%" + PlayerHost.MultiplayerSession.P1Country + "%" + PlayerHost.MultiplayerSession.P2Country
                , true);

            ScoreboardUI.Scoreboard.SetPlayer1Name("Player 1" + "(" + PlayerHost.MultiplayerSession.P1Country + ")");
            ScoreboardUI.Scoreboard.SetPlayer2Name("Player 2" + "(" + PlayerHost.MultiplayerSession.P2Country + ")");
        }
    }