示例#1
0
        /// <summary>
        /// Creates new dynamic region.
        /// </summary>
        /// <param name="baseRegionId"></param>
        /// <param name="variationFile"></param>
        /// <param name="mode"></param>
        public DynamicRegion(int baseRegionId, string variationFile = "", RegionMode mode = RegionMode.RemoveWhenEmpty)
            : base(baseRegionId)
        {
            this.BaseId = baseRegionId;

            var baseRegionInfoData = AuraData.RegionInfoDb.Find(this.BaseId);

            if (baseRegionInfoData == null)
            {
                throw new Exception("DynamicRegion: No region info data found for '" + this.BaseId + "'.");
            }

            var baseRegion = ChannelServer.Instance.World.GetRegion(baseRegionId);

            if (baseRegion != null)
            {
                this.Properties.Load(baseRegion.Properties.GetList());
            }

            this.BaseName  = baseRegionInfoData.Name;
            this.Id        = ChannelServer.Instance.World.DynamicRegions.GetFreeDynamicRegionId();
            this.Name      = "DynamicRegion" + this.Id;
            this.Variation = variationFile;
            this.Mode      = mode;

            this.RegionInfoData = CreateVariation(baseRegionInfoData, this.Id, variationFile);

            this.InitializeFromData();

            ChannelServer.Instance.World.DynamicRegions.Add(this);
        }
示例#2
0
		/// <summary>
		/// Creates new dynamic region.
		/// </summary>
		/// <param name="baseRegionId"></param>
		/// <param name="variationFile"></param>
		/// <param name="mode"></param>
		public DynamicRegion(int baseRegionId, string variationFile = "", RegionMode mode = RegionMode.RemoveWhenEmpty)
			: base(baseRegionId)
		{
			this.BaseId = baseRegionId;

			var baseRegionInfoData = AuraData.RegionInfoDb.Find(this.BaseId);
			if (baseRegionInfoData == null)
				throw new Exception("DynamicRegion: No region info data found for '" + this.BaseId + "'.");

			var baseRegion = ChannelServer.Instance.World.GetRegion(baseRegionId);
			if (baseRegion != null)
				this.Properties.Load(baseRegion.Properties.GetList());

			this.BaseName = baseRegionInfoData.Name;
			this.Id = ChannelServer.Instance.World.DynamicRegions.GetFreeDynamicRegionId();
			this.Name = "DynamicRegion" + this.Id;
			this.Variation = variationFile;
			this.Mode = mode;

			this.Data = CreateVariation(baseRegionInfoData, this.Id, variationFile);

			this.InitializeFromData();

			ChannelServer.Instance.World.DynamicRegions.Add(this);
		}
        static string GetModeLabel(RegionMode mode)
        {
            switch (mode)
            {
            case RegionMode.Red: return("R");

            case RegionMode.Green: return("G");

            default: return(string.Empty);
            }
        }
示例#4
0
        /// <summary>
        /// Creates new region by id.
        /// </summary>
        /// <param name="regionId"></param>
        private Region(int regionId, RegionMode mode)
        {
            _creaturesRWLS = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
            _propsRWLS     = new ReaderWriterLockSlim();
            _itemsRWLS     = new ReaderWriterLockSlim();

            this.Id     = regionId;
            this.BaseId = regionId;

            this.Mode = mode;

            _creatures = new Dictionary <long, Creature>();
            _props     = new Dictionary <long, Prop>();
            _items     = new Dictionary <long, Item>();

            _clients = new HashSet <ChannelClient>();

            this.Collisions = new RegionCollision();
        }
示例#5
0
        private void MapImageParsedArguments_ProcessOption(ParsedArguments sender, ProcessArgumentEventArgs e)
        {
            switch ( e.Value.ToLower() ) {
                case "lds":
                    action = Action.LightmapDownSizing;
                    if ( e.Data.Length > 0 ) {
                        if ( e.Data.ToLower() == "full" ) {
                            region = new Rectangle( -1, -1, -1, -1 );
                            mode = RegionMode.Full;
                        }
                        else {
                            int size = -1;
                            try {
                                size = int.Parse( e.Data );
                            }
                            catch ( FormatException ) {
                                size = -1;
                            }

                            if ( size <= 0 ) {
                                string[] spec= e.Data.Split( new char[] {','}, 4 );

                                if ( spec.Length >= 4 ) {
                                    Rectangle newRegion = region;
                                    try {
                                        newRegion = new Rectangle( int.Parse( spec[0] ), int.Parse( spec[1] ), int.Parse( spec[2] ), int.Parse( spec[3] ) );
                                    }
                                    catch ( FormatException ) {
                                        // Do nothing
                                    }
                                    region = newRegion;
                                }
                                mode = RegionMode.Normal;
                            }
                            else {
                                region = new Rectangle( 0, 0, size, size );
                                mode = RegionMode.All;
                            }
                        }
                    }
                    break;
            }
        }
示例#6
0
        private void MapImageParsedArguments_ProcessOption(ParsedArguments sender, ProcessArgumentEventArgs e)
        {
            switch ( e.Value.ToLower() ) {
                case "i": case "import":
                    action = Action.ImportImage;
                    simulate = false;
                    break;
                case "e": case "export":
                    action = Action.ExportImage;
                    break;
                case "q": case "query":
                    action = Action.QueryImage;
                    break;
                case "si": case "simulateimport":
                    action = Action.ImportImage;
                    simulate = true;
                    break;
                case "c": case "check":
                    action = Action.CheckImage;
                    break;
                case "o":
                    overwrite = true;
                    break;
                case "1": case "2": case "3":
                    useLightmap = int.Parse( e.Value );
                    break;
                case "p": case "png":
                    if (e.Data.Length > 0) {
                        foreach(string s in e.Data.Split(new char[] { ',' })) {
                            switch (s.ToLower()) {
                                case "shading":
                                case "s":
                                case "shades":
                                case "shade":
                                    pngLevel |= PngLevel.Shading;
                                    break;

                                case "ids":
                                case "i":
                                case "id":
                                case "idmap":
                                    pngLevel |= PngLevel.IDs;
                                    break;

                                case "borders":
                                case "b":
                                case "border":
                                    pngLevel |= PngLevel.Borders;
                                    break;
                            }
                        }
                    }
                    else {
                        pngLevel = PngLevel.All;
                    }
                    break;
                case "d": case "direct":
                    direct = true;
                    break;
                case "g":
                    if ( e.Data.Length > 0 ) {
                        try {
                            regen = int.Parse( e.Data );
                        }
                        catch ( FormatException ) {
                            // Do nothing
                        }
                    }
                    else {
                        regen = 1;
                    }
                    break;
                case "r":
                    if ( e.Data.Length > 0 ) {
                        if ( e.Data.ToLower() == "full" ) {
                            region = new Rectangle( -1, -1, -1, -1 );
                            mode = RegionMode.Full;
                        }
                        else {
                            int size = -1;
                            try {
                                size = int.Parse( e.Data );
                            }
                            catch ( FormatException ) {
                                size = -1;
                            }

                            if ( size <= 0 ) {
                                string[] spec= e.Data.Split( new char[] {','}, 4 );

                                if ( spec.Length >= 4 ) {
                                    Rectangle newRegion = region;
                                    try {
                                        newRegion = new Rectangle( int.Parse( spec[0] ), int.Parse( spec[1] ), int.Parse( spec[2] ), int.Parse( spec[3] ) );
                                    }
                                    catch ( FormatException ) {
                                        // Do nothing
                                    }
                                    region = newRegion;
                                }
                                mode = RegionMode.Normal;
                            }
                            else {
                                region = new Rectangle( 0, 0, size, size );
                                mode = RegionMode.All;
                            }
                        }
                    }
                    break;
                case "relocate":
                    if ( e.Data.Length > 0 ) {
                        string[] spec= e.Data.Split( new char[] {','}, 2 );

                        if ( spec.Length >= 2 ) {
                            Point newReloc = reloc;
                            try {
                                newReloc = new Point( int.Parse( spec[0] ), int.Parse( spec[1] ) );
                            }
                            catch ( FormatException ) {
                                // Do nothing
                            }
                            reloc = newReloc;
                        }
                    }
                    break;
                case "id":
                    try {
                        id = int.Parse( e.Data );
                    }
                    catch ( FormatException ) {
                        id = -1;
                    }
                    break;
                case "pedantic":
                    tolerant = false;
                    break;
                case "checkidgrid":
                    checkidgrid = true;
                    break;
            }
        }
示例#7
0
        /// <summary>
        /// Creates new dynamic region, based on a region and variation file.
        /// Region is automatically added to the dynamic region manager.
        /// </summary>
        /// <param name="regionId"></param>
        /// <param name="variationFile"></param>
        public static Region CreateDynamic(int baseRegionId, string variationFile = "", RegionMode mode = RegionMode.RemoveWhenEmpty)
        {
            var region = new Region(baseRegionId, mode);

            region.Id        = ChannelServer.Instance.World.DynamicRegions.GetFreeDynamicRegionId();
            region.Variation = variationFile;

            var baseRegionInfoData = AuraData.RegionInfoDb.Find(region.BaseId);

            if (baseRegionInfoData == null)
            {
                throw new Exception("Region.CreateDynamic: No region info data found for '" + region.BaseId + "'.");
            }

            region.RegionInfoData = CreateVariation(baseRegionInfoData, region.Id, variationFile);

            region.InitializeFromData();

            ChannelServer.Instance.World.DynamicRegions.Add(region);

            return(region);
        }
示例#8
0
        public static void Run( string source, string target, Rectangle region, RegionMode mode, int zoom, PngLevel pngLevel, bool direct )
        {
            if ( (mode == RegionMode.Normal && region.IsEmpty) || (mode == RegionMode.All && region.Width <= 0 ) ) {
                Console.WriteLine( "No region was specified. Use \"/r:<x,y,width,height>\", \"/r:full\" or \"/r:<size>\" to specify the region to export." );
                return;
            }

            Console.WriteLine( "Opening source file \"{0}\"...", Path.GetFileName( source ) );

            region.Width -= 1;
            region.Height -= 1;

            IFile file;
            if ( direct ) {
                file = new EU2.Edit.EU2Proxy();
                file.ReadFrom( source ); // source is EU2 dir
            }
            else {
                file = new EU2.Edit.File();
                file.ReadFrom( source );
            }

            Lightmap map = null;
            switch ( zoom ) {
                case 1:
                    map = file.Lightmap1; break;
                case 2:
                    map = file.Lightmap2; break;
                case 3:
                    map = file.Lightmap3; break;
            }

            if ( map == null ) {
                Console.WriteLine( "The source file does not contain lightmap{0}.", zoom );
                return;
            }

            map.VolatileDecompression = true;

            if ( mode == RegionMode.All ) {
                int size = ((region.Width+Lightmap.BlockSize-1) >> Lightmap.BlockFactor) << Lightmap.BlockFactor;
                Console.WriteLine( "Exporting full map as separate files of size {0}x{0}.", size );
                for ( int y=0; y<map.Size.Height; y+=size ) {
                    for ( int x=0; x<map.Size.Width; x+=size ) {
                        region = new Rectangle( x, y, size, size );
                        string parttarget = Path.Combine( Path.GetDirectoryName( target ),
                            Path.GetFileNameWithoutExtension( target ) +
                            String.Format( "-[{0},{1}-{2},{3}]", region.Left, region.Top, region.Right, region.Bottom ) +
                            Path.GetExtension( target ) );
                        DoExport( map, region, pngLevel, file.IDMap, Path.GetFileName( source ), parttarget );
                    }
                }
            }
            else if ( mode == RegionMode.Full ) {
                Console.WriteLine( "Exporting full map as one file." );
                region = new Rectangle( new Point( 0, 0 ), map.Size );
                DoExport( map, region, pngLevel, file.IDMap, Path.GetFileName( source ), target );
            }
            else {
                Console.WriteLine( "Exporting map region: ({0},{1})-({2},{3}) (width={4}, height={5}).", region.Left, region.Top, region.Right, region.Bottom, region.Width, region.Height );
                DoExport(map, region, pngLevel, file.IDMap, Path.GetFileName(source), target);
            }

            Console.Write( "Export successful." );
        }