示例#1
0
    bool Run(DoScriptEvent doScriptEvent, Action continuation)
    {
        var assets     = Resolve <IAssetManager>();
        var mapManager = Resolve <IMapManager>();

        var events = assets.LoadScript(doScriptEvent.ScriptId);

        if (events == null)
        {
            Error($"Could not load script {doScriptEvent.ScriptId}");
            return(false);
        }

        var nodes = new EventNode[events.Count];

        // Create, link and add all the nodes.
        for (ushort i = 0; i < events.Count; i++)
        {
            nodes[i] = new EventNode(i, events[i]);
        }
        for (ushort i = 0; i < events.Count - 1; i++)
        {
            nodes[i].Next = nodes[i + 1];
        }

        var source  = new EventSource(mapManager.Current.MapId, mapManager.Current.MapId.ToMapText(), TriggerTypes.Default); // TODO: Is there a better trigger type for this?
        var trigger = new TriggerChainEvent(AssetId.None, 0, nodes[0], source);

        return(RaiseAsync(trigger, continuation) > 0);
    }
示例#2
0
        bool Run(DoScriptEvent doScriptEvent, Action continuation)
        {
            var assets     = Resolve <IAssetManager>();
            var mapManager = Resolve <IMapManager>();

            var events = assets.LoadScript(doScriptEvent.ScriptId);
            var nodes  = new EventNode[events.Count];
            var chain  = new EventChain(0);

            // Create, link and add all the nodes.
            for (ushort i = 0; i < events.Count; i++)
            {
                nodes[i] = new EventNode(i, events[i]);
            }
            for (ushort i = 0; i < events.Count - 1; i++)
            {
                nodes[i].Next = nodes[i + 1];
            }
            for (ushort i = 0; i < events.Count; i++)
            {
                chain.Events.Add(nodes[i]);
            }

            var source  = new EventSource.Map(mapManager.Current.MapId, TriggerType.Default, 0, 0); // TODO: Is there a better trigger type for this?
            var trigger = new TriggerChainEvent(chain, chain.FirstEvent, source);

            return(RaiseAsync(trigger, continuation) > 0);
        }
示例#3
0
        bool TriggerAction(ActionType type, byte small, ushort large, Action continuation = null)
        {
            var assets   = Resolve <IAssetManager>();
            var eventSet = _npc.EventSetId == null ? null : assets.LoadEventSet(_npc.EventSetId.Value);
            var wordSet  = _npc.WordSetId == null ? null : assets.LoadEventSet(_npc.WordSetId.Value);

            bool fromWordSet = false;
            var  chain       = eventSet?.Chains.FirstOrDefault(x =>
                                                               x.FirstEvent?.Event is ActionEvent action &&
                                                               action.ActionType == type &&
                                                               action.SmallArg == small &&
                                                               action.LargeArg == large);

            if (chain == null)
            {
                chain = wordSet?.Chains.FirstOrDefault(x =>
                                                       x.FirstEvent?.Event is ActionEvent action && action.ActionType == type &&
                                                       action.SmallArg == small && action.LargeArg == large);
                fromWordSet = true;
            }

            if (chain != null)
            {
                var triggerEvent = new TriggerChainEvent(chain, chain.FirstEvent, fromWordSet ? wordSet.Id : eventSet.Id);
                RaiseAsync(triggerEvent, () => continuation?.Invoke());
                return(true);
            }
            return(false);
        }