예제 #1
0
        /// <summary>
        /// Spawn blob player and gib old body!
        /// </summary>
        private void FormBlob()
        {
            UpdateManager.Remove(CallbackType.PERIODIC_UPDATE, PeriodicUpdate);

            var playerScript = gameObject.GetComponent <PlayerScript>();

            var bound = MatrixManager.MainStationMatrix.LocalBounds;

            //To ensure that it has to be station matrix
            var matrixInfo = GetComponent <RegisterTile>().Matrix.MatrixInfo;

            //Teleport user to random location on station if outside radius of 600 or on a space tile
            if (((gameObject.AssumedWorldPosServer() - MatrixManager.MainStationMatrix.GameObject.AssumedWorldPosServer())
                 .magnitude > 600f) || MatrixManager.IsSpaceAt(gameObject.GetComponent <PlayerSync>().ServerPosition, true, matrixInfo) || matrixInfo != MatrixManager.MainStationMatrix)
            {
                Vector3 position = new Vector3(Random.Range(bound.xMin, bound.xMax), Random.Range(bound.yMin, bound.yMax), 0);
                while (MatrixManager.IsSpaceAt(Vector3Int.FloorToInt(position), true, matrixInfo) || MatrixManager.IsWallAt(Vector3Int.FloorToInt(position), true))
                {
                    position = new Vector3(Random.Range(bound.xMin, bound.xMax), Random.Range(bound.yMin, bound.yMax), 0);
                }

                gameObject.GetComponent <PlayerSync>().SetPosition(position, true);
            }

            var spawnResult = Spawn.ServerPrefab(AntagManager.Instance.blobPlayerViewer, gameObject.RegisterTile().WorldPositionServer, gameObject.transform.parent);

            if (spawnResult.Successful == false)
            {
                Logger.LogError("Failed to spawn blob!", Category.Blob);
                Destroy(this);
                return;
            }

            if (playerScript.mind == null)
            {
                //If this is true, block blob spawning
                _ = Despawn.ServerSingle(spawnResult.GameObject);
                Destroy(this);
                return;
            }

            spawnResult.GameObject.GetComponent <PlayerScript>().mind = playerScript.mind;

            var connection = GetComponent <NetworkIdentity>().connectionToClient;

            PlayerSpawn.ServerTransferPlayerToNewBody(connection, spawnResult.GameObject, playerScript.mind.GetCurrentMob(), Event.BlobSpawned, playerScript.characterSettings);

            playerScript.mind = null;

            //Start the blob control script
            spawnResult.GameObject.GetComponent <BlobPlayer>().BlobStart();

            Chat.AddActionMsgToChat(spawnResult.GameObject, $"<color=#FF151F>You explode from your {bodyPart}, a new being has been born.</color>",
                                    $"<color=#FF151F>{gameObject.ExpensiveName()} explodes into a pile of mush.</color>");

            gameObject.GetComponent <LivingHealthMasterBase>().Gib();

            Destroy(this);
        }
예제 #2
0
        /// <summary>
        /// Spawn blob player and gib old body!
        /// </summary>
        private void FormBlob()
        {
            var playerScript = gameObject.GetComponent <PlayerScript>();

            if (playerScript.IsDeadOrGhost)
            {
                return;
            }

            var bound = MatrixManager.MainStationMatrix.Bounds;

            //Teleport user to random location on station if outside radius of 600 or on a space tile
            if (((gameObject.AssumedWorldPosServer() - MatrixManager.MainStationMatrix.GameObject.AssumedWorldPosServer())
                 .magnitude > 600f) || MatrixManager.IsSpaceAt(gameObject.GetComponent <PlayerSync>().ServerPosition, true))
            {
                Vector3 position = new Vector3(Random.Range(bound.xMin, bound.xMax), Random.Range(bound.yMin, bound.yMax), 0);
                while (MatrixManager.IsSpaceAt(Vector3Int.FloorToInt(position), true) || MatrixManager.IsWallAtAnyMatrix(Vector3Int.FloorToInt(position), true))
                {
                    position = new Vector3(Random.Range(bound.xMin, bound.xMax), Random.Range(bound.yMin, bound.yMax), 0);
                }

                gameObject.GetComponent <PlayerSync>().SetPosition(position, true);
            }

            var spawnResult = Spawn.ServerPrefab(AntagManager.Instance.blobPlayerViewer, gameObject.GetComponent <PlayerSync>().ServerPosition, gameObject.transform.parent);

            if (!spawnResult.Successful)
            {
                Debug.LogError("Failed to spawn blob!");
                return;
            }

            spawnResult.GameObject.GetComponent <PlayerScript>().mind = playerScript.mind;

            playerScript.mind = null;

            PlayerSpawn.ServerTransferPlayerToNewBody(connectionToClient, spawnResult.GameObject, gameObject, EVENT.BlobSpawned, playerScript.characterSettings);

            //Start the blob control script
            spawnResult.GameObject.GetComponent <BlobPlayer>().BlobStart();

            gameObject.GetComponent <LivingHealthBehaviour>().Harvest();

            UpdateManager.Remove(CallbackType.PERIODIC_UPDATE, PeriodicUpdate);
            Destroy(this);
        }