wyvern.kernel.combat
Class AttackCommand

java.lang.Object
  extended bywyvern.kernel.combat.AttackCommand
All Implemented Interfaces:
BuiltInCommand, Command

public final class AttackCommand
extends java.lang.Object
implements BuiltInCommand

Controls the attacking sequence. Figures out the attacker and defender, and what attacks the attacker will be using. Enqueues a HitEvent for each attack. Also handles automatic followup attacks for implementing synchronous, timed combat.

Version:
1.0, Nov 04, 1997
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 alreadyAttacking(Commandable agent, Attackable target)
          Checks if we're already attacking this target.
 void computeAttacks(CommandEvent event, Commandable agent, int num_attacks)
          Figures out what things the agent will be attacking with.
 CommandEvent createAttackEvent(boolean player_originated, java.lang.String originalText, Commandable agent, Attackable target)
          Creates an AttackEvent and stuffs the event parameters.
 CommandEvent createEvent(CommandEvent initial)
          Creates a CommandEvent that encapsulates all the state necessary to perform the command.
 boolean execute(CommandEvent event)
          Executes the attack.
static AttackCommand getImpl()
           
 void handlePostAttack(CommandEvent event, Commandable agent)
          Handles automatically maybe-enqueuing another attack.
 boolean knowsCommand(java.lang.String command)
          Returns true if this Command wants to handle the command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static AttackCommand 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)
Description copied from interface: Command
Creates a CommandEvent that encapsulates all the state necessary to perform the command. A well-designed CommandEvent exposes all of its "properties" so that hook objects can modify its behavior. For instance, many commands result in some sort of message being sent back to the client. The message should be among the properties that hooks can override.

This method is called by the kernel. The kernel passes the event to the pre-hook, then calls Command.execute() (below) to execute the event, and finally calls the post-hook.

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.

createAttackEvent

public CommandEvent createAttackEvent(boolean player_originated,
                                      java.lang.String originalText,
                                      Commandable agent,
                                      Attackable target)
Creates an AttackEvent and stuffs the event parameters. Called by the wyvern.kernel.motion.ContactManager if it's determined that the motion should result in an attack attempt.

Parameters:
player_originated - true if the player explicitly originated this attack, e.g. by moving into the defender or typing "kill ".
originalText - e.g. "kill "
agent - the event agent
target - the target of the attack

alreadyAttacking

public boolean alreadyAttacking(Commandable agent,
                                Attackable target)
Checks if we're already attacking this target.

Parameters:
agent - the agent
target - the target we're attacking
Returns:
true if we're already attacking it

computeAttacks

public void computeAttacks(CommandEvent event,
                           Commandable agent,
                           int num_attacks)
Figures out what things the agent will be attacking with. Called by createAttackEvent.

Parameters:
event - the attack event
agent - the Commandable doing the attacking
num_attacks - the actual number of attacks the agent gets

execute

public boolean execute(CommandEvent event)
Executes the attack.

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

handlePostAttack

public void handlePostAttack(CommandEvent event,
                             Commandable agent)
Handles automatically maybe-enqueuing another attack.

Parameters:
event - the event
agent - the attacker