audio: stop precast sound on spell completion, failure, or interrupt

Add AudioEngine::playSound2DStoppable() + stopSound() so callers can
hold a handle and cancel playback early. SpellSoundManager::playPrecast()
now stores the handle in activePrecastId_; stopPrecast() cuts the sound.

playCast() calls stopPrecast() before playing the release sound, so the
channeling audio never bleeds past cast time. SMSG_SPELL_FAILURE and
SMSG_CAST_FAILED both call stopPrecast() so interrupted casts silence
immediately.
This commit is contained in:
Kelsi 2026-03-09 21:04:24 -07:00
parent e0d47040d3
commit 9d1616a11b
5 changed files with 100 additions and 3 deletions

View file

@ -220,12 +220,22 @@ void SpellSoundManager::playPrecast(MagicSchool school, SpellPower power) {
return;
}
if (library) {
playSound(*library);
if (library && !library->empty() && (*library)[0].loaded) {
stopPrecast(); // Stop any previous precast still playing
float volume = 0.75f * volumeScale_;
activePrecastId_ = AudioEngine::instance().playSound2DStoppable((*library)[0].data, volume);
}
}
void SpellSoundManager::stopPrecast() {
if (activePrecastId_ != 0) {
AudioEngine::instance().stopSound(activePrecastId_);
activePrecastId_ = 0;
}
}
void SpellSoundManager::playCast(MagicSchool school) {
stopPrecast(); // Ensure precast doesn't overlap the cast sound
switch (school) {
case MagicSchool::FIRE:
playSound(castFireSounds_);