private void SetPlayersAliveState(bool on) { if (!on) { heldPlayers = matrix.Get <ObjectBehaviour>(registerTile.Position, ObjectType.Player); } foreach (ObjectBehaviour player in heldPlayers) { if (on) { player.transform.position = transform.position; player.GetComponent <PlayerSync>().SetPosition(transform.position); } player.visibleState = on; if (!on) { //Make sure a ClosetPlayerHandler is created on the client to monitor //the players input inside the storage. The handler also controls the camera follow targets: if (!player.GetComponent <PlayerMove>().isGhost) { ClosetHandlerMessage.Send(player.gameObject, gameObject); } } } }
private void SetPlayersAliveState(bool on) { if (!on) { heldPlayers = matrix.Get <ObjectBehaviour>(registerTile.Position, ObjectType.Player); } for (var i = 0; i < heldPlayers.Count; i++) { ObjectBehaviour player = heldPlayers[i]; var playerScript = player.GetComponent <PlayerScript>(); var playerSync = playerScript.PlayerSync; if (@on) { playerSync.AppearAtPositionServer(registerTile.WorldPosition); if (pushPull && pushPull.Pushable.IsMovingServer) { playerScript.pushPull.TryPush(pushPull.InheritedImpulse.To2Int(), pushPull.Pushable.MoveSpeedServer); } } player.visibleState = @on; if (!@on) { playerSync.DisappearFromWorldServer(); //Make sure a ClosetPlayerHandler is created on the client to monitor //the players input inside the storage. The handler also controls the camera follow targets: if (!playerScript.playerMove.isGhost) { ClosetHandlerMessage.Send(player.gameObject, gameObject); } } } }
/// <summary> /// Connects a client to a character or redirects a logged out ConnectedPlayer. /// </summary> /// <param name="conn">The client's NetworkConnection. If logged out the playerlist will return an invalid connectedplayer</param> /// <param name="playerControllerId">ID of the client player to be transfered. If logged out it's empty.</param> /// <param name="newBody">The character gameobject to be transfered into.</param> /// <param name="oldBody">The old body of the character.</param> /// <param name="eventType">Event type for the player sync.</param> public static void TransferPlayer(NetworkConnection conn, short playerControllerId, GameObject newBody, GameObject oldBody, EVENT eventType, CharacterSettings characterSettings) { var oldPlayerNetworkActions = oldBody.GetComponent <PlayerNetworkActions>(); if (oldPlayerNetworkActions) { oldPlayerNetworkActions.RpcBeforeBodyTransfer(); } var connectedPlayer = PlayerList.Instance.Get(conn); if (connectedPlayer == ConnectedPlayer.Invalid) //this isn't an online player { PlayerList.Instance.UpdateLoggedOffPlayer(newBody, oldBody); NetworkServer.Spawn(newBody); } else { PlayerList.Instance.UpdatePlayer(conn, newBody); NetworkServer.ReplacePlayerForConnection(conn, newBody, playerControllerId); NetworkServer.ReplacePlayerForConnection(new NetworkConnection(), oldBody, 0); TriggerEventMessage.Send(newBody, eventType); } var playerScript = newBody.GetComponent <PlayerScript>(); if (playerScript.PlayerSync != null) { playerScript.PlayerSync.NotifyPlayers(true); } // If the player is inside a container, send a ClosetHandlerMessage. // The ClosetHandlerMessage will attach the container to the transfered player. var playerObjectBehavior = newBody.GetComponent <ObjectBehaviour>(); if (playerObjectBehavior && playerObjectBehavior.parentContainer) { ClosetHandlerMessage.Send(newBody, playerObjectBehavior.parentContainer.gameObject); } bool newMob = false; if (characterSettings != null) { playerScript.characterSettings = characterSettings; playerScript.playerName = characterSettings.Name; newBody.name = characterSettings.Name; var playerSprites = newBody.GetComponent <PlayerSprites>(); if (playerSprites) { playerSprites.OnCharacterSettingsChange(characterSettings); } newMob = true; } var healthStateMonitor = newBody.GetComponent <HealthStateMonitor>(); if (healthStateMonitor) { healthStateMonitor.ProcessClientUpdateRequest(newBody); } }
public void StorePlayer(ObjectBehaviour player) { heldPlayers.Add(player); var playerScript = player.GetComponent <PlayerScript>(); player.VisibleState = false; player.parentContainer = objectBehaviour; //Start tracking closet if (!playerScript.IsGhost) { ClosetHandlerMessage.Send(player.gameObject, gameObject); } }
private void OpenPlayerHandling() { foreach (ObjectBehaviour player in heldPlayers) { player.VisibleState = true; if (pushPull && pushPull.Pushable.IsMovingServer) { player.TryPush(pushPull.InheritedImpulse.To2Int(), pushPull.Pushable.SpeedServer); } player.parentContainer = null; //Stop tracking closet ClosetHandlerMessage.Send(player.gameObject, null); } heldPlayers = new List <ObjectBehaviour>(); }
public void StorePlayer(ObjectBehaviour player) { heldPlayers.Add(player); var playerScript = player.GetComponent <PlayerScript>(); var playerSync = playerScript.PlayerSync; player.visibleState = false; player.parentContainer = objectBehaviour; playerSync.DisappearFromWorldServer(); //Make sure a ClosetPlayerHandler is created on the client to monitor //the players input inside the storage. The handler also controls the camera follow targets: if (!playerScript.IsGhost) { ClosetHandlerMessage.Send(player.gameObject, gameObject); } }
/// <summary> /// Connects a client to a character or redirects a logged out ConnectedPlayer. /// </summary> /// <param name="conn">The client's NetworkConnection. If logged out the playerlist will return an invalid connectedplayer</param> /// <param name="playerControllerId">ID of the client player to be transfered. If logged out it's empty.</param> /// <param name="newBody">The character gameobject to be transfered into.</param> /// <param name="oldBody">The old body of the character.</param> /// <param name="eventType">Event type for the player sync.</param> public static void TransferPlayer(NetworkConnection conn, short playerControllerId, GameObject newBody, GameObject oldBody, EVENT eventType, CharacterSettings characterSettings) { var connectedPlayer = PlayerList.Instance.Get(conn); if (connectedPlayer == ConnectedPlayer.Invalid) //this isn't an online player { PlayerList.Instance.UpdateLoggedOffPlayer(newBody, oldBody); NetworkServer.Spawn(newBody); } else { PlayerList.Instance.UpdatePlayer(conn, newBody); NetworkServer.ReplacePlayerForConnection(conn, newBody, playerControllerId); TriggerEventMessage.Send(newBody, eventType); } var playerScript = newBody.GetComponent <PlayerScript>(); if (playerScript.PlayerSync != null) { playerScript.PlayerSync.NotifyPlayers(true); } // If the player is inside a container, send a ClosetHandlerMessage. // The ClosetHandlerMessage will attach the container to the transfered player. var playerObjectBehavior = newBody.GetComponent <ObjectBehaviour>(); if (playerObjectBehavior && playerObjectBehavior.parentContainer) { ClosetHandlerMessage.Send(newBody, playerObjectBehavior.parentContainer.gameObject); } CustomNetworkManager.Instance.SyncPlayerData(newBody); if (characterSettings != null) { playerScript.characterSettings = characterSettings; } }
private void SetPlayersAliveState(bool isOpen) { if (!isOpen) { heldPlayers = matrix.Get <ObjectBehaviour>(registerTile.PositionServer, ObjectType.Player, true); } foreach (ObjectBehaviour player in heldPlayers) { var playerScript = player.GetComponent <PlayerScript>(); var playerSync = playerScript.PlayerSync; if (isOpen) { playerSync.AppearAtPositionServer(registerTile.WorldPositionServer); player.parentContainer = null; if (pushPull && pushPull.Pushable.IsMovingServer) { playerScript.pushPull.TryPush(pushPull.InheritedImpulse.To2Int(), pushPull.Pushable.SpeedServer); } } player.visibleState = isOpen; if (!isOpen) { player.parentContainer = objectBehaviour; playerSync.DisappearFromWorldServer(); //Make sure a ClosetPlayerHandler is created on the client to monitor //the players input inside the storage. The handler also controls the camera follow targets: if (!playerScript.IsGhost) { ClosetHandlerMessage.Send(player.gameObject, gameObject); } } } }