Skip to content

Commit

Permalink
Noises for effects
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 13, 2022
1 parent f26b177 commit ab1b045
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 101 deletions.
2 changes: 1 addition & 1 deletion EndlessClient/Audio/AudioActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ToggleSound()

var noise = _currentMapProvider.CurrentMap.Properties.AmbientNoise;
if (noise > 0)
_sfxPlayer.PlayLoopingSfx((SoundEffectID)noise);
_sfxPlayer.PlayLoopingSfx((SoundEffectID)noise - 1);
else
_sfxPlayer.StopLoopingSfx();
}
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/Audio/SfxPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SfxPlayer(IContentProvider contentProvider)

public void PlaySfx(SoundEffectID id)
{
_contentProvider.SFX[id-1].Play();
_contentProvider.SFX[id].Play();
}

public void PlayHarpNote(int index)
Expand All @@ -44,7 +44,7 @@ public void PlayLoopingSfx(SoundEffectID id)

StopLoopingSfx();

_activeSfx = _contentProvider.SFX[id-1].CreateInstance();
_activeSfx = _contentProvider.SFX[id].CreateInstance();
_activeSfx.IsLooped = true;
_activeSfx.Play();
}
Expand Down
34 changes: 25 additions & 9 deletions EndlessClient/Audio/SoundEffectID.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace EndlessClient.Audio
{

//sfx001 will be ID int 0
// These are 0 based indexes even though the files start at sfx001
// sfx001 will be id 0
// sfx060 will be id 59
public enum SoundEffectID
{
LayeredTechIntro,
Expand Down Expand Up @@ -59,17 +61,31 @@ public enum SoundEffectID
Gun = 52,
UltimaBlastSpell,
ShieldSpell,
UnknownAggressiveShieldSound,
RingOfFireSpell,
IceBlastSpell1 = 56,
EnergyBallSpell,
WhirlSpell,
BouldersSpell,
HeavenSpell = 60,
//there's another ice blast spell in here
MapEffectHPDrain = 69,
MapEffectTPDrain = 70,
Spikes = 71,
//not sure what the remaining sounds are but I think map ambient noises start eventually
//map noises seem to fade out as you change maps or get farther away from them
AuraSpell = 60,
HeavenSpell,
IceBlastSpell2,
MapAmbientNoiseWater,
MapAmbientNoiseDrone1 = 64,
UnknownMapAmbientNoise1,
UnknownMapAmbientNoise2,
UnknownMapAmbientNoise3,
UnknownMapAmbientNoise4 = 68,
MapEffectHPDrain,
MapEffectTPDrain,
Spikes,
UnknownClick = 72,
UnknownBoing,
UnknownMapAmbientNoise5,
DarkHandSpell,
TentaclesSpell = 76,
MagicWhirlSpell,
PowerWindSpell,
FireBlastSpell,
UnknownBubblesNoise = 80,
}
}
11 changes: 8 additions & 3 deletions EndlessClient/Rendering/Character/CharacterRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EndlessClient.Controllers;
using EndlessClient.Audio;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.Input;
using EndlessClient.Rendering.CharacterProperties;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class CharacterRenderer : DrawableGameComponent, ICharacterRenderer
private readonly IGameStateProvider _gameStateProvider;
private readonly ICurrentMapProvider _currentMapProvider;
private readonly IUserInputProvider _userInputProvider;
private readonly ISfxPlayer _sfxPlayer;
private readonly IEffectRenderer _effectRenderer;

private EOLib.Domain.Character.Character _character;
Expand Down Expand Up @@ -92,7 +94,8 @@ public CharacterRenderer(INativeGraphicsManager nativeGraphicsmanager,
EOLib.Domain.Character.Character character,
IGameStateProvider gameStateProvider,
ICurrentMapProvider currentMapProvider,
IUserInputProvider userInputProvider)
IUserInputProvider userInputProvider,
ISfxPlayer sfxPlayer)
: base(game)
{
_mapInteractionController = mapInteractionController;
Expand All @@ -108,7 +111,9 @@ public CharacterRenderer(INativeGraphicsManager nativeGraphicsmanager,
_gameStateProvider = gameStateProvider;
_currentMapProvider = currentMapProvider;
_userInputProvider = userInputProvider;
_effectRenderer = new EffectRenderer(nativeGraphicsmanager, this);
_sfxPlayer = sfxPlayer;

_effectRenderer = new EffectRenderer(nativeGraphicsmanager, _sfxPlayer, this);
_chatBubble = new Lazy<IChatBubble>(() => _chatBubbleFactory.CreateChatBubble(this));
}

Expand Down
36 changes: 17 additions & 19 deletions EndlessClient/Rendering/Effects/EffectRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EndlessClient.Audio;
using EOLib.Graphics;
using Microsoft.Xna.Framework.Graphics;

Expand All @@ -24,10 +25,10 @@ public enum EffectState

public sealed class EffectRenderer : IEffectRenderer
{
private readonly ISfxPlayer _sfxPlayer;
private readonly IEffectTarget _target;
private readonly EffectSpriteManager _effectSpriteManager;
// todo: effect sounds
//private readonly EffectSoundManager _effectSoundManager;
private readonly EffectSoundMapper _effectSoundMapper;

private IList<IEffectSpriteInfo> _effectInfo;
private DateTime _lastFrameChange;
Expand All @@ -38,16 +39,18 @@ public sealed class EffectRenderer : IEffectRenderer

public EffectState State { get; private set; }

public EffectRenderer(INativeGraphicsManager nativeGraphicsManager, IEffectTarget target)
public EffectRenderer(INativeGraphicsManager nativeGraphicsManager,
ISfxPlayer sfxPlayer,
IEffectTarget target)
{
_sfxPlayer = sfxPlayer;
_target = target;

_effectSpriteManager = new EffectSpriteManager(nativeGraphicsManager);
_effectSoundMapper = new EffectSoundMapper();

_lastFrameChange = DateTime.Now;
_effectInfo = new List<IEffectSpriteInfo>();

// todo: effect sounds
//_effectSoundManager = new EffectSoundManager()
}

public void PlayEffect(EffectType effectType, int effectID)
Expand All @@ -59,9 +62,7 @@ public void PlayEffect(EffectType effectType, int effectID)
_effectInfo = _effectSpriteManager.GetEffectInfo(EffectType, _effectID);

State = EffectState.Playing;

// todo: effect sounds
//PlaySoundsFromBeginning();
PlaySoundsFromBeginning();
}

public void Restart()
Expand All @@ -70,9 +71,7 @@ public void Restart()
effect.Restart();

State = EffectState.Playing;

// todo: effect sounds
//PlaySoundsFromBeginning();
PlaySoundsFromBeginning();
}

public void Update()
Expand Down Expand Up @@ -122,13 +121,12 @@ private void DrawEffects(SpriteBatch sb, bool beginHasBeenCalled, IEnumerable<IE
sb.End();
}

// todo: effect sounds
//private void PlaySoundsFromBeginning()
//{
// var soundInfo = _effectSoundManager.GetSoundEffectsForEffect(_effectType, _effectID);
// foreach (var sound in soundInfo)
// sound.Play();
//}
private void PlaySoundsFromBeginning()
{
var soundInfo = _effectSoundMapper.GetSoundEffectsForEffect(EffectType, _effectID);
foreach (var sound in soundInfo)
_sfxPlayer.PlaySfx(sound);
}
}

public interface IEffectRenderer
Expand Down
50 changes: 0 additions & 50 deletions EndlessClient/Rendering/Effects/EffectSoundManager.cs

This file was deleted.

76 changes: 76 additions & 0 deletions EndlessClient/Rendering/Effects/EffectSoundMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using EndlessClient.Audio;

namespace EndlessClient.Rendering.Effects
{
public class EffectSoundMapper
{
public IEnumerable<SoundEffectID> GetSoundEffectsForEffect(EffectType type, int id)
{
switch (type)
{
case EffectType.Potion: return GetPotionSoundEffect(id);
case EffectType.Spell: return GetSpellSoundEffect(id);
case EffectType.WarpOriginal:
case EffectType.WarpDestination: return GetWarpSoundEffect();
case EffectType.WaterSplashies: return GetWaterSoundEffect();
default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}

private static IEnumerable<SoundEffectID> GetPotionSoundEffect(int id)
{
switch ((HardCodedPotionEffect)id)
{
case HardCodedPotionEffect.FLAMES: yield return SoundEffectID.PotionOfFlamesEffect; break;
case HardCodedPotionEffect.LOVE: yield return SoundEffectID.LearnNewSpell; break;
case HardCodedPotionEffect.CELEBRATE: yield return SoundEffectID.PotionOfFireworksEffect; break;
case HardCodedPotionEffect.SPARKLES: yield return SoundEffectID.PotionOfSparklesEffect; break;
case HardCodedPotionEffect.EVIL:
case HardCodedPotionEffect.TERROR: yield return SoundEffectID.PotionOfEvilTerrorEffect; break;
}
}

private static IEnumerable<SoundEffectID> GetSpellSoundEffect(int id)
{
switch (id) // id is GFX; not pub file id
{
case 1: // small fire / fire from the sky
case 14: yield return SoundEffectID.PotionOfFlamesEffect; break;
case 10: yield return SoundEffectID.Heal; break; // various heals
case 11: yield return SoundEffectID.Thunder; break;
case 13: yield return SoundEffectID.UltimaBlastSpell; break;
case 15: yield return SoundEffectID.ShieldSpell; break; // magic/attack shield
case 16: yield return SoundEffectID.RingOfFireSpell; break;
case 17: yield return SoundEffectID.IceBlastSpell1; break;
case 18: // energy ball / green flame
case 34: yield return SoundEffectID.EnergyBallSpell; break;
case 19: yield return SoundEffectID.WhirlSpell; break;
case 20: // aura/shell
case 33: yield return SoundEffectID.AuraSpell; break;
case 21: yield return SoundEffectID.BouldersSpell; break;
case 22: // heaven/dark beam
case 24: yield return SoundEffectID.HeavenSpell; break;
case 23: yield return SoundEffectID.IceBlastSpell2; break;
case 26: // dark hand/dark skull/dark bite
case 27:
case 32: yield return SoundEffectID.DarkHandSpell; break;
case 28: yield return SoundEffectID.FireBlastSpell; break;
case 29: yield return SoundEffectID.TentaclesSpell; break;
case 30: yield return SoundEffectID.PowerWindSpell; break;
case 31: yield return SoundEffectID.MagicWhirlSpell; break;
}
}

private static IEnumerable<SoundEffectID> GetWarpSoundEffect()
{
yield return SoundEffectID.AdminWarp;
}

private static IEnumerable<SoundEffectID> GetWaterSoundEffect()
{
yield return SoundEffectID.Water;
}
}
}
12 changes: 1 addition & 11 deletions EndlessClient/Rendering/Effects/EffectSpriteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@
namespace EndlessClient.Rendering.Effects
{
//todo: it would be cool to load this from a config file instead of having it hard-coded
public class EffectSpriteManager
public partial class EffectSpriteManager
{
private enum HardCodedPotionEffect
{
FLAMES = 0,
LOVE = 1,
CELEBRATE = 4,
SPARKLES = 5,
EVIL = 6,
TERROR = 7
}

private enum HardCodedSpellGraphic
{
FIRE = 1,
Expand Down
12 changes: 12 additions & 0 deletions EndlessClient/Rendering/Effects/HardCodedPotionEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace EndlessClient.Rendering.Effects
{
public enum HardCodedPotionEffect
{
FLAMES = 0,
LOVE = 1,
CELEBRATE = 4,
SPARKLES = 5,
EVIL = 6,
TERROR = 7
}
}
Loading

0 comments on commit ab1b045

Please sign in to comment.