コード例 #1
0
        private bool SubStringToVar(TriggerReader reader)
        {
            var str    = reader.ReadString();
            var start  = reader.ReadNumber();
            var end    = reader.ReadNumber();
            var var    = reader.ReadVariable(true);
            var subStr = str.Substring((int)start, (int)end);

            var.Value = subStr;
            return(true);
        }
コード例 #2
0
        private bool CallJob(TriggerReader reader)
        {
            double jobNumber = 0;

            if (reader.PeekVariable())
            {
                jobNumber = reader.ReadVariable().Value.AsDouble();
            }
            else if (reader.PeekNumber())
            {
                jobNumber = reader.ReadNumber();
            }

            var args = reader.ReadValues().ToArray();

            if (jobNumber > 0)
            {
                if (args == null || args.Length == 0)
                {
                    reader.Page.Execute(100, jobNumber);
                }
                else
                {
                    reader.Page.Execute(100, Enumerable.Concat(new object[] { jobNumber }, args).ToArray());
                }
            }
            return(true);
        }
コード例 #3
0
        private bool IsVariableEqualToNumberOrVar(TriggerReader reader)
        {
            var    var = reader.ReadVariable();
            double num = 0;

            return(reader.ReadNumber() == var.Value.AsDouble());
        }
コード例 #4
0
        private bool VariableGreaterThanOrEqual(TriggerReader reader)
        {
            var    mainVar = reader.ReadVariable();
            double num     = reader.ReadNumber();

            return(mainVar.Value.AsDouble() >= num);
        }
コード例 #5
0
        private bool VariableLessThan(TriggerReader reader)
        {
            var    mainVar = reader.ReadVariable();
            double num     = reader.ReadNumber();

            return(mainVar.Value.AsDouble() < num);
        }
コード例 #6
0
        private bool JobCalled(TriggerReader reader)
        {
            double jobNumber = 0;

            if (reader.PeekVariable())
            {
                jobNumber = reader.ReadVariable().Value.AsDouble();
            }
            else if (reader.PeekNumber())
            {
                jobNumber = reader.ReadNumber();
            }

            double requiredJobNumber = reader.GetParameter <double>(0);

            if (reader.TryReadVariableTable(out VariableTable table, true))
            {
                object[] args = reader.Parameters.Skip(1).ToArray();
                for (int i = 0; i <= args.Length - 1; i++)
                {
                    table.Add(i.ToString(), args[i]);
                }
            }

            bool result = false;

            if (jobNumber > 0 && jobNumber == requiredJobNumber)
            {
                result = reader.CurrentBlock.IndexOfTrigger(TriggerCategory.Effect, 115, reader.CurrentBlockIndex) == -1;
            }
            return(result);
        }
コード例 #7
0
        private bool PauseScriptExecution(TriggerReader reader)
        {
            double delay = reader.ReadNumber();

            Thread.Sleep(TimeSpan.FromSeconds(delay));
            return(true);
        }
コード例 #8
0
        private bool MultiplyByVariable(TriggerReader reader)
        {
            var    toAssign = reader.ReadVariable(true);
            double num      = reader.ReadNumber();

            toAssign.Value = toAssign.Value.AsDouble() * num;
            return(true);
        }
コード例 #9
0
 public static bool AndControlIs(TriggerReader reader)
 {
     if (reader.PeekNumber() == false)
     {
         return(false);
     }
     return(controls.ContainsKey(reader.ReadNumber()));
 }
コード例 #10
0
        private bool SubtractFromVariable(TriggerReader reader)
        {
            var    toAssign = reader.ReadVariable(true);
            double num      = reader.ReadNumber();

            toAssign.Value = toAssign.Value.AsDouble() - num;
            return(true);
        }
コード例 #11
0
        private bool PutNumIntoTable(TriggerReader reader)
        {
            var var   = reader.ReadVariableTable(true);
            var value = reader.ReadNumber();
            var key   = reader.ReadString();

            var.Add(key, value);
            return(true);
        }
コード例 #12
0
        public static bool MakeTriggeredControl(TriggerReader reader)
        {
            if (reader.PeekNumber() == false)
            {
                return(false);
            }
            double id = reader.ReadNumber();

            reader.Page.SetVariable("triggered.control", id, true);
            return(true);
        }
コード例 #13
0
        private bool TryGetTimerFrom(TriggerReader reader, out TimerTask timerTask)
        {
            double num = reader.ReadNumber();

            if (num > 0)
            {
                timerTask = timers.FirstOrDefault(task => task.Id == num);
                return(timerTask != null);
            }
            timerTask = null;
            return(false);
        }
コード例 #14
0
        private bool CreateTimer(TriggerReader reader)
        {
            if (timers.Count >= timersLimit)
            {
                throw new MonkeyspeakException("The amount of timers has exceeded the limit of {0}", timersLimit);
            }
            double id = reader.ReadNumber();

            double interval = reader.ReadNumber();

            reader.TryReadNumber(out double delay);

            Logger.Debug <Timers>($"id={id} interval={TimeSpan.FromSeconds(interval)} delay = {delay}");
            if (interval <= 0)
            {
                return(false);
            }
            if (id <= 0)
            {
                return(false);         // NOTE no more timers with id 0, must be > 0
            }
            lock (lck)
            {
                var existing = timers.FirstOrDefault(task => task.Id == id);
                if (existing != null)
                {
#warning Replacing existing timer may cause any triggers dependent on that timer to behave differently
                    existing.Dispose();
                    timers.Remove(existing);
                }
                var timerTask = new TimerTask(reader.Page, interval, id, delay > 0 ? delay : 0);
                timers.Add(timerTask);
            }

            return(true);
        }
コード例 #15
0
        public double ReadVariableOrNumber(TriggerReader reader, bool addIfNotExist = false)
        {
            double num = 0;

            if (reader.PeekVariable())
            {
                string str = reader.ReadVariable(addIfNotExist).Value.ToString();
                double.TryParse(str, out num);
            }
            else if (reader.PeekNumber())
            {
                num = reader.ReadNumber();
            }
            return(num);
        }
コード例 #16
0
        private bool SetVariableToNumberOrVariable(TriggerReader reader)
        {
            var var = reader.ReadVariable(true);

            if (reader.PeekVariable <double>())
            {
                var.Value = reader.ReadVariable().Value.AsDouble(0d);
            }
            else if (reader.PeekNumber())
            {
                var.Value = reader.ReadNumber();
            }

            return(true);
        }
コード例 #17
0
        public static bool MakeControlInVisible(TriggerReader reader)
        {
            if (reader.PeekNumber() == false)
            {
                return(false);
            }
            Control control;
            bool    containsControl = controls.TryGetValue(reader.ReadNumber(), out control);

            if (containsControl == false)
            {
                return(false);                                      // Maybe throw exception for control not found
            }
            control.Visible = false;
            return(true);
        }
コード例 #18
0
        public static bool SetText(TriggerReader reader)
        {
            if (reader.PeekNumber() == false)
            {
                return(false);
            }
            Control control;
            bool    containsControl = controls.TryGetValue(reader.ReadNumber(), out control);

            if (containsControl == false)
            {
                return(false);
            }

            control.Text = (reader.PeekString()) ? reader.ReadString() : "";
            return(true);
        }
コード例 #19
0
        public static bool HideForm(TriggerReader reader)
        {
            if (reader.PeekNumber() == false)
            {
                return(false);
            }
            Control control;
            bool    containsControl = ControlLib.controls.TryGetValue(reader.ReadNumber(), out control);

            if (containsControl == false)
            {
                return(false);                                      // Maybe throw exception for control not found
            }
            if ((control is Form) == false)
            {
                return(false);
            }

            ((Form)control).Hide();
            return(true);
        }
コード例 #20
0
        private bool WhileVarIsNotValue(TriggerReader reader)
        {
            var  var         = reader.ReadVariable();
            var  value       = reader.ReadNumber();
            bool canContinue = var.Value.AsDouble() != value;

            if (!reader.Page.HasVariable("___while_counter", out ConstantVariable whileCounter))
            {
                whileCounter = reader.Page.SetVariable(new ConstantVariable("___while_counter", 0d));
            }
            whileCounter.SetValue(whileCounter.Value.AsDouble() + 1);
            if (whileCounter.Value.AsDouble() >= reader.Engine.Options.LoopLimit)
            {
                canContinue = false;
            }
            if (!canContinue)
            {
                reader.Page.RemoveVariable(whileCounter);
            }
            return(canContinue);
        }