/// <summary>
    /// Callback used when the player successfully joins a room.
    /// </summary>
    public void OnJoinedRoom()
    {
        playersInRoom = new List <PhotonPlayer>(PhotonNetwork.playerList);
        myTeam        = (TeamTypes)((playersInRoom.Count + 1) % 2);


        ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
        properties.Add("Team", myTeam.GetHashCode());
        properties.Add("Character", myCharacter.GetHashCode());
        properties.Add("PlayFabID", PlayFabManager.instance.GetMyPlayerID());

        bool containsOwner = false;

        for (int i = 0; i < PhotonNetwork.otherPlayers.Length; i++)
        {
            object ownerName;
            if (PhotonNetwork.otherPlayers[i].customProperties.TryGetValue("Owner", out ownerName))
            {
                containsOwner = true;
                break;
            }
        }
        if (!containsOwner)
        {
            properties.Add("Owner", PhotonNetwork.player.name);
        }
        PhotonNetwork.player.SetCustomProperties(properties);

        myRoomInfo = PhotonNetwork.room;

        OnJoinedRoomCallback(PhotonNetwork.room);
    }
Esempio n. 2
0
    public void ChangeTeam(bool syncNetwork)
    {
        if (ready)
        {
            return;
        }

        Debug.Log("change team from " + selectedTeam);
        int newID = selectedTeam.GetHashCode();

        newID++;
        if (newID > TeamTypes.Orange.GetHashCode())
        {
            newID = 0;
        }

        TeamTypes newTeam = (TeamTypes)newID;

        if (teamsCount[newTeam.GetHashCode()] == PhotonNetwork.room.maxPlayers / 2)
        {
            return;
        }

        if (newTeam != selectedTeam)
        {
            selectedTeam = newTeam;
            this.RebuildAvatarTextures();

            MultiplayerRoomsManager.instance.ChangeTeam(selectedTeam, syncNetwork);
        }
    }
    /// <summary>
    /// Allocates a new ViewID from Photon, and sends message to instantiate a new character.
    /// </summary>
    /// <param name="myCharacter">Character prefab to use.</param>
    public void AllocateViewIDAndCallInstantiate(CharacterTypes myCharacter,TeamTypes team)
    {
        if (!enteredGame)
        {
            enteredGame = true;

            int myID = PhotonNetwork.AllocateViewID();

            view.RPC("InstantiateObject", PhotonTargets.AllBuffered, myID, myCharacter.GetHashCode(), team.GetHashCode(),PlayFabManager.instance.GetMyPlayerID(),PlayFabManager.instance.playerDisplayName);
        }
    }
    /// <summary>
    /// Rotates player between teams.
    /// </summary>
    public void ChangeTeam(TeamTypes newTeam, bool syncNetwork)
    {
        myTeam = newTeam;

        ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
        properties.Add("Team", myTeam.GetHashCode());
        PhotonNetwork.player.SetCustomProperties(properties);

        if (syncNetwork)
        {
            networkLayer.OnPropertiesChanged();
        }
    }
    /// <summary>
    /// Creates bullet buffer.
    /// </summary>
    public void CreateBuffer(TeamTypes myTeam)
    {
        unusedBullets = new Bullet[bufferSize];
        usedBullets = new Bullet[bufferSize];


        int playerPhotonID = this.GetComponent<PhotonView>().viewID;
        GameObject _obj;
        for (int i = 0; i < unusedBullets.Length; i++)
        {
            _obj = (GameObject)GameObject.Instantiate(bulletPrefabs[myTeam.GetHashCode()]);
            _obj.name = "Player" + playerPhotonID + "Bullet" + i;
            unusedBullets[i] = _obj.GetComponent<Bullet>();
            unusedBullets[i].Setup(this);
            _obj.SetActive(false);
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Creates bullet buffer.
    /// </summary>
    public void CreateBuffer(TeamTypes myTeam)
    {
        unusedBullets = new Bullet[bufferSize];
        usedBullets   = new Bullet[bufferSize];


        int        playerPhotonID = this.GetComponent <PhotonView>().viewID;
        GameObject _obj;

        for (int i = 0; i < unusedBullets.Length; i++)
        {
            _obj             = (GameObject)GameObject.Instantiate(bulletPrefabs[myTeam.GetHashCode()]);
            _obj.name        = "Player" + playerPhotonID + "Bullet" + i;
            unusedBullets[i] = _obj.GetComponent <Bullet>();
            unusedBullets[i].Setup(this);
            _obj.SetActive(false);
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Start method. Gets all references.
    /// </summary>
    public void StartPlayer(bool playerControlled, TeamTypes myTeam, string playerPlayFabID, string playFabName)
    {
        this.playerPlayFabID   = playerPlayFabID;
        this.myTeam            = myTeam;
        this.playerControlled  = playerControlled;
        this.playerPlayFabName = playFabName;

        myProperties     = this.GetComponent <PlayerProperties>();
        networkLayer     = this.GetComponent <PlayerNetworkLayer>();
        animationManager = this.GetComponent <PlayerAnimationManager>();
        shooterManager   = this.GetComponent <ShooterManager>();
        aiManager        = this.GetComponent <PlayerAIManager>();

        shooterManager.CreateBuffer(myTeam);

        myTower = GameController.instance.GetTower(myTeam);

        playerExp = playerLevel = 0;

        myProperties.Initialize();

        baseSprite.color = spriteTeamColors[myTeam.GetHashCode()];

        Debug.Log("initializing player. is human? " + playerControlled + " is local? " + networkLayer.isMine);
        if (networkLayer.isMine)
        {
            if (playerControlled)
            {
                Camera.main.transform.SetParent(this.transform, true);

                //levelText = GameController.instance.GetLevelText();
                expText = GameController.instance.GetExpText();

                GameplayUI.instance.Initialize(myTeam, this);
                GameplayUI.instance.UpdateSidebarStats(myProperties);

                InGameStoreAndCurrencyManager.instance.SetUpgradesCallbacks(new ProjectDelegates.OnPlayerBoughtStatUpgradeCallback[] {
                    myProperties.IncreaseAtk, myProperties.IncreaseMovSpd, myProperties.IncreaseHP
                });
            }

            this.transform.position = GameController.instance.GetRandomSpawnPoint(myTeam);
        }
    }
Esempio n. 8
0
 /// <summary>
 /// Event to be called when the game ends.
 /// </summary>
 /// <param name="winner">Winner team.</param>
 public void OnGameEnded(TeamTypes winner)
 {
     photonView.RPC("OnNetworkGameEnded", PhotonTargets.AllBuffered, winner.GetHashCode());
 }
Esempio n. 9
0
    void OnRoomPropertiesChanged(RoomInfo roomInfo)
    {
        this.ClearPortraits();

        this.CheckStartTimer();

        PhotonPlayer[] players = PhotonNetwork.playerList;

        if (!timerStarted)
        {
            gameTimerText.text = players.Length + "/" + PhotonNetwork.room.maxPlayers;
        }

        int readyCount = 0;

        for (int i = 0; i < players.Length; i++)
        {
            string         playerName  = players[i].name;
            TeamTypes      playerTeam  = (TeamTypes)int.Parse(players[i].customProperties["Team"].ToString());
            CharacterTypes playerChar  = (CharacterTypes)int.Parse(players[i].customProperties["Character"].ToString());
            bool           playerReady = System.Convert.ToBoolean(players[i].customProperties["Ready"]);

            bool isMe = players[i].name == AccountManager.instance.displayName;

            if (playerReady)
            {
                readyCount++;
            }

            if (isMe)
            {
                this.CheckMyPlayerProperties(playerName, playerTeam, playerChar);
            }

            int myTeamCount = teamsCount[playerTeam.GetHashCode()];

            if (playerTeam == TeamTypes.Blue)
            {
                //blueTeamNames[myTeamCount].text = playerName;
                if (playerChar == CharacterTypes.He)
                {
                    blueTeamPortraits[myTeamCount].sprite = hePortraits[playerTeam.GetHashCode()];
                }
                else
                {
                    blueTeamPortraits[myTeamCount].sprite = shePortraits[playerTeam.GetHashCode()];
                }

                if (isMe)
                {
                    blueTeamPortraitBorders[myTeamCount].color = Color.yellow;
                }
                else
                {
                    blueTeamPortraitBorders[myTeamCount].color = Color.white;
                }
            }
            else
            {
                //orangeTeamNames[myTeamCount].text = playerName;
                if (playerChar == CharacterTypes.He)
                {
                    orangeTeamPortraits[myTeamCount].sprite = hePortraits[playerTeam.GetHashCode()];
                }
                else
                {
                    orangeTeamPortraits[myTeamCount].sprite = shePortraits[playerTeam.GetHashCode()];
                }

                if (isMe)
                {
                    orangeTeamPortraitBorders[myTeamCount].color = Color.yellow;
                }
                else
                {
                    orangeTeamPortraitBorders[myTeamCount].color = Color.white;
                }
            }

            teamsCount[playerTeam.GetHashCode()]++;
        }

        playersReady = readyCount;

        if (playersReady == PhotonNetwork.room.playerCount)
        {
            timerCounter = 0;
            MultiplayerRoomsManager.instance.StartGame();
        }

        if (timerStarted && players.Length < PhotonNetwork.room.playerCount)
        {
            MultiplayerRoomsManager.instance.ResetTimer();
        }
    }
    /// <summary>
    /// Callback used when the player successfully joins a room.
    /// </summary>
    public void OnJoinedRoom()
    {
        playersInRoom = new List<PhotonPlayer>(PhotonNetwork.playerList);
        myTeam = (TeamTypes)((playersInRoom.Count + 1) % 2);


        ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
        properties.Add("Team", myTeam.GetHashCode());
        properties.Add("Character", myCharacter.GetHashCode());
        properties.Add("PlayFabID", PlayFabManager.instance.GetMyPlayerID());

        bool containsOwner = false;
        for (int i = 0; i < PhotonNetwork.otherPlayers.Length; i++)
        {
            object ownerName;
            if (PhotonNetwork.otherPlayers[i].customProperties.TryGetValue("Owner", out ownerName))
            {
                containsOwner = true;
                break;
            }
        }
        if (!containsOwner)
        {
            properties.Add("Owner", PhotonNetwork.player.name);
        }
        PhotonNetwork.player.SetCustomProperties(properties);

        myRoomInfo = PhotonNetwork.room;

        OnJoinedRoomCallback(PhotonNetwork.room);
    }
    /// <summary>
    /// Rotates player between teams.
    /// </summary>
    public void ChangeTeam(TeamTypes newTeam, bool syncNetwork)
    {
        myTeam = newTeam;

        ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
        properties.Add("Team", myTeam.GetHashCode());
        PhotonNetwork.player.SetCustomProperties(properties);

        if (syncNetwork)
        {
            networkLayer.OnPropertiesChanged();
        }
    }
Esempio n. 12
0
    /// <summary>
    /// Allocates a new ViewID from Photon, and sends message to instantiate a new character.
    /// </summary>
    /// <param name="myCharacter">Character prefab to use.</param>
    public void AllocateViewIDAndCallInstantiate(CharacterTypes myCharacter, TeamTypes team)
    {
        if (!enteredGame)
        {
            enteredGame = true;

            int myID = PhotonNetwork.AllocateViewID();

            view.RPC("InstantiateObject", PhotonTargets.AllBuffered, myID, myCharacter.GetHashCode(), team.GetHashCode(), PlayFabManager.instance.GetMyPlayerID(), PlayFabManager.instance.playerDisplayName);
        }
    }
    /// <summary>
    /// Event to be called when the game ends.
    /// </summary>
    /// <param name="winner">Winner team.</param>
	public void OnGameEnded (TeamTypes winner)
	{
		photonView.RPC("OnNetworkGameEnded", PhotonTargets.AllBuffered, winner.GetHashCode());
	}
    /// <summary>
    /// Start method. Gets all references.
    /// </summary>
    public void StartPlayer(bool playerControlled, TeamTypes myTeam, string playerPlayFabID, string playFabName)
    {
        this.playerPlayFabID = playerPlayFabID;
        this.myTeam = myTeam;
        this.playerControlled = playerControlled;
        this.playerPlayFabName = playFabName;

        myProperties = this.GetComponent<PlayerProperties>();
        networkLayer = this.GetComponent<PlayerNetworkLayer>();
        animationManager = this.GetComponent<PlayerAnimationManager>();
        shooterManager = this.GetComponent<ShooterManager>();
        aiManager = this.GetComponent<PlayerAIManager>();

        shooterManager.CreateBuffer(myTeam);

        myTower = GameController.instance.GetTower(myTeam);

        playerExp = playerLevel = 0;

        myProperties.Initialize();

        baseSprite.color = spriteTeamColors[myTeam.GetHashCode()];

        Debug.Log("initializing player. is human? " + playerControlled+" is local? "+networkLayer.isMine);
        if (networkLayer.isMine)
        {
            if (playerControlled)
            {
                Camera.main.transform.SetParent(this.transform, true);

                //levelText = GameController.instance.GetLevelText();
                expText = GameController.instance.GetExpText();

                GameplayUI.instance.Initialize(myTeam,this);
                GameplayUI.instance.UpdateSidebarStats(myProperties);

                InGameStoreAndCurrencyManager.instance.SetUpgradesCallbacks(new ProjectDelegates.OnPlayerBoughtStatUpgradeCallback[]{
                    myProperties.IncreaseAtk,myProperties.IncreaseMovSpd,myProperties.IncreaseHP
                });
            }

            this.transform.position = GameController.instance.GetRandomSpawnPoint(myTeam);
        }
    }