public static void Postfix()
        {
            TimerCooldown.Update();
            try
            {
                while (EventLookup.TimedActionsQueue.Count > 0)
                {
                    // Execute all the timed event cleanup code BEFORE any of the other events
                    Action localAction = EventLookup.TimedActionsQueue[0];
                    localAction();
                    EventLookup.TimedActionsQueue.RemoveAt(0);
                }

                if (EventLookup.ActionQueue.Count > 0)
                {
                    KeyValuePair <string, EventInfo> localEventInfo = new KeyValuePair <string, EventInfo>();
                    int eventIndex = -1;

                    for (int i = 0; i < EventLookup.ActionQueue.Count; i++)
                    {
                        KeyValuePair <string, EventInfo> keyValuePair = EventLookup.ActionQueue[i];
                        if (!EventLookup.IsRunningOrCooldown(keyValuePair.Key))
                        {
                            // Safe to use, doesnt have cooldown / is currently in use
                            localEventInfo = keyValuePair;
                            eventIndex     = i;
                        }
                    }

                    if (eventIndex >= 0)
                    {
                        EventLookup.ActionQueue.RemoveAt(eventIndex);
                        TimerCooldown.RemoveQueueText(localEventInfo.Key);
                        if (localEventInfo.Value is TimedEventInfo)
                        {
                            // If its a timed event, pass that info to the TimerCooldown
                            TimedEventInfo timedEventInfo = (TimedEventInfo)localEventInfo.Value;
                            TimerCooldown.AddCooldown(localEventInfo.Key, timedEventInfo);
                            // Don't start the cooldown yet, cooldown starts after the cleanup code
                        }
                        else
                        {
                            // Otherwise quickly make it pop up in the UI
                            TimerCooldown.AddCooldown(localEventInfo.Key, 1, localEventInfo.Value);
                            EventLookup.Cooldowns.Add(localEventInfo.Key, Time.time);
                            TimerCooldown.AddCooldownText(localEventInfo.Key, localEventInfo.Value.CooldownSeconds, localEventInfo.Value);
                        }

                        localEventInfo.Value.Action.Invoke();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to invoke action " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #2
0
        public static void Postfix()
        {
            TimerCooldown.Update();
            try
            {
                while (EventLookup.TimedActionsQueue.Count > 0)
                {
                    // Execute all the timed event cleanup code BEFORE any of the other events
                    Tuple <string, string, TimedEventInfo> localAction = EventLookup.TimedActionsQueue[0];
                    localAction.Item3.TimedAction.Invoke();
                    EventLookup.TimedActionsQueue.RemoveAt(0);
                }

                if (EventLookup.ActionQueue.Count > 0)
                {
                    Tuple <string, string, EventInfo> localEventInfo = null;
                    int eventIndex = -1;

                    for (int i = 0; i < EventLookup.ActionQueue.Count; i++)
                    {
                        Tuple <string, string, EventInfo> data = EventLookup.ActionQueue[i];
                        if (!EventLookup.IsRunningOrCooldown(data.Item1))
                        {
                            // Safe to use, doesnt have cooldown / is currently in use
                            localEventInfo = data;
                            eventIndex     = i;
                        }
                    }

                    if (eventIndex >= 0)
                    {
                        EventLookup.ActionQueue.RemoveAt(eventIndex);
                        TimerCooldown.RemoveQueueText(localEventInfo.Item1);
                        if (localEventInfo.Item3 is TimedEventInfo)
                        {
                            // If its a timed event, pass that info to the TimerCooldown
                            TimedEventInfo timedEventInfo = (TimedEventInfo)localEventInfo.Item3;
                            TimerCooldown.AddCooldown(localEventInfo.Item1, new Tuple <string, string, TimedEventInfo>(localEventInfo.Item1, localEventInfo.Item2, timedEventInfo));
                            // Don't start the cooldown yet, cooldown starts after the cleanup code
                        }
                        else
                        {
                            // Otherwise quickly make it pop up in the UI
                            TimerCooldown.AddCooldown(localEventInfo.Item1, 1, localEventInfo);
                            EventLookup.Cooldowns.Add(localEventInfo.Item1, Time.time);
                            TimerCooldown.AddCooldownText(localEventInfo.Item1, localEventInfo.Item3.CooldownSeconds, localEventInfo);
                        }

                        if (localEventInfo.Item3.RequiresUsername)
                        {
                            localEventInfo.Item3.ActionWithUsername.Invoke(localEventInfo.Item2);
                        }
                        else
                        {
                            localEventInfo.Item3.Action.Invoke();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to invoke action " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }