public void Use(IActor targetActor) { //get variables IChunk chunk = this.Chunk; int x = this.Position.X; int y = this.Position.Y; int z = this.Position.Z; IActor actor = targetActor; //permission check, is the Player allowed to open the door? Chunk castedChunk = chunk as Chunk; string nationName = castedChunk.NationOwner; if ((!string.IsNullOrEmpty(nationName) && (actor.Nation != nationName))) { return; } //get the index for the Block array from the given x, y and z int index = chunk.GetBlockIndex(x, y, z); //get the specific Block data by its index ushort currentBlock = chunk.Blocks[index]; if (IsOdd((int)currentBlock)) { chunk.ChangeBlock((ushort)(currentBlock - 1), x, y, z); } else { chunk.ChangeBlock((ushort)(currentBlock + 1), x, y, z); } }
//BlocksToBePlacedInSystem = ChunkPos -> [localpos, BlockID] public static bool PlaceBlocksInSystem(Dictionary <Point3D, Dictionary <Point3D, ushort> > BlocksToBePlacedInSystem, IBiomeSystem System, bool replacemode, ushort replaceThisBlockID) { Dictionary <Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(System); foreach (KeyValuePair <Point3D, Dictionary <Point3D, ushort> > BlockToBePlacedInChunk in BlocksToBePlacedInSystem) { bool chunkNeedsCleanup = false; IChunk workChunk = null as IChunk; if (ChunkDictionary.ContainsKey(BlockToBePlacedInChunk.Key)) {//Chunk exists already, just retrieve it from the ChunkDictionary workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3); } else {//The Chunk does not exist, it has to be created first ushort[] tmpBlock = new ushort[32768]; tmpBlock[0] = 4; System.CreateLandChunk(tmpBlock, BlockToBePlacedInChunk.Key.ToDoubleVector3); workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3); chunkNeedsCleanup = true; } List <Point3D> replacePoints = new List <Point3D>(); if (replacemode) { for (int i = 0; i < workChunk.Blocks.Count(); i++) { if (replaceThisBlockID == workChunk.Blocks[i]) { replacePoints.Add(_Utils.getLocalPosFromBlockIndex(i)); } } } //Place all Blocks in the Chunk foreach (KeyValuePair <Point3D, ushort> BlocksInChunk in BlockToBePlacedInChunk.Value) { if (replacemode && replacePoints.Contains(BlocksInChunk.Key)) { workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true); } if (!replacemode) { workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true); } } if (chunkNeedsCleanup) { ushort tmpBlockID = 4; ushort blockID; blockID = workChunk.Blocks[0]; if (blockID == tmpBlockID) { workChunk.ChangeBlock(0, 0, 0, 0, true, true); } } } return(true); }
//BlocksToBePlacedInSystem = ChunkPos -> [localpos, BlockID] public static bool PlaceBlocksInSystem(Dictionary <Point3D, Dictionary <Point3D, ushort> > BlocksToBePlacedInSystem, IBiomeSystem System) { List <IChunk> newChunkList = new List <IChunk>(); Dictionary <Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(System); foreach (KeyValuePair <Point3D, Dictionary <Point3D, ushort> > BlockToBePlacedInChunk in BlocksToBePlacedInSystem) { bool chunkNeedsCleanup = false; IChunk workChunk = null as IChunk; if (ChunkDictionary.ContainsKey(BlockToBePlacedInChunk.Key)) {//Chunk exists already, just retrieve it from the ChunkDictionary workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3); } else {//The Chunk does not exist, it has to be created first ushort[] tmpBlock = new ushort[32768]; tmpBlock[32767] = 4; System.CreateLandChunk(tmpBlock, BlockToBePlacedInChunk.Key.ToDoubleVector3); workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3); chunkNeedsCleanup = true; } //Place all Blocks in the Chunk foreach (KeyValuePair <Point3D, ushort> BlocksInChunk in BlockToBePlacedInChunk.Value) { workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true); } if (chunkNeedsCleanup) { ushort tmpBlockID = 4; ushort blockID; blockID = workChunk.Blocks[32767]; if (blockID == tmpBlockID) { workChunk.ChangeBlock(0, 31, 31, 31, true, true); } newChunkList.Add(workChunk); } } return(true); }
public void Use(IActor targetActor) { //get variables IChunk chunk = this.Chunk; int x = this.Position.X; int y = this.Position.Y; int z = this.Position.Z; IActor actor = targetActor; //permission check, is the Player allowed to open the door? Chunk castedChunk = chunk as Chunk; string nationName = castedChunk.NationOwner; if ((!string.IsNullOrEmpty(nationName) && (actor.Nation != nationName))) { return; } //get the index for the Block array from the given x, y and z int index = chunk.GetBlockIndex(x, y, z); //get the specific Block data by its index ushort currentBlock = chunk.Blocks[index]; //get baseHatchID (reason why the hatchID has to be a multiple of 10, for this script to properly work) int baseHatchID = ((int)currentBlock / 10) * 10; int offset = (int)currentBlock - baseHatchID; if (0 <= offset && offset <= 3) { chunk.ChangeBlock((ushort)(currentBlock + 4), x, y, z); } if (4 <= offset && offset <= 7) { chunk.ChangeBlock((ushort)(currentBlock - 4), x, y, z); } }
private void ToggleDoor(IChunk chunk, int baseDoorID, int offset, int x, int y, int z) { switch (offset) { case 0: chunk.ChangeBlock((ushort)(baseDoorID + 1), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 5), x, y + 1, z); break; case 1: chunk.ChangeBlock((ushort)(baseDoorID + 0), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 4), x, y + 1, z); break; case 2: chunk.ChangeBlock((ushort)(baseDoorID + 3), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 7), x, y + 1, z); break; case 3: chunk.ChangeBlock((ushort)(baseDoorID + 2), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 6), x, y + 1, z); break; case 4: chunk.ChangeBlock((ushort)(baseDoorID + 5), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 1), x, y - 1, z); break; case 5: chunk.ChangeBlock((ushort)(baseDoorID + 4), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 0), x, y - 1, z); break; case 6: chunk.ChangeBlock((ushort)(baseDoorID + 7), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 3), x, y - 1, z); break; case 7: chunk.ChangeBlock((ushort)(baseDoorID + 6), x, y, z); chunk.ChangeBlock((ushort)(baseDoorID + 2), x, y - 1, z); break; } }