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); } }
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 baseDoorID (reason why the doorID has to be a multiple of 10, for this script to properly work) int baseDoorID = ((int)currentBlock / 10) * 10; int offset = (int)currentBlock - baseDoorID; //call ToggleDoors function with variables ToggleDoor(chunk, baseDoorID, offset, x, y, z); }
public static bool FindCustomSpecialBlockByOffSet(Point3D sourceLocalPos, int xOffset, int yOffset, int zOffset, uint blockID, IChunk Chunk, Dictionary <Point3D, IChunk> ChunkDictionary, out KeyValuePair <Point3D, IChunk> SpecialBlock) { SpecialBlock = new KeyValuePair <Point3D, IChunk>(); Point3D tmpFakeGlobalPos = new Point3D( (int)Chunk.Position.X + sourceLocalPos.X + xOffset, (int)Chunk.Position.Y + sourceLocalPos.Y + yOffset, (int)Chunk.Position.Z + sourceLocalPos.Z + zOffset ); Point3D staticChunkKey = _Utils.GetChunkKeyFromFakeGlobalPos(tmpFakeGlobalPos.ToDoubleVector3); if (!ChunkDictionary.ContainsKey(staticChunkKey)) { return(false); } IChunk tmpChunk = ChunkDictionary[staticChunkKey]; Point3D tmpFakeLocalPos = new Point3D( tmpFakeGlobalPos.X - (int)tmpChunk.Position.X, tmpFakeGlobalPos.Y - (int)tmpChunk.Position.Y, tmpFakeGlobalPos.Z - (int)tmpChunk.Position.Z ); ushort targetBlockID = new ushort(); targetBlockID = tmpChunk.Blocks[tmpChunk.GetBlockIndex(tmpFakeLocalPos.X, tmpFakeLocalPos.Y, tmpFakeLocalPos.Z)]; if ((targetBlockID) == (ushort)blockID) { SpecialBlock = new KeyValuePair <Point3D, IChunk>(tmpFakeLocalPos, tmpChunk); return(true); } else { return(false); } }
public static bool GetBlockIdAtFakeGlobalPos(Dictionary <Point3D, IChunk> ChunkDictionary, Point3D fakeGlobalPos, out ushort blockID) { blockID = (ushort)0; Point3D staticChunkKey = _Utils.GetChunkKeyFromFakeGlobalPos(fakeGlobalPos.ToDoubleVector3); int x1 = fakeGlobalPos.X - staticChunkKey.X; int y1 = fakeGlobalPos.Y - staticChunkKey.Y; int z1 = fakeGlobalPos.Z - staticChunkKey.Z; if (!ChunkDictionary.ContainsKey(staticChunkKey)) { return(false); } IChunk chunk = ChunkDictionary[staticChunkKey]; blockID = chunk.Blocks[chunk.GetBlockIndex(x1, y1, z1)]; return(true); }
public static bool FindCustomSpecialBlockByOffSet(Point3D sourceLocalPos, int xOffset, int yOffset, int zOffset, uint blockID, IChunk Chunk, Dictionary <Point3D, IChunk> ChunkDictionary, out KeyValuePair <Point3D, IChunk> SpecialBlock) { //Console.WriteLine("Inside FindByOffset."); SpecialBlock = new KeyValuePair <Point3D, IChunk>(); Point3D tmpFakeGlobalPos = new Point3D( (int)Chunk.Position.X + sourceLocalPos.X + xOffset, (int)Chunk.Position.Y + sourceLocalPos.Y + yOffset, (int)Chunk.Position.Z + sourceLocalPos.Z + zOffset ); Point3D staticChunkKey = _Utils.GetChunkKeyFromFakeGlobalPos(tmpFakeGlobalPos.ToDoubleVector3); if (!ChunkDictionary.ContainsKey(staticChunkKey)) { return(false); } IChunk tmpChunk = ChunkDictionary[staticChunkKey]; Point3D tmpFakeLocalPos = new Point3D( tmpFakeGlobalPos.X - (int)tmpChunk.Position.X, tmpFakeGlobalPos.Y - (int)tmpChunk.Position.Y, tmpFakeGlobalPos.Z - (int)tmpChunk.Position.Z ); //Console.WriteLine("got fakelocalpos as " + tmpFakeLocalPos.ToString()); ushort targetBlockID = new ushort(); targetBlockID = tmpChunk.Blocks[tmpChunk.GetBlockIndex(tmpFakeLocalPos.X, tmpFakeLocalPos.Y, tmpFakeLocalPos.Z)]; //Console.WriteLine("got targetBlockID as " + ((int)targetBlockID).ToString()); if ((targetBlockID) == (ushort)blockID) { //Console.WriteLine("Found Teleporter, returning as keyvaluepair"); SpecialBlock = new KeyValuePair <Point3D, IChunk>(tmpFakeLocalPos, tmpChunk); return(true); } else { //Console.WriteLine("Found No Teleporter at Offset, returning(IN)"); return(false); } }
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 as IActor; IGameServer Server = actor.State as IGameServer; IBiomeManager biomeManager = Server.Biomes; var SystemsCollection = biomeManager.GetSystems(); uint currentSystemID = actor.InstanceID; IBiomeSystem currentSystem; SystemsCollection.TryGetValue(currentSystemID, out currentSystem); this.ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(currentSystem); if (!chunk.IsStaticChunk) { Server.ChatManager.SendActorMessage("A Teleporter cannot be used on a ship.", actor); } else 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); } else { //save global position of Block which has just been clicked on Point3D posA = new Point3D((int)chunk.Position.X + x, (int)chunk.Position.Y + y, (int)chunk.Position.Z + z); //if there already is a stored Variable .. if (actor.SessionVariables.ContainsKey("Teleporter")) { // .. get the saved point (a previously clicked teleporter) Point3D posB = (Point3D)actor.SessionVariables["Teleporter"]; // and delete it from the sessionVariables, we have it in posA and posB now actor.SessionVariables.Remove("Teleporter"); // obvious check if (posA == posB) { Server.ChatManager.SendActorMessage("A Teleporter can not link with itself.", actor); } //if they differ we have two points: The two Teleporters, the player wants to link! else { ushort blockID; //check if previously clicked Teleporter still exists if (!SNScriptUtils._Utils.GetBlockIdAtFakeGlobalPos(this.ChunkDictionary, posB, out blockID) || (int)blockID != 7100) { if (debug) { Console.WriteLine("blockID=" + ((int)blockID).ToString()); } Server.ChatManager.SendActorMessage("The previous Teleporter you clicked has been destroyed", actor); } else { //now we can link the two teleporters //get the ChunkKey of the Chunk where the SourceTeleporter is in Point3D staticChunkKey = SNScriptUtils._Utils.GetChunkKeyFromFakeGlobalPos(posB.ToDoubleVector3); //Get SourceChunk Object IChunk sourceChunk = this.ChunkDictionary[staticChunkKey]; //Get all SpecialBlocks in the SourceChunk (our Teleporter is in there) List <ISpecialBlock> specialblockslist = sourceChunk.GetSpecialBlocks(); //calculate position of SourceTeleporter within its Chunk Point3D posSourceTelePorter = new Point3D(posB.X - staticChunkKey.X, posB.Y - staticChunkKey.Y, posB.Z - staticChunkKey.Z); //get the SourceTeleporter by the Position we just calculated ISpecialBlock SpecialBlock = specialblockslist.First(item => (item is Teleporter) && ((item as Teleporter).Position == posSourceTelePorter)); //Now we have the previously clicked Teleporter as accesible Object Teleporter sourceTeleporter = SpecialBlock as Teleporter; //Set the Teleporter, the SourceTeleporter is linked to sourceTeleporter.SetTargetTeleporter(posA); //Inform the Player what happened: The two Teleporters are linked Server.ChatManager.SendActorMessage("You can now Teleport from the first Teleporter to the one you clicked last.", actor); } } } else { actor.SessionVariables.Add("Teleporter", (object)posA); Server.ChatManager.SendActorMessage("Right click a second Teleporter to link it with this one.", actor); } } //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]; }