wyvern.lib.commands
Class CastCommand

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

public class CastCommand
extends java.lang.Object
implements BuiltInCommand

Handles casting spells.

Version:
1.0, Nov 04, 1999
Author:
Steve Yegge

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.
 boolean adjustCasterMana(CastEvent event)
          Deducts the appropriate amount of mana.
 CommandEvent createEvent(CommandEvent initial)
          Creates the command event for the "cast" command.
 boolean dispel(CastEvent event)
          Dispels a spell you've cast.
 boolean execute(CommandEvent ev)
          Implements Command.execute()
static CastCommand getImpl()
           
 boolean isNoSpellsArea(CastEvent event)
          Checks whether it's OK to cast the spell in this location.
 boolean knowsCommand(java.lang.String command)
          Returns true if this Command wants to handle the command.
 boolean knowsSpell(Commandable agent, java.lang.String spell)
           
 boolean reagents(CastEvent event)
          Lists the reagents for a particular spell.
 boolean showActiveSpells(CommandEvent event)
          Displays to the user a list of the spells they have active.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static CastCommand 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 initial)
Creates the command event for the "cast" command.

The command supports the following syntax:

  cast  [dir | x y | [on|at ] | [with-args ]]
 
You can specify a direction to cast it, a specific map position to cast it on/at (e. 10 -8), or "on/at" at target. "on" and "at" are currently synonymous.

If you specify "with-args", the remainder of the argument string is passed to the spell using setSpellArgs(). Examples:

	cast knock
	cast fireball north
  cast earth wall 17 10
	cast polymorph other at orc
  cast detect magic on gray stone
  cast magic mouth with-args Abandon All Hope Ye Who Enter Here
 
The event that's returned has a number of properties set: Notes: We might eventually support other syntax, such as "with (reagent)".

Specified by:
createEvent in interface Command
Parameters:
initial - the original event with the command text
Returns:
an event containing any parsed parameters

isNoSpellsArea

public boolean isNoSpellsArea(CastEvent event)
Checks whether it's OK to cast the spell in this location. Checks for objects with "no-spells" property in the square, and for the map having an overall "no-spells" property. If the spell has "ok-no-spells", always allows it.

Parameters:
event - the event
Returns:
true if it's not OK to cast here.

execute

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

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)

adjustCasterMana

public boolean adjustCasterMana(CastEvent event)
Deducts the appropriate amount of mana.

Parameters:
event - the event

reagents

public boolean reagents(CastEvent event)
Lists the reagents for a particular spell.

Parameters:
event - the event
Returns:
true if event was handled

knowsSpell

public boolean knowsSpell(Commandable agent,
                          java.lang.String spell)

dispel

public boolean dispel(CastEvent event)
Dispels a spell you've cast.


showActiveSpells

public boolean showActiveSpells(CommandEvent event)
Displays to the user a list of the spells they have active. Only shows spells they've cast using the cast command, not potions/scrolls/wands etc.