key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/**
  *  DirectedBroadcast
  *
  *
 */

package key.effect;

import key.*;
import java.util.StringTokenizer;

/**
  *  A communication effect that goes to an entire
  *  medium, such as a room or channel.  (Technically,
  *  it goes to any scape)
 */
public class DirectedBroadcast extends Broadcast
{
	Splashable directedAt;
	String otherMessage;
	char targetCode;
	
	/**
	  *  Creates a new communication
	  *
	  * @param from the player who sent it
	  * @param location where the local effect is to take place
	  * @param main the message to show to everyone in the location scape
	  * @param self the message to show to the player
	  * @param other the UNPARSED other message
	 */
	public DirectedBroadcast( Scape location, Player from, Splashable to, String main, String self, String other, char tCode )
	{
		super( location, from, main, self );
		
		directedAt = to;
		otherMessage = other;
		targetCode = tCode;
	}
	
	public String getMessage( Player receiver )
	{
		if( originator == receiver )
			return( super.getMessage( receiver ) );
		else
		{
			if( directedAt instanceof PlayerGroup )
			{
				if( ((PlayerGroup)directedAt).containsPlayer( receiver ) )
					originator.putCode( targetCode, ((PlayerGroup)directedAt).allNames( receiver ) );
				else
					return( super.getMessage( receiver ) );
			}
			else
			{
				if( receiver == directedAt )
					originator.putCode( targetCode, "you" );
				else
					return( super.getMessage( receiver ) );
			}
			
			return( Grammar.substitute( otherMessage, originator.getCodes() ) );
		}
	}

	/**
	  *  Directly splashes the location, with the exception of those
	  *  in the directedAt, who are splashed directly themselves
	 */
	public void cause()
	{
		loc.splashExcept( this, directedAt, null );
		directedAt.splash( this, null );
	}

	/**
	  *  Doesn't splash the directedAt people directly,
	  *  instead, this routine is used when we can
	  *  guarantee that the players will be in the location
	  *  scape.
	 */
	public void causeExclusive()
	{
		loc.splash( this, null );
	}
}