Exemplo n.º 1
0
        public bool FixStability(Vector3i playerPos)
        {
            if (start == Vector3i.zero || end == Vector3i.zero)
            {
                return(false);
            }
            if (selectionPrefab == null)
            {
                if (Copy() < 1)
                {
                    Log.Out("Could not Copy Selection");
                    return(false);
                }
            }

            int startX, startY, startZ;

            if (start.x < end.x)
            {
                startX = start.x;
            }
            else
            {
                startX = end.x;
            }

            if (start.y < end.y)
            {
                startY = start.y;
            }
            else
            {
                startY = end.y;
            }

            if (start.z < end.z)
            {
                startZ = start.z;
            }
            else
            {
                startZ = end.z;
            }

            int width  = selectionPrefab.size.x;
            int height = selectionPrefab.size.y;
            int length = selectionPrefab.size.z;

            StabilityInitializer stabInit = new StabilityInitializer(GameManager.Instance.World);

            for (int yOffset = -1; yOffset < height + 2; yOffset++)
            {
                for (int xOffset = -1; xOffset < width + 2; xOffset++)
                {
                    for (int zOffset = -1; zOffset < length + 2; zOffset++)
                    {
                        BlockValue block = GameManager.Instance.World.GetBlock(startX + xOffset, startY + yOffset, startZ + zOffset);
                        if (block.type != 0)
                        {
                            stabInit.BlockPlacedAt(startX + xOffset, startY + yOffset, startZ + zOffset, block);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool PasteSelection(Vector3i pos)
        {
            int width  = selectionPrefab.size.x;
            int height = selectionPrefab.size.y;
            int length = selectionPrefab.size.z;

            this.start = pos;
            this.end   = new Vector3i(pos.x + width, pos.y + height, pos.z + length);
            FixSelections();

            Dictionary <long, Chunk> usedChunks = new Dictionary <long, Chunk>();


            for (int xOffset = -1; xOffset < width + 2; xOffset++)
            {
                for (int zOffset = -1; zOffset < length + 2; zOffset++)
                {
                    for (int yOffset = -1; yOffset < height + 2; yOffset++)
                    {
                        if (GameManager.Instance.World.IsChunkAreaLoaded(pos.x + xOffset, pos.y + yOffset, pos.z + zOffset))
                        {
                            Chunk usedChunk = GameManager.Instance.World.GetChunkFromWorldPos(pos.x + xOffset, pos.y + yOffset, pos.z + zOffset) as Chunk;
                            if (!usedChunks.ContainsKey(usedChunk.Key))
                            {
                                usedChunks [usedChunk.Key] = usedChunk;
                            }
                        }
                        else
                        {
                            //SdtdConsole.Instance.Output ("[WorldTool Selections] Prefab will use chunks that are not Loaded.  Aborting Paste.");
                            return(false);
                        }
                    }
                }
            }

            Prefab prefabClone = selectionPrefab.Clone();

            System.Random rnd = new System.Random();
            for (int blockX = 0; blockX < width; blockX++)
            {
                for (int blockY = 0; blockY < height; blockY++)
                {
                    for (int blockZ = 0; blockZ < length; blockZ++)
                    {
                        BlockValue currentBV = prefabClone.GetBlock(blockX, blockY, blockZ);
                        if (currentBV.type != 0)
                        {
                            BlockValue lootBV = LootContainer.lootPlaceholderMap.Replace(currentBV, rnd);
                            if (lootBV.type != currentBV.type)
                            {
                                prefabClone.SetBlock(blockX, blockY, blockZ, lootBV);
                            }
                        }
                    }
                }
            }


            bool currentPhysicsState = GameManager.bPhysicsActive;

            GameManager.bPhysicsActive = false;
            if (selectionPrefab.yOffset != 0)
            {
                pos.y += selectionPrefab.yOffset;
            }

            if (this.YOffset != 0)
            {
                pos.y += this.YOffset;
            }

            if (this.rotations > 0)
            {
                prefabClone.RotateY(false, this.rotations);
            }

            prefabClone.CopyIntoLocal(GameManager.Instance.World.ChunkClusters[0], new Vector3i(pos.x, pos.y, pos.z), true, true);
            GameManager.bPhysicsActive = currentPhysicsState;

            //Thread.Sleep(50);

            Log.Out("PASTING PREFAB");
            Log.Out(pos.ToString());

            StabilityInitializer stabInit = new StabilityInitializer(GameManager.Instance.World);

            for (int yOffset = -1; yOffset < height + 2; yOffset++)
            {
                for (int xOffset = -1; xOffset < width + 2; xOffset++)
                {
                    for (int zOffset = -1; zOffset < length + 2; zOffset++)
                    {
                        BlockValue block = GameManager.Instance.World.GetBlock(pos.x + xOffset, yOffset, pos.z + zOffset);
                        if (block.type != 0)
                        {
                            stabInit.BlockPlacedAt(pos.x + xOffset, pos.y + yOffset, pos.z + zOffset, block);
                        }
                    }
                }
            }

            Dictionary <String, List <Chunk> > playerChunksToReload = new Dictionary <String, List <Chunk> >();

            foreach (Chunk currentChunk in usedChunks.Values)
            {
                //currentChunk.RepairDensities ();
                foreach (string playerSteamId in GameManager.Instance.persistentPlayers.Players.Keys)
                {
                    ClientInfo connectedPlayer = ConsoleHelper.ParseParamIdOrName(playerSteamId);
                    //TODO: for efficieny, we should probably add a check to see if the player is in range
                    if (connectedPlayer != null)
                    {
                        List <Chunk> playerChunks;

                        if (!playerChunksToReload.ContainsKey(playerSteamId))
                        {
                            playerChunks = new List <Chunk> ();
                        }
                        else
                        {
                            playerChunks = playerChunksToReload [playerSteamId];
                        }

                        playerChunks.Add(currentChunk);
                        playerChunksToReload.Remove(playerSteamId);
                        playerChunksToReload.Add(playerSteamId, playerChunks);
                    }
                }
            }

            //send chunk remove messages
            foreach (string playerSteamId in playerChunksToReload.Keys)
            {
                ClientInfo connectedPlayer = ConsoleHelper.ParseParamIdOrName(playerSteamId);

                List <Chunk> playerChunks = playerChunksToReload [playerSteamId];
                if (playerChunks != null && playerChunks.Count > 0)
                {
                    foreach (Chunk currentChunk in playerChunks)
                    {
                        connectedPlayer.SendPackage(new NetPackageChunkRemove(currentChunk.Key));
                    }
                }
            }

            //send chunk add messages
            foreach (string playerSteamId in playerChunksToReload.Keys)
            {
                ClientInfo connectedPlayer = ConsoleHelper.ParseParamIdOrName(playerSteamId);

                List <Chunk> playerChunks = playerChunksToReload [playerSteamId];
                if (playerChunks != null && playerChunks.Count > 0)
                {
                    foreach (Chunk currentChunk in playerChunks)
                    {
                        connectedPlayer.SendPackage(new NetPackageChunk(currentChunk));
                    }
                }
            }

            return(true);
        }