Example #1
0
 public SpellsManager()
     : base()
 {
     m_gcd       = 0;
     m_cast      = new SpellCast();
     m_target    = new TargetEntry();
     m_cooldowns = new CountdownList();
     m_cast_args = new SpellCastArgs();
 }
Example #2
0
        public void Enqueue(string Anime, TimeSpan Countdown, TimeSpan Length)
        {
            CountdownItem item = new CountdownItem();

            item.Title        = Anime;
            item.Length       = Length;
            item.PreCountdown = Countdown;

            CountdownList.Enqueue(item);
        }
Example #3
0
 public void Enqueue(CountdownItem item)
 {
     CountdownList.Enqueue(item);
 }
Example #4
0
        /// <summary>
        /// Main countdown thread.
        /// </summary>
        private void CountdownThread()
        {
            while (ct.IsCancellationRequested == false)
            {
                switch (_state)
                {
                case CountdownState.Idle:
                    // Idle loop (waiting for items)
                    while (ct.IsCancellationRequested == false)
                    {
                        lock (_lockobject)
                        {
                            if (CountdownList.Count != 0)
                            {
                                _state = CountdownState.PreCountdown;
                                break;
                            }
                        }
                        System.Threading.Thread.Sleep(1000);
                    }
                    break;

                case CountdownState.PreCountdown:
                    CountdownItem _nextItem;
                    lock (_lockobject)
                    {
                        _nextItem = CountdownList.Dequeue();
                    }
                    _nextItem.Epoch = DateTime.Now.Add(_nextItem.PreCountdown);
                    CurrentItem     = _nextItem;

                    // This moves our alert index forward to where we initially should be
                    int _alertIndex = 0;
                    for (int i = 0; i < Alerts.Length; i++)
                    {
                        if (Alerts[i] <= CurrentItem.PreCountdown)
                        {
                            _alertIndex = i;
                            break;
                        }
                    }
                    // Main pre-countdown loop.
                    while (ct.IsCancellationRequested == false)
                    {
                        if ((CurrentItem.Epoch - DateTime.Now) < Alerts[_alertIndex])
                        {
                            // alart
                            //Console.WriteLine($"{(CurrentItem.Epoch - DateTime.Now).TotalSeconds} < {Alerts[_alertIndex]}");
                            PrintAlert(CurrentItem, Alerts[_alertIndex]);
                            if (_alertIndex == Alerts.Length - 1)
                            {       // Ran out of alerts, less than one second left
                                _state = CountdownState.PostCountdown;
                                break;
                            }
                            _alertIndex++;
                        }
                        System.Threading.Thread.Sleep(100);
                    }
                    break;

                case CountdownState.PostCountdown:
                    if (DateTime.Now > (CurrentItem.Epoch + CurrentItem.Length))
                    {
                        lock (_lockobject)
                        {
                            if (CountdownList.Count == 0)
                            {
                                // no more things to countdown
                                _state      = CountdownState.Idle;
                                CurrentItem = CountdownItem.Empty;
                                OnMessageEvent("THE END N SHIT");
                            }
                            else
                            {
                                // Move to next anime  (PreCountdown will dequeue)
                                _state = CountdownState.PreCountdown;
                            }
                        }
                    }
                    // Long sleep
                    System.Threading.Thread.Sleep(1000);
                    break;
                }
            }
            // end of loop
        }