Пример #1
0
        /// <summary>
        /// Takes the given object out of storage, dropping it in the tile of the container, inheriting the inertia of the container.
        /// If the object belongs to a player, then sends a <see cref="FollowCameraMessage"/>.
        /// </summary>
        public void RetrieveObject(GameObject obj)
        {
            storedObjects.Remove(obj);

            if (obj.TryGetComponent <ObjectBehaviour>(out var objBehaviour))
            {
                objBehaviour.parentContainer = null;

                if (obj.TryGetComponent <CustomNetTransform>(out var cnt))
                {
                    //avoids blinking of premapped items when opening first time in another place:
                    Vector3Int pos = registerTile.WorldPositionServer;
                    cnt.AppearAtPositionServer(pos);
                    if (objectBehaviour.Pushable.IsMovingServer)
                    {
                        cnt.InertiaDrop(pos, objectBehaviour.Pushable.SpeedServer, objectBehaviour.InheritedImpulse.To2Int());
                    }
                }
                else if (obj.TryGetComponent <PlayerScript>(out var playerScript))
                {
                    playerScript.PlayerSync.AppearAtPositionServer(registerTile.WorldPositionServer);
                    playerScript.playerMove.IsTrapped = false;
                    if (objectBehaviour.Pushable.IsMovingServer)
                    {
                        objBehaviour.TryPush(objectBehaviour.InheritedImpulse.To2Int(), objectBehaviour.Pushable.SpeedServer);
                    }

                    // Stop tracking closet
                    FollowCameraMessage.Send(obj, obj);
                    CheckPlayerCrawlState(objBehaviour);
                }
            }
        }
Пример #2
0
    protected override void Gib()
    {
        EffectsFactory.BloodSplat(transform.position, BloodSplatSize.large, bloodColor);
        //drop clothes, gib... but don't destroy actual player, a piece should remain

        //drop everything
        foreach (var slot in itemStorage.GetItemSlots())
        {
            Inventory.ServerDrop(slot);
        }

        if (!playerMove.PlayerScript.IsGhost)
        {         //dirty way to follow gibs. change this when implementing proper gibbing, perhaps make it follow brain
            var gibsToFollow = MatrixManager.GetAt <RawMeat>(transform.position.CutToInt(), true);
            if (gibsToFollow.Count > 0)
            {
                var gibs = gibsToFollow[0];
                FollowCameraMessage.Send(gameObject, gibs.gameObject);
                var gibsIntegrity = gibs.GetComponent <Integrity>();
                if (gibsIntegrity != null)
                {                       //Stop cam following gibs if they are destroyed
                    gibsIntegrity.OnWillDestroyServer.AddListener(x => FollowCameraMessage.Send(gameObject, null));
                }
            }
        }
        playerMove.PlayerScript.pushPull.VisibleState = false;
    }
Пример #3
0
    public static FollowCameraMessage Send(GameObject recipient, GameObject objectToFollow)
    {
        FollowCameraMessage msg = new FollowCameraMessage
        {
            ObjectToFollow = objectToFollow.NetId()
        };

        msg.SendTo(recipient);
        return(msg);
    }
        void EjectPlayer(ObjectBehaviour player)
        {
            if (player == null)
            {
                return;
            }

            player.parentContainer = null;
            player.GetComponent <PlayerSync>()?.SetPosition(ContainerWorldPosition);
            FollowCameraMessage.Send(player.gameObject, player.gameObject);
        }
Пример #5
0
	protected virtual void GatherPlayers()
	{
		var players = Matrix.Get<ObjectBehaviour>(TrayLocalPosition, ObjectType.Player, true);
		foreach (ObjectBehaviour player in players)
		{
			serverHeldPlayers.Add(player);
			player.parentContainer = drawerPushPull;
			player.VisibleState = false;

			// Start tracking the drawer
			var playerScript = player.GetComponent<PlayerScript>();
			if (!playerScript.IsGhost) FollowCameraMessage.Send(player.gameObject, gameObject);
		}
	}
Пример #6
0
    public void StorePlayer(ObjectBehaviour player)
    {
        heldPlayers.Add(player);
        var playerScript = player.GetComponent <PlayerScript>();

        player.VisibleState    = false;
        player.parentContainer = PushPull;

        //Start tracking closet
        if (!playerScript.IsGhost)
        {
            FollowCameraMessage.Send(player.gameObject, gameObject);
        }
    }
Пример #7
0
    protected void ServerStorePlayer(ObjectBehaviour player)
    {
        serverHeldPlayers.Add(player);
        var playerScript = player.GetComponent <PlayerScript>();

        player.VisibleState = false;
        playerScript.playerMove.IsTrapped = true;
        player.parentContainer            = PushPull;

        //Start tracking closet
        if (!playerScript.IsGhost)
        {
            FollowCameraMessage.Send(player.gameObject, gameObject);
        }
    }
Пример #8
0
	/// <summary>
	/// Ejects players when drawer is opened or despawned. If action is despawning, set drawerDespawning true.
	/// </summary>
	/// <param name="drawerDespawning"></param>
	protected virtual void EjectPlayers(bool drawerDespawning = false)
	{
		Vector3 position = TrayWorldPosition;
		if (drawerDespawning) position = DrawerWorldPosition;

		foreach (ObjectBehaviour player in serverHeldPlayers)
		{
			player.parentContainer = null;
			player.GetComponent<PlayerSync>().SetPosition(position);

			//Stop tracking the drawer
			FollowCameraMessage.Send(player.gameObject, player.gameObject);
		}

		serverHeldPlayers = new List<ObjectBehaviour>();
	}
Пример #9
0
    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
            FollowCameraMessage.Send(player.gameObject, null);
        }
        heldPlayers = new List <ObjectBehaviour>();
    }
Пример #10
0
        public void ReceiveObjects(Dictionary <GameObject, Vector3> objects)
        {
            foreach (var kvp in objects)
            {
                if (kvp.Key == null)
                {
                    continue;
                }

                storedObjects[kvp.Key] = kvp.Value;
                kvp.Key.GetComponent <ObjectBehaviour>().parentContainer = pushPullObject;

                if (kvp.Key.TryGetComponent <PlayerScript>(out var playerScript))
                {
                    // update player camera target
                    if (playerScript.IsGhost == false)
                    {
                        FollowCameraMessage.Send(kvp.Key, gameObject);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Stores the given object. Remembers the offset, if provided.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="offset"></param>
        public void StoreObject(GameObject obj, Vector3 offset = new Vector3())
        {
            storedObjects.Add(obj, offset);

            if (obj.TryGetComponent <ObjectBehaviour>(out var objBehaviour))
            {
                objBehaviour.parentContainer = pushPullObject;
                objBehaviour.VisibleState    = false;

                if (obj.TryGetComponent <PlayerScript>(out var playerScript))
                {
                    playerScript.playerMove.IsTrapped = true;

                    // Start tracking container
                    if (playerScript.IsGhost == false)
                    {
                        FollowCameraMessage.Send(obj, gameObject);
                    }

                    CheckPlayerCrawlState(objBehaviour);
                }
            }
        }
Пример #12
0
    /// <summary>
    /// Server-side only. Transfers control of a player object to the indicated connection.
    /// </summary>
    /// <param name="conn">The client's NetworkConnection. If logged out the playerlist will return an invalid connectedplayer</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>
    /// <param name="characterSettings">settings, ignored if transferring to an existing player body</param>
    /// <param name="willDestroyOldBody">if true, indicates the old body is going to be destroyed rather than pooled,
    /// thus we shouldn't send any network message which reference's the old body's ID since it won't exist.</param>
    private static void ServerTransferPlayer(NetworkConnection conn, GameObject newBody, GameObject oldBody,
                                             EVENT eventType, CharacterSettings characterSettings, bool willDestroyOldBody = false)
    {
        if (oldBody)
        {
            var oldPlayerNetworkActions = oldBody.GetComponent <PlayerNetworkActions>();
            if (oldPlayerNetworkActions)
            {
                oldPlayerNetworkActions.RpcBeforeBodyTransfer();
            }

            //no longer can observe their inventory
            oldBody.GetComponent <ItemStorage>()?.ServerRemoveObserverPlayer(oldBody);
        }

        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);
            if (oldBody)
            {
                NetworkServer.ReplacePlayerForConnection(new NetworkConnection("0.0.0.0"), oldBody);
            }
            //mirrorworkaround: only added setLocal/unsetlocal for workaround for https://github.com/vis2k/Mirror/issues/962
            TriggerEventMessage.Send(newBody, eventType, willDestroyOldBody ? null : oldBody, newBody);

            //can observe their new inventory
            newBody.GetComponent <ItemStorage>()?.ServerAddObserverPlayer(newBody);
        }

        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)
        {
            FollowCameraMessage.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 AddPlayer(ObjectBehaviour player)
 {
     containedPlayers.Add(player);
     SetContainerAndMakeInvisible(player);
     FollowCameraMessage.Send(player.gameObject, gameObject);
 }
Пример #14
0
    /// <summary>
    /// Server-side only. Transfers control of a player object to the indicated connection.
    /// </summary>
    /// <param name="conn">The client's NetworkConnection. If logged out the playerlist will return an invalid connectedplayer</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>
    /// <param name="characterSettings">settings, ignored if transferring to an existing player body</param>
    /// <param name="willDestroyOldBody">if true, indicates the old body is going to be destroyed rather than pooled,
    /// thus we shouldn't send any network message which reference's the old body's ID since it won't exist.</param>
    private static void ServerTransferPlayer(NetworkConnection conn, GameObject newBody, GameObject oldBody,
                                             EVENT eventType, CharacterSettings characterSettings, bool willDestroyOldBody = false)
    {
        if (oldBody)
        {
            var oldPlayerNetworkActions = oldBody.GetComponent <PlayerNetworkActions>();
            if (oldPlayerNetworkActions)
            {
                oldPlayerNetworkActions.RpcBeforeBodyTransfer();
            }

            //no longer can observe their inventory
            oldBody.GetComponent <ItemStorage>()?.ServerRemoveObserverPlayer(oldBody);
        }

        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);
            //NOTE: With mirror upgrade 04 Feb 2020, it appears we no longer need to do what has been
            //commented out below. Below appears to have been an attempt to give authority back to server
            //But it's implicitly given such authority by the ReplacePlayerForConnection call - that call
            //now removes authority for the player's old object
            // if (oldBody)
            // {
            //  NetworkServer.ReplacePlayerForConnection(new NetworkConnectionToClient(0), oldBody);
            // }
            TriggerEventMessage.Send(newBody, eventType);

            //can observe their new inventory
            newBody.GetComponent <ItemStorage>()?.ServerAddObserverPlayer(newBody);
        }

        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)
        {
            FollowCameraMessage.Send(newBody, playerObjectBehavior.parentContainer.gameObject);
        }

        if (characterSettings != null)
        {
            playerScript.characterSettings = characterSettings;
            playerScript.playerName        = characterSettings.Name;
            newBody.name = characterSettings.Name;
            var playerSprites = newBody.GetComponent <PlayerSprites>();
            if (playerSprites)
            {
                playerSprites.OnCharacterSettingsChange(characterSettings);
            }
        }
        var healthStateMonitor = newBody.GetComponent <HealthStateMonitor>();

        if (healthStateMonitor)
        {
            healthStateMonitor.ProcessClientUpdateRequest(newBody);
        }
    }
Пример #15
0
    /// <summary>
    /// Server-side only. Transfers control of a player object to the indicated connection.
    /// </summary>
    /// <param name="conn">The client's NetworkConnection. If logged out the playerlist will return an invalid connectedplayer</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>
    /// <param name="characterSettings">settings, ignored if transferring to an existing player body</param>
    /// <param name="occupation">occupation, ignored if transferring to an existing player body</param>
    private static void ServerTransferPlayer(NetworkConnection conn, GameObject newBody, GameObject oldBody,
                                             EVENT eventType, CharacterSettings characterSettings, Occupation occupation)
    {
        if (oldBody)
        {
            var oldPlayerNetworkActions = oldBody.GetComponent <PlayerNetworkActions>();
            if (oldPlayerNetworkActions)
            {
                oldPlayerNetworkActions.RpcBeforeBodyTransfer();
            }
            //no longer can observe their inventory
            oldBody.GetComponent <ItemStorage>()?.ServerRemoveObserverPlayer(oldBody);
        }

        var connectedPlayer = PlayerList.Instance.Get(conn);

        if (connectedPlayer == ConnectedPlayer.Invalid)         //this isn't an online player
        {
            Logger.LogErrorFormat("Cannot transfer player from {0} to {1}, networkconnection of player to transfer is not online.",
                                  Category.ItemSpawn, oldBody, newBody);
            return;
        }

        PlayerList.Instance.UpdatePlayer(conn, newBody);
        NetworkServer.ReplacePlayerForConnection(conn, newBody);
        if (oldBody)
        {
            NetworkServer.ReplacePlayerForConnection(new NetworkConnection("0.0.0.0"), oldBody);
        }
        TriggerEventMessage.Send(newBody, eventType);
        //can observe their new inventory
        newBody.GetComponent <ItemStorage>()?.ServerAddObserverPlayer(newBody);

        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)
        {
            FollowCameraMessage.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);
        }
    }