コード例 #1
0
ファイル: Network.cs プロジェクト: webconfig/Ballz
        public void ConnectToServer(IPAddress hostname, int port, Action onSuccess = null, Action onFail = null)
        {
            if (StartupTask != null)
            {
                throw new Exception("Trying to connect to server while network is already trying to start something else");
            }

            if (Role != NetworkRole.None)
            {
                Disconnect();
            }

            Role      = NetworkRole.Client;
            GameState = NetworkGameState.Connecting;

            client = new Client(new IPEndPoint(hostname, port));

            client.Connected += (s, e) =>
            {
                GameState = NetworkGameState.InLobby;
                RaiseMessageEvent(NetworkMessage.MessageType.ConnectedToServer);
                onSuccess?.Invoke();
            };

            client.PlayerListChanged += (s, e) => { PlayerListChanged?.Invoke(s, e); };

            client.Start();
        }
コード例 #2
0
    // Bolt's version of the Unity's Start()
    public override void Attached()
    {
        BoltConsole.Write("Attached - NetworkGameState");
        //Check if there is already an instance of SoundManager
        if (instance == null)
        {
            //if not, set it to this.
            instance = this;
        }
        //If instance already exists:
        else if (instance != this)
        {
            //Destroy this, this enforces our singleton pattern so there can only be one instance of SoundManager.
            Destroy(gameObject);
        }

        DontDestroyOnLoad(this);

        if (entity.isOwner)
        {
            spellcasterList = new int[6];

            //state.SpellcasterList[0] = 0;
            //combatOrder = new int[6];
            state.BossMaxHealth = 30f;
            state.BossHealth    = 30f;

            state.TapSecondsAllowed = 8f;
            turnOrder = new List <int>();
        }
    }
コード例 #3
0
    // Start is called before the first frame update
    void Start()
    {
        //Check if there is already an instance of SoundManager
        if (instance == null)
        {
            //if not, set it to this.
            instance = this;
        }
        //If instance already exists:
        else if (instance != this)
        {
            //Destroy this, this enforces our singleton pattern so there can only be one instance of SoundManager.
            Destroy(gameObject);
            BoltConsole.Write("ItemBox copy destroyed");
        }


        gamestate       = GameObject.Find("GameState(Clone)").GetComponent <NetworkGameState>();
        localPlayer     = GameObject.FindGameObjectWithTag("LocalPlayer").GetComponent <Player>();
        itemForGrabsStr = gamestate.ItemForGrabs();
        if (itemForGrabsStr != null && !itemForGrabsStr.Equals(""))
        {
            textStatus.text = yesItemHere;
            itemObjNetwork  = ItemList.instance.GetItemFromName(itemForGrabsStr);
            itemSlotButton.onClick.AddListener(() => inventory.ShowThirdPartyItemInfo(itemObjNetwork));
            itemForGrabsImage.sprite  = itemObjNetwork.sprite;
            itemForGrabsImage.enabled = true;
        }
        else
        {
            textStatus.text = noItemHere;
        }
    }
コード例 #4
0
 // Closes all networking interfaces
 public void closeAllNetworking()
 {
     matchMaker.endMatchMaker();
     GameObject.Find("Network Manager").GetComponent <NetworkManager> ().StopHost();
     ourGamestate   = null;
     theirGamestate = null;
 }
コード例 #5
0
ファイル: Network.cs プロジェクト: webconfig/Ballz
 public void StartServer(FullGameInfo gameInfo)
 {
     if (Role != NetworkRole.None)
     {
         Disconnect();
     }
     Role      = NetworkRole.Server;
     GameState = NetworkGameState.InLobby;
     server    = new Server(gameInfo);
     server.PlayerListChanged += PlayerListChanged;
     server.Start();
 }
コード例 #6
0
ファイル: Network.cs プロジェクト: webconfig/Ballz
        public void StartNetworkGame(MatchSettings gameSettings, int localPlayerId)
        {
            if (Role == NetworkRole.Server)
            {
                server.StartNetworkGame(gameSettings);
            }
            else if (Role == NetworkRole.Client)
            {
                gameSettings.GameMode.InitializeSession(Ballz.The(), gameSettings);
                Ballz.The().Logic.StartGame(gameSettings, true, localPlayerId);
            }

            GameState = NetworkGameState.InGame;
        }
コード例 #7
0
        private void SendGameState(NetworkGameState state)
        {
            bool hasState = state != null;

            if (state == null)
            {
                state = new NetworkGameState()
                {
                    pieces = new NetworkGameStatePiece[0],
                };
            }
            NetworkTracker.ClientSendLoadingGameState(new LoadingGameStateMessage()
            {
                hasState  = hasState,
                gameState = state,
            });
            gameStateRefresher.Active = true;
        }
コード例 #8
0
ファイル: Network.cs プロジェクト: webconfig/Ballz
        public void Disconnect()
        {
            if (client != null)
            {
                client.Stop();
                client.PlayerListChanged -= PlayerListChanged;
                client = null;
            }

            if (server != null)
            {
                server.Stop();
                server.PlayerListChanged -= PlayerListChanged;
                server = null;
            }

            Role      = NetworkRole.None;
            GameState = NetworkGameState.None;
            RaiseMessageEvent(NetworkMessage.MessageType.Disconnected);
        }