public Map Load([NotNull] string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenRead(fileName)) { using (GZipStream gs = new GZipStream(mapStream, CompressionMode.Decompress)) { Map map = LoadHeaderInternal(gs); if (!map.ValidateHeader()) { throw new MapFormatException("One or more of the map dimensions are invalid."); } // Read in the map data map.Blocks = new byte[map.Volume]; MapUtility.ReadAll(gs, map.Blocks); map.ConvertBlockTypes(Mapping); return(map); } } }
static Map LoadHeaderInternal([NotNull] Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } BinaryReader reader = new BinaryReader(stream); // Read in the magic number if (reader.ReadUInt32() != Identifier) { throw new MapFormatException(); } // Read in the map dimesions int width = reader.ReadInt16(); int length = reader.ReadInt16(); int height = reader.ReadInt16(); // ReSharper disable UseObjectOrCollectionInitializer Map map = new Map(null, width, length, height, false); // ReSharper restore UseObjectOrCollectionInitializer // Read in the spawn location map.Spawn = new Position { X = reader.ReadInt16(), Y = reader.ReadInt16(), Z = reader.ReadInt16(), R = reader.ReadByte(), L = reader.ReadByte() }; return(map); }
public static void GetOffGrass() { world.Games.Remove(GetOffGrass); mode = GameMode.getOffGrass; Map map = world.Map; world.Players.Message("&WKEEP OFF THE GRASS!!!", 0); wait(6000); foreach (Player p in world.Players) { if (world.Map.GetBlock(p.Position.X / 32, p.Position.Y / 32, (short)(p.Position.Z / 32 - 1.59375)) != Block.Grass) { p.Message("&8Thanks."); if (world.blueTeam.Contains(p) && !completed.Contains(p)) { world.blueScore++; completed.Add(p); } else { world.redScore++; completed.Add(p); } } else { p.Message("&8I told you to stay off the grass..."); } } scoreCounter(); completed.Clear(); interval(); GamePicker(); }
static Map LoadMapMetadata([NotNull] Stream mapStream) { if (mapStream == null) { throw new ArgumentNullException("mapStream"); } BinaryReader reader = new BinaryReader(mapStream); reader.ReadInt16(); int metaDataSize = reader.ReadInt32(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(OpticraftMetaData)); byte[] rawMetaData = new byte[metaDataSize]; reader.Read(rawMetaData, 0, metaDataSize); MemoryStream memStream = new MemoryStream(rawMetaData); OpticraftMetaData metaData = (OpticraftMetaData)serializer.ReadObject(memStream); // ReSharper disable UseObjectOrCollectionInitializer Map mapFile = new Map(null, metaData.X, metaData.Y, metaData.Z, false); // ReSharper restore UseObjectOrCollectionInitializer mapFile.Spawn = new Position { X = (short)(metaData.SpawnX), Y = (short)(metaData.SpawnY), Z = (short)(metaData.SpawnZ), R = metaData.SpawnOrientation, L = metaData.SpawnPitch }; return(mapFile); }
public Map Load([NotNull] string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenRead(fileName)) { BinaryReader reader = new BinaryReader(mapStream); // Load MetaData Map mapFile = LoadMapMetadata(mapStream); // Load the data store int dataBlockSize = reader.ReadInt32(); byte[] jsonDataBlock = new byte[dataBlockSize]; reader.Read(jsonDataBlock, 0, dataBlockSize); MemoryStream memStream = new MemoryStream(jsonDataBlock); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(OpticraftDataStore)); OpticraftDataStore dataStore = (OpticraftDataStore)serializer.ReadObject(memStream); reader.ReadInt32(); // Load Zones LoadZones(mapFile, dataStore); // Load the block store mapFile.Blocks = new Byte[mapFile.Volume]; using (GZipStream decompressor = new GZipStream(mapStream, CompressionMode.Decompress)) { decompressor.Read(mapFile.Blocks, 0, mapFile.Blocks.Length); } return(mapFile); } }
public bool Save([NotNull] Map mapToSave, [NotNull] string fileName) { if (mapToSave == null) { throw new ArgumentNullException("mapToSave"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.Create(fileName)) { using (GZipStream gs = new GZipStream(mapStream, CompressionMode.Compress)) { BinaryWriter bs = new BinaryWriter(gs); // Write the magic number bs.Write(IPAddress.HostToNetworkOrder(1050)); bs.Write((byte)0); bs.Write((byte)0); // Write the map dimensions bs.Write(IPAddress.NetworkToHostOrder(mapToSave.Width)); bs.Write(IPAddress.NetworkToHostOrder(mapToSave.Length)); bs.Write(IPAddress.NetworkToHostOrder(mapToSave.Height)); // Write the map data MapUtility.WriteAll(mapToSave.Blocks, bs); bs.Close(); return(true); } } }
public static void RaisePlayerPlacedBlockEvent(Player player, Map map, Vector3I coords, Block oldBlock, Block newBlock, BlockChangeContext context) { var handler = PlacedBlock; handler?.Invoke(null, new PlayerPlacedBlockEventArgs(player, map, coords, oldBlock, newBlock, context)); }
protected DrawOperation([NotNull] Player player) { Player = player ?? throw new ArgumentNullException("player"); Map = player.WorldMap; Context |= BlockChangeContext.Drawn; AnnounceCompletion = true; LogCompletion = Updater.CheckUpdates(true) == VersionResult.Developer; }
static void ZoneListHandler(Player player, Command cmd) { World world = player.World; string worldName = cmd.Next(); if (worldName != null) { world = WorldManager.FindWorldOrPrintMatches(player, worldName); if (world == null) { return; } player.Message("List of zones on {0}&S:", world.ClassyName); } else if (world != null) { player.Message("List of zones on this world:"); } else { player.Message("When used from console, &H/Zones&S command requires a world name."); return; } Map map = world.Map; if (map == null) { if (!MapUtility.TryLoadHeader(world.MapFileName, out map)) { player.Message("&WERROR:Could not load mapfile for world {0}.", world.ClassyName); return; } } Zone[] zones = map.Zones.Cache; if (zones.Length > 0) { foreach (Zone zone in zones) { player.Message(" {0} ({1}&S) - {2} x {3} x {4}", zone.Name, zone.Controller.MinRank.ClassyName, zone.Bounds.Width, zone.Bounds.Length, zone.Bounds.Height); } player.Message(" Type &H/ZInfo ZoneName&S for details."); } else { player.Message(" No zones defined."); } }
internal WorldCreatingEventArgs([CanBeNull] Player player, [NotNull] string worldName, [CanBeNull] Map map) { if (worldName == null) { throw new ArgumentNullException("worldName"); } Player = player; WorldName = worldName; Map = map; }
internal void WriteMapEnd([NotNull] Map map) { if (map == null) { throw new ArgumentNullException("map"); } Write(OpCode.MapEnd); Write((short)map.Width); Write((short)map.Height); Write((short)map.Length); }
public Map LoadHeader([NotNull] string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } Map map = Load(fileName); map.Blocks = null; return(map); }
public bool Save([NotNull] Map mapToSave, [NotNull] string fileName) { if (mapToSave == null) { throw new ArgumentNullException("mapToSave"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } throw new NotImplementedException(); }
public static void Removal(ConcurrentDictionary <string, Vector3I> bullets, Map map) { foreach (Vector3I bp in bullets.Values) { map.QueueUpdate(new BlockUpdate(null, (short)bp.X, (short)bp.Y, (short)bp.Z, Block.Air)); bullets.TryRemove(bp.ToString(), out _); } }
public static Life2DZone Deserialize(string name, string sdata, Map map) { Life2DZone life = new Life2DZone(name, map); byte[] bdata = Convert.FromBase64String(sdata); DataContractSerializer serializer = new DataContractSerializer(typeof(SerializedData)); MemoryStream s = new MemoryStream(bdata); SerializedData data = (SerializedData)serializer.ReadObject(s); data.UpdateLife2DZone(life); return(life); }
private static void SetNewborn(Player p, Life2DZone life, string val) { Block b = Map.GetBlockByName(val); if (b == Block.Undefined) { p.Message("&WUnrecognized block name " + val); return; } life.Newborn = b; p.Message("&yNewborn block set to " + val); }
public Map Load([NotNull] string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenRead(fileName)) { Map map = LoadHeaderInternal(mapStream); if (!map.ValidateHeader()) { throw new MapFormatException("One or more of the map dimensions are invalid."); } BinaryReader reader = new BinaryReader(mapStream); // Read the metadata int metaSize = reader.ReadUInt16(); for (int i = 0; i < metaSize; i++) { string key = ReadLengthPrefixedString(reader); string value = ReadLengthPrefixedString(reader); if (key.StartsWith("@zone", StringComparison.OrdinalIgnoreCase)) { try { map.Zones.Add(new Zone(value, map.World)); } catch (Exception ex) { Logger.Log(LogType.Error, "MapFCMv2.Load: Error importing zone definition: {0}", ex); } } else { Logger.Log(LogType.Warning, "MapFCMv2.Load: Metadata discarded: \"{0}\"=\"{1}\"", key, value); } } // Read in the map data map.Blocks = new Byte[map.Volume]; using (GZipStream decompressor = new GZipStream(mapStream, CompressionMode.Decompress)) { decompressor.Read(map.Blocks, 0, map.Blocks.Length); } //map.RemoveUnknownBlocktypes(); return(map); } }
internal PlayerPlacedBlockEventArgs([NotNull] Player player, [NotNull] Map map, Vector3I coords, Block oldBlock, Block newBlock, BlockChangeContext context) { if (map == null) { throw new ArgumentNullException("map"); } Player = player; Map = map; Coords = coords; OldBlock = oldBlock; NewBlock = newBlock; Context = context; }
static Map LoadHeaderInternal(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } // Setup a GZipStream to decompress and read the map file using (GZipStream gs = new GZipStream(stream, CompressionMode.Decompress, true)) { BinaryReader bs = new BinaryReader(gs); int formatVersion = IPAddress.NetworkToHostOrder(bs.ReadInt32()); // Read in the map dimesions int width = IPAddress.NetworkToHostOrder(bs.ReadInt16()); int length = IPAddress.NetworkToHostOrder(bs.ReadInt16()); int height = IPAddress.NetworkToHostOrder(bs.ReadInt16()); Map map = new Map(null, width, length, height, false); Position spawn = new Position(); switch (formatVersion) { case 1000: case 1010: break; case 1020: spawn.X = IPAddress.NetworkToHostOrder(bs.ReadInt16()); spawn.Y = IPAddress.NetworkToHostOrder(bs.ReadInt16()); spawn.Z = IPAddress.NetworkToHostOrder(bs.ReadInt16()); map.Spawn = spawn; break; //case 1030: //case 1040: //case 1050: default: spawn.X = IPAddress.NetworkToHostOrder(bs.ReadInt16()); spawn.Y = IPAddress.NetworkToHostOrder(bs.ReadInt16()); spawn.Z = IPAddress.NetworkToHostOrder(bs.ReadInt16()); spawn.R = (byte)IPAddress.NetworkToHostOrder(bs.ReadInt16()); spawn.L = (byte)IPAddress.NetworkToHostOrder(bs.ReadInt16()); map.Spawn = spawn; break; } return(map); } }
public static bool CanPlacePortal(short x, short y, short z, Map map) { int count = 0; // ReSharper disable once InconsistentNaming for (short Z = z; Z < z + 2; Z++) { Block check = map.GetBlock(x, y, Z); if (check != Block.Air && check != Block.Water && check != Block.Lava) { count++; } } return(count == 2); }
public Life2DZone(string name, Map map, Vector3I[] marks, Player creator, string minRankToChange) { _map = map; _bounds = new BoundingBox(marks[0], marks[1]); if (_bounds.Dimensions.X == 1 && _bounds.Dimensions.Y > 1 && _bounds.Dimensions.Z > 1) { _orientation = Orientation.X; _life2d = new Life2d(_bounds.Dimensions.Y, _bounds.Dimensions.Z); _coords.X = _bounds.XMin; } else if (_bounds.Dimensions.X > 1 && _bounds.Dimensions.Y == 1 && _bounds.Dimensions.Z > 1) { _orientation = Orientation.Y; _life2d = new Life2d(_bounds.Dimensions.X, _bounds.Dimensions.Z); _coords.Y = _bounds.YMin; } else if (_bounds.Dimensions.X > 1 && _bounds.Dimensions.Y > 1 && _bounds.Dimensions.Z == 1) { _orientation = Orientation.Z; _life2d = new Life2d(_bounds.Dimensions.X, _bounds.Dimensions.Y); _coords.Z = _bounds.ZMin; } else { throw new ArgumentException("bounds must be a 2d rectangle"); } if (_bounds.Dimensions.X * _bounds.Dimensions.Y * _bounds.Dimensions.Z > MaxSize) { throw new ArgumentException("The life if too large. Width*Length must be less or equal than " + MaxSize); } CheckPermissionsToDraw(creator); Name = name; CreatorName = creator.Name; MinRankToChange = minRankToChange; _normal = DefaultBlocks[NormalIdx]; _empty = DefaultBlocks[EmptyIdx]; _dead = DefaultBlocks[DeadIdx]; _newborn = DefaultBlocks[NewbornIdx]; _halfStepDelay = DefaultHalfStepDelay; _delay = DefaultDelay; Torus = false; _autoReset = AutoResetMethod.ToRandom; _initialState = _life2d.GetArrayCopy(); }
public Block NextBlockWithParam([NotNull] Player player, ref int param) { if (player == null) { throw new ArgumentNullException("player"); } string jointString = Next(); if (jointString == null) { return(Block.Undefined); } Block targetBlock; int slashIndex = jointString.IndexOf('/'); if (slashIndex != -1) { string blockName = jointString.Substring(0, slashIndex); string paramString = jointString.Substring(slashIndex + 1); targetBlock = Map.GetBlockByName(blockName); if (targetBlock == Block.Undefined) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } int tempParam; if (Int32.TryParse(paramString, out tempParam)) { param = tempParam; } else { player.Message("Could not parse \"{0}\" as an integer.", paramString); } } else { targetBlock = Map.GetBlockByName(jointString); if (targetBlock == Block.Undefined) { player.Message("Unrecognized blocktype \"{0}\"", jointString); } } return(targetBlock); }
public bool Save([NotNull] Map mapToSave, [NotNull] string fileName) { if (mapToSave == null) { throw new ArgumentNullException("mapToSave"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.Create(fileName)) { using (GZipStream gs = new GZipStream(mapStream, CompressionMode.Compress)) { BinaryWriter bs = new BinaryWriter(gs); // Write the magic number bs.Write((ushort)0x752); // Write the map dimensions bs.Write(mapToSave.Width); bs.Write(mapToSave.Length); bs.Write(mapToSave.Height); // Write the spawn location bs.Write(mapToSave.Spawn.X / 32); bs.Write(mapToSave.Spawn.Z / 32); bs.Write(mapToSave.Spawn.Y / 32); //Write the spawn orientation bs.Write(mapToSave.Spawn.R); bs.Write(mapToSave.Spawn.L); // Write the VistPermission and BuildPermission bytes bs.Write((byte)0); bs.Write((byte)0); // Write the map data MapUtility.WriteAll(mapToSave.Blocks, bs); bs.Close(); } return(true); } }
public Block NextBlock([NotNull] Player player) { if (player == null) { throw new ArgumentNullException("player"); } string blockName = Next(); Block targetBlock = Block.Undefined; if (blockName != null) { targetBlock = Map.GetBlockByName(blockName); if (targetBlock == Block.Undefined) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } } return(targetBlock); }
public static bool CanPlacePortal(int x, int y, int z, Map map) { int Count = 0; for (int Z = z; Z < z + 2; Z++) { Block check = map.GetBlock(x, y, Z); if (check != Block.Air && check != Block.Water && check != Block.Lava) { Count++; } } if (Count == 2) { return(true); } else { return(false); } }
public static void pinkPlatform() { world.Games.Remove(pinkPlatform); mode = GameMode.pinkplatform; Map map = world.Map; int startX = ((map.Bounds.XMin + map.Bounds.XMax) / 2) + new Random().Next(10, 50); int startY = ((map.Bounds.YMin + map.Bounds.YMax) / 2) + new Random().Next(10, 50); int startZ = ((map.Bounds.ZMin + map.Bounds.ZMax) / 2) + new Random().Next(10, 30); for (int x = startX; x <= startX + 5; x++) { for (int y = startY; y <= startY + 5; y++) { for (int z = startZ; z <= startZ + 1; z++) { world.Map.QueueUpdate(new BlockUpdate(null, (short)x, (short)y, (short)z, Block.Pink)); platform.TryAdd(new Vector3I(x, y, z).ToString(), new Vector3I(x, y, z)); } } } world.Players.Message("&WYou have 30 seconds to get onto the PINK platform.... &AGO!", 0); wait(20000); world.Players.Message("&WYou have 10 seconds left to get onto the PINK platform.", 0); wait(10000); PositionCheck(); scoreCounter(); foreach (Vector3I block in platform.Values) { if (world.Map != null && world.IsLoaded) { world.Map.QueueUpdate(new BlockUpdate(null, block, Block.Air)); Vector3I removed; platform.TryRemove(block.ToString(), out removed); } } completed.Clear(); interval(); GamePicker(); }
public Map Load([NotNull] string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenRead(fileName)) { Map map = LoadHeaderInternal(mapStream); if (!map.ValidateHeader()) { throw new MapFormatException("One or more of the map dimensions are invalid."); } // Read in the map data map.Blocks = new byte[map.Volume]; mapStream.Read(map.Blocks, 0, map.Blocks.Length); map.ConvertBlockTypes(Mapping); return(map); } }
public bool Save([NotNull] Map mapToSave, [NotNull] string fileName) { if (mapToSave == null) { throw new ArgumentNullException("mapToSave"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.Create(fileName)) { using (GZipStream gs = new GZipStream(mapStream, CompressionMode.Compress)) { BinaryWriter bs = new BinaryWriter(gs); // Write the magic number bs.Write((byte)0x01); // Write the spawn location bs.Write(IPAddress.NetworkToHostOrder((short)(mapToSave.Spawn.X / 32))); bs.Write(IPAddress.NetworkToHostOrder((short)(mapToSave.Spawn.Z / 32))); bs.Write(IPAddress.NetworkToHostOrder((short)(mapToSave.Spawn.Y / 32))); //Write the spawn orientation bs.Write(mapToSave.Spawn.R); bs.Write(mapToSave.Spawn.L); // Write the map dimensions bs.Write(IPAddress.NetworkToHostOrder(mapToSave.Width)); bs.Write(IPAddress.NetworkToHostOrder(mapToSave.Length)); bs.Write(IPAddress.NetworkToHostOrder(mapToSave.Height)); // Write the map data MapUtility.WriteAll(mapToSave.Blocks, bs); } return(true); } }
public static void Start(Player player) { Map map = MapGenerator.GenerateEmpty(64, 128, 16); map.Save("maps/minefield.fcm"); if (_world != null) { WorldManager.RemoveWorld(_world); } WorldManager.AddWorld(Player.Console, "Minefield", map, true); _map = map; _world = WorldManager.FindWorldExact("Minefield"); SetUpRed(); SetUpMiddleWater(); SetUpGreen(); SetUpMines(); _map.Spawn = new Position(_map.Width / 2, 5, _ground + 3).ToVector3I().ToPlayerCoords(); _world.LoadMap(); _world.gameMode = GameMode.MineField; _world.EnableTNTPhysics(Player.Console, false); Server.Message("{0}&S started a game of MineField on world Minefield!", player.ClassyName); WorldManager.SaveWorldList(); Server.RequestGC(); }
public bool Save([NotNull] Map mapToSave, [NotNull] string fileName) { if (mapToSave == null) { throw new ArgumentNullException("mapToSave"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenWrite(fileName)) { BinaryWriter writer = new BinaryWriter(mapStream); // Version writer.Write(MapVersion); MemoryStream serializationStream = new MemoryStream(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(OpticraftMetaData)); // Create and serialize core meta data OpticraftMetaData oMetadate = new OpticraftMetaData { X = mapToSave.Width, Y = mapToSave.Length, Z = mapToSave.Height, // Spawn SpawnX = mapToSave.Spawn.X, SpawnY = mapToSave.Spawn.Y, SpawnZ = mapToSave.Spawn.Z, SpawnOrientation = mapToSave.Spawn.R, SpawnPitch = mapToSave.Spawn.L }; // World related values. if (mapToSave.World != null) { oMetadate.Hidden = mapToSave.World.IsHidden; oMetadate.MinimumJoinRank = mapToSave.World.AccessSecurity.MinRank.Name; oMetadate.MinimumBuildRank = mapToSave.World.BuildSecurity.MinRank.Name; } else { oMetadate.Hidden = false; oMetadate.MinimumJoinRank = oMetadate.MinimumBuildRank = "guest"; } oMetadate.CreationDate = 0; // This is ctime for when the world was created. Unsure on how to extract it. Opticraft makes no use of it as of yet serializer.WriteObject(serializationStream, oMetadate); byte[] jsonMetaData = serializationStream.ToArray(); writer.Write(jsonMetaData.Length); writer.Write(jsonMetaData); // Now create and serialize core data store (zones) Zone[] zoneCache = mapToSave.Zones.Cache; OpticraftDataStore oDataStore = new OpticraftDataStore { Zones = new OpticraftZone[zoneCache.Length] }; int i = 0; foreach (Zone zone in zoneCache) { OpticraftZone oZone = new OpticraftZone { Name = zone.Name, MinimumRank = zone.Controller.MinRank.Name, Owner = "", X1 = zone.Bounds.XMin, X2 = zone.Bounds.XMax, Y1 = zone.Bounds.YMin, Y2 = zone.Bounds.YMax, Z1 = zone.Bounds.ZMin, Z2 = zone.Bounds.ZMax, Builders = new string[zone.Controller.ExceptionList.Included.Length] }; // Bounds // Builders int j = 0; foreach (PlayerInfo pInfo in zone.Controller.ExceptionList.Included) { oZone.Builders[j++] = pInfo.Name; } // Excluded players oZone.Excluded = new string[zone.Controller.ExceptionList.Excluded.Length]; j = 0; foreach (PlayerInfo pInfo in zone.Controller.ExceptionList.Excluded) { oZone.Builders[j++] = pInfo.Name; } oDataStore.Zones[i++] = oZone; } // Serialize it serializationStream = new MemoryStream(); serializer = new DataContractJsonSerializer(typeof(OpticraftDataStore)); serializer.WriteObject(serializationStream, oDataStore); byte[] jsonDataStore = serializationStream.ToArray(); writer.Write(jsonDataStore.Length); writer.Write(jsonDataStore); // Blocks MemoryStream blockStream = new MemoryStream(); using (GZipStream zipper = new GZipStream(blockStream, CompressionMode.Compress, true)) { zipper.Write(mapToSave.Blocks, 0, mapToSave.Blocks.Length); } byte[] compressedBlocks = blockStream.ToArray(); writer.Write(compressedBlocks.Length); writer.Write(compressedBlocks); } return(true); }