wyvern.lib.commands
Class OpenCommand

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

public class OpenCommand
extends java.lang.Object
implements BuiltInCommand

Handles open, close, lock and unlock.

Version:
1.0, Apr 29, 1998
Author:
Steve Yegge

Nested Class Summary
 class OpenCommand.KeyPredicate
          A predicate to look for a key that will open the specified lock.
 
Method Summary
 void addCommands(java.util.Map map, CommandList list)
          Add known commands.
 CommandEvent createEvent(CommandEvent initial)
          Implements Command.createEvent()
 GameObject determineTarget(java.lang.String arg, TargetedEvent event)
          Parses the args and gets the appropriate object to operate on.
 GameObject ensureKey(Openable target, Commandable agent)
          Makes sure user can lock or unlock the door.
 boolean execute(CommandEvent e)
          Implements Command.execute()
 Openable getDirectionalTarget(int dir, TargetedEvent event)
          Looks in specified direction for an openable target.
static OpenCommand getImpl()
           
 GameObject getNoArgTarget(TargetedEvent event)
          If they just typed "open", "close" or whatever, look for a nearby door to do it to.
 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.
 boolean performClose(Openable target, TargetedEvent event)
          Attempts to close the target.
 boolean performLock(Openable target, TargetedEvent event)
          Attempts to lock the target.
 boolean performOpen(Openable obj, TargetedEvent event)
          Attempts to open the target.
 boolean performUnlock(Openable target, TargetedEvent event)
          Attempts to unlock the target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static OpenCommand getImpl()

addCommands

public void addCommands(java.util.Map map,
                        CommandList list)
Add known commands.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
map - the map to add the commands to
list - the CommandList the Command is being added to.

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 command verb to verify
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)

getNoArgTarget

public GameObject getNoArgTarget(TargetedEvent event)
If they just typed "open", "close" or whatever, look for a nearby door to do it to.

Parameters:
event - the event
Returns:
a suitable target object, or null if none found. Sets the target object in the event as well. If a suitable target can't be found, vetoes the event and sets the failure message to something appropriate.

determineTarget

public GameObject determineTarget(java.lang.String arg,
                                  TargetedEvent event)
Parses the args and gets the appropriate object to operate on.

Parameters:
arg - the argument string
event - the TargetedEvent or TargetedEvent
Returns:
the target object, or null if none found

getDirectionalTarget

public Openable getDirectionalTarget(int dir,
                                     TargetedEvent event)
Looks in specified direction for an openable target.

Parameters:
dir - a valid Direction constant
event - the event for this command
Returns:
an Openable object in that direction, or null if not found. Doesn't veto the event or set any messages.

execute

public boolean execute(CommandEvent e)
Implements Command.execute()

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

performOpen

public boolean performOpen(Openable obj,
                           TargetedEvent event)
Attempts to open the target.

Parameters:
obj - the object to open
event - the TargetedEvent
Returns:
true if we opened it successfully

performClose

public boolean performClose(Openable target,
                            TargetedEvent event)
Attempts to close the target.

Parameters:
target - the object to close
event - the TargetedEvent
Returns:
true if we closed it successfully

performLock

public boolean performLock(Openable target,
                           TargetedEvent event)
Attempts to lock the target.

Parameters:
target - the object to lock
event - the TargetedEvent
Returns:
true if we locked it successfully

performUnlock

public boolean performUnlock(Openable target,
                             TargetedEvent event)
Attempts to unlock the target.

Parameters:
target - the object to unlock
event - the TargetedEvent
Returns:
true if we unlocked it successfully

ensureKey

public GameObject ensureKey(Openable target,
                            Commandable agent)
Makes sure user can lock or unlock the door.