コード例 #1
0
    public void ActivateLogin()
    {
        ConnectionChecker connChecker = MainGameHandler.GetConnectionChecker();

        if (connChecker == null)
        {
            MainGameHandler.ShowMessageBox("Login button handler - ActivateLogin() - no reference to connection checker!", "Critical error", null);
            return;
        }

        ConnectionChecker.LoginState loginState = connChecker.ClientLoginState;
        if (loginState == ConnectionChecker.LoginState.WaitingForResponse)
        {
            return;
        }

        string login = _loginInputField.text;
        string pass  = _passInputField.text;

        if (String.IsNullOrWhiteSpace(login))
        {
            MainGameHandler.ShowMessageBox("Your login cannot be empty!");
            return;
        }

        connChecker.SetLoginState(ConnectionChecker.LoginState.WaitingForResponse);
        CommandHandler.Send(new LoginRequestCmdBuilder(login, pass));
    }
コード例 #2
0
        private async void ExecuteAsync()
        {
            await Task.Factory.StartNew(() => Thread.Sleep(500));

            CommandHandler.Send(new LogoutCmdBuilder());
            MainGameHandler.CloseApplication();
        }
コード例 #3
0
        public void SetLoginState(LoginState state)
        {
            this.ClientLoginState = state;

            switch (state)
            {
            case LoginState.NotLoggedInOrLoginFailed:
            {
                _loginAttemptCount++;

                Action closeAppAction = null;
                if (_loginAttemptCount >= 3)
                {
                    closeAppAction = () => { MainGameHandler.CloseApplication(); }
                }
                ;

                MainGameHandler.ShowMessageBox($"Failed to log in ({_loginAttemptCount}/3)", "Login failed", closeAppAction);
            }
            break;

            case LoginState.Logged:
            {
                _loginAttemptCount = 0;
                Action changeSceneAction = () => { MainGameHandler.ChangeScene(MainGameHandler.SceneType.CharLobby); };
                MainGameHandler.ShowMessageBox($"You have successfully logged in!", "Login success", changeSceneAction);
            }
            break;

            case LoginState.WaitingForResponse:
                //Debug.Log("Login - waiting for response");
                break;
            }
        }
コード例 #4
0
    private static void RemoveCharacter(int charId)
    {
        _instance._gameStateDetails.RemoveLocalCharacterDetails(charId);

        LocalCharacterHandler charHandler;
        LocalCharacterDetails details;

        try
        {
            GameObject localCharObject;

            for (int i = 0; i < _instance._localCharacterObjectList.Count; i++)
            {
                localCharObject = _instance._localCharacterObjectList[i];
                charHandler     = localCharObject.GetComponent <LocalCharacterHandler>();
                details         = charHandler.GetDetails();

                if (details.CharId == charId)
                {
                    Destroy(localCharObject);
                    _instance._localCharacterObjectList.RemoveAt(i);
                    break;
                }
            }
        }
        catch (Exception exception)
        {
            MainGameHandler.GetChatHandler().UpdateLog($"Local place manager - RemoveCharacter() - error: {exception.Message}");
        }
    }
コード例 #5
0
        public bool Execute()
        {
            bool executed = false;

            try
            {
                if (_cmdElements.Length != 2)
                {
                    throw new Exception($"wrong count of elements [{_cmdElements.Length}]");
                }

                bool show = false;

                if (_cmdElements[1].Equals("true", StringComparison.InvariantCultureIgnoreCase))
                {
                    show = true;
                }
                else
                if (_cmdElements[1].Equals("false", StringComparison.InvariantCultureIgnoreCase))
                {
                    show = false;
                }
                else
                {
                    throw new Exception($"incorrect command element [{_cmdElements[1]}]. Must be 'true' or 'false'!");
                }

                if (!MainGameHandler.CheckIfSceneActive(MainGameHandler.SceneType.LocalPlace, MainGameHandler.CurrentScene))
                {
                    throw new Exception("local place scene is not active!");
                }

                GameObject[] gameObjects = MainGameHandler.CurrentScene.GetRootGameObjects();
                LocalPlaceSceneManagerHandler handler = null;

                foreach (GameObject obj in gameObjects)
                {
                    if (obj.name.Equals("LocalPlaceSceneManager", StringComparison.InvariantCultureIgnoreCase))
                    {
                        handler = obj.GetComponent <LocalPlaceSceneManagerHandler>();
                        break;
                    }
                }

                if (handler == null)
                {
                    throw new Exception("cannot find scene manager handler!");
                }

                handler.ShowServerCollisionBoxes(show);
                executed = true;
            }
            catch (Exception exception)
            {
                _chat.UpdateLog($"Cannot execute command [{_keyWord}]: {exception.Message}");
            }

            return(executed);
        }
コード例 #6
0
 void OnSceneLoaded(Scene scene, LoadSceneMode mode)
 {
     if (MainGameHandler.CheckIfSceneActive(MainGameHandler.SceneType.Startup, scene))
     {
         _timer   = 0f;
         _enabled = true;
     }
 }
コード例 #7
0
 //on collision
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.name.Equals("Terrain"))
     {
         MainGameHandler.CreateCreature(MainGameHandler.CreatureType.Plant, transform.position - new Vector3(0, 5, 0));
         Destroy(gameObject);
     }
 }
コード例 #8
0
    private void LoadCharacterList()
    {
        LobbyCharactersHandler lobbyCharHandler = MainGameHandler.GetLobbyCharactersHandler();

        lobbyCharHandler.ListConfirmed = false;
        lobbyCharHandler.Clear();
        CommandHandler.Send(new GetAccountCharsCmdBuilder()); //sends request to the server
    }
コード例 #9
0
 void Start()
 {
     MainGameHandler.RegisterSceneManager(this);
     _instance         = this;
     _chat             = MainGameHandler.GetChatHandler();
     _gameStateDetails = MainGameHandler.GetGameStateDetails();
     WaitForServerDataAndLoadScene();
 }
コード例 #10
0
        public static void Unlock(bool unlock)
        {
            if (_lastInstance == null)
            {
                MainGameHandler.GetChatHandler().UpdateLog("Connection checker - Unlock() - checker instance is NULL!");
                return;
            }

            _lastInstance.IsUnlocked = unlock;
        }
コード例 #11
0
    public static void MovePlayerExternally(Vector2 from, Vector2 to)
    {
        if (_instance == null)
        {
            MainGameHandler.GetChatHandler().UpdateLog($"WM scene manager handler - MovePlayerExternally() - manager instance is NULL!");
            return;
        }

        _instance.MovePlayer(from, to);
    }
コード例 #12
0
    //fire weapon
    public void FireWeapon(bool localIsWhale, bool sentByRemote)
    {
        if (ammo > 0 && canFire && !reloading)
        {
            MainGameHandler.bulletsFiredByPlayer.Add(MainGameHandler.CreateBullet(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.rotation, damage, bulletSpeed, sentByRemote, localIsWhale, type));
            gameObject.GetComponent <SpriteRenderer>().sprite = unloadedSprite;

            ammo--;
            canFire = false;
        }
    }
コード例 #13
0
    public void OnCancelButtonClick()
    {
        CharLobbySceneManagerHandler _sceneHandler = CharLobbySceneManagerHandler.GetLastInstance();

        if (_sceneHandler == null)
        {
            MainGameHandler.ShowMessageBox("Error #2: cannot find char lobby scene manager handler!");
            return;
        }

        _sceneHandler.ChangeLobbyState(CharLobbySceneManagerHandler.LobbyState.CharacterList);
    }
コード例 #14
0
ファイル: GameStateDetails.cs プロジェクト: AWieczorek89/MMOC
        public void LogCurrentState()
        {
            IChat chat = MainGameHandler.GetChatHandler();

            chat.UpdateLog("========GAME STATE DETAILS");
            chat.UpdateLog($"CharId [{this.CharId}]");
            chat.UpdateLog($"WmId [{this.WmId}]");
            chat.UpdateLog($"MapWidth [{this.MapWidth}]");
            chat.UpdateLog($"MapHeight [{this.MapHeight}]");
            chat.UpdateLog($"LocalBound [{this.LocalBound.x}, {this.LocalBound.y}, {this.LocalBound.y}]");
            chat.UpdateLog($"IsOnWorldMap [{this.IsOnWorldMap}]");
            chat.UpdateLog($"Position [{this.Position.x}, {this.Position.y}, {this.Position.z}]");
            chat.UpdateLog("========");
        }
コード例 #15
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Rigidbody2D body = gameObject.transform.GetComponent <Rigidbody2D>();

        if (body.velocity == Vector2.zero)
        {
            Destroy(gameObject, 0);
        }

        if (!canCollide)
        {
            MainGameHandler.CreateBubble(body.position.x, body.position.y);
        }
    }
コード例 #16
0
 private void ReloadScene()
 {
     try
     {
         ReloadTerrain();
         ReloadCharacters();
         ReloadBoundingBox();
         HideLoadingScreen();
     }
     catch (Exception exception)
     {
         MainGameHandler.ShowMessageBox($"Failed to reload local scene: {exception.Message} | {exception.StackTrace}");
     }
 }
コード例 #17
0
ファイル: CreatureSpawn.cs プロジェクト: xXGreeXx/Evolvere
    //update
    void FixedUpdate()
    {
        //spawn creatures
        if (Random.Range(0, 10001) < MainGameHandler.creatureSpawnRate && !colliding)
        {
            //decide whether creature is plant or animal
            MainGameHandler.CreatureType type = MainGameHandler.CreatureType.Plant;
            if (Random.Range(1, 3) == 1)
            {
                type = MainGameHandler.CreatureType.Animal;
            }

            MainGameHandler.CreateCreature(type, this.transform.position);
        }
    }
コード例 #18
0
        private void ShowDisconnectionMessage(string reason = "")
        {
            if (_disconnectionFlag)
            {
                return;
            }

            _disconnectionFlag = true;
            Action closingAction = () => { MainGameHandler.CloseApplication(); };

            MainGameHandler.ShowMessageBox
            (
                $"Cannot connect to the server!{(!String.IsNullOrWhiteSpace(reason) ? $" Reason: {reason}" : "")}",
                "Connection problem",
                closingAction
            );
        }
コード例 #19
0
    public static void Reload()
    {
        if (_lastInstance == null)
        {
            return;
        }

        try
        {
            LobbyCharactersHandler charHandler = MainGameHandler.GetLobbyCharactersHandler();
            _lastInstance._lobbyCharDetailsList = charHandler.GetAll();
            _lastInstance.ReloadCharactersPosition();
        }
        catch (Exception exception)
        {
            Debug.Log($"CharacterListPanelHandler - Reload() - error: {exception.Message}");
        }
    }
コード例 #20
0
ファイル: UiChatController.cs プロジェクト: AWieczorek89/MMOC
    private void HandleMsgSending()
    {
        if (Input.GetKeyDown(KeyCode.Return))
        {
            GameObject obj = EventSystem.current.currentSelectedGameObject;

            if (obj != null && obj.name.Equals("MsgInputField", StringComparison.InvariantCultureIgnoreCase))
            {
                string msgCommand = _msgInput.text;

                if (!String.IsNullOrWhiteSpace(msgCommand))
                {
                    LocalCommandHandler cmdHandler = MainGameHandler.GetLocalCommandHandler();
                    cmdHandler.ExecuteCommand(msgCommand);
                    _msgInput.text = "";
                }
            }
        }
    }
コード例 #21
0
        public bool Execute()
        {
            bool executed = false;

            try
            {
                bool              loginSuccess = false;
                string            info         = "";
                ConnectionChecker connChecker  = MainGameHandler.GetConnectionChecker();

                if (_cmdElements.Length >= 2)
                {
                    loginSuccess = _cmdElements[1].Equals("true", GlobalData.InputDataStringComparison);
                }

                if (_cmdElements.Length > 2)
                {
                    for (int i = 2; i < _cmdElements.Length; i++)
                    {
                        if (i > 2)
                        {
                            info += ' ';
                        }
                        info += _cmdElements[i];
                    }
                }

                connChecker.SetLoginState(loginSuccess ? ConnectionChecker.LoginState.Logged : ConnectionChecker.LoginState.NotLoggedInOrLoginFailed);

                if (info.Length > 0)
                {
                    MainGameHandler.ShowMessageBox(info, "Server login message", null);
                }

                executed = true;
            }
            catch (Exception exception)
            {
                MainGameHandler.ShowMessageBox($"Cannot execute login command: {exception.Message}", "Login error", null);
            }

            return(executed);
        }
コード例 #22
0
    public void OnButtonPressed(string button)
    {
        //main menu
        if (button.Equals("Play"))
        {
            MainGameHandler.IP = GameObject.Find("IPField").transform.Find("Text").GetComponent <UnityEngine.UI.Text>().text;
            SceneManager.LoadScene("Game");
        }
        else if (button.Equals("Shop"))
        {
            SceneManager.LoadScene("Shop");
        }
        else if (button.Equals("Quit"))
        {
            MainGameHandler.Disconnect();
            MainGameHandler.ExitAndSave();
        }

        //shop
        if (button.Equals("Back"))
        {
            SceneManager.LoadScene("MainMenu");
        }
        else if (button.Equals("GoWhale"))
        {
            GameObject.Find("GoWhaleButton").GetComponent <UnityEngine.UI.Button>().interactable = false;
            MainGameHandler.isWhale = true;
            MainGameHandler.type    = MainGameHandler.CreatureTypes.BottleNose;
            ShopMenuHandler.ChangeBackground();
        }

        //game
        if (button.Equals("Return"))
        {
            MainGameHandler.escapeMenuPanel.SetActive(false);
        }
        else if (button.Equals("DC"))
        {
            MainGameHandler.Disconnect();
            SceneManager.LoadScene("MainMenu");
        }
    }
コード例 #23
0
        public bool Execute()
        {
            bool executed = false;

            if (_cmdElements.Length == 2 && !String.IsNullOrWhiteSpace(_cmdElements[1]))
            {
                DateTime result;

                if (DateTime.TryParseExact(_cmdElements[1], "HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
                {
                    ConnectionChecker checker = MainGameHandler.GetConnectionChecker();
                    if (checker != null)
                    {
                        checker.ServerTime = result;
                        executed           = true;
                    }
                }
            }
            return(executed);
        }
コード例 #24
0
    void Update()
    {
        _timeCounter += Time.deltaTime;

        if (_timeCounter > 0.5f)
        {
            _timeCounter = 0f;

            switch (MainGameHandler.CheckLoginState())
            {
            case ConnectionChecker.LoginState.WaitingForResponse:
                _loginButtonText.text = "Logging in...";
                break;

            default:
                _loginButtonText.text = _loginButtonDefaultText;
                break;
            }
        }
    }
コード例 #25
0
        public void AddCommandElements()
        {
            try
            {
                string to      = "";
                string message = _rawText;

                int cutIndex = -1;

                if (_rawText.Length >= 2 && _rawText.Substring(0, 2).Equals("/\"", StringComparison.InvariantCultureIgnoreCase))
                {
                    string cutSection = _rawText.Substring(2);
                    cutIndex = cutSection.IndexOf('"');

                    if (cutIndex > -1)
                    {
                        to      = cutSection.Substring(0, cutIndex);
                        message = cutSection.Substring(cutIndex + 1);
                    }
                }

                if (message.Length >= 1 && message[0] == ' ')
                {
                    message = message.Substring(1);
                }

                ChatMessageDetails details = new ChatMessageDetails()
                {
                    IsPrivate = !String.IsNullOrWhiteSpace(to),
                    From      = "",
                    To        = to,
                    Message   = message
                };

                _commandDetails.CommandElementList.Add(JsonConvert.SerializeObject(details));
            }
            catch (Exception exception)
            {
                MainGameHandler.ShowMessageBox($"Message building error: {exception.Message}");
            }
        }
コード例 #26
0
        public bool Execute()
        {
            bool executed = false;

            try
            {
                LobbyCharactersHandler handler = MainGameHandler.GetLobbyCharactersHandler();
                if (handler == null)
                {
                    throw new Exception("lobby char. handler is NULL!");
                }

                if (_cmdElements.Length == 2 && _cmdElements[1].Equals("endlist", GlobalData.InputDataStringComparison))
                {
                    handler.ListConfirmed = true;

                    if (MainGameHandler.CheckIfSceneActive(MainGameHandler.SceneType.CharLobby, SceneManager.GetActiveScene()))
                    {
                        CharacterListPanelHandler.Reload();
                    }

                    MainGameHandler.HideLoadingScreen();
                    executed = true;
                }
                else
                if (_cmdElements.Length > 2 && _cmdElements[1].Equals("position", GlobalData.InputDataStringComparison))
                {
                    string           discardedText = $"{_keyWord} position";
                    LobbyCharDetails charDetails   = JsonConvert.DeserializeObject <LobbyCharDetails>(_rawText.Substring(discardedText.Length));
                    handler.Add(charDetails);
                    executed = true;
                }
            }
            catch (Exception exception)
            {
                _chat.UpdateLog($"Lobby char. command execution error: {exception.Message}");
            }

            return(executed);
        }
コード例 #27
0
        public bool Execute()
        {
            bool executed = false;

            try
            {
                string jsonString = _rawText.Substring(_keyWord.Length);
                CharacterPositionBasicDetails charPosDetails = JsonConvert.DeserializeObject <CharacterPositionBasicDetails>(jsonString);

                _gameStateDetails.CharId       = charPosDetails.CharId;
                _gameStateDetails.WmId         = charPosDetails.WmId;
                _gameStateDetails.MapWidth     = charPosDetails.MapWidth;
                _gameStateDetails.MapHeight    = charPosDetails.MapHeight;
                _gameStateDetails.LocalBound   = PointConverter.Point3ToVector(charPosDetails.LocalBound);
                _gameStateDetails.IsOnWorldMap = charPosDetails.IsOnWorldMap;
                _gameStateDetails.Position     = PointConverter.Point3ToVector(charPosDetails.Position);

                //_gameStateDetails.LogCurrentState(); //for testing

                if (charPosDetails.IsOnWorldMap)
                {
                    MainGameHandler.ChangeScene(MainGameHandler.SceneType.WorldMap);
                }
                else
                {
                    MainGameHandler.ChangeScene(MainGameHandler.SceneType.LocalPlace);
                }

                executed = true;
            }
            catch (Exception exception)
            {
                _chat.UpdateLog($"Cannot execute char. basic details command: {exception.Message}");
            }

            return(executed);
        }
コード例 #28
0
        public bool Execute()
        {
            bool executed = false;

            try
            {
                bool charChoosingSuccess = false;

                if (_cmdElements.Length == 2)
                {
                    if (_cmdElements[1].Equals("true", GlobalData.InputDataStringComparison))
                    {
                        charChoosingSuccess = true;
                    }
                }

                if (charChoosingSuccess)
                {
                    MainGameHandler.ShowLoadingScreen();
                    MainGameHandler.GetGameStateDetails().Reset();
                    CommandHandler.Send(new GetWorldDetailsCmdBuilder());
                }
                else
                {
                    MainGameHandler.ShowMessageBox("Server declined character selection!");
                }

                executed = true;
            }
            catch (Exception exception)
            {
                MainGameHandler.ShowMessageBox($"Cannot execute character choosing success command! {exception.Message}");
            }

            return(executed);
        }
コード例 #29
0
 void Start()
 {
     MainGameHandler.RegisterSceneManager(this);
     ConnectionChecker.Unlock(true);
 }
コード例 #30
0
 void Update()
 {
     MainGameHandler.GlobalUpdate();
 }