Beispiel #1
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--;
    }
    public static D20DispatcherKey DispatchHasImmunityTrigger(this GameObject critter,
                                                              DispIoTypeImmunityTrigger dispIo)
    {
        var dispatcher = critter.GetDispatcher();

        if (dispatcher == null)
        {
            return(D20DispatcherKey.NONE);
        }

        for (var i = D20DispatcherKey.IMMUNITY_SPELL; i <= D20DispatcherKey.IMMUNITY_SPECIAL; i++)
        {
            dispatcher.Process(DispatcherType.ImmunityTrigger, i, dispIo);
            if (dispIo.interrupt == 1)
            {
                return(i);
            }
        }

        return(D20DispatcherKey.NONE);
    }