示例#1
0
文件: Sounds.cs 项目: uotools/PlayUO
 public void PlaySound(int SoundID, int X, int Y, int Z, float Volume)
 {
     if ((m_Device != null) && this.m_Enabled)
     {
         SoundID &= 0xfff;
         SoundCache cache = m_Cache[SoundID];
         if (cache == null)
         {
             cache = m_Cache[SoundID] = new SoundCache(SoundID);
         }
         try
         {
             SecondaryBuffer buffer = cache.GetBuffer(this);
             if (buffer != null)
             {
                 Mobile player = World.Player;
                 if ((((X == -1) && (Y == -1)) && (Z == -1)) || (player == null))
                 {
                     try
                     {
                         buffer.set_Pan(0);
                     }
                     catch
                     {
                     }
                     try
                     {
                         buffer.set_Volume(-10000 + (this.ScaledVolume * 100));
                     }
                     catch
                     {
                     }
                 }
                 else
                 {
                     int num  = Math.Abs((int)((X - player.X) * 11));
                     int num2 = Math.Abs((int)((Y - player.Y) * 11));
                     int num3 = Math.Abs((int)(Z - player.Z));
                     int num4 = (int)Math.Sqrt((double)(((num * num) + (num2 * num2)) + (num3 * num3)));
                     int num5 = (X - Y) - (player.X - player.Y);
                     num5 *= 350;
                     num4 *= 10;
                     num4  = -num4;
                     num4 -= (int)(5000f * (1f - Volume));
                     int scaledVolume = this.ScaledVolume;
                     num4 = ((-10000 * (100 - scaledVolume)) + (num4 * scaledVolume)) / 100;
                     if (num4 > 0)
                     {
                         num4 = 0;
                     }
                     else if (num4 < -10000)
                     {
                         num4 = -10000;
                     }
                     if (num5 > 0x2710)
                     {
                         num5 = 0x2710;
                     }
                     else if (num5 < -10000)
                     {
                         num5 = -10000;
                     }
                     try
                     {
                         buffer.set_Pan(num5);
                     }
                     catch
                     {
                     }
                     try
                     {
                         buffer.set_Volume(num4);
                     }
                     catch
                     {
                     }
                 }
                 buffer.SetCurrentPosition(0);
                 buffer.Play(0, 0);
             }
         }
         catch (Exception exception)
         {
             Debug.Error(exception);
         }
     }
 }
示例#2
0
 public void PlaySound(int SoundID, int X, int Y, int Z, float Volume)
 {
     if ((m_Device != null) && this.m_Enabled)
     {
         SoundID &= 0xfff;
         SoundCache cache = m_Cache[SoundID];
         if (cache == null)
         {
             cache = m_Cache[SoundID] = new SoundCache(SoundID);
         }
         try
         {
             SecondaryBuffer buffer = cache.GetBuffer(this);
             if (buffer != null)
             {
                 Mobile player = World.Player;
                 if ((((X == -1) && (Y == -1)) && (Z == -1)) || (player == null))
                 {
                     try
                     {
                         buffer.set_Pan(0);
                     }
                     catch
                     {
                     }
                     try
                     {
                         buffer.set_Volume(-10000 + (this.ScaledVolume * 100));
                     }
                     catch
                     {
                     }
                 }
                 else
                 {
                     int num = Math.Abs((int) ((X - player.X) * 11));
                     int num2 = Math.Abs((int) ((Y - player.Y) * 11));
                     int num3 = Math.Abs((int) (Z - player.Z));
                     int num4 = (int) Math.Sqrt((double) (((num * num) + (num2 * num2)) + (num3 * num3)));
                     int num5 = (X - Y) - (player.X - player.Y);
                     num5 *= 350;
                     num4 *= 10;
                     num4 = -num4;
                     num4 -= (int) (5000f * (1f - Volume));
                     int scaledVolume = this.ScaledVolume;
                     num4 = ((-10000 * (100 - scaledVolume)) + (num4 * scaledVolume)) / 100;
                     if (num4 > 0)
                     {
                         num4 = 0;
                     }
                     else if (num4 < -10000)
                     {
                         num4 = -10000;
                     }
                     if (num5 > 0x2710)
                     {
                         num5 = 0x2710;
                     }
                     else if (num5 < -10000)
                     {
                         num5 = -10000;
                     }
                     try
                     {
                         buffer.set_Pan(num5);
                     }
                     catch
                     {
                     }
                     try
                     {
                         buffer.set_Volume(num4);
                     }
                     catch
                     {
                     }
                 }
                 buffer.SetCurrentPosition(0);
                 buffer.Play(0, 0);
             }
         }
         catch (Exception exception)
         {
             Debug.Error(exception);
         }
     }
 }