Ejemplo n.º 1
0
            /// <summary>
            /// Adds a region to the appropriate list for its type; returns the region.
            /// </summary>
            public Region Add(Region region)
            {
                switch (region)
                {
                case Region.InvasionPoint r: InvasionPoints.Add(r); break;

                case Region.EnvironmentMapPoint r: EnvironmentMapPoints.Add(r); break;

                case Region.Sound r: Sounds.Add(r); break;

                case Region.SFX r: SFX.Add(r); break;

                case Region.WindSFX r: WindSFX.Add(r); break;

                case Region.SpawnPoint r: SpawnPoints.Add(r); break;

                case Region.Message r: Messages.Add(r); break;

                case Region.PatrolRoute r: PatrolRoutes.Add(r); break;

                case Region.MovementPoint r: MovementPoints.Add(r); break;

                case Region.WarpPoint r: WarpPoints.Add(r); break;

                case Region.ActivationArea r: ActivationAreas.Add(r); break;

                case Region.Event r: Events.Add(r); break;

                case Region.Logic r: Logic.Add(r); break;

                case Region.EnvironmentMapEffectBox r: EnvironmentMapEffectBoxes.Add(r); break;

                case Region.WindArea r: WindAreas.Add(r); break;

                case Region.MufflingBox r: MufflingBoxes.Add(r); break;

                case Region.MufflingPortal r: MufflingPortals.Add(r); break;

                case Region.Other r: Others.Add(r); break;

                default:
                    throw new ArgumentException($"Unrecognized type {region.GetType()}.", nameof(region));
                }
                return(region);
            }
Ejemplo n.º 2
0
            internal override Region ReadEntry(BinaryReaderEx br)
            {
                RegionType type = br.GetEnum32 <RegionType>(br.Position + 8);

                switch (type)
                {
                case RegionType.Region0:
                    var region0 = new Region.Region0(br);
                    Region0s.Add(region0);
                    return(region0);

                case RegionType.InvasionPoint:
                    var invasionPoint = new Region.InvasionPoint(br);
                    InvasionPoints.Add(invasionPoint);
                    return(invasionPoint);

                case RegionType.EnvironmentMapPoint:
                    var environmentMapPoint = new Region.EnvironmentMapPoint(br);
                    EnvironmentMapPoints.Add(environmentMapPoint);
                    return(environmentMapPoint);

                case RegionType.Sound:
                    var sound = new Region.Sound(br);
                    Sounds.Add(sound);
                    return(sound);

                case RegionType.SFX:
                    var sfx = new Region.SFX(br);
                    SFXs.Add(sfx);
                    return(sfx);

                case RegionType.WindSFX:
                    var windSFX = new Region.WindSFX(br);
                    WindSFXs.Add(windSFX);
                    return(windSFX);

                case RegionType.SpawnPoint:
                    var spawnPoint = new Region.SpawnPoint(br);
                    SpawnPoints.Add(spawnPoint);
                    return(spawnPoint);

                case RegionType.WalkRoute:
                    var walkRoute = new Region.WalkRoute(br);
                    WalkRoutes.Add(walkRoute);
                    return(walkRoute);

                case RegionType.WarpPoint:
                    var warpPoint = new Region.WarpPoint(br);
                    WarpPoints.Add(warpPoint);
                    return(warpPoint);

                case RegionType.ActivationArea:
                    var activationArea = new Region.ActivationArea(br);
                    ActivationAreas.Add(activationArea);
                    return(activationArea);

                case RegionType.Event:
                    var evt = new Region.Event(br);
                    Events.Add(evt);
                    return(evt);

                case RegionType.EnvironmentMapEffectBox:
                    var environmentMapEffectBox = new Region.EnvironmentMapEffectBox(br);
                    EnvironmentMapEffectBoxes.Add(environmentMapEffectBox);
                    return(environmentMapEffectBox);

                case RegionType.WindArea:
                    var windArea = new Region.WindArea(br);
                    WindAreas.Add(windArea);
                    return(windArea);

                case RegionType.MufflingBox:
                    var mufflingBox = new Region.MufflingBox(br);
                    MufflingBoxes.Add(mufflingBox);
                    return(mufflingBox);

                case RegionType.MufflingPortal:
                    var mufflingPortal = new Region.MufflingPortal(br);
                    MufflingPortals.Add(mufflingPortal);
                    return(mufflingPortal);

                case RegionType.Region23:
                    var region23 = new Region.Region23(br);
                    Region23s.Add(region23);
                    return(region23);

                case RegionType.Region24:
                    var region24 = new Region.Region24(br);
                    Region24s.Add(region24);
                    return(region24);

                case RegionType.PartsGroup:
                    var partsGroup = new Region.PartsGroup(br);
                    PartsGroups.Add(partsGroup);
                    return(partsGroup);

                case RegionType.AutoDrawGroup:
                    var autoDrawGroup = new Region.AutoDrawGroup(br);
                    AutoDrawGroups.Add(autoDrawGroup);
                    return(autoDrawGroup);

                case RegionType.Other:
                    var other = new Region.Other(br);
                    Others.Add(other);
                    return(other);

                default:
                    throw new NotImplementedException($"Unimplemented region type: {type}");
                }
            }
Ejemplo n.º 3
0
        /// <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);
                }
            }
        }