Ejemplo n.º 1
0
 /// <summary>
 ///   onCustomEvent handler
 /// </summary>
 public override void OnCustomEvent(CustomEvent e)
 {
     // If our custom event "triggerhit" went off,
     if (e.Condition.Name == "triggerhit")
     {
         // Adjust the trigger value, or
         // else the event will fire again and again and again...
         trigger -= 20;
         Out.WriteLine("Ouch, down to " + (int) (Energy + .5) + " energy.");
         // move around a bit.
         TurnLeft(65);
         Ahead(100);
     }
 }
Ejemplo n.º 2
0
 public override void OnCustomEvent(CustomEvent e)
 {
     Out.WriteLine(Time + " " + e.Condition.Name);
 }
Ejemplo n.º 3
0
 /// <inheritdoc />
 public virtual void OnCustomEvent(CustomEvent evnt)
 {
 }
Ejemplo n.º 4
0
        public void processEvents()
        {
            // remove too old stuff
            eventQueue.clear(getTime() - MAX_EVENT_STACK);

            //copy prior iterration, because user could call RemoveCustomEvent
            List<Condition> eventsCopy = new List<Condition>(customEvents);

            // Process custom events
            foreach (Condition customEvent in eventsCopy)
            {
                bool conditionSatisfied = CallUserCode(customEvent);
                if (conditionSatisfied)
                {
                    var evnt = new CustomEvent(customEvent);

                    HiddenAccessN.setEventTime(evnt, getTime());
                    addImpl(evnt);
                }
            }

            // Process event queue here
            eventQueue.sort();

            Event currentEvent = null;

            if (eventQueue.Count > 0)
            {
                currentEvent = eventQueue[0];
            }
            while (currentEvent != null && currentEvent.Priority >= currentTopEventPriority)
            {
                if (currentEvent.Priority == currentTopEventPriority)
                {
                    if (currentTopEventPriority > int.MinValue && getInterruptible(currentTopEventPriority))
                    {
                        setInterruptible(currentTopEventPriority, false); // we're going to restart it, so reset.

                        // We are already in an event handler, took action, and a new event was generated.
                        // So we want to break out of the old handler to process it here.
                        throw new EventInterruptedException(currentEvent.Priority);
                    }
                    break;
                }

                int oldTopEventPriority = currentTopEventPriority;

                currentTopEventPriority = currentEvent.Priority;
                currentTopEvent = currentEvent;

                eventQueue.Remove(currentEvent);
                try
                {
                    dispatch(currentEvent);

                    setInterruptible(currentTopEventPriority, false);
                }
                catch (EventInterruptedException)
                {
                    currentTopEvent = null;
                }
                catch (Exception)
                {
                    currentTopEventPriority = oldTopEventPriority;
                    currentTopEvent = null;
                    throw;
                }
                currentTopEventPriority = oldTopEventPriority;
                currentEvent = (eventQueue.Count > 0) ? eventQueue[0] : null;
            }
        }