public void FallIntoHole(HolePoint point)
    {
        if (IsFalling || IsBallDead)
        {
            return;
        }

        holePosition       = point.gameObject.transform.position;
        IsFalling          = true;
        HoleFallInTimeLeft = HoleFallInTime;

        if (!point.IsHostHole)
        {
            SocketClientBase.GetInstance().C2A_GameResult(SocketClientBase.GetInstance().HostClientObjectID.Value);
        }
        else
        {
            if (SocketClientBase.GetInstance().GuestClientObjectID.HasValue)
            {
                SocketClientBase.GetInstance().C2A_GameResult(SocketClientBase.GetInstance().GuestClientObjectID.Value);
            }
            else
            {
                SocketClientBase.GetInstance().C2A_GameResult(1);
            }
        }
    }
    IEnumerator ManualRegisterClientIenumerator()
    {
        selfReady = false;
        var client = SocketClientBase.GetInstance();

        Debug.Log("ManualRegisterClientIenumerator as Client ");

        client.ConnectToServer(GetInputingIp());

        while (client.Client == null && !client.Client.Connected)
        {
            yield return(null);
        }

        yield return(new WaitForSeconds(0.1f));

        Debug.Log("ManualRegisterClientIenumerator Client.Connected ");

        SocketClientBase.GetInstance().C2A_RegisterAsClient();

        while (!SocketClientBase.GetInstance().SelfClientObjectID.HasValue)
        {
            yield return(null);
        }

        Debug.Log("Got ObjectID " + SocketClientBase.GetInstance().SelfClientObjectID + " As Client");
        waitForRegisterCoroutine = null;
        selfReady = true;
    }
Beispiel #3
0
    public void SetLineDead()
    {
        IsDead = true;

        if (isLocal)
        {
            SocketClientBase.GetInstance().C2A_UpdateLine(SocketClientBase.GetInstance().SelfClientObjectID.Value, this, false);
            FieldManager.GetInstance().RemoveLine(this);
        }
    }
Beispiel #4
0
    public void OnClickStartGameInReady()
    {
        if (!SocketClientBase.IsGameHost || !SocketClientBase.GetInstance().HostClientObjectID.HasValue || !SocketClientBase.GetInstance().GuestClientObjectID.HasValue)
        {
            if (!soloMode)
            {
                return;
            }
        }

        SocketClientBase.GetInstance().C2A_RequestStartGame();
    }
Beispiel #5
0
    public void OnClickStopServerInReady()
    {
        GameServer.GetInstance().StopServer();
        SocketClientBase.GetInstance().StopClient();
        FieldManager.GetInstance().UpdateGameState(GameState.Title);
        SocketClientBase.IsGameHost = false;

        if (waitForRegisterCoroutine != null)
        {
            StopCoroutine(waitForRegisterCoroutine);
        }
        waitForRegisterCoroutine = null;
    }
Beispiel #6
0
        private SocketClientBase GetSelectedClient()
        {
            SocketClientBase socketClient = null;
            var selectedRows = gridConnectedClients.SelectedRows;

            if (selectedRows.Count > 0)
            {
                var selectedRow = selectedRows[0];
                if (selectedRow.Cells.Count == 2 && selectedRow.Cells[0].Value != null && selectedRow.Cells[1].Value != null)
                {
                    var address  = (IPAddress)selectedRow.Cells[0].Value;
                    var port     = (Int32)selectedRow.Cells[1].Value;
                    var endPoint = new IPEndPoint(address, port);
                    socketClient = (SocketClientBase)_socketServer.FindClient(endPoint);
                }
            }
            return(socketClient);
        }
Beispiel #7
0
    public void SetupAsGoal()
    {
        ipConfigInfoRootObj.SetActive(false);
        titleRootObj.SetActive(false);
        readyRootObj.SetActive(false);
        playRootObj.SetActive(false);
        goalRootObj.SetActive(true);
        restartButtonObj.SetActive(SocketClientBase.IsGameHost);

        if (SocketClientBase.GetInstance().WinObjectID.Value == SocketClientBase.GetInstance().SelfClientObjectID.Value)
        {
            winLabel.text = "あなたの勝だよ!";
        }
        else
        {
            winLabel.text = "相手の勝だよ!";
        }
    }
    IEnumerator PowerUpEnumerator()
    {
        var headTime  = powerUpHeadTime;
        var beforePos = gameObject.transform.position;

        while (headTime > 0)
        {
            headTime -= Time.unscaledDeltaTime;
            yield return(null);
        }

        var currentPos = gameObject.transform.position;
        var dir        = currentPos - beforePos;

        dir.z = 0;
        dir  *= powerUpForcePower;

        SocketClientBase.GetInstance().C2A_AddForceToBall(SocketClientBase.GetInstance().SelfClientObjectID.Value, dir, currentPos, ballRigidbody.velocity);
        ballRigidbody.AddForce(dir, ForceMode.Impulse);
    }
    IEnumerator AutoRegisterHostIenumerator()
    {
        selfReady = false;
        var client = SocketClientBase.GetInstance();

        Debug.Log("AutoRegisterHostIenumerator as Host ");


        while (!GameServer.IsServerStarted())
        {
            yield return(null);
        }

        Debug.Log("AutoRegisterHostIenumerator IsServerStarted ");
        yield return(new WaitForSeconds(0.1f));


        client.ConnectToServer(ipLabel.text);

        while (client.Client == null && !client.Client.Connected)
        {
            yield return(null);
        }

        Debug.Log("AutoRegisterHostIenumerator Client.Connected ");
        yield return(new WaitForSeconds(0.1f));


        SocketClientBase.GetInstance().C2A_RegisterAsHost();


        while (!SocketClientBase.GetInstance().SelfClientObjectID.HasValue)
        {
            yield return(null);
        }

        Debug.Log("Got ObjectID " + SocketClientBase.GetInstance().SelfClientObjectID + " As Host");

        waitForRegisterCoroutine = null;
        selfReady = true;
    }
Beispiel #10
0
 private void ButtonConnectClick(object sender, EventArgs e)
 {
     try
     {
         _socketClient                 = cmbUseSSL.SelectedIndex == 0 ? (SocketClientBase) new SocketClientSsl() : (SocketClientBase) new SocketClient();
         _socketClient.Context         = WindowsFormsSynchronizationContext.Current;
         _socketClient.Connected      += SocketClientConnected;
         _socketClient.SentData       += SocketClientSentData;
         _socketClient.ReceivedData   += SocketClientReceivedData;
         _socketClient.Disconnected   += SocketClientDisconnected;
         _socketClient.SocketError    += SocketClientSocketError;
         _socketClient.Error          += SocketClientError;
         _socketClient.SocketSecurity += SocketSecurityEventRaised;
         Int32 port;
         if (!Int32.TryParse(txtRemotePort.Text, out port))
         {
             throw new Exception("Remote port number is wrong.");
         }
         var address = txtRemoteAddress.Text;
         if (cmbUseSSL.SelectedIndex == 0)
         {
             ((SocketClientSsl)_socketClient).RemoteHostName                = txtTargetHostName.Text;
             ((SocketClientSsl)_socketClient).SslProtocol                   = (SslProtocols)Enum.Parse(typeof(SslProtocols), cmbSSLProtocol.Text);
             ((SocketClientSsl)_socketClient).CheckCertificateRevocation    = cmbCertificateRevocation.SelectedIndex == 0;
             ((SocketClientSsl)_socketClient).CertificateValidationCallback = CertificateErrorsCallback;
             if (cmbUseCertificate.SelectedIndex == 0)
             {
                 var certificate = String.IsNullOrEmpty(txtCertificatePassword.Text) ? new X509Certificate2(txtCertificateFile.Text) : new X509Certificate2(txtCertificateFile.Text, txtCertificatePassword.Text);
                 ((SocketClientSsl)_socketClient).ClientCertificates.Add(certificate);
             }
         }
         _socketClient.ConnectAsync(address, port);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         EnableDisableButtonControls(true);
     }
 }
    void UpdateReady()
    {
        if (SocketClientBase.IsGameHost && !SocketClientBase.GetInstance().SelfClientObjectID.HasValue&& waitForRegisterCoroutine == null)
        {
            waitForRegisterCoroutine = StartCoroutine(AutoRegisterHostIenumerator());
        }

        if (SocketClientBase.IsGameHost)
        {
            if (selfReady)
            {
                gameStartButtonLabel.text = SocketClientBase.GetInstance().GuestClientObjectID.HasValue ? "Start" : "WaitForPlayers";
            }
            else
            {
                gameStartButtonLabel.text = "CreatingServer";
            }
        }
        else
        {
            gameStartButtonLabel.text = SocketClientBase.GetInstance().HostClientObjectID.HasValue ? "Connected" : "FindingServer";
        }
    }
Beispiel #12
0
 public int GetNextSelfLineId()
 {
     selfLineIDIndex++;
     return(SocketClientBase.GetInstance().SelfClientObjectID.Value * 100000 + selfLineIDIndex);
 }
Beispiel #13
0
 // if (!GameServer.IsServerStarted())
 // {
 //     Debug.Log("There is no server running");
 //     return;
 // }
 //serverIp = GameServer.localServerIp;
 public void InitializeGameClient()
 {
     _instance = this;
 }
    void UpdateInteractive()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var selectObj = CheckIsHoveringLine();

            // create new
            if (selectObj == null)
            {
                if (LineLeft > 0)
                {
                    startPoint = GetMouseCameraPoint();
                    var endPoint = startPoint + Vector3.up * 0.01f;

                    var line = Instantiate(linePrefab);
                    creatingLine = line.GetComponent <LineController>();
                    UpdateLineObj(creatingLine, startPoint, endPoint);
                    selfLineList.Add(creatingLine);
                    DecreaseLineCount();
                }

                isChargeMode = false;
            }
            // selectOne
            else
            {
                selectedLine = selectObj.GetComponent <LineController>();

                // 万が一
                if (selectedLine == null)
                {
                    Destroy(selectObj);
                    return;
                }

                isChargeMode = true;
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (creatingLine != null)
            {
                LineLenghtLeft -= creatingLine.length;
                SocketClientBase.GetInstance().C2A_UpdateLine(SocketClientBase.GetInstance().SelfClientObjectID.Value, creatingLine, true);
                creatingLine = null;
            }

            if (selectedLine != null)
            {
                selectedLine = null;
            }

            isChargeMode           = false;
            nextChargePointIsStart = false;
        }
        else if (Input.GetMouseButtonDown(1))
        {
            prevMosePosition = Input.mousePosition;
            targetCameraPos  = targetCamera.transform.position;
        }
        else if (Input.GetMouseButton(1))
        {
            var currentPos = Input.mousePosition;

            var offSet = currentPos - prevMosePosition;
            offSet.z = 0;

            if (offSet.sqrMagnitude > float.Epsilon)
            {
                offSet.x = -offSet.x;
                offSet.y = -offSet.y;

                Debug.Log(offSet);
                targetCameraPos += offSet * cameraMoveSpeed * Time.deltaTime;

                if (targetCameraPos.x > 50)
                {
                    targetCameraPos.x = 50;
                }
                else if (targetCameraPos.x < -50)
                {
                    targetCameraPos.x = -50;
                }

                if (targetCameraPos.y > 30)
                {
                    targetCameraPos.y = 30;
                }
                else if (targetCameraPos.y < -30)
                {
                    targetCameraPos.y = -30;
                }
            }

            targetCameraPos.z = -cameraDepth;

            prevMosePosition = currentPos;
        }
        else
        {
            if (isChargeMode)
            {
                if (selectedLine == null || selectedLine.IsDead)
                {
                    isChargeMode = false;
                    return;
                }

                var endPoint = GetMouseCameraPoint();

                if (nextChargePointIsStart)
                {
                    if (selectedLine.CheckPointRange(endPoint, true))
                    {
                        nextChargePointIsStart = false;
                        selectedLine.PowerUpOneRound();
                    }
                }
                else
                {
                    if (selectedLine.CheckPointRange(endPoint, false))
                    {
                        nextChargePointIsStart = true;
                        selectedLine.PowerUpOneRound();
                    }
                }
            }
            else
            {
                if (creatingLine == null || creatingLine.IsDead)
                {
                    return;
                }

                var endPoint = GetMouseCameraPoint();
                creatingLine.Setup(startPoint, endPoint, GetNextSelfLineId(), true);
                UpdateLineObj(creatingLine, startPoint, endPoint);
            }
        }
    }