wyvern.kernel.player
Class MusicManager

java.lang.Object
  extended bywyvern.kernel.player.MusicManager
All Implemented Interfaces:
MusicState.States

public final class MusicManager
extends java.lang.Object
implements MusicState.States

Handles switching background music.

Version:
1.0, Jul 25, 2003
Author:
Steve Yegge

Field Summary
static double LOW_HP_THRESHOLD
          The ratio of hp/maxhp below which the time-running-out combat music starts playing.
 
Fields inherited from interface wyvern.kernel.player.MusicState.States
NAMES, NOT_READY, PLAYING, PRIORITY, READY
 
Method Summary
static boolean checkCombat(Player player)
          Checks if the player is moving into combat, moving out of combat, continuing combat, or continuing non-combat.
static void endSound(CommandEvent event)
          Client is notifying is that it's finished playing a sound.
static Music getMapMusic(Player player)
          Retrieves the default music to play for the player, based on their map.
static void noAudio(CommandEvent event)
          Client has requested that we send no audio events whatsoever.
static boolean playDefault(Commandable agent)
          Figures out the default background music for the specified player, and plays it.
static boolean playPriority(Commandable agent, java.lang.String path, int repeats, int delay, double gain)
          Plays a piece of music at a higher priority than the normal background music.
static void setMusicGain(Player p, double gain)
          Sets the volume for the background music.
static void stopMusic(Player p)
          Stops the background music for a given player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOW_HP_THRESHOLD

public static final double LOW_HP_THRESHOLD
The ratio of hp/maxhp below which the time-running-out combat music starts playing.

See Also:
Constant Field Values
Method Detail

playDefault

public static boolean playDefault(Commandable agent)
Figures out the default background music for the specified player, and plays it.

Parameters:
agent - any Commandable - it's ignored unless it's a Player.
Returns:
true if there was any change in the soundtrack (either the music changed, or it shut off)

playPriority

public static boolean playPriority(Commandable agent,
                                   java.lang.String path,
                                   int repeats,
                                   int delay,
                                   double gain)
Plays a piece of music at a higher priority than the normal background music. For example, if you just solved a quest, and while the triumphant music is playing, you step into another map, you don't want the map to override the quest music.

Rules:

  1. Currently there are only two priorities: normal and high. playMusic() plays at normal priority, and playPriority() plays at high priority. This method always interrupts the current soundtrack and starts the passed piece, even if the player was already playing it. If you want to avoid this, don't call this method if agent.getMusicState().sameMusic(path) returns true.

Sets the agent's MusicState to PRIORITY.

Parameters:
agent - the player
path - relative path to music to play
Returns:
true if the agent's soundtrack changed, false if they had audio turned off.

getMapMusic

public static Music getMapMusic(Player player)
Retrieves the default music to play for the player, based on their map.

Parameters:
player - the player to get the music for
Returns:
the path to their map music, or null if none specified

endSound

public static void endSound(CommandEvent event)
Client is notifying is that it's finished playing a sound. The command argument is the unique ID assigned by the server to that particular track. ID numbers are usually integers, but can be anything as long as they're unique for each sound instance on a given client. This method publishes the following Message:

Use Kernel.subscribe() to listen for the message.

Parameters:
event - the event containing the player whose client is sending the notification.

noAudio

public static void noAudio(CommandEvent event)
Client has requested that we send no audio events whatsoever. This doesn't shut off the music on the client. If you're calling it from the server-side, make sure you call stopMusic() and stopAllSounds() after calling this function.


checkCombat

public static boolean checkCombat(Player player)
Checks if the player is moving into combat, moving out of combat, continuing combat, or continuing non-combat. Handles transitioning the soundtrack.


stopMusic

public static void stopMusic(Player p)
Stops the background music for a given player.

Parameters:
p - the player

setMusicGain

public static void setMusicGain(Player p,
                                double gain)
Sets the volume for the background music.