IEnumerator TryAutoMove(MatrixMove matrixMove) { while (!matrixMove.Initialized) { yield return(WaitFor.EndOfFrame); } yield return(WaitFor.Seconds(RoundStartDelay)); matrixMove.SetSpeed(SetInitialSpeed); matrixMove.SafetyProtocolsOn = ShuttleSafetyEnabled; matrixMove.RequiresFuel = false; matrixMove.StartMovement(); }
protected override void OnEnable() { base.OnEnable(); if (MatrixMove == null) { MatrixMove = this.GetComponent <MatrixMove>(); MatrixMove.RegisterShuttleFuelSystem(this); } if (Connector == null) { Logger.LogError($"{nameof(Connector)} was null on {this}!"); } }
private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(this); } mm = GetComponent <MatrixMove>(); mm.SetAccuracy(0); }
public void SetAutopilot(bool on) { Autopilot = on; if (on) { //touchscreen on } else { //touchscreen off, hide waypoint, invalidate MM target HideWaypoint(); MatrixMove.DisableAutopilotTarget(); } }
private IEnumerator WaitForProvider() { while (Provider == null) { yield return(WaitFor.EndOfFrame); } Trigger = Provider.GetComponent <ShuttleConsole>(); Trigger.OnStateChange.AddListener(OnStateChange); MatrixMove.RegisterCoordReadoutScript(CoordReadout); MatrixMove.RegisterShuttleGuiScript(this); //Not doing this for clients if (IsServer) { EntryList.Origin = MatrixMove; //Init listeners string temp = "1"; StartButton.SetValueServer(temp); MatrixMove.MatrixMoveEvents.OnStartMovementServer.AddListener(() => { // dont enable button when moving with RCS if (!matrixMove.rcsModeActive) { StartButton.SetValueServer("1"); } }); MatrixMove.MatrixMoveEvents.OnStopMovementServer.AddListener(() => { StartButton.SetValueServer("0"); HideWaypoint(); }); if (!Waypoint) { Waypoint = new GameObject($"{MatrixMove.gameObject.name}Waypoint"); } HideWaypoint(false); rulersColor = Rulers.Value; rayColor = RadarScanRay.Value; crosshairColor = Crosshair.Value; OnStateChange(State); } else { ClientToggleRcs(matrixMove.rcsModeActive); } }
public void ServerToggleRcs(bool on, ConnectedPlayer subject) { RcsMode = on; MatrixMove.ToggleRcs(on); SetRcsLight(on); if (on) { playerControllingRcs = subject; } else { playerControllingRcs = null; } }
protected void OnEnable() { if (MatrixMove == null) { MatrixMove = this.GetComponent <MatrixMove>(); MatrixMove.RegisterShuttleFuelSystem(this); } if (CustomNetworkManager.IsServer == false) { return; } UpdateManager.Add(CallbackType.UPDATE, UpdateMe); }
private void OnEnable() { if (ShuttleMatrixMove == null) { ShuttleMatrixMove = GetComponentInParent <MatrixMove>(); if (ShuttleMatrixMove == null) { Logger.LogError($"{this} has no reference to MatrixMove, didn't find any in parents either", Category.Matrix); } else { Logger.Log($"No MatrixMove reference set to {this}, found {ShuttleMatrixMove} automatically", Category.Matrix); } } }
private void Awake() { if (transform.parent == null) { Logger.LogError($"{gameObject.name} had null transform parent", Category.Matrix); } networkedMatrix = transform.parent.GetComponent <NetworkedMatrix>(); if (networkedMatrix == null) { Logger.LogError($"{gameObject.name} had null networkedMatrix", Category.Matrix); } networkedMatrix.MatrixSync = this; matrixMove = networkedMatrix.GetComponent <MatrixMove>(); }
public void InitFromMatrix() { RotationOffset = RotationOffset.Same; if (this == null) { return; } matrixMove = transform?.root?.GetComponent <MatrixMove>(); if (matrixMove != null) { Logger.LogTraceFormat("{0} layer initializing from matrix", Category.Matrix, matrixMove); matrixMove.MatrixMoveEvents.OnRotate.AddListener(OnRotate); //initialize from current rotation OnRotate(MatrixRotationInfo.FromInitialRotation(matrixMove, NetworkSide.Client, RotationEvent.Register)); } }
public void Start() { InitDirection(); matrixMove = transform.root.GetComponent <MatrixMove>(); var registerTile = GetComponent <RegisterTile>(); if (ROTATE_AT_END) { registerTile.OnRotateEnd.AddListener(OnRotate); } else { registerTile.OnRotateStart.AddListener(OnRotate); } if (matrixMove != null) { //TODO: Is this still needed? StartCoroutine(WaitForInit()); } }
IEnumerator ProcessSpaceBody(MatrixMove mm) { if (SceneManager.GetActiveScene().name == "BoxStationV1") { minDistanceBetweenSpaceBodies = 200f; } //Change this for larger maps to avoid asteroid spawning on station. else { minDistanceBetweenSpaceBodies = 200f; } bool validPos = false; while (!validPos) { Vector3 proposedPosition = RandomPositionInSolarSystem(); bool failedChecks = Vector3.Distance(proposedPosition, MatrixManager.Instance.spaceMatrix.transform.parent.transform.position) < minDistanceBetweenSpaceBodies; //Make sure it is away from the middle of space matrix for (int i = 0; i < SpaceBodies.Count; i++) { if (Vector3.Distance(proposedPosition, SpaceBodies[i].transform.position) < minDistanceBetweenSpaceBodies) { failedChecks = true; } } if (!failedChecks) { validPos = true; mm.SetPosition(proposedPosition); SpaceBodies.Add(mm); } yield return(WaitFor.EndOfFrame); } yield return(WaitFor.EndOfFrame); isProcessingSpaceBody = false; }
private void CommonStartProgress() { done = false; //common logic used between client / server progress start logic matrixMove = GetComponentInParent <MatrixMove>(); if (matrixMove != null) { matrixMove.OnRotateEnd.AddListener(OnRotationEnd); } anim = 0f; if (Random.value < 0.02f) { spriteRenderer.transform.parent.localRotation = Quaternion.identity; animIdx = Random.Range(1, progressSprites.Length / 2); animSpd = Random.Range(360f, 720f); } else { animIdx = -1; } }
private IEnumerator WaitForProvider() { while (Provider == null) { yield return(WaitFor.EndOfFrame); } shuttleConsole = Provider.GetComponent <ShuttleConsole>(); matrixMove = shuttleConsole.ShuttleMatrixMove; matrixMove.RegisterCoordReadoutScript(CoordReadout); matrixMove.RegisterShuttleGuiScript(this); shuttleFuelSystem = matrixMove.ShuttleFuelSystem; radarList = this["EntryList"] as RadarList; //Not doing this for clients if (IsServer) { shuttleConsole.GUItab = this; radarList.Origin = matrixMove; StartButton.SetValueServer("1"); //Init listeners matrixMove.MatrixMoveEvents.OnStartMovementServer.AddListener(OnStartMovementServer); matrixMove.MatrixMoveEvents.OnStopMovementServer.AddListener(OnStopMovementServer); if (!Waypoint) { Waypoint = new GameObject($"{matrixMove.gameObject.name}Waypoint"); } HideWaypoint(false); rulersColor = Rulers.Value; rayColor = RadarScanRay.Value; crosshairColor = Crosshair.Value; OnStateChange(shuttleConsole.shuttleConsoleState); } }
private IEnumerator InitMatrixMove() { ShuttleMatrixMove = GetComponentInParent <MatrixMove>(); if (ShuttleMatrixMove == null) { while (!registerTile.Matrix) { yield return(WaitFor.EndOfFrame); } ShuttleMatrixMove = MatrixManager.Get(registerTile.Matrix).MatrixMove; } if (ShuttleMatrixMove == null) { Logger.LogError($"{this} has no reference to MatrixMove, current matrix doesn't seem to have it either", Category.Matrix); } else { Logger.Log($"No MatrixMove reference set to {this}, found {ShuttleMatrixMove} automatically", Category.Matrix); } }
IEnumerator Init() { int tries = 0; while (shipMatrixMove == null) { tries++; shipMatrixMove = transform.root.gameObject.GetComponent <MatrixMove>(); yield return(new WaitForEndOfFrame()); if (tries >= 5) { this.enabled = false; yield break; } } yield return(new WaitForEndOfFrame()); shipMatrixMove.OnStart.AddListener(UpdateEngineState); shipMatrixMove.OnStop.AddListener(UpdateEngineState); shipMatrixMove.OnRotateStart.AddListener(RotateFX); shipMatrixMove.OnSpeedChange.AddListener(SpeedChange); }
IEnumerator Init() { int tries = 0; while (shipMatrixMove == null) { tries++; shipMatrixMove = transform.root.gameObject.GetComponent <MatrixMove>(); yield return(WaitFor.EndOfFrame); if (tries >= 5) { this.enabled = false; yield break; } } yield return(WaitFor.EndOfFrame); shipMatrixMove.MatrixMoveEvents.OnStartMovementClient.AddListener(UpdateEngineState); shipMatrixMove.MatrixMoveEvents.OnStopMovementClient.AddListener(UpdateEngineState); //TODO: Refactor to use Directional shipMatrixMove.MatrixMoveEvents.OnRotate.AddListener(RotateFX); shipMatrixMove.MatrixMoveEvents.OnSpeedChange.AddListener(SpeedChange); }
void Awake() { //Gets ship matrix move by getting root (top parent) of current gameobject shipMatrixMove = transform.root.gameObject.GetComponent <MatrixMove>(); particleFX = GetComponentInChildren <ParticleSystem>(); }
IEnumerator ReverseIntoStation(MatrixMove mm) { yield return(new WaitForSeconds(3f)); mm.MoveFor(offSetReverse); }
IEnumerator ProcessSpaceBody(MatrixMove mm) { if (SceneManager.GetActiveScene().name == "BoxStationV1") { minDistanceBetweenSpaceBodies = 200f; } //Change this for larger maps to avoid asteroid spawning on station. else { minDistanceBetweenSpaceBodies = 200f; } //Fills list of Vectors all along shuttle path var beginning = GameManager.Instance.PrimaryEscapeShuttle.stationTeleportLocation; var target = GameManager.Instance.PrimaryEscapeShuttle.stationDockingLocation; var distance = (int)Vector2.Distance(beginning, target); if (!EscapeShuttlePathGenerated) //Only generated once { EscapeShuttlePath.Add(beginning); //Adds original vector for (int i = 0; i < (distance / 50); i++) { beginning = Vector2.MoveTowards(beginning, target, 50); //Vector 50 distance apart from prev vector EscapeShuttlePath.Add(beginning); } EscapeShuttlePathGenerated = true; } bool validPos = false; while (!validPos) { Vector3 proposedPosition = RandomPositionInSolarSystem(); bool failedChecks = Vector3.Distance(proposedPosition, MatrixManager.Instance.spaceMatrix.transform.parent.transform.position) < minDistanceBetweenSpaceBodies; //Make sure it is away from the middle of space matrix //Checks whether position is near (100 distance) any of the shuttle path vectors foreach (var vectors in EscapeShuttlePath) { if (Vector3.Distance(proposedPosition, vectors) < 100) { failedChecks = true; } } //Checks whether the other spacebodies are near for (int i = 0; i < SpaceBodies.Count; i++) { if (Vector3.Distance(proposedPosition, SpaceBodies[i].transform.position) < minDistanceBetweenSpaceBodies) { failedChecks = true; } } if (!failedChecks) { validPos = true; mm.SetPosition(proposedPosition); SpaceBodies.Add(mm); } yield return(WaitFor.EndOfFrame); } yield return(WaitFor.EndOfFrame); isProcessingSpaceBody = false; }
private PlayerState NextStateServer(PlayerState state, PlayerAction action) { //Check if there is a bump interaction according to the server BumpType serverBump = CheckSlideAndBump(state, ref action); //Client only needs to check whether movement was prevented, specific type of bump doesn't matter bool isClientBump = action.isBump; //we only lerp back if the client thinks it's passable but server does not...if client //thinks it's not passable and server thinks it's passable, then it's okay to let the client continue if (!isClientBump && serverBump != BumpType.None) { Logger.LogWarningFormat("isBump mismatch, resetting: C={0} S={1}", Category.Movement, isClientBump, serverBump != BumpType.None); RollbackPosition(); } if (isClientBump || serverBump != BumpType.None) { // we bumped something, an interaction might occur // try pushing things / opening doors BumpInteract(state.WorldPosition, (Vector2)action.Direction()); playerSprites.FaceDirection(Orientation.From(action.Direction())); return(state); } if (IsNonStickyServer) { PushPull pushable; if (IsAroundPushables(serverState, out pushable)) { StartCoroutine(InteractSpacePushable(pushable, action.Direction())); } return(state); } if (action.isNonPredictive) { Logger.Log("Ignored action marked as Non-predictive while being indoors", Category.Movement); return(state); } bool matrixChangeDetected; PlayerState nextState = NextState(state, action, out matrixChangeDetected); if (!matrixChangeDetected) { return(nextState); } //todo: subscribe to current matrix rotations on spawn var newMatrix = MatrixManager.Get(nextState.MatrixId); Logger.Log($"Matrix will change to {newMatrix}", Category.Movement); if (newMatrix.MatrixMove) { //Subbing to new matrix rotations newMatrix.MatrixMove.OnRotate.AddListener(OnRotation); // Logger.Log( $"Registered rotation listener to {newMatrix.MatrixMove}" ); } //Unsubbing from old matrix rotations MatrixMove oldMatrixMove = MatrixManager.Get(Matrix).MatrixMove; if (oldMatrixMove) { // Logger.Log( $"Unregistered rotation listener from {oldMatrixMove}" ); oldMatrixMove.OnRotate.RemoveListener(OnRotation); } return(nextState); }
private PlayerState NextStateServer(PlayerState state, PlayerAction action) { bool isServerBump = !CanMoveThere(state, action); bool isClientBump = action.isBump; if (!isClientBump && isServerBump) { Logger.LogWarningFormat("isBump mismatch, resetting: C={0} S={1}", Category.Movement, isClientBump, isServerBump); RollbackPosition(); } if (isClientBump || isServerBump) { //gotta try pushing things BumpInteract(state.WorldPosition, (Vector2)action.Direction()); playerSprites.FaceDirection(Orientation.From(action.Direction())); return(state); } if (IsNonStickyServer) { PushPull pushable; if (IsAroundPushables(serverState, out pushable)) { StartCoroutine(InteractSpacePushable(pushable, action.Direction())); } return(state); } if (action.isNonPredictive) { Logger.Log("Ignored action marked as Non-predictive while being indoors", Category.Movement); return(state); } bool matrixChangeDetected; PlayerState nextState = NextState(state, action, out matrixChangeDetected); if (!matrixChangeDetected) { return(nextState); } //todo: subscribe to current matrix rotations on spawn var newMatrix = MatrixManager.Get(nextState.MatrixId); Logger.Log($"Matrix will change to {newMatrix}", Category.Movement); if (newMatrix.MatrixMove) { //Subbing to new matrix rotations newMatrix.MatrixMove.OnRotate.AddListener(OnRotation); // Logger.Log( $"Registered rotation listener to {newMatrix.MatrixMove}" ); } //Unsubbing from old matrix rotations MatrixMove oldMatrixMove = MatrixManager.Get(matrix).MatrixMove; if (oldMatrixMove) { // Logger.Log( $"Unregistered rotation listener from {oldMatrixMove}" ); oldMatrixMove.OnRotate.RemoveListener(OnRotation); } return(nextState); }
/// <summary> /// Matrix rotation info where a rotation is performed from the matrixmove's initial facing to its current facing. /// </summary> /// <returns></returns> public static MatrixRotationInfo FromInitialRotation(MatrixMove matrixMove, NetworkSide side, RotationEvent rotationEvent) { return(new MatrixRotationInfo(matrixMove, matrixMove.FacingOffsetFromInitial, side, rotationEvent)); }
private void Awake() { matrixMove = GetComponent <MatrixMove>(); }
/// <summary> /// Gets the rotation offset this state represents from the matrix move's initial mapped /// facing. /// </summary> /// <param name="matrixMove"></param> public RotationOffset FacingOffsetFromInitial(MatrixMove matrixMove) { return(matrixMove.InitialFacing.OffsetTo(FacingDirection)); }