Ejemplo n.º 1
0
        /// <summary>
        /// 放置位置まで移動する
        /// </summary>
        public void Move( FEZWindow window )
        {
            // 現在の実装では、掲示板横に移動する
            var screenShot = window.CaptureWindow();
            Point mapHeaderPosition = Point.Empty;
            while( !stopRequested ) {
                try {
                    mapHeaderPosition = ImageComparator.Find( screenShot, Resource.map_move_handle );
                    break;
                } catch( FEZBotException e ) {
                    screenShot.Save( GetType() + "_Move_" + DateTime.Now.ToFileTime() + ".png", ImageFormat.Png );
                    Console.WriteLine( "マップがどこに表示されているか見つけられなかった。リトライする。" );
                }
                screenShot = window.CaptureWindow();
            }
            var mapImageGeometry = FEZWindow.GetMapGeometry( mapHeaderPosition );
            var detector = new CurrentPositionDetector( mapImageGeometry );

            // マップが「全体」モードで表示されている場合、「周囲」モードに切り替える
            window.Activate();
            var mapScaleButtonGeometry = FEZWindow.GetMapScaleButtonGeometry( mapHeaderPosition );
            var mapScaleButtonImage = screenShot.Clone( mapScaleButtonGeometry, screenShot.PixelFormat );
            if( ImageComparator.CompareStrict( mapScaleButtonImage, Resource.chat_log_plus_button ) ) {
                int x = mapScaleButtonGeometry.Left + mapScaleButtonGeometry.Width / 2;
                int y = mapScaleButtonGeometry.Top + mapScaleButtonGeometry.Height / 2;
                window.Click( new Point( x, y ) );
            }

            VMultiKeyboardClient client = null;
            try {
                client = new VMultiKeyboardClient();
                client.ClearKey();

                // 2回左ステップ
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
                InputKey( client, (byte)'Q' );
                Thread.Sleep( TimeSpan.FromSeconds( 10 ) );
                InputKey( client, (byte)'Q' );
                Thread.Sleep( TimeSpan.FromSeconds( 2 ) );

                // しばらくWキーで前進
                while( !stopRequested ) {
                    client.SetKey( (byte)'W' );
                    Thread.Sleep( TimeSpan.FromSeconds( 5 ) );
                    client.ClearKey();

                    try {
                        screenShot = window.CaptureWindow();
                        var position = detector.Detect( screenShot );
                        if( position.Y <= -36 ) {
                            break;
                        }
                    } catch( FEZBotException e ) {
                        Console.Error.WriteLine( "座標が検出できない。とりあえず前進し続ける" );
                    }
                }

                // 右ステップ
                InputKey( client, (byte)'E' );
                Thread.Sleep( TimeSpan.FromSeconds( 2 ) );

                // 1歩後ろ
                InputKey( client, (byte)'S' );
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );

                // 1歩右
                InputKey( client, (byte)'D' );
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
            } catch( Exception e ) {
                Console.Error.WriteLine( e.Message );
            } finally {
                if( client != null ) {
                    client.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// トレード要請を受諾し、トレード画面を開く。
        /// トレード要請のアイコンとPT要請のアイコンは同じ位置に出るので、タイミングによっては
        /// PT要請のアイコンを押してしまう可能性がある。このため、可能な限りキーボードから
        /// 操作するようにした。
        /// </summary>
        private void OpenTradeWindow()
        {
            VMultiKeyboardClient client = null;
            try {
                client = new VMultiKeyboardClient();
            } catch( FEZBotException e ) {
                Console.Error.WriteLine( e.Message );
            }

            if( client == null ) {
                var iconArea = window.GetIconAreaRectangle();
                int x = iconArea.Left + iconArea.Width / 2;
                int y = iconArea.Top + iconArea.Height / 2;
                var position = new Point( x, y );
                window.Click( position );
            } else {
                client.ClearKey();
                window.Activate();
                client.SetKey( (byte)'T' );
                Thread.Sleep( TimeSpan.FromMilliseconds( 50 ) );
                client.ClearKey();
                client.Dispose();
            }
            Thread.Sleep( 3000 );
        }