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); }
private void Start() { _instance = this; MainGameHandler.RegisterSceneManager(this); _chat = MainGameHandler.GetChatHandler(); _gameStateDetails = MainGameHandler.GetGameStateDetails(); WaitForServerDataAndLoadScene(); }
public bool Execute() { bool executed = false; try { if (_cmdElements.Length < 2) { throw new Exception("wrong count of elements"); } if (_cmdElements[1].Equals("position", GlobalData.InputDataStringComparison)) { string jsonTxt = _rawText.Substring($"{_keyWord} position".Length); LocalCharacterDetails details = JsonConvert.DeserializeObject <LocalCharacterDetails>(jsonTxt); _gameStateDetails.AddOrUpdateLocalCharacterDetails(details); if (details.Action.Equals("requestspawn")) { LocalPlaceSceneManagerHandler.AddNewNonPlayerCharacterExternally(details); } } else if (_cmdElements[1].Equals("endlist", GlobalData.InputDataStringComparison)) { _gameStateDetails.LocalCharacterDetailsListConfirmed = true; } else { throw new Exception($"wrong second keyword [{_cmdElements[1]}]"); } executed = true; } catch (Exception exception) { _chat.UpdateLog($"Cannot execute local character details command: {exception.Message}"); } return(executed); }
public bool Execute() { bool executed = false; //Debug.Log(_rawText); try { string jsonText = _rawText.Substring(_keyWord.Length); CharacterPositionUpdateDetails posUpdateDetails = JsonConvert.DeserializeObject <CharacterPositionUpdateDetails>(jsonText); int currentCharId = _gameStateDetails.CharId; bool isOnWorldMap = _gameStateDetails.IsOnWorldMap; if ( posUpdateDetails.MovementType.Equals("movelocal", GlobalData.InputDataStringComparison) || posUpdateDetails.MovementType.Equals("moveworld", GlobalData.InputDataStringComparison) ) { #region Movement section //MOVEMENT SECTION if (isOnWorldMap) { if (currentCharId == posUpdateDetails.CharId) { Point2 <int> oldLocationWorld = posUpdateDetails.OldLocationWorld; Point2 <int> newLocationWorld = posUpdateDetails.NewLocationWorld; _gameStateDetails.Position = new Vector3 ( newLocationWorld.X, newLocationWorld.Y, 0f ); WorldMapSceneManagerHandler.MovePlayerExternally ( PointConverter.Point2ToVector(oldLocationWorld), PointConverter.Point2ToVector(newLocationWorld) ); } } else { LocalPlaceSceneManagerHandler.MovePlayerExternally ( posUpdateDetails.CharId, /*posUpdateDetails.OldLocationLocal, */ posUpdateDetails.NewLocationLocal, posUpdateDetails.TimeArrivalMsLocal ); } #endregion } else if (posUpdateDetails.MovementType.Equals("switchmap", GlobalData.InputDataStringComparison)) { if (currentCharId == posUpdateDetails.CharId) { SwitchScene(); } else { LocalPlaceSceneManagerHandler.RemoveNonPlayerCharacterExternally(posUpdateDetails.CharId); } } else if (posUpdateDetails.MovementType.Equals("switchlocal", GlobalData.InputDataStringComparison)) { if (currentCharId == posUpdateDetails.CharId) { SwitchScene(); } else { CommandHandler.Send(new GetLocationCharsCmdBuilder(posUpdateDetails.CharId)); } } else { throw new Exception($"unknown movement type [{posUpdateDetails.MovementType}]"); } executed = true; } catch (Exception exception) { _chat.UpdateLog($"Character position update command execution error: {exception.Message}"); } return(executed); }
private void OnDestroy() { _instance = null; }