|
1 | 1 | using Celeste.Mod.CommunalHelper.Components; |
2 | 2 | using Celeste.Mod.CommunalHelper.Utils; |
| 3 | +using FMOD.Studio; |
3 | 4 | using System.Collections; |
4 | 5 | using System.Linq; |
5 | 6 |
|
@@ -89,6 +90,7 @@ public class Shapeshifter : Solid |
89 | 90 | private readonly float rainbowMix; |
90 | 91 |
|
91 | 92 | private readonly SoundSource sfx; |
| 93 | + private EventInstance quakeSfx; |
92 | 94 |
|
93 | 95 | public Shapeshifter(EntityData data, Vector2 offset, EntityID id) |
94 | 96 | : this |
@@ -244,10 +246,11 @@ private IEnumerator Sequence(ShapeshifterPath path) |
244 | 246 |
|
245 | 247 | if (path.QuakeTime > 0.0f) |
246 | 248 | { |
247 | | - var quakeSfx = Audio.Play(CustomSFX.game_shapeshifter_shake, Position); |
| 249 | + quakeSfx = Audio.Play(CustomSFX.game_shapeshifter_shake, Position); |
248 | 250 | StartShaking(path.QuakeTime); |
249 | 251 | yield return path.QuakeTime; |
250 | | - quakeSfx.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); |
| 252 | + quakeSfx.stop(STOP_MODE.ALLOWFADEOUT); |
| 253 | + quakeSfx = null; |
251 | 254 | } |
252 | 255 |
|
253 | 256 | Audio.Play(startSound, Position); |
@@ -372,4 +375,45 @@ public override void Update() |
372 | 375 | base.Update(); |
373 | 376 | mesh.Matrix = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll); |
374 | 377 | } |
| 378 | + |
| 379 | + private void StopSfx() |
| 380 | + { |
| 381 | + sfx?.Stop(); |
| 382 | + quakeSfx?.stop(STOP_MODE.IMMEDIATE); |
| 383 | + } |
| 384 | + |
| 385 | + public override void Removed(Scene scene) |
| 386 | + { |
| 387 | + StopSfx(); |
| 388 | + base.Removed(scene); |
| 389 | + } |
| 390 | + |
| 391 | + public override void SceneEnd(Scene scene) |
| 392 | + { |
| 393 | + StopSfx(); |
| 394 | + base.SceneEnd(scene); |
| 395 | + } |
| 396 | + |
| 397 | + #region Hooks |
| 398 | + |
| 399 | + internal static void Load() |
| 400 | + { |
| 401 | + Everest.Events.Player.OnDie += OnDie; |
| 402 | + } |
| 403 | + |
| 404 | + internal static void Unload() |
| 405 | + { |
| 406 | + Everest.Events.Player.OnDie -= OnDie; |
| 407 | + } |
| 408 | + |
| 409 | + private static void OnDie(Player player) |
| 410 | + { |
| 411 | + if (player.Scene?.Tracker?.GetEntities<Shapeshifter>()?.Cast<Shapeshifter>() is not { } shapeshifters) |
| 412 | + return; |
| 413 | + |
| 414 | + foreach (Shapeshifter shapeshifter in shapeshifters) |
| 415 | + shapeshifter.StopSfx(); |
| 416 | + } |
| 417 | + |
| 418 | + #endregion |
375 | 419 | } |
0 commit comments