Esempio n. 1
0
 public void DieRPC()
 {
     if (_killer != null)
     {
         ScoreExtensions.AddScore(_killer, ScoreCost);
     }
     PhotonNetwork.Destroy(gameObject);
 }
Esempio n. 2
0
 private IEnumerator UpdateScore()
 {
     while (true)
     {
         var list = new List <Photon.Realtime.Player>(PhotonNetwork.PlayerList);
         list.Sort((player1, player2) => ScoreExtensions.GetScore(player2).CompareTo(ScoreExtensions.GetScore(player1)));
         HudView?.UpdateBoard(list);
         yield return(new WaitForSeconds(0.5f));
     }
 }
Esempio n. 3
0
 public void OnGameEndRPC()
 {
     HudView.Close();
     EndGameView.EndGame(new List <Photon.Realtime.Player>(PhotonNetwork.PlayerList));
     ScoreExtensions.SetScore(PhotonNetwork.LocalPlayer, 0);
     if (PhotonNetwork.IsMasterClient)
     {
         Controller.Base.Health.DieEvent -= OnGameEnd;
         Controller.StopGame();
         PhotonNetwork.DestroyAll();
     }
 }
Esempio n. 4
0
    // on collision spawn the explode effect, kill the zombie, add score, and put the bullet back in the pool
    void OnCollisionEnter(Collision c)
    {
        Debug.Log("Collision");
        Vector3    e = transform.rotation.eulerAngles;
        GameObject t = (GameObject)Instantiate(explodeEffect, transform.position, Quaternion.Euler(new Vector3(e.x, e.y + 180, e.z)));

        t.GetComponent <ParticleSystem>().startColor = GetComponent <Renderer> ().material.color;
        if (c.gameObject.tag == "Zombie")
        {
            ScoreExtensions.AddScore(shooter, 1);
        }
        bp.Destroy(gameObject);
    }
Esempio n. 5
0
    // OnGUI show scores
    // Using OnGUI for this because it's far simpler for basic things like this
    // Who needs a canvas :^)


    void OnGUI()
    {
        int x = 50;
        int y = 20;

        GUILayout.BeginArea(new Rect(25, 25, 200, 30 * PhotonNetwork.playerList.Length), GUI.skin.box);
        foreach (PhotonPlayer p in PhotonNetwork.playerList)
        {
            GUILayout.Label(p.name + ": " + ScoreExtensions.GetScore(p), GUILayout.Height(30));
            y += 50;
        }
        GUILayout.EndArea();
    }
Esempio n. 6
0
        public void UpdateBoard(List <Photon.Realtime.Player> newPlayerList)
        {
            int i;

            for (i = 0; i < PlayerInfos.Capacity && i < newPlayerList.Capacity; i++)
            {
                PlayerInfos[i].Name  = newPlayerList[i].NickName;
                PlayerInfos[i].Score = ScoreExtensions.GetScore(newPlayerList[i]);
                PlayerInfos[i].UpdateView();
            }
            while (i <= 3)
            {
                PlayerInfos[i].Name  = "";
                PlayerInfos[i].Score = -1;
                PlayerInfos[i].UpdateView();
                i++;
            }
        }
Esempio n. 7
0
    //To save the stats before leaving
    public void saveStats()
    {
        //We get our player
        PhotonView   myView   = PhotonView.Get(transform.parent.gameObject);
        PhotonPlayer myPlayer = myView.owner;

        //We get ou score
        int myKills  = ScoreExtensions.GetScore(myPlayer);
        int myDeaths = DeathExtensions.GetDeath(myPlayer);

        Debug.Log("Got stats= K: " + myKills + " D: " + myDeaths);

        //We get the old values
        int totalKills  = PlayerPrefs.GetInt("totalKills");
        int totalDeaths = PlayerPrefs.GetInt("totalDeaths");

        //We add the score
        totalKills  += myKills;
        totalDeaths += myDeaths;

        //We set the new values
        PlayerPrefs.SetInt("totalKills", totalKills);
        PlayerPrefs.SetInt("totalDeaths", totalDeaths);
    }
    /*---------------------------- UPDATE ----------------------------*/

    // Update is called once per frame
    void Update()
    {
        PhotonView photonView = PhotonView.Get(this);

        /*------------------------- VERIFYING SYNCHRONIZATION -------------*/
        //We check if we have the scores of everyone

        /*if(!isUpdated) //We're not updated
         * {
         *      if(updateCounter >= 2.0f)
         *      {
         *              int myID = photonView.owner.ID;
         *
         *              photonView.RPC("updateMe", PhotonTargets.MasterClient, null);
         *              updateCounter = 0f;
         *              Debug.Log("Requesting update");
         *      }
         *      else
         *      {
         *              updateCounter += Time.deltaTime;
         *      }
         * }
         *
         * /*----------------------------- WE UPDATE THE PLAYERS REGULARLY -----------*/
        if (PhotonNetwork.isMasterClient)
        {
            /*if(updateTimer >= 2.0f)
             * {
             *      string theTeamScores = blueScore + ";" + redScore;
             *      photonView.RPC("updateTeamScores", PhotonTargets.Others, theTeamScores);
             *      updateTimer = 0f;
             * }
             * else
             * {
             *      updateTimer += Time.deltaTime;
             * }*/

            if (pingUpdate >= 5.0f)
            {
                pingFunction();
                pingUpdate = 0f;
            }
            else
            {
                pingUpdate += Time.deltaTime;
            }
            pingTimer += Time.deltaTime;
        }

        /*--------------------------------------------------------------------*/

        //When our playerCreator is created we add ourself on the scoreboards
        playerSpawn playSpawn = GetComponent <playerSpawn>();


        //Managing the kills

        //We update the last shot each frame
        foreach (Transform child in transform)
        {
            if (child.name != "globalHUD" && child.name != "scoreBoardUI" && child.name != "InGameMenu" && child.name != "littleScoreBoardUI" && child.name != "PlayerHUD")
            {
                playerNetwork playSet = child.GetComponent <playerNetwork>();
                myLastShot = playSet.lastShot;
            }
        }

        //If we're killed we add the kill and update the score
        if (wasKilled)
        {
            PhotonPlayer    killer            = PhotonPlayer.Find(myLastShot);
            PunPlayerScores playerScoreScript = GetComponent <PunPlayerScores>();
            ScoreExtensions.AddScore(killer, 1);

            int myID = photonView.owner.ID;
            //photonView.RPC("addKill", killer, null);
            //photonView.RPC("addKill", PhotonTargets.All, myLastShot);

            if (myTeam == "Blue")
            {
                //photonView.RPC("addRedKill", PhotonTargets.All, myLastShot);
                //photonView.RPC("addRedKill", PhotonTargets.All, null);
                TeamExtensions.AddTeamScore("Red");
                //photonView.RPC("addBlueDeath", PhotonTargets.All, myID);
            }
            else
            {
                //photonView.RPC("addBlueKill", PhotonTargets.All, myLastShot);
                //photonView.RPC("addBlueKill", PhotonTargets.All, null);
                TeamExtensions.AddTeamScore("Blue");
                //photonView.RPC("addRedDeath", PhotonTargets.All, myID);
            }

            PhotonPlayer myPlayer = PhotonPlayer.Find(myID);
            //addDeath();
            DeathExtensions.AddDeath(myPlayer, 1);

            //KILLFEED
            TeamExtensions.AddKillFeed(myLastShot, myID);
            wasKilled = false;
        }

        /*--------------------------- SCOREBOARD ----------------------*/

        //We get the scoreboard object
        Transform scoreB = transform.Find("scoreBoardUI");

        //Drawing the score
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            drawTheScore = true;
        }
        if (Input.GetKeyUp(KeyCode.Tab))
        {
            drawTheScore = false;
        }

        if (photonView.isMine)
        {
            if (drawTheScore || isMatchEnded)            //If the player press tab we activate the board
            {
                scoreB.gameObject.active = true;
            }
            else
            {
                scoreB.gameObject.active = false;
            }
        }
        else
        {
            scoreB.gameObject.active = false;
        }

        /*------------------------------ TIMER ------------------------*/

        //At the end of the match the masterclient stops it
        if (matchTimer <= 0f)
        {
            if (PhotonNetwork.isMasterClient)
            {
                photonView.RPC("stopMatch", PhotonTargets.All, null);
            }
        }
        else
        {
            matchTimer -= Time.deltaTime;

            //if(PhotonNetwork.isMasterClient)
            //updateMatchTimer();
        }
    }
    // Update is called once per frame
    void Update()
    {
        //Increment
        int i = 0;       //For each player
        int j = 0;       //For each button

        foreach (PhotonPlayer pl in PhotonNetwork.playerList)
        {
            string playerTeam = TeamExtensions.getStringTeam(pl);

            //If the team of the player is the one of the panel
            if (playerTeam == panelTeam)
            {
                string scoreButton;
                if (panelTeam == "Blue")
                {
                    scoreButton = "blueNo" + (j + 1).ToString();
                }
                else
                {
                    scoreButton = "redNo" + (j + 1).ToString();
                }

                Transform child = transform.Find(scoreButton);
                child.gameObject.active = true;                 //We activate the button

                //We get the child text of the button
                Transform playerText = child.transform.GetChild(0);
                displayScore = playerText.gameObject.GetComponent <Text>();

                int playScore = ScoreExtensions.GetScore(pl);
                int playDeath = DeathExtensions.GetDeath(pl);
                displayScore.text = "(" + pl.ID + ") " + pl.name + " | " + playScore + " | " + playDeath;

                //BUTTONS COLORS

                //Host color
                ColorBlock hostColor = ColorBlock.defaultColorBlock;
                hostColor.normalColor      = new Color(0, 0.6f, 0.2f, 1);
                hostColor.highlightedColor = new Color(0, 0.7f, 0.25f, 1);
                hostColor.pressedColor     = new Color(0, 0.5f, 0.15f, 1);

                //Player color
                ColorBlock myColor = ColorBlock.defaultColorBlock;
                myColor.normalColor      = new Color(0, 0.2f, 0.6f, 1);
                myColor.highlightedColor = new Color(0, 0.25f, 0.7f, 1);
                myColor.pressedColor     = new Color(0, 0.15f, 0.5f, 1);

                ColorBlock defColor = ColorBlock.defaultColorBlock;
                defColor.normalColor      = new Color(0.3f, 0.3f, 0.3f, 1);
                defColor.highlightedColor = new Color(0.4f, 0.4f, 0.4f, 1);
                defColor.pressedColor     = new Color(0.2f, 0.2f, 0.2f, 1);

                if (pl.isLocal)
                {
                    child.GetComponent <Button>().colors = myColor;
                }
                else
                {
                    if (pl.isMasterClient)
                    {
                        child.GetComponent <Button>().colors = hostColor;
                    }
                    else
                    {
                        child.GetComponent <Button>().colors = defColor;
                    }
                }

                j++;
            }
            i++;
        }

        //We deactivate the useless buttons
        for (int n = j; n < 4; n++)
        {
            Transform disabledButton = transform.GetChild(n);

            //We deactivate the button
            disabledButton.gameObject.active = false;
        }



        //For each button we display the score if there's one

        /*while(i<4)
         * {
         *      if(panelTeam=="Blue")
         *      {
         *              if(scoreScript.playerScoreBlue[i,0]!=0) //If there's one player on this button
         *              {
         *                      Transform child = transform.GetChild(j);
         *                      child.gameObject.active = true; //We activate the button
         *
         *                      //We get the child text of the button
         *                      Transform playerText = child.transform.GetChild(0);
         *                      displayScore = playerText.gameObject.GetComponent<Text>();
         *
         *                      //We take the score to display
         *                      playerScore = scoreScript.playerTagsBlue[i] + " | " + scoreScript.playerScoreBlue[i,1].ToString() + " | " + scoreScript.playerScoreBlue[i,2].ToString() + " | " + scoreScript.playerScoreBlue[i,3].ToString();
         *                      displayScore.text = playerScore;
         *
         *                      j++;
         *              }
         *      }
         *      else
         *      {
         *              if(scoreScript.playerScoreRed[i,0]!=0) //If there's one player on this button
         *              {
         *                      Transform child = transform.GetChild(j);
         *                      child.gameObject.active = true; //We activate the button
         *
         *                      //We get the child text of the button
         *                      Transform playerText = child.transform.GetChild(0);
         *                      displayScore = playerText.gameObject.GetComponent<Text>();
         *
         *                      //We take the score to display
         *                      playerScore = scoreScript.playerTagsRed[i] + " | " + scoreScript.playerScoreRed[i,1].ToString() + " | " + scoreScript.playerScoreRed[i,2].ToString() + " | " + scoreScript.playerScoreRed[i,3].ToString();
         *                      displayScore.text = playerScore;
         *
         *                      j++;
         *              }
         *      }
         *      i++;
         * }*/
    }