public override void Kill(int timeLeft) { Main.PlaySound(SoundLoader.customSoundType, projectile.position, SoundLoader.GetSoundSlot(SoundType.Custom, "Sounds/Custom/Wind2")); for (int i = 0; i < 9; i++) { } { if (Main.rand.Next(3) == 0) { Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("ShortSparkle"), projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } else if (Main.rand.Next(3) == 0) { Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.AncientLight, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } } Projectile.NewProjectile(projectile.position.X + projectile.velocity.X, projectile.position.Y + projectile.velocity.Y, projectile.velocity.X * 0.001f, 0, mod.ProjectileType("WindFieldBlast"), projectile.damage / 2, projectile.knockBack / 3, projectile.owner); }
public static void PlaySound(object soundType, int x, int y, object sound, bool stop = true, bool newInstance = true, float?overrideVolume = null, float?overridePitch = null) { if (Main.netMode == 2 || Main.dedServ || Main.soundVolume == 0f) { return; } Rectangle screenRect = new Rectangle((int)(Main.screenPosition.X - Main.screenWidth * 2), (int)(Main.screenPosition.Y - Main.screenHeight * 2), Main.screenWidth * 5, Main.screenHeight * 5); Rectangle locRect = new Rectangle(x, y, 1, 1); bool usePan = locRect.Intersects(screenRect); if ((x == -1 && y == -1) || usePan) { SoundEffect soundEffect = null; float pitch = 0f; int soundID = -1; SoundEffect[] soundArray = null; SoundEffectInstance[] soundInstanceArray = null; int soundType2 = (soundType is int?(int)soundType : 0); if (soundType is SoundType) { switch ((SoundType)soundType) { case SoundType.Custom: soundType2 = -1; break; case SoundType.Item: soundType2 = 2; break; case SoundType.NPCHit: soundType2 = 3; break; case SoundType.NPCKilled: soundType2 = 4; break; default: soundType2 = 0; break; } } switch (soundType2) { case -1: soundID = SoundLoader.GetSoundSlot(SoundType.Custom, (string)sound); if (soundField == null) { soundField = typeof(SoundLoader).GetField("customSounds", BindingFlags.NonPublic | BindingFlags.Static); } if (soundInstanceField == null) { soundInstanceField = typeof(SoundLoader).GetField("customSoundInstances", BindingFlags.NonPublic | BindingFlags.Static); } soundArray = (SoundEffect[])soundField.GetValue(null); // SoundLoader.customSounds[soundID]; soundInstanceArray = (SoundEffectInstance[])soundInstanceField.GetValue(null); break; case 2: if (sound is string) { soundID = SoundLoader.GetSoundSlot(SoundType.Item, (string)sound); } else { soundID = (int)sound; } soundArray = Main.soundItem; soundInstanceArray = Main.soundInstanceItem; pitch = Main.rand.Next(-6, 7) * 0.01f; break; case 3: if (sound is string) { soundID = SoundLoader.GetSoundSlot(SoundType.NPCHit, (string)sound); } else { soundID = (int)sound; } soundArray = Main.soundNPCHit; soundInstanceArray = Main.soundInstanceNPCHit; pitch = Main.rand.Next(-10, 11) * 0.01f; break; case 4: if (sound is string) { soundID = SoundLoader.GetSoundSlot(SoundType.NPCKilled, (string)sound); } else { soundID = (int)sound; } soundArray = Main.soundNPCKilled; soundInstanceArray = Main.soundInstanceNPCKilled; pitch = Main.rand.Next(-10, 11) * 0.01f; break; default: return; } //TODO: FIX SOUND VOLUME/PAN soundEffect = soundArray[soundID]; if (stop && soundID != -1 && soundInstanceArray[soundID] != null) { soundInstanceArray[soundID].Stop(); } float soundPan = 0f; float soundVol = 1f; if (usePan) { Vector2 vector = new Vector2(Main.screenPosition.X + Main.screenWidth * 0.5f, Main.screenPosition.Y + Main.screenHeight * 0.5f); float absX = Math.Abs(x - vector.X); float absY = Math.Abs(y - vector.Y); float absSQ = (float)Math.Sqrt(absX * absX + absY * absY); soundPan = (x - vector.X) / (Main.screenWidth * 0.5f); soundVol = 1f - absSQ / (Main.screenWidth * 1.5f); } SoundEffectInstance soundInstance = (newInstance ? soundEffect.CreateInstance() : (soundInstanceArray[soundID].State == SoundState.Playing ? soundInstanceArray[soundID] : soundEffect.CreateInstance())); soundInstance.Volume = Math.Max(0f, Math.Min(1f, (overrideVolume != null ? (float)overrideVolume : soundVol) * Main.soundVolume)); soundInstance.Pitch = (overridePitch != null ? (float)overridePitch : pitch); soundInstance.Pan = Math.Max(-1f, Math.Min(1f, soundPan)); Main.PlaySoundInstance(soundInstance); soundInstanceArray[soundID] = soundInstance; switch (soundType2) { case -1: soundField.SetValue(null, soundArray); soundInstanceField.SetValue(null, soundInstanceArray); break; case 2: Main.soundItem = soundArray; Main.soundInstanceItem = soundInstanceArray; break; case 3: Main.soundNPCHit = soundArray; Main.soundInstanceNPCHit = soundInstanceArray; break; case 4: Main.soundNPCKilled = soundArray; Main.soundInstanceNPCKilled = soundInstanceArray; break; default: return; } } //OLD CODE //Main.PlaySound(soundEffect, x, y, newInstance, null, Single.NaN, overrideVolume == null ? Single.NaN : (float)overrideVolume, pitch); /*if (soundType == 100) { soundType = 3; if (overridePitch == null) { overridePitch = 0f; } } * if (Main.dedServ || Main.soundVolume <= 0f) { return; } * Microsoft.Xna.Framework.Audio.SoundEffect sound = null; * Microsoft.Xna.Framework.Audio.SoundEffectInstance instance = null; * float volume = 1f; * float pan = 0f; * float pitch = 0f; * bool canPlay = false; * if (x == -1 || y == -1) { canPlay = true; }else * { * if (WorldGen.gen || Main.netMode == 2) { return; } * Rectangle value = new Rectangle((int)(Main.screenPosition.X - (float)(Main.screenWidth * 2)), (int)(Main.screenPosition.Y - (float)(Main.screenHeight * 2)), Main.screenWidth * 5, Main.screenHeight * 5); * Rectangle rectangle = new Rectangle(x, y, 1, 1); * Vector2 vector = new Vector2(Main.screenPosition.X + (float)Main.screenWidth * 0.5f, Main.screenPosition.Y + (float)Main.screenHeight * 0.5f); * canPlay = rectangle.Intersects(value); * if (canPlay) * { * pan = ((float)x - vector.X) / ((float)Main.screenWidth * 0.5f); * float distX = Math.Abs((float)x - vector.X); * float distY = Math.Abs((float)y - vector.Y); * float dist = (float)Math.Sqrt((double)(distX * distX + distY * distY)); * volume = 1f - dist / ((float)Main.screenWidth * 1.5f); * } * } * pan = Math.Max(-1, Math.Min(1, pan)); * if (volume > 1f) { volume = 1f; } * if (volume > 0f && canPlay) * { * switch (soundType) * { * case 2: * instance = Main.soundInstanceItem[soundID]; * sound = Main.soundItem[soundID]; * pitch = (float)Main.rand.Next(-6, 7) * 0.01f; * break; * case 3: * instance = Main.soundInstanceNPCHit[soundID]; * sound = Main.soundNPCHit[soundID]; * pitch = (float)Main.rand.Next(-10, 11) * 0.01f; * break; * case 4: * instance = Main.soundInstanceNPCKilled[soundID]; * sound = Main.soundNPCKilled[soundID]; * pitch = (float)Main.rand.Next(-10, 11) * 0.01f; * break; * default: break; * } * if (sound == null) { return; } * if (overridePitch != null) { pitch = (float)overridePitch; } * if (overrideVolume != null) { volume = (float)overrideVolume; } * volume *= Main.soundVolume; * if (stop && instance != null) { instance.Stop(); } * if (newInstance || instance == null || instance.State == Microsoft.Xna.Framework.Audio.SoundState.Stopped) * { * newInstance = true; * switch (soundType) * { * case 2: instance = Main.soundInstanceItem[soundID] = sound.CreateInstance(); break; * case 3: instance = Main.soundInstanceNPCHit[soundID] = sound.CreateInstance(); break; * case 4: instance = Main.soundInstanceNPCKilled[soundID] = sound.CreateInstance(); break; * default: break; * } * } * instance.Volume = volume; * instance.Pan = pan; * instance.Pitch = pitch; * if (stop || newInstance) { instance.Play(); } * }*/ }
/// <summary> /// Shorthand for <see cref="Main.PlaySound(int, int, int, int, float, float)"/>, for landing sounds. /// </summary> private static SoundEffectInstance PlayLanding(string path, int x, int y, float volume) => SoundWrapper.PlaySound((int)SoundType.Custom, x, y, SoundLoader.GetSoundSlot(SoundType.Custom, "OriMod/Sounds/Custom/NewSFX/Ori/Land/" + path), volume, 0.1f);
public static int AddSound(string path, SoundType type = SoundType.Custom, ModSound modSound = null) { instance.AddSound(type, "Origins/" + path, modSound); return(SoundLoader.GetSoundSlot(type, "Origins/" + path)); }