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); }
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); }
private bool IsVariableEqualToNumberOrVar(TriggerReader reader) { var var = reader.ReadVariable(); double num = 0; return(reader.ReadNumber() == var.Value.AsDouble()); }
private bool VariableGreaterThanOrEqual(TriggerReader reader) { var mainVar = reader.ReadVariable(); double num = reader.ReadNumber(); return(mainVar.Value.AsDouble() >= num); }
private bool VariableLessThan(TriggerReader reader) { var mainVar = reader.ReadVariable(); double num = reader.ReadNumber(); return(mainVar.Value.AsDouble() < num); }
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); }
private bool PauseScriptExecution(TriggerReader reader) { double delay = reader.ReadNumber(); Thread.Sleep(TimeSpan.FromSeconds(delay)); return(true); }
private bool MultiplyByVariable(TriggerReader reader) { var toAssign = reader.ReadVariable(true); double num = reader.ReadNumber(); toAssign.Value = toAssign.Value.AsDouble() * num; return(true); }
public static bool AndControlIs(TriggerReader reader) { if (reader.PeekNumber() == false) { return(false); } return(controls.ContainsKey(reader.ReadNumber())); }
private bool SubtractFromVariable(TriggerReader reader) { var toAssign = reader.ReadVariable(true); double num = reader.ReadNumber(); toAssign.Value = toAssign.Value.AsDouble() - num; return(true); }
private bool PutNumIntoTable(TriggerReader reader) { var var = reader.ReadVariableTable(true); var value = reader.ReadNumber(); var key = reader.ReadString(); var.Add(key, value); return(true); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }