private void DispatchForItem(GameObject item, DispatcherType dispType, D20DispatcherKey dispKey,
                                 object dispIo)
    {
        var condArray     = item.GetInt32Array(obj_f.item_pad_wielder_condition_array);
        var argArrayCount = 0; // there's only one argument list for all attached conditions

        for (var i = 0; i < condArray.Count; i++)
        {
            var condNameHash = condArray[i];

            var condition = Conditions.GetByHash(condNameHash);
            if (condition != null)
            {
                using var condArgsInMem = MemoryPool <int> .Shared.Rent(condition.numArgs);

                var condArgsIn = condArgsInMem.Memory.Slice(0, condition.numArgs).Span;
                foreach (ref var arg in condArgsIn)
                {
                    arg = item.GetInt32(obj_f.item_pad_wielder_argument_array, argArrayCount++);
                }

                condArgsIn[2] = -1; // ... why?
                ItemDispatcher.DispatcherProcessorForItems(condition, condArgsIn, dispType, dispKey, dispIo);
            }
        }
    }
Beispiel #2
0
        public static FluentConfig DefaultDispatcher(this FluentConfig self, DispatcherType dispatcherType, int throughput = 100, TimeSpan?throughputDeadlineTimeout = null)
        {
            var type = dispatcherType.GetName();

            self.ConfigureDispatcher(type, throughput, throughputDeadlineTimeout);

            return(self);
        }
Beispiel #3
0
        private static Timer _createTimerImpl(Int64 _interval, bool _auto_reset, DispatcherType _type)
        {
            ++s_max_timer_id;
            Timer timer = new Timer(s_max_timer_id, _type);

            timer.Interval  = _interval;
            timer.AutoReset = _auto_reset;
            return(timer);
        }
 /// <summary>
 /// Gets the lead dispatcher.
 /// </summary>
 /// <param name="dispatcherType">Type of the dispatcher.</param>
 /// <returns></returns>
 public ILeadDispatcher GetDispatcher(DispatcherType dispatcherType)
 {
     ILeadDispatcher leadDispatcher;
     switch (dispatcherType)
     {
         case DispatcherType.TerritoryDispatcher:
             leadDispatcher = new TerritoryDispatcher();
             break;
         default:
             leadDispatcher = new TerritoryDispatcher();
             break;
     }
     return leadDispatcher;
 }
Beispiel #5
0
 //分发事件
 public void Dispatcher(DispatcherType type,string str)
 {
     if (DispatcherType.Error == type)
     {
         if (error != null)
         {
             error.SetContent(str);
         }
     }
     else if (DispatcherType.Building == type)
     {
         if (output != null)
         {
             output.SetContent(str);
         }
     }
 }
Beispiel #6
0
    public void Process(DispatcherType type, D20DispatcherKey key, object dispIo)
    {
        if (_dispCounter > DISPATCHER_MAX)
        {
            Logger.Error("Dispatcher maximum recursion reached!");
            return;
        }

        _dispCounter++;

        foreach (var subDispNode in GetSubDispatcher(type))
        {
            if ((subDispNode.subDispDef.dispKey == key ||
                 subDispNode.subDispDef.dispKey == D20DispatcherKey.NONE) && !subDispNode.condNode.IsExpired)
            {
                DispIoTypeImmunityTrigger dispIoImmunity = DispIoTypeImmunityTrigger.Default;
                dispIoImmunity.condNode = subDispNode.condNode;

                if (type != DispatcherType.ImmunityTrigger || key != D20DispatcherKey.IMMUNITY_SPELL)
                {
                    Process(DispatcherType.ImmunityTrigger, D20DispatcherKey.IMMUNITY_SPELL, dispIoImmunity);
                }

                if (dispIoImmunity.interrupt == 1 && type != DispatcherType.Unused63)
                {
                    // dispType63 is essentially <. Minor globe of invulnerability
                    dispIoImmunity.interrupt = 0;
                    dispIoImmunity.val2      = 10;
                    Process(DispatcherType.Unused63, D20DispatcherKey.NONE, dispIo);
                    if (dispIoImmunity.interrupt == 0)
                    {
                        var args = new DispatcherCallbackArgs(subDispNode, _owner, type, key, dispIo);
                        subDispNode.subDispDef.callback(in args);
                    }
                }
                else
                {
                    var args = new DispatcherCallbackArgs(subDispNode, _owner, type, key, dispIo);

                    subDispNode.subDispDef.callback(in args);
                }
            }
        }

        _dispCounter--;
    }
Beispiel #7
0
    public static void DispatcherProcessorForItems(ConditionSpec condStruct, Span <int> condArgs,
                                                   DispatcherType dispType, D20DispatcherKey key, object dispIo)
    {
        var condAttachment = new ConditionAttachment(condStruct);

        for (int i = 0; i < condStruct.numArgs; i++)
        {
            condAttachment.args[i] = condArgs[i];
        }

        for (int i = 0; i < condStruct.subDispDefs.Length; i++)
        {
            var sdd = condStruct.subDispDefs[i];
            if (sdd.dispType == dispType && (sdd.dispKey == key || sdd.dispKey == D20DispatcherKey.NONE))
            {
                var attachment = new SubDispatcherAttachment();
                attachment.subDispDef = sdd;
                attachment.condNode   = condAttachment;
                var callbackArgs = new DispatcherCallbackArgs(attachment, null, dispType, key, dispIo);
                sdd.callback(in callbackArgs);
            }
        }
    }
Beispiel #8
0
 public TypeAttribute(DispatcherType type)
 {
     Type = type;
 }
Beispiel #9
0
 public static Timer CreateAutoResetTimer(Int64 _interval, DispatcherType _type = DispatcherType.Game)
 {
     return(_createTimerImpl(_interval, true, _type));
 }
Beispiel #10
0
 private Timer(UInt64 _timer_id, DispatcherType _type)
 {
     m_timer_id        = _timer_id;
     m_dispatcher_type = _type;
 }
Beispiel #11
0
 public static string GetName(this DispatcherType self)
 {
     //TODO: switch case return string?
     return(self.ToString());
 }
    public static ConditionSpec.Builder AddHandler <T, U>(this ConditionSpec.Builder builder, DispatcherType type,
                                                          D20DispatcherKey key, SubDispatcherCallback <T, U> handler, T data1, U data2)
    {
        void HandlerWithArgs(in DispatcherCallbackArgs args) => handler(in args, data1, data2);

        return(builder.AddHandler(type, key, HandlerWithArgs));
    }
    public static void DispatchDamage(this GameObject critter, DispatcherType type, DispIoDamage dispIo)
    {
        var dispatcher = critter.GetDispatcher();

        dispatcher?.Process(type, D20DispatcherKey.NONE, dispIo);
    }
    public static int DispatchForCritter(this GameObject obj, DispIoBonusList eventObj, DispatcherType dispType,
                                         D20DispatcherKey dispKey)
    {
        if (obj == null || !obj.IsCritter())
        {
            return(0);
        }

        var dispatcher = obj.GetDispatcher();

        if (dispatcher == null)
        {
            return(0);
        }

        if (eventObj == null)
        {
            eventObj = DispIoBonusList.Default;
        }

        dispatcher.Process(dispType, dispKey, eventObj);

        return(eventObj.bonlist.OverallBonus);
    }
Beispiel #15
0
 /// <summary>
 /// Creates a new <see cref="UwpDispatcher"/>.
 /// </summary>
 public UwpDispatcher()
 {
     DispatcherType = DispatcherType.Main;
 }
Beispiel #16
0
        /// <summary>
        /// Gets the first found <see cref="IDispatcher"/> with the specified <see cref="DispatcherType"/> flag.
        /// </summary>
        /// <param name="dispatchers">The collection of available <see cref="IDispatcher"/>s.</param>
        /// <param name="type">The <see cref="DispatcherType"/> requested from the desired <see cref="IDispatcher"/>.</param>
        /// <returns>The <see cref="IDispatcher"/> managing the background thread.</returns>
        public static IDispatcher GetDispatcher(this IEnumerable <IDispatcher> dispatchers, DispatcherType type)
        {
            if (dispatchers == null || !dispatchers.Any())
            {
                throw new ArgumentException("The collection must contain at least one available IDispatcher.", nameof(dispatchers));
            }

            var background = dispatchers.FirstOrDefault(d => d.DispatcherType.HasFlag(type));

            if (background != null)
            {
                return(background);
            }
            else
            {
                throw new ArgumentException($"No IDispatchers of the specified type {type} were avaliable in the provided collection", nameof(dispatchers));
            }
        }
Beispiel #17
0
 /// <summary>
 /// Creates a new <see cref="WpfDispatcher"/>.
 /// </summary>
 public WpfDispatcher()
 {
     DispatcherType = DispatcherType.Main;
 }
    public static ConditionSpec.Builder AddHandler <T>(this ConditionSpec.Builder builder, DispatcherType type,
                                                       SubDispatcherCallback <T> handler, T data)
    {
        void HandlerWithArgs(in DispatcherCallbackArgs args) => handler(in args, data);

        return(builder.AddHandler(type, HandlerWithArgs));
    }
Beispiel #19
0
 /// <summary>
 /// Creates a new <see cref="BaseDispatcher"/> with the specified flags.
 /// </summary>
 /// <param name="dispatcherType">A set of <see cref="DispatcherType"/> flags indicating whether this <see cref="IDispatcher"/> manages special kinds of threads, which can (and should) be utilized in scenarios such as updating UI elements from code.</param>
 public BaseDispatcher(DispatcherType dispatcherType = DispatcherType.None)
 {
     DispatcherType = dispatcherType;
 }
Beispiel #20
0
        public static FluentConfig DefaultDispatcher(this FluentConfig self, DispatcherType dispatcherType,
            int throughput = 100, TimeSpan? throughputDeadlineTimeout = null)
        {
            string type = dispatcherType.GetName();
            self.ConfigureDispatcher(type, throughput, throughputDeadlineTimeout);

            return self;
        }