wyvern.lib.commands
Class PutCommand

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

public class PutCommand
extends java.lang.Object
implements BuiltInCommand

This class implements "put" - for putting things in containers.

Version:
1.0, Jun 15, 1998
Author:
Steve Yegge

Nested Class Summary
 class PutCommand.PutEvent
          This class encapsulates the parameters for a Put event.
 
Method Summary
 void addCommands(java.util.Map commands, CommandList list)
          Tells the Command to add the commands that it wants to implement into the passed data structure.
 CommandEvent createEvent(CommandEvent e)
          Creates a PutEvent from the original event.
 boolean execute(CommandEvent e)
          Executes the specified CommandEvent.
 Bag findBag(Commandable agent, PutCommand.PutEvent event, java.lang.String desc)
          Looks for the destination bag, first in inventory, then on the ground beneath the player.
static PutCommand getImpl()
           
 boolean knowsCommand(java.lang.String command)
          Returns true if this Command wants to handle the command.
 void parseArgs(PutCommand.PutEvent event)
          Tries to parse a direct and indirect object from the arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static PutCommand getImpl()

addCommands

public void addCommands(java.util.Map commands,
                        CommandList list)
Description copied from interface: BuiltInCommand
Tells the Command to add the commands that it wants to implement into the passed data structure.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
commands - a Map whose keys are commands, and whose values are Commands that handle those commands.
list - the CommandList the Command is being added to.

knowsCommand

public boolean knowsCommand(java.lang.String command)
Description copied from interface: Command
Returns true if this Command wants to handle the command. The Command can examine the arguments and determine that it doesn't actually understand the command, in which case it should return false.

This method exists to allow more than one game object to implement the same command verb, but with different expected arguments.

If two objects register for the same command and the same arguments, the object that was registered most recently gets to handle at the command.

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 e)
Creates a PutEvent from the original event.

Specified by:
createEvent in interface Command
Parameters:
e - 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.

parseArgs

public void parseArgs(PutCommand.PutEvent event)
Tries to parse a direct and indirect object from the arguments. The direct object is the thing to put, and the indirect obj is where to put it.

Parameters:
event - the event containing the command args

findBag

public Bag findBag(Commandable agent,
                   PutCommand.PutEvent event,
                   java.lang.String desc)
Looks for the destination bag, first in inventory, then on the ground beneath the player.

Parameters:
agent - the agent
event - the event
desc - the indirect object of the command
Returns:
the Bag specified in the command, or null if not found

execute

public boolean execute(CommandEvent e)
Description copied from interface: Command
Executes the specified CommandEvent. The CommandEvent contains all the parameters and state required to execute the command; the parameters have been filtered through hook objects, so they may not be the same as when the event was created.

Specified by:
execute in interface Command
Parameters:
e - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.