Beispiel #1
0
        public void Reset()
        {
            if ( m_Playing && World.Player != null && DragDropManager.Holding != null && DragDropManager.Holding == LiftAction.LastLift )
                ClientCommunication.SendToServer( new DropRequest( DragDropManager.Holding, World.Player.Serial ) );

            m_Wait = null;

            m_IfStatus.Clear();

            bool resync = false;
            foreach ( MacroAction a in m_Actions )
            {
                if ( a is WalkAction )
                    resync = true;
                else if ( a is ForAction )
                    ((ForAction)a).Count = 0;
            }

            if ( resync && World.Player != null )
            {
                // resync if the macro walked for us
                //ClientCommunication.SendToClient( new MoveReject( World.Player.WalkSequence, World.Player ) );
                ClientCommunication.SendToClient( new MobileIncoming( World.Player ) );
                ClientCommunication.SendToClient( new MobileIncoming( World.Player ) );
                ClientCommunication.SendToServer( new ResyncReq() );
                World.Player.Resync();
            }
        }
Beispiel #2
0
        // returns true if the were waiting for this action
        public bool Action( MacroAction action )
        {
            if ( m_Recording )
            {
                action.Parent = this;
                m_Actions.Insert( m_CurrentAction, action );
                if ( m_ListBox != null )
                    m_ListBox.Items.Insert( m_CurrentAction, action );
                m_CurrentAction++;

                return false;
            }
            else if ( m_Playing && m_Wait != null && m_Wait.CheckMatch( action ) )
            {
                m_Wait = null;
                ExecNext();
                return true;
            }

            return false;
        }
Beispiel #3
0
        //return true to continue the macro, false to stop (macro's over)
        public bool ExecNext()
        {
            try
            {
                if ( !m_Playing )
                    return false;

                if ( m_Wait != null )
                {
                    TimeSpan waitLen = DateTime.Now - m_Wait.StartTime;
                    if ( !( m_Wait is PauseAction ) && waitLen >= m_Wait.Timeout )
                    {
                        if ( Loop )
                        {
                            if ( Engine.MainWindow.WaitDisplay != null )
                                Engine.MainWindow.WaitDisplay.Text = "";
                            m_CurrentAction = -1;
                            m_IfStatus.Clear();
                            PauseB4Loop.Perform();
                            PauseB4Loop.Parent = this;
                            m_Wait = PauseB4Loop;
                            return true;
                        }
                        else
                        {
                            Stop();
                            return false;
                        }
                    }
                    else
                    {
                        if ( !m_Wait.PerformWait() )
                        {
                            m_Wait = null; // done waiting
                            if ( Engine.MainWindow.WaitDisplay != null )
                                Engine.MainWindow.WaitDisplay.Text = "";
                        }
                        else
                        {
                            if ( waitLen >= TimeSpan.FromSeconds( 4.0 ) && Engine.MainWindow.WaitDisplay != null )
                            {
                                StringBuilder sb = new StringBuilder( Language.GetString( LocString.WaitingTimeout ) );
                                int s = (int)(m_Wait.Timeout - waitLen).TotalSeconds;
                                int m = 0;

                                if ( s > 60 )
                                {
                                    m = s/60;
                                    s %= 60;
                                    if ( m > 60 )
                                    {
                                        sb.AppendFormat( "{0}:", m/60 );
                                        m %= 60;
                                    }
                                }

                                sb.AppendFormat( "{0:00}:{1:00}", m, s );
                                Engine.MainWindow.WaitDisplay.Text = sb.ToString();
                            }
                            return true; // keep waiting
                        }
                    }
                }

                m_CurrentAction ++;
                //MacroManager.ActionUpdate( this, m_CurrentAction );
                if ( m_ListBox != null )
                {
                    if ( m_CurrentAction < m_ListBox.Items.Count )
                        m_ListBox.SelectedIndex = m_CurrentAction;
                    else
                        m_ListBox.SelectedIndex = -1;
                }

                if ( m_CurrentAction >= 0 && m_CurrentAction < m_Actions.Count )
                {
                    MacroAction action = (MacroAction)m_Actions[m_CurrentAction];

                    if ( action is IfAction )
                    {
                        bool val = ((IfAction)action).Evaluate();
                        m_IfStatus.Push( val );

                        if ( !val )
                        {
                            // false so skip to an else or an endif
                            int ifcount = 0;
                            while ( m_CurrentAction+1 < m_Actions.Count )
                            {
                                if ( m_Actions[m_CurrentAction+1] is IfAction )
                                {
                                    ifcount++;
                                }
                                else if ( m_Actions[m_CurrentAction+1] is ElseAction && ifcount <= 0 )
                                {
                                    break;
                                }
                                else if ( m_Actions[m_CurrentAction+1] is EndIfAction )
                                {
                                    if ( ifcount <= 0 )
                                        break;
                                    else
                                        ifcount--;
                                }

                                m_CurrentAction++;
                            }
                        }
                    }
                    else if ( action is ElseAction && m_IfStatus.Count > 0 )
                    {
                        bool val = (bool)m_IfStatus.Peek();
                        if ( val )
                        {
                            // the if was true, so skip to an endif
                            int ifcount = 0;
                            while ( m_CurrentAction+1 < m_Actions.Count )
                            {
                                if ( m_Actions[m_CurrentAction+1] is IfAction )
                                {
                                    ifcount++;
                                }
                                else if ( m_Actions[m_CurrentAction+1] is EndIfAction )
                                {
                                    if ( ifcount <= 0 )
                                        break;
                                    else
                                        ifcount--;
                                }

                                m_CurrentAction++;
                            }
                        }
                    }
                    else if ( action is EndIfAction && m_IfStatus.Count > 0 )
                    {
                        m_IfStatus.Pop();
                    }
                    else if ( action is ForAction )
                    {
                        ForAction fa = (ForAction)action;
                        fa.Count++;

                        if ( fa.Count > fa.Max )
                        {
                            fa.Count = 0;

                            int forcount = 0;
                            m_CurrentAction++;
                            while ( m_CurrentAction < m_Actions.Count )
                            {
                                if ( m_Actions[m_CurrentAction] is ForAction )
                                {
                                    forcount++;
                                }
                                else if ( m_Actions[m_CurrentAction] is EndForAction )
                                {
                                    if ( forcount <= 0 )
                                        break;
                                    else
                                        forcount--;
                                }

                                m_CurrentAction++;
                            }

                            if ( m_CurrentAction < m_Actions.Count )
                                action = (MacroAction)m_Actions[m_CurrentAction];
                        }
                    }
                    else if ( action is EndForAction && ClientCommunication.AllowBit( FeatureBit.LoopingMacros ) )
                    {
                        int ca = m_CurrentAction - 1;
                        int forcount = 0;

                        while ( ca >= 0 )
                        {
                            if ( m_Actions[ca] is EndForAction )
                            {
                                forcount--;
                            }
                            else if ( m_Actions[ca] is ForAction )
                            {
                                if ( forcount >= 0 )
                                    break;
                                else
                                    forcount++;
                            }

                            ca--;
                        }

                        if ( ca >= 0 && m_Actions[ca] is ForAction )
                            m_CurrentAction = ca - 1;
                    }

                    bool isWait = action is MacroWaitAction;
                    if ( !action.Perform() && isWait )
                    {
                        m_Wait = (MacroWaitAction)action;
                        m_Wait.StartTime = DateTime.Now;
                    }
                    else if ( NextIsInstantWait() && !isWait )
                    {
                        return ExecNext();
                    }
                }
                else
                {
                    if ( Engine.MainWindow.WaitDisplay != null )
                        Engine.MainWindow.WaitDisplay.Text = "";

                    if ( Loop )
                    {
                        m_CurrentAction = -1;

                        Reset();

                        PauseB4Loop.Perform();
                        PauseB4Loop.Parent = this;
                        m_Wait = PauseB4Loop;
                    }
                    else
                    {
                        Stop();
                        return false;
                    }
                }
            }
            catch ( Exception e )
            {
                new MessageDialog( "Macro Exception", true, e.ToString() ).Show();
                return false;
            }
            return true;
        }