public override bool Use(IActor actor, string message, string[] parameters) { if (!_Utils.checkParameterCount(parameters, 1, actor)) { return(false); } ushort blockID = ushort.Parse(parameters[1]); IBiomeSystem checkSystem = Server.Biomes.GetSystems()[actor.InstanceID]; IChunk checkChunk = checkSystem.ChunkCollection[0]; if (!_Utils.blockTypeExists(checkChunk, blockID, actor)) { return(false); } Point3D pos1 = new Point3D(); Point3D pos2 = new Point3D(); if (!_Utils.checkStoredPositions(actor, out pos1, out pos2)) { return(false); } //calculate absolute distance (absdiff) and direction (valinc) to get from Point1 to Point2 int absdiffx; int valincx; int absdiffy; int valincy; int absdiffz; int valincz; _Utils.calcAbsDiffAndValinc(pos1.X, pos2.X, out absdiffx, out valincx); _Utils.calcAbsDiffAndValinc(pos1.Y, pos2.Y, out absdiffy, out valincy); _Utils.calcAbsDiffAndValinc(pos1.Z, pos2.Z, out absdiffz, out valincz); Dictionary <Point3D, ushort> fakeGlobalPosAndBlockID = new Dictionary <Point3D, ushort>(); for (int y = 0; y <= (absdiffy); y++) { for (int z = 0; z <= (absdiffz); z++) { for (int x = 0; x <= (absdiffx); x++) { //Dictionary contains <fakeGlobalPos, blockID> fakeGlobalPosAndBlockID.Add(new Point3D((pos1.X + (x * valincx)), (pos1.Y + (y * valincy)), (pos1.Z + (z * valincz))), blockID); } } } Dictionary <Point3D, Dictionary <Point3D, ushort> > BlocksToBePlacedInSystem = new Dictionary <Point3D, Dictionary <Point3D, ushort> >(); if (!_Utils.SplitFakeGlobalPosBlocklistIntoChunksAndLocalPos(fakeGlobalPosAndBlockID, out BlocksToBePlacedInSystem)) { return(false); } if (_Utils.PlaceBlocksInSystem(BlocksToBePlacedInSystem, checkSystem)) { return(true); } else { return(false); } }
public static bool getChunkObjFromFakeGlobalPos(Point3D fakeGlobalPos, IBiomeSystem System, out IChunk Chunk) { Chunk = new Object() as IChunk; //Get ChunkDictionary Dictionary <Point3D, IChunk> ChunkDictionary = _Utils.CreateChunkDictionary(System); //call base function and return results return(_Utils.getChunkObjFromFakeGlobalPos(fakeGlobalPos, ChunkDictionary, out Chunk)); }
//Create a Dictionary of all the Chunk in a System with their root coords public static Dictionary <Point3D, IChunk> CreateChunkDictionary(IBiomeSystem currentSystem) { Dictionary <Point3D, IChunk> Dictionary = new Dictionary <Point3D, IChunk>(); for (int i = 0; i < currentSystem.ChunkCollection.Count; i++) { if (currentSystem.ChunkCollection[i].IsStaticChunk) { Dictionary.Add(Point3D.ConvertDoubleVector3(currentSystem.ChunkCollection[i].Position), currentSystem.ChunkCollection[i]); } } return(Dictionary); }
public static Boolean storeAreaAsSchematic(IActor actor, String schematicName, Boolean overwriteFile) { Point3D fakeGlobalPos1 = new Point3D(); Point3D fakeGlobalPos2 = new Point3D(); if (!_Utils.checkStoredPositions(actor, out fakeGlobalPos1, out fakeGlobalPos2)) { return(false); } IBiomeSystem system = ((IGameServer)actor.State).Biomes.GetSystems()[actor.InstanceID]; _Utils.storeAreaAsSchematic(fakeGlobalPos1, fakeGlobalPos2, system, schematicName, overwriteFile, null); return(true); }
public void Use(IActor actor) { //set up needed Variables IGameServer Server = actor.State as IGameServer; IBiomeSystem currentSystem = ((IGameServer)actor.State).Biomes.GetSystems()[actor.InstanceID]; //Permission Check, is the Player allowed to use the Teleporter? if (currentSystem.Nation != string.Empty && currentSystem.Nation != actor.Nation) { Server.ChatManager.SendActorMessage("You must be in the Nation that claimed this System to use the Teleporter.", actor); return; } //Set up ChunkDictionary so we can access the Chunks in System (We need the Chunk to Teleport the player to later) Dictionary <Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(currentSystem); //create offset List (the 4 Positions around our Activator where we expect at least one Teleporter) List <Point3D> offsetList = new List <Point3D>(); offsetList.Add(new Point3D(0, -1, -1)); offsetList.Add(new Point3D(0, -1, 1)); offsetList.Add(new Point3D(1, -1, 0)); offsetList.Add(new Point3D(-1, -1, 0)); List <Object[, ]> SpecialBlockList = null; Teleporter nearbyTeleporter = new Object() as Teleporter; //Get List of Teleporters in vicinity to the Activator based on offsetList (expected Teleporter locations) if (SNScriptUtils._Utils.FindCustomSpecialBlocksAround(this.Position, this.Chunk, offsetList, (uint)7100, ChunkDictionary, out SpecialBlockList)) { //just take the first one found for now IChunk tmpChunk = SpecialBlockList[0][0, 1] as IChunk; Point3D TeleporterLocalPos = (Point3D)SpecialBlockList[0][0, 0]; ISpecialBlock targetSpecialBlock = tmpChunk.GetSpecialBlocks().FirstOrDefault(item => (item is Teleporter) && ((item as Teleporter).Position == TeleporterLocalPos)); nearbyTeleporter = targetSpecialBlock as Teleporter; } else { Server.ChatManager.SendActorMessage("There is no Teleporter around the Activator!", actor); return; } //Check if Player is standing on the Teleporter right now Point3D teleporterPadFakeGlobalPos = new Point3D( nearbyTeleporter.Position.X + (int)((IChunk)SpecialBlockList[0][0, 1]).Position.X, nearbyTeleporter.Position.Y + (int)((IChunk)SpecialBlockList[0][0, 1]).Position.Y + 1, nearbyTeleporter.Position.Z + (int)((IChunk)SpecialBlockList[0][0, 1]).Position.Z ); Point3D actorPos = _Utils.GetActorFakeGlobalPos(actor, new Point3D(0, -1, 0)); if (teleporterPadFakeGlobalPos != actorPos) { Server.ChatManager.SendActorMessage("You have to stand on the Teleporter platform to use the Teleporter!", actor); return; } //Get TargetTeleporterPos Point3D TargetTeleporterFakeGlobalPos = nearbyTeleporter.GetTargetTeleporter(); //Check if TargetTeleporter exists //Get Chunk where the TargetTeleporter is in IChunk targetChunk = new Object() as IChunk; if (SNScriptUtils._Utils.getChunkObjFromFakeGlobalPos(TargetTeleporterFakeGlobalPos, ChunkDictionary, out targetChunk)) { Point3D TargetTeleporterLocalPos = new Point3D( TargetTeleporterFakeGlobalPos.X - (int)targetChunk.Position.X, TargetTeleporterFakeGlobalPos.Y - (int)targetChunk.Position.Y, TargetTeleporterFakeGlobalPos.Z - (int)targetChunk.Position.Z ); ushort targetBlockID = new ushort(); targetBlockID = targetChunk.Blocks[targetChunk.GetBlockIndex(TargetTeleporterLocalPos.X, TargetTeleporterLocalPos.Y, TargetTeleporterLocalPos.Z)]; if ((targetBlockID) == (ushort)7100) //TargetTeleporter still exists! { ISpecialBlock targetSpecialBlock = targetChunk.GetSpecialBlocks().FirstOrDefault(item => (item is Teleporter) && ((item as Teleporter).Position == TargetTeleporterLocalPos)); Teleporter targetTeleporter = targetSpecialBlock as Teleporter; //Teleport Player to TargetTeleporterPos + Offset (2.1 Blocks Up (Y)) or he'd get stuck in the Teleporter double playerTeleportLocalPosY = (double)targetTeleporter.Position.Y + 2.1; DoubleVector3 playerTeleportLocalPos = new DoubleVector3((double)targetTeleporter.Position.X, playerTeleportLocalPosY, (double)targetTeleporter.Position.Z); actor.SetLocalPosition(targetChunk.ID, targetChunk.World, playerTeleportLocalPos); } else { if (debug) { Console.WriteLine("TargetTeleporter does not exist anymore, other block ID found: " + ((int)targetBlockID).ToString()); } ; if (debug) { Console.WriteLine("I've been looking at Position: " + TargetTeleporterLocalPos.ToString()); } ; Server.ChatManager.SendActorMessage("The Teleporter you wanted to teleport to, does not exist anymore!", actor); nearbyTeleporter.DeleteTargetTeleporter(); return; } } else { if (debug) { Console.WriteLine("Chunk does not exist! Pos: " + TargetTeleporterFakeGlobalPos.ToString()); } ; Server.ChatManager.SendActorMessage("The Teleporter you wanted to teleport to, does not exist anymore!", actor); nearbyTeleporter.DeleteTargetTeleporter(); return; } }
public override bool Use(IActor actor, string message, string[] parameters) { ushort replaceThisBlockID = new ushort(); ushort newBlockID = new ushort(); bool replaceAllSolids = false; if (parameters.Length == 3) { replaceThisBlockID = ushort.Parse(parameters[1]); newBlockID = ushort.Parse(parameters[2]); } if (parameters.Length == 2) { replaceAllSolids = true; replaceThisBlockID = 0; newBlockID = ushort.Parse(parameters[1]); } if (!_Utils.checkParameterCount(parameters, 2, actor)) { return(false); } IBiomeSystem checkSystem = Server.Biomes.GetSystems()[actor.InstanceID]; IChunk checkChunk = checkSystem.ChunkCollection[0]; if (!_Utils.blockTypeExists(checkChunk, replaceThisBlockID, actor)) { return(false); } if (!_Utils.blockTypeExists(checkChunk, newBlockID, actor)) { return(false); } Point3D pos1 = new Point3D(); Point3D pos2 = new Point3D(); if (!_Utils.checkStoredPositions(actor, out pos1, out pos2)) { return(false); } Point3D posOrigin = _Utils.calcCuboidOrigin(pos1, pos2); Point3D cuboidDimensions = _Utils.calcCuboidDimensions(pos1, pos2); Dictionary <Point3D, IChunk> chunkDictionary = _Utils.CreateChunkDictionary(checkSystem); Dictionary <Point3D, ushort> fakeGlobalPosAndBlockID = new Dictionary <Point3D, ushort>(); ushort blockID; Point3D tmpPoint; for (int y = 0; y < (cuboidDimensions.Y); y++) { for (int z = 0; z < (cuboidDimensions.Z); z++) { for (int x = 0; x < (cuboidDimensions.X); x++) { tmpPoint = new Point3D(posOrigin.X + x, posOrigin.Y + y, posOrigin.Z + z); _Utils.GetBlockIdAtFakeGlobalPos(chunkDictionary, tmpPoint, out blockID); if ((blockID == replaceThisBlockID) && !replaceAllSolids) { fakeGlobalPosAndBlockID.Add(tmpPoint, newBlockID); } if ((blockID != 0) && replaceAllSolids) { fakeGlobalPosAndBlockID.Add(tmpPoint, newBlockID); } } } } Dictionary <Point3D, Dictionary <Point3D, ushort> > BlocksToBePlacedInSystem = new Dictionary <Point3D, Dictionary <Point3D, ushort> >(); if (!_Utils.SplitFakeGlobalPosBlocklistIntoChunksAndLocalPos(fakeGlobalPosAndBlockID, out BlocksToBePlacedInSystem)) { return(false); } if (_Utils.PlaceBlocksInSystem(BlocksToBePlacedInSystem, checkSystem)) { return(true); } else { return(false); } }
//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 static Boolean storeAreaAsSchematic(Point3D fakeGlobalPos1, Point3D fakeGlobalPos2, IBiomeSystem system, String schematicName, Boolean overwriteFile, IActor actorForNotifications) { Point3D posOrigin = _Utils.calcCuboidOrigin(fakeGlobalPos1, fakeGlobalPos2); Point3D cuboidDimensions = _Utils.calcCuboidDimensions(fakeGlobalPos1, fakeGlobalPos2); String sanitizedFileName = _Utils.sanitizeString(schematicName); Dictionary <Point3D, IChunk> chunkDictionary = CreateChunkDictionary(system); int[] tileArray = new int[cuboidDimensions.X * cuboidDimensions.Y * cuboidDimensions.Z]; ushort blockID; int i = 0; for (int y = 0; y < (cuboidDimensions.Y); y++) { for (int z = 0; z < (cuboidDimensions.Z); z++) { for (int x = 0; x < (cuboidDimensions.X); x++) { GetBlockIdAtFakeGlobalPos(chunkDictionary, new Point3D(posOrigin.X + x, posOrigin.Y + y, posOrigin.Z + z), out blockID); tileArray[i] = blockID; i++; } } } var schematic = new NbtCompound("tmpSchematic"); schematic.Add(new NbtString("SNEdit", "true")); schematic.Add(new NbtInt("Height", cuboidDimensions.Y)); schematic.Add(new NbtInt("Length", cuboidDimensions.Z)); schematic.Add(new NbtInt("Width", cuboidDimensions.X)); schematic.Add(new NbtIntArray("Tiles", tileArray)); var serverFile = new NbtFile(schematic); serverFile.SaveToFile(SNEditSettings.SchematicDir + sanitizedFileName + ".schematic", NbtCompression.None); return(true); }
//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; }
public static bool getChunkObjFromFakeGlobalPos(Point3D fakeGlobalPos, IBiomeSystem System, out IChunk Chunk) { Chunk = new Object() as IChunk; //Get ChunkDictionary Dictionary<Point3D, IChunk> ChunkDictionary = _Utils.CreateChunkDictionary(System); //call base function and return results return _Utils.getChunkObjFromFakeGlobalPos(fakeGlobalPos, ChunkDictionary, out Chunk); }
//Create a Dictionary of all the Chunk in a System with their root coords public static Dictionary<Point3D, IChunk> CreateChunkDictionary(IBiomeSystem currentSystem) { Dictionary<Point3D, IChunk> Dictionary = new Dictionary<Point3D, IChunk>(); for (int i = 0; i < currentSystem.ChunkCollection.Count; i++) { if (currentSystem.ChunkCollection[i].IsStaticChunk) { Dictionary.Add(Point3D.ConvertDoubleVector3(currentSystem.ChunkCollection[i].Position), currentSystem.ChunkCollection[i]); } } return Dictionary; }