コード例 #1
0
ファイル: Action.cs プロジェクト: nazariitashak/UOMachine
 public static void Action(int client, MacroAction action)
 {
     switch (action)
     {
         case MacroAction.Last_Spell:
             Event(client, 16, 0);
             break;
         case MacroAction.Last_Object:
             Event(client, 17, 0);
             break;
         case MacroAction.Bow:
             Event(client, 18, 0);
             break;
         case MacroAction.Salute:
             Event(client, 19, 0);
             break;
         case MacroAction.Quit_Game:
             Event(client, 20, 0);
             break;
         case MacroAction.All_Names:
             Event(client, 21, 0);
             break;
         case MacroAction.Last_Target:
             Event(client, 22, 0);
             break;
         case MacroAction.Target_Self:
             Event(client, 23, 0);
             break;
         case MacroAction.Arm_Disarm_Left:
             Event(client, 24, 1);
             break;
         case MacroAction.Arm_Disarm_Right:
             Event(client, 24, 2);
             break;
         case MacroAction.Wait_For_Target:
             Event(client, 25, 0);
             break;
         case MacroAction.Target_Next:
             Event(client, 26, 0);
             break;
         case MacroAction.Attack_Last:
             Event(client, 27, 0);
             break;
         case MacroAction.Circletrans:
             Event(client, 29, 0);
             break;
         case MacroAction.Close_Gumps:
             Event(client, 31, 0);
             break;
         case MacroAction.Always_Run:
             Event(client, 32, 0);
             break;
         case MacroAction.Save_Desktop:
             Event(client, 33, 0);
             break;
         case MacroAction.Kill_Gump_Open:
             Event(client, 34, 0);
             break;
         case MacroAction.Primary_Ability:
             Event(client, 35, 0);
             break;
         case MacroAction.Secondary_Ability:
             Event(client, 36, 0);
             break;
         case MacroAction.Equip_Last_Weapon:
             Event(client, 37, 0);
             break;
         case MacroAction.Open_Door:
             Event(client, 12, 0);
             break;
         case MacroAction.Toggle_War_Peace:
             Event(client, 6, 0);
             break;
         case MacroAction.Paste:
             Event(client, 7, 0);
             break;
         case MacroAction.Last_Skill:
             Event(client, 14, 0);
             break;
     }
 }
コード例 #2
0
ファイル: Action.cs プロジェクト: nazariitashak/UOMachine
 public static void Action(int client, MacroAction action, string DelayNum)
 {
     switch (action)
     {
         case MacroAction.Delay:
             Event(client, 28, 0, DelayNum);
             break;
         default:
             //TODO throw exception
             break;
     }
 }
コード例 #3
0
ファイル: MacroState.cs プロジェクト: ewrogers/SleepHunter4
 protected virtual void TakeAction(MacroAction action)
 {
     switch (action)
       {
     case MacroAction.Start:
       Start();
       break;
     case MacroAction.Resume:
       Start();
       break;
     case MacroAction.Restart:
       Stop();
       Start();
       break;
     case MacroAction.Pause:
       Pause();
       break;
     case MacroAction.Stop:
       Stop();
       break;
     case MacroAction.ForceQuit:
       Stop();
       client.Terminate();
       break;
       }
 }
コード例 #4
0
ファイル: MacroInsertWhile.cs プロジェクト: sorsarre/Razor
        private void insert_Click(object sender, System.EventArgs e)
        {
            MacroAction a = null;

            try
            {
                if (varList.SelectedIndex == (int)WhileAction.WhileVarType.SysMessage)
                {
                    a = new WhileAction((WhileAction.WhileVarType)varList.SelectedIndex, txtAmount.Text);
                }
                else if (varList.SelectedIndex >= m_SkillStart)
                {
                    int skillId = -1;

                    foreach (Skill skill in World.Player.Skills)
                    {
                        if (Language.Skill2Str(skill.Index).Equals(varList.SelectedItem as string))
                        {
                            skillId = skill.Index;
                            break;
                        }
                    }

                    if (skillId != -1)
                    {
                        a = new WhileAction(WhileAction.WhileVarType.Skill, (sbyte)opList.SelectedIndex,
                                            Utility.ToDouble(txtAmount.Text, 0.0), skillId);
                    }
                }
                else if (varList.SelectedIndex >= (int)WhileAction.WhileVarType.BeginCountersMarker)
                {
                    a = new WhileAction(WhileAction.WhileVarType.Counter, (sbyte)opList.SelectedIndex,
                                        Utility.ToInt32(txtAmount.Text, 0), varList.SelectedItem as string);
                }
                else
                {
                    a = txtAmount.Text.Contains("{") // using an if variable
                        ? new WhileAction((WhileAction.WhileVarType)varList.SelectedIndex,
                                          (sbyte)opList.SelectedIndex,
                                          txtAmount.Text)
                        : new WhileAction((WhileAction.WhileVarType)varList.SelectedIndex,
                                          (sbyte)opList.SelectedIndex,
                                          Utility.ToInt32(txtAmount.Text, 0));
                }
            }
            catch
            {
                return;
            }

            if (m_Action == null)
            {
                m_Macro.Insert(m_Idx + 1, a);
            }
            else
            {
                m_Action.Parent.Convert(m_Action, a);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #5
0
ファイル: Macro.cs プロジェクト: mbnunes/razor
        //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.UtcNow - 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.UtcNow;
                    }
                    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);
        }
コード例 #6
0
ファイル: Macro.cs プロジェクト: mbnunes/razor
        public void Load()
        {
            m_Actions.Clear();
            m_Loaded = false;

            if (!File.Exists(m_Path))
            {
                return;
            }

            using (StreamReader reader = new StreamReader(m_Path))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Length <= 2)
                    {
                        continue;
                    }

                    if (line == "!Loop")
                    {
                        m_Loop = true;
                        continue;
                    }

                    if (line[0] == '#')
                    {
                        m_Actions.Add(new MacroComment(line.Substring(1)));
                        continue;
                    }
                    else if (line[0] == '/' && line[1] == '/')
                    {
                        MacroAction a = new MacroComment(line.Substring(2));
                        a.Parent = this;
                        m_Actions.Add(a);
                        continue;
                    }

                    string[] args       = line.Split('|');
                    object[] invokeArgs = new object[1] {
                        args
                    };

                    Type at = null;
                    try{ at = Type.GetType(args[0], false); } catch {}
                    if (at == null)
                    {
                        continue;
                    }

                    if (args.Length > 1)
                    {
                        try
                        {
                            ConstructorInfo ctor = at.GetConstructor(ctorArgs);
                            if (ctor == null)
                            {
                                continue;
                            }

                            MacroAction a = (MacroAction)ctor.Invoke(invokeArgs);
                            m_Actions.Add(a);
                            a.Parent = this;
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        try
                        {
                            ConstructorInfo ctor = at.GetConstructor(Type.EmptyTypes);
                            if (ctor == null)
                            {
                                continue;
                            }

                            MacroAction a = (MacroAction)ctor.Invoke(null);
                            m_Actions.Add(a);
                            a.Parent = this;
                        }
                        catch
                        {
                        }
                    }
                }
            }
            m_Loaded = true;
        }