示例#1
0
        /// <summary>
        /// Register a new trigger.
        /// </summary>
        /// <param name="Name">Unique identifier for the trigger.</param>
        /// <param name="Pattern">Regex pattern for the trigger.</param>
        /// <param name="Function">Function that will be called if this trigger fires.</param>
        /// <param name="Flags">Options for the trigger.</param>
        /// <param name="Priority">Lower priority triggers get matched first. Default: 1000</param>
        /// <param name="Arg">Custom argument to pass to trigger data.</param>
        /// <param name="Plugin">From which plugin was this registered.</param>
        internal static void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags, int Priority, int Arg, string Plugin)
        {
            if (string.IsNullOrEmpty(Pattern) || string.IsNullOrEmpty(Name) || Function == null)
            {
                return;
            }

            Name = Name.ToLower().Trim();
            if (Name.Length == 0)
            {
                return;
            }

            Regex p = null;

            if ((Flags & TriggerFlags.NotRegex) == TriggerFlags.None)
            {
                try
                {
                    RegexOptions op = RegexOptions.None;
                    if ((Flags & TriggerFlags.RightToLeft) != TriggerFlags.None)
                    {
                        op |= RegexOptions.RightToLeft;
                    }
                    if ((Flags & TriggerFlags.CaseInsensitive) != TriggerFlags.None)
                    {
                        op |= RegexOptions.IgnoreCase;
                    }
                    p = new Regex(Pattern, op);
                }
                catch
                {
                    return;
                }
            }

            TriggerEntry e = new TriggerEntry();

            e.Function   = Function;
            e.Pattern    = p;
            e.PatternStr = Pattern;
            e.Priority   = Priority;
            e.Name       = Name;
            e.Flags      = Flags;
            e.Arg        = Arg;
            e.Plugin     = Plugin;

            if (TriggersName.ContainsKey(Name))
            {
                Triggers[TriggersName[Name].Priority].Remove(TriggersName[Name]);
            }

            TriggersName[Name] = e;
            if (!Triggers.ContainsKey(e.Priority))
            {
                Triggers[e.Priority] = new List <TriggerEntry>();
            }
            Triggers[e.Priority].Add(e);
        }
示例#2
0
文件: Neuron.cs 项目: cantte/NeuronUI
        public Neuron(int inputsNumber, double trainingRate, TriggerFunction triggerFunction)
        {
            Weights         = new List <double>(inputsNumber);
            TrainingRate    = trainingRate;
            TriggerFunction = triggerFunction;

            Init();
        }
示例#3
0
文件: Plugin.cs 项目: xeryax/proxymud
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 /// <param name="Flags">Options for the trigger.</param>
 /// <param name="Priority">Lower priority triggers get matched first.</param>
 /// <param name="Arg">Custom argument that will be passed to trigger data.</param>
 protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags, int Priority, int Arg)
 {
     TriggerHandler.RegisterTrigger(Keyword.ToLower().Trim() + "." + Name, Pattern, Function, Flags, Priority, Arg, Keyword.ToLower().Trim());
 }
示例#4
0
文件: Plugin.cs 项目: xeryax/proxymud
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 /// <param name="Flags">Options for the trigger.</param>
 /// <param name="Priority">Lower priority triggers get matched first.</param>
 protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags, int Priority)
 {
     RegisterTrigger(Name, Pattern, Function, Flags, Priority, 0);
 }
示例#5
0
文件: Plugin.cs 项目: xeryax/proxymud
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 /// <param name="Flags">Options for the trigger.</param>
 protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags)
 {
     RegisterTrigger(Name, Pattern, Function, Flags, 1000);
 }
示例#6
0
文件: Plugin.cs 项目: xeryax/proxymud
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function)
 {
     RegisterTrigger(Name, Pattern, Function, TriggerFlags.None);
 }
示例#7
0
文件: Verb.cs 项目: stuart2w/SAW
 public LambdaVerb(TriggerFunction fn, bool abandonsCurrent, Predicate <EditableView> applicableFunction)
 {
     m_Function           = fn;
     AbandonsCurrent      = abandonsCurrent;
     m_ApplicableFunction = applicableFunction;
 }
示例#8
0
 public static void Write(this BinaryWriter writer, TriggerFunction triggerFunction, MapTriggersFormatVersion formatVersion, MapTriggersSubVersion?subVersion) => triggerFunction.WriteTo(writer, formatVersion, subVersion);
示例#9
0
 public void BindFunctionToTrigger(string _name, TriggerFunction _function)
 {
     Console.WriteLine("bound " + _name);
     BoundFunctions[_name] = _function;
 }
示例#10
0
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 internal static void RegisterTrigger(string Name, string Pattern, TriggerFunction Function)
 {
     RegisterTrigger(Name, Pattern, Function, TriggerFlags.None);
 }
示例#11
0
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 /// <param name="Flags">Options for the trigger.</param>
 /// <param name="Priority">Lower priority triggers get matched first. Default: 1000</param>
 internal static void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags, int Priority)
 {
     RegisterTrigger(Name, Pattern, Function, Flags, Priority, 0, "core");
 }
示例#12
0
 /// <summary>
 /// Register a new trigger.
 /// </summary>
 /// <param name="Name">Unique identifier for the trigger.</param>
 /// <param name="Pattern">Regex pattern for the trigger.</param>
 /// <param name="Function">Function that will be called if this trigger fires.</param>
 /// <param name="Flags">Options for the trigger.</param>
 internal static void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags)
 {
     RegisterTrigger(Name, Pattern, Function, Flags, 1000);
 }