public void OnClickNewMatch()
        {
            if (newMatchName.text == "")
            {
                return;
            }

            gameName = newMatchName.text;

            if (matchMaker == null)
            {
                StartMatchMaker();
            }

            JuloDebug.Log(string.Format("Creating game {0}", gameName));
            if (matchMaker != null)
            {
                matchMaker.CreateMatch(gameName, 16, true, "", "", "", 0, 0, OnInternetMatchCreate);
                creatingDisplay.SetActive(true);
            }
            else
            {
                Debug.LogWarning("No matchmaker");
            }
        }
Exemple #2
0
        // only client
        private IEnumerator HandleTurn()
        {
            // TODO select with unit has the turn
            //int unitNumber = 0;

            // TODO units should be cached in client?
            List <Unit> units = JuloFind.allWithComponent <Unit>();

            bool found = false;

            foreach (Unit unit in units)
            {
                if (unit.playerNetId == this.netId /* TODO && .unitNumber == unitNumber*/)
                {
                    currentUnit = unit;
                    found       = true;
                    break;
                }
            }

            if (found)
            {
                bool keepPlaying = true;

                while (keepPlaying)
                {
                    if (Input.GetKeyDown(KeyCode.Return))
                    {
                        keepPlaying = false;
                    }
                    else if (Input.GetKey("left"))
                    {
                        Vector3 pos = currentUnit.transform.position;
                        currentUnit.transform.position = new Vector3(pos.x - moveSpeed * Time.deltaTime, pos.y, pos.z);
                    }
                    else if (Input.GetKey("right"))
                    {
                        Vector3 pos = currentUnit.transform.position;
                        currentUnit.transform.position = new Vector3(pos.x + moveSpeed * Time.deltaTime, pos.y, pos.z);
                    }

                    yield return(null);
                }
            }
            else
            {
                JuloDebug.Log("Unit not found");
                yield return(new WaitForSeconds(1.5f));
            }

            //JuloDebug.Log("Turn is over");

            CmdEndTurn();

            yield return(null);
        }
 public void OnClickBack()
 {
     if (backDelegate != null)
     {
         backDelegate();
         backDelegate = null; // TODO right ?
     }
     else
     {
         JuloDebug.Warn("No back callback");
     }
 }
Exemple #4
0
        public override void OnClientSceneChanged(NetworkConnection connectionToServer)
        {
            //JuloDebug.Log("On client scene changed");
            //base.OnClientSceneChanged(conn);

            if (ClientScene.ready)
            {
                JuloDebug.Warn("Is already ready");
            }
            else
            {
                ClientScene.Ready(connectionToServer);
            }
        }
        protected override DualGamePlayer CreatePlayer(int connectionId, short playerControllerId)
        {
            bool           isLocal = (connectionId == 0);
            DualGamePlayer player  = null;

            if (isLocal)
            {
                JuloDebug.Err("Should not be called for hosted players");
            }
            else
            {
                player = NewPlayer(remotePlayerModel);
            }

            return(player);
        }
Exemple #6
0
        // called on server when a client requests to add a player for it
        // TODO should receive a message with initial name/color
        public override void OnServerAddPlayer(NetworkConnection connectionToClient, short playerControllerId, NetworkReader extraMessage)
        {
            string playerName = "Guest";

            if (extraMessage != null)
            {
                var s = extraMessage.ReadMessage <NewPlayerMessage>();
                playerName = s.playerName;
            }
            else
            {
                Debug.LogWarning("Mo message");
            }

            if (state != DNMState.Host)
            {
                Debug.LogErrorFormat("Invalid state: {0}", state);
                return;
            }

            DualGamePlayer newPlayer = null;

            bool isLocal = (connectionToClient.connectionId == 0);

            if (isLocal)
            { // if the player is local it should be cached
                if (gameState != GameState.NoGame)
                {
                    Debug.LogErrorFormat("Invalid state: {0}", gameState);
                }
                else if (playerControllerId < cachedLocalPlayers.Count)
                {
                    newPlayer = cachedLocalPlayers[playerControllerId];
                }
                else
                {
                    JuloDebug.Err("Player " + playerControllerId + " should be cached");
                    //return;
                }
            }
            else
            { // if is remote should be created
                if (connectionToClient.playerControllers.Count > 0)
                {
                    Debug.LogWarning("Already a player for that connection");
                    return;
                }

                bool isPlaying = gameState != GameState.NoGame;

                newPlayer            = CreatePlayer(connectionToClient.connectionId, playerControllerId);
                newPlayer.playerName = playerName;

                int newRole = -1;

                if (isPlaying || joinAsSpectator)
                {
                    // join as spectator
                    newRole = maximumSpectatorRole + 1;
                }
                else
                {
                    // try to join as player
                    bool assigned = false;

                    // try to enter as player
                    for (int i = 0; !assigned && i < currentMaxPlayers; i++)
                    {
                        if (!playerMap.ContainsKey(i))
                        {
                            newRole  = i;
                            assigned = true;
                        }
                    }

                    if (!assigned)
                    {
                        newRole = maximumSpectatorRole + 1;
                    }
                }

                maximumSpectatorRole = Math.Max(maximumSpectatorRole, newRole);

                newPlayer.role = newRole;
            }

            if (newPlayer != null)
            {
                PlayerWrapper wrapper = new PlayerWrapper(connectionToClient.connectionId, playerControllerId, newPlayer);

                //Debug.LogFormat("ADDING {0}: {1}-{2}", newRole, connectionToClient.connectionId, playerControllerId);
                playerMap.Add(newPlayer.role, wrapper);

                newPlayer.gameObject.SetActive(true);
                NetworkServer.AddPlayerForConnection(connectionToClient, newPlayer.gameObject, playerControllerId);
            }
            else
            {
                JuloDebug.Warn("Player could not be added: " + connectionToClient.connectionId + ":" + playerControllerId);
            }
        }