public static Sound3D PlaySound(string name, Vector3 location, bool randomPitch, float volume = 1.0f, float pitch = 0.0f) { if (!HasAudioDevice) { return(null); } if (Content == null) { return(null); } SoundEffect effect = null; if (!EffectLibrary.ContainsKey(name)) { effect = Content.Load <SoundEffect>(name); EffectLibrary[name] = effect; } else { effect = EffectLibrary[name]; } if (!SoundCounts.ContainsKey(name)) { SoundCounts[name] = 0; } if (SoundCounts[name] < MaxSounds) { SoundCounts[name]++; Sound3D sound = new Sound3D { Position = location, EffectInstance = effect.CreateInstance(), HasStarted = false, Name = name }; SFXMixer.Levels levels = Mixer.GetOrCreateLevels(name); sound.EffectInstance.IsLooped = false; sound.VolumeMultiplier = volume * levels.Volume; if (randomPitch) { sound.EffectInstance.Pitch = MathFunctions.Clamp((float)(MathFunctions.Random.NextDouble() * 1.0f - 0.5f) * levels.RandomPitch + pitch, -1.0f, 1.0f); } ActiveSounds.Add(sound); return(sound); } return(null); }
public static Sound3D PlaySound(string name, Vector3 location, bool randomPitch, float volume = 1.0f) { if (Content == null) { return(null); } SoundEffect effect = null; if (!EffectLibrary.ContainsKey(name)) { effect = Content.Load <SoundEffect>(name); EffectLibrary[name] = effect; } else { effect = EffectLibrary[name]; } if (!SoundCounts.ContainsKey(name)) { SoundCounts[name] = 0; } if (SoundCounts[name] < MaxSounds) { SoundCounts[name]++; Sound3D sound = new Sound3D { Position = location, EffectInstance = effect.CreateInstance(), HasStarted = false, Name = name }; sound.EffectInstance.IsLooped = false; sound.VolumeMultiplier = volume; if (randomPitch) { sound.EffectInstance.Pitch = (float)(PlayState.Random.NextDouble() * 1.0f - 0.5f); } ActiveSounds.Add(sound); return(sound); } return(null); }
public override IEnumerable <Act.Status> Run() { if (Spell.IsResearched) { Creature.CurrentCharacterMode = CharacterMode.Idle; Creature.OverrideCharacterMode = false; yield return(Status.Success); yield break; } Timer starParitcle = new Timer(0.5f, false); float totalResearch = 0.0f; Sound3D sound = null; while (!Spell.IsResearched) { Creature.CurrentCharacterMode = CharacterMode.Attacking; Creature.OverrideCharacterMode = true; Creature.Sprite.ReloopAnimations(CharacterMode.Attacking); float research = Creature.Stats.BuffedInt * 0.25f * DwarfTime.Dt; Spell.ResearchProgress += research; totalResearch += research; Creature.Physics.Velocity *= 0; Drawer2D.DrawLoadBar(Creature.World.Camera, Creature.Physics.Position, Color.Cyan, Color.Black, 64, 4, Spell.ResearchProgress / Spell.ResearchTime); if ((int)totalResearch > 0) { if (sound == null || sound.EffectInstance.IsDisposed || sound.EffectInstance.State == SoundState.Stopped) { sound = SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_ic_dwarf_magic_research, Creature.AI.Position, true); } //SoundManager.PlaySound(ContentPaths.Audio.tinkle, Creature.AI.Position, true); Creature.AI.AddXP((int)(totalResearch)); totalResearch = 0.0f; } if (Spell.ResearchProgress >= Spell.ResearchTime) { Creature.Manager.World.MakeAnnouncement( new Gui.Widgets.QueuedAnnouncement { Text = String.Format("{0} ({1}) discovered the {2} spell!", Creature.Stats.FullName, Creature.Stats.CurrentLevel.Name, Spell.Spell.Name), ClickAction = (gui, sender) => Agent.ZoomToMe() }); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_positive_generic, 0.15f); } starParitcle.Update(DwarfTime.LastTime); if (starParitcle.HasTriggered) { Creature.Manager.World.ParticleManager.Trigger("star_particle", Creature.AI.Position, Color.White, 3); } yield return(Status.Running); } if (sound != null) { sound.Stop(); } Creature.AI.AddThought(Thought.ThoughtType.Researched); Creature.OverrideCharacterMode = false; Creature.CurrentCharacterMode = CharacterMode.Idle; yield return(Status.Success); yield break; }