void SendGame_RPC(int randomGameSeed) { try { if (PhotonNetwork.isMasterClient && !gameCreated) { try { Debug.Log("More than two players. Building game."); //Here is where code should go to build personal Decks. For now we make a random deck (first 40 cards in database). //Both players will use the same deck for this test app. MainDeckBuilder mdb = new MainDeckBuilder(); List <Assets.Scripts.BattleHandler.Cards.Card> randomDeck = mdb.getRandomDeck(); Debug.Log("Loaded Random Decks."); //Initialize Card Back CardBackTexture = mdb.getCardBack() as Texture; Debug.Log("Loaded CardBack Texture."); //Build the players. gameSeed = randomGameSeed; GameObject p1Object = Instantiate((Resources.Load("Player") as UnityEngine.Object)) as GameObject; GameObject p2Object = Instantiate((Resources.Load("Player") as UnityEngine.Object)) as GameObject; p1 = Player.MakePlayer(p1Object, PhotonNetwork.masterClient.ID, PhotonNetwork.masterClient.name); foreach (PhotonPlayer p in PhotonNetwork.playerList) { if (p != PhotonNetwork.masterClient) { p2 = Player.MakePlayer(p2Object, p.ID, p.name); } } Debug.Log("Instantiated 2 players on the network and assigned their names/ids"); //Now the network manager gives a handle to the users and to the game. Debug.Log("Setting p1=" + p1.id + " p2=" + p2.id + " and game seed to " + gameSeed); g = new Game(p1, p2, gameSeed); g.RequestSetPlayer1Deck(randomDeck); g.RequestSetPlayer2Deck(randomDeck); g.setCurrentGame(); g.StartGame(); //PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "game", g } }); //GetComponent<PhotonView>().RPC("UpdateGame_RPC", PhotonTargets.All); Debug.Log("Instantiated a game on the network and started it."); gameCreated = true; } catch (Exception e) { Debug.Log("Failed to create game: " + e.Message); } } } catch (Exception e) { Debug.Log(e.Message); } }
void OnJoinedRoom() { Debug.Log("OnJoinedRoom"); SpawnMyPlayer(); connecting = false; if (PhotonNetwork.playerList.Length == 2) { try { Debug.Log("More than two players. Building game."); //Here is where code should go to build personal Decks. For now we make a random deck (first 40 cards in database). //Both players will use the same deck for this test app. MainDeckBuilder mdb = new MainDeckBuilder(); List <Assets.Scripts.BattleHandler.Cards.Card> randomDeck = mdb.getRandomDeck(); Debug.Log("Loaded Random Decks."); //Initialize Card Back CardBackTexture = mdb.getCardBack() as Texture; Debug.Log("Loaded CardBack Texture."); //Build the players. int randomGameId = rand.Next(); Debug.Log("Assigning gameId=" + randomGameId); GameObject p1Object = Instantiate((Resources.Load("Player") as UnityEngine.Object)) as GameObject; GameObject p2Object = Instantiate((Resources.Load("Player") as UnityEngine.Object)) as GameObject; p1 = Player.MakePlayer(p1Object, PhotonNetwork.masterClient.ID, PhotonNetwork.masterClient.name); foreach (PhotonPlayer p in PhotonNetwork.playerList) { if (p != PhotonNetwork.masterClient) { p2 = Player.MakePlayer(p2Object, p.ID, p.name); } } Debug.Log("Instantiated 2 players on the network and assigned their names/ids"); //Now the network manager gives a handle to the users and to the game. g = new Game(p1, p2, randomGameId); Debug.Log("Setting p1=" + p1.id + " p2=" + p2.id); g.RequestSetPlayer1Deck(randomDeck); g.RequestSetPlayer2Deck(randomDeck); g.setCurrentGame(); g.StartGame(); Debug.Log("Instantiated a game on the network and started it."); gameCreated = true; GetComponent <PhotonView>().RPC("SendGame_RPC", PhotonTargets.All, randomGameId); Debug.Log("Sent other client id the game seed=" + randomGameId); } catch (Exception e) { Debug.Log("Failed to create game: " + e.Message); } } }