wyvern.lib.commands
Class LookCommand

java.lang.Object
  extended bywyvern.lib.commands.LookCommand
All Implemented Interfaces:
BuiltInCommand, Command

public class LookCommand
extends java.lang.Object
implements BuiltInCommand

Built-in command to examine something. Also handles the Zoology skill for appraising monsters.

Version:
1.0, Aug 21, 1997
Author:
Steve Yegge

Nested Class Summary
 class LookCommand.LookEvent
          Event to encapsulate the parameters for the user examining something.
static interface LookCommand.LookOverride
          Interface for objects that want to provide a custom description, depending on who looks at them.
 
Method Summary
 void addCommands(java.util.Map commands, CommandList list)
          Registers commands for looking.
 void appendWizInfo(GameObject obj, java.lang.StringBuffer sb)
          Appends which wizard created the object to the description of the object that we're building up in the passed StringBuffer.
 CommandEvent createEvent(CommandEvent initial)
          Implements Command.createEvent()
 boolean execute(CommandEvent ev)
          Looks at the target object.
 GameObject findTopObject(DisplayPolicy frame, Commandable agent, int x, int y)
          Locates the topmost object under the agent at the (x, y) spot where they clicked.
static java.lang.String getContribInfo(GameObject obj)
          Returns which wizard contributed the object, if it has a "wiz-contrib" property, or the player that contributed it, if it has a "player-contrib" property.
 java.lang.String getDescription(GameObject obj)
          Returns the description for the object, if any.
static LookCommand getImpl()
           
 java.lang.String getShortDesc(GameObject obj)
          Returns a short description for the object.
 CommandEvent handleLookAll(CommandEvent event, Commandable agent)
          Creates an event that shows every object on the ground where the user is at.
 CommandEvent handleLookXY(LookCommand.LookEvent event, Commandable agent)
          Looks at the top object at the (x,y) location specified in the event's arguments.
 boolean isLookAll(CommandEvent event)
          Checks if this is a look-all event, and if so, issues the message to the agent.
 boolean isLookXY(CommandEvent event, GameObject obj)
          Executes the lookxy command, which is usually from clicking on something with the mouse.
 boolean knowsCommand(java.lang.String command)
          We don't have any way of determining that we don't know how to handle the command based just on its arguments.
 java.lang.String printInventory(GameObject target)
          Prints out the target's inventory, or some subset of it.
 void readObject(GameObject obj, LookCommand.LookEvent event)
          Shows the object description in fancy text.
 void showImageDesc(Commandable agent, GameObject obj)
          Shows the description of the object along with a picture of some sort.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static LookCommand getImpl()

addCommands

public void addCommands(java.util.Map commands,
                        CommandList list)
Registers commands for looking.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
commands - the map to add to
list - the player getting the commands

knowsCommand

public boolean knowsCommand(java.lang.String command)
We don't have any way of determining that we don't know how to handle the command based just on its arguments.

Specified by:
knowsCommand in interface Command
Parameters:
command - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent initial)
Implements Command.createEvent()

Specified by:
createEvent in interface Command
Parameters:
initial - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.
See Also:
Command.createEvent(wyvern.lib.CommandEvent)

handleLookXY

public CommandEvent handleLookXY(LookCommand.LookEvent event,
                                 Commandable agent)
Looks at the top object at the (x,y) location specified in the event's arguments. Sets the target, target name, and an additional property, "point", whose value is the (x,y) location (in absolute map coordinates in the agent's map) to look at.

When finding the top object, the code skips over any objects that have a "mouse-ignore" property.

Parameters:
event - the LookEvent
agent - the event's agent

findTopObject

public GameObject findTopObject(DisplayPolicy frame,
                                Commandable agent,
                                int x,
                                int y)
Locates the topmost object under the agent at the (x, y) spot where they clicked.

Parameters:
frame - the agent's camera's DisplayPolicy, which decides what the agent can and can't see
agent - the player
x - map x location of mouse click
y - map y location of mouse click

handleLookAll

public CommandEvent handleLookAll(CommandEvent event,
                                  Commandable agent)
Creates an event that shows every object on the ground where the user is at.

Sets a "lookall" property on the event, where the value is a List of the short descriptions of all the items in the map under the agent.

Parameters:
agent - the agent
event - the event

execute

public boolean execute(CommandEvent ev)
Looks at the target object. For most objects, returns the long text description of the object. For Readables, calls a special interface method to get the description. Handles some other forms of the command as well.

Specified by:
execute in interface Command
Parameters:
ev - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.
See Also:
Command.execute(wyvern.lib.CommandEvent)

getShortDesc

public java.lang.String getShortDesc(GameObject obj)
Returns a short description for the object. If it's a player, returns name plus self-description.


readObject

public void readObject(GameObject obj,
                       LookCommand.LookEvent event)
Shows the object description in fancy text.

Parameters:
event - the event
obj - the object being looked at

getDescription

public java.lang.String getDescription(GameObject obj)
Returns the description for the object, if any.

Parameters:
obj - an object to check for a description property
Returns:
the description of the object, or null if not found

printInventory

public java.lang.String printInventory(GameObject target)
Prints out the target's inventory, or some subset of it.


showImageDesc

public void showImageDesc(Commandable agent,
                          GameObject obj)
Shows the description of the object along with a picture of some sort.

Parameters:
obj - the object
agent - the player looking at it

isLookAll

public boolean isLookAll(CommandEvent event)
Checks if this is a look-all event, and if so, issues the message to the agent.

Parameters:
event - the event
Returns:
true if the event had a "lookall" property

isLookXY

public boolean isLookXY(CommandEvent event,
                        GameObject obj)
Executes the lookxy command, which is usually from clicking on something with the mouse. Returns false if it wasn't a lookxy command.

Parameters:
event - the event
obj - the event target

appendWizInfo

public void appendWizInfo(GameObject obj,
                          java.lang.StringBuffer sb)
Appends which wizard created the object to the description of the object that we're building up in the passed StringBuffer.

Parameters:
obj - the object being examined
sb - the StringBuffer with the description so far

getContribInfo

public static java.lang.String getContribInfo(GameObject obj)
Returns which wizard contributed the object, if it has a "wiz-contrib" property, or the player that contributed it, if it has a "player-contrib" property.

Parameters:
obj - the object to examine
Returns:
a string such as "This object was contributed by the Wizard soandso.", or null if there was no external contributor