/// <summary> /// Initializes a new instance of the <see cref="MapDataFile"/> class. /// </summary> public MapDataFile() { WaterPlanes = new List<MapWaterPlane>(); Objects = new List<MapObject>(); NPCs = new List<MapNPC>(); Buildings = new List<MapBuilding>(); Sounds = new List<MapSound>(); Effects = new List<MapEffect>(); Animations = new List<MapAnimation>(); WaterPatches = new MapWaterPatches(); MonsterSpawns = new List<MapMonsterSpawn>(); WarpPoints = new List<MapWarpPoint>(); CollisionObjects = new List<MapCollisionObject>(); EventObjects = new List<MapEventObject>(); Reset(); }
/// <summary> /// Resets properties to their default values. /// </summary> public override void Reset() { base.Reset(); WaterPatches = new MapWaterPatches(); MapPosition = new IntVector2(); ZonePosition = new IntVector2(); World = Matrix4x4.identity; Name = string.Empty; WaterSize = 2000.0f; Clear(); }
/// <summary> /// Loads the file from the specified stream. /// </summary> /// <param name="stream">The stream to read from.</param> public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR")); int blockCount = reader.ReadInt32(); for (int i = 0; i < blockCount; i++) { MapBlockType type = (MapBlockType)reader.ReadInt32(); if (!Enum.IsDefined(typeof(MapBlockType), type)) { throw new InvalidMapBlockTypeException((int)type); } int offset = reader.ReadInt32(); long nextBlock = stream.Position; stream.Seek(offset, SeekOrigin.Begin); if (type == MapBlockType.MapInformation) { MapPosition = new IntVector2(reader.ReadInt32(), reader.ReadInt32()); ZonePosition = new IntVector2(reader.ReadInt32(), reader.ReadInt32()); World = reader.ReadMatrix(); Name = reader.ReadString(); }else if(type == MapBlockType.WaterPatch){ WaterPatches = new MapWaterPatches(); WaterPatches.Read(reader); } else { if (type == MapBlockType.WaterPlane) { WaterSize = reader.ReadSingle(); } int entryCount = reader.ReadInt32(); Type classType = type.GetAttributeValue<MapBlockTypeAttribute, Type>(x => x.Type); for (int j = 0; j < entryCount; j++) { IMapBlock block = (IMapBlock)Activator.CreateInstance(classType); block.Read(reader); switch (type) { case MapBlockType.Object: Objects.Add((MapObject)block); break; case MapBlockType.NPC: NPCs.Add((MapNPC)block); break; case MapBlockType.Building: Buildings.Add((MapBuilding)block); break; case MapBlockType.Sound: Sounds.Add((MapSound)block); break; case MapBlockType.Effect: Effects.Add((MapEffect)block); break; case MapBlockType.Animation: Animations.Add((MapAnimation)block); break; case MapBlockType.MonsterSpawn: MonsterSpawns.Add((MapMonsterSpawn)block); break; case MapBlockType.WaterPlane: WaterPlanes.Add((MapWaterPlane)block); break; case MapBlockType.WarpPoint: WarpPoints.Add((MapWarpPoint)block); break; case MapBlockType.CollisionObject: CollisionObjects.Add((MapCollisionObject)block); break; case MapBlockType.EventObject: EventObjects.Add((MapEventObject)block); break; } } } if (i < blockCount - 1) { stream.Seek(nextBlock, SeekOrigin.Begin); } } }