コード例 #1
0
ファイル: Play.cs プロジェクト: githuborwhatever/Angel-Island
            protected override void OnTick()
            {
                if (DateTime.Now < m_PauseTime)
                {
                    //					Console.WriteLine("Waiting pause time");
                    return;
                }

                if (m_Player.PlayList.Count == 0)                 // If the tune is done, stop the timer.
                {
                    m_Player.Playing = false;
                    Stop();
                    return;
                }
                else
                {
                    try
                    {
                        //						Console.WriteLine(DateTime.Now.TimeOfDay);
                        object obj = m_Player.PlayList.Dequeue();

                        // If the first item in the queue is a string, make sure a string
                        // instrument is selected, and play the note.
                        if (obj.GetType() == (typeof(string)))
                        {
                            BaseInstrument instrument = BaseInstrument.GetInstrument(m_Player);

                            // Unfortunately, there are no note files for percussion instruments.
                            if (instrument is Drums || instrument is Tambourine || instrument is TambourineTassel)
                            {
                                m_Player.SendMessage("You cannot play a tune on that instrument.");
                                m_Player.PlayList = null;
                                m_Player.Playing  = false;
                                Stop();
                            }
                            else if (instrument == null)
                            {
                                m_Player.SendMessage("Something has happened to your instrument.");
                                m_Player.PlayList = null;
                                m_Player.Playing  = false;
                                Stop();
                            }
                            else
                            {
                                Music.PlayNote(m_Player, (string)obj, instrument);
                                //								Console.WriteLine("Playing Music");
                            }
                        }
                        else                         // If the first item is a double, treat it as a pause.
                        {
                            double pause = (double)obj;
                            //							Console.WriteLine(pause);
                            m_PauseTime = DateTime.Now + TimeSpan.FromSeconds(pause);
                            //							Console.WriteLine(m_PauseTime);
                            //							Console.WriteLine(DateTime.Now.TimeOfDay);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        Server.Commands.LogHelper.LogException(ex);
                    }
                }
            }