wyvern.kernel.combat
Class DamageCommand

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

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

Handles dealing out damage, the last phase of the combat sequence.

Version:
1.0, Dec 04, 1998
Author:
Steve Yegge

Method Summary
 void addCommands(java.util.Map map, CommandList list)
          Tells the Command to add the commands that it wants to implement into the passed data structure.
 java.lang.String addHitLocation(java.lang.String msg, DamageEvent e)
          Appends the hit-location, if any, to the defender message.
 DamageEvent createDamageEvent(Commandable agent, GameObject defender, DamageType[] dtypes, BodyPart hitLoc, Attack attack)
          Utility method for creating a damage event suitable for placement in the agent's queue.
 DamageEvent createDamageEvent(Commandable agent, GameObject defender, DamageType dtype, BodyPart hitLoc, Attack attack)
          Utility method for creating a to-hit event suitable for placement in the agent's queue.
 CommandEvent createEvent(CommandEvent e)
          Creates a CommandEvent that encapsulates all the state necessary to perform the command.
 void damageArmor(DamageEvent e)
          Figures out how much damage to do to the armor, if any.
 void damageWeapon(DamageEvent e)
          Figures out how much damage to to do the weapon, if any.
 boolean execute(CommandEvent event)
          Executes the damage for a DamageEvent, which could have been from a spell, a monster attack, a trap, or just about anything else.
static DamageCommand getImpl()
           
 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 DamageCommand getImpl()

addCommands

public void addCommands(java.util.Map map,
                        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:
map - 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)
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:
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.

createDamageEvent

public DamageEvent createDamageEvent(Commandable agent,
                                     GameObject defender,
                                     DamageType dtype,
                                     BodyPart hitLoc,
                                     Attack attack)
Utility method for creating a to-hit event suitable for placement in the agent's queue. If you don't have a Commandable attacker handy, you can use Combat.damageMonster() or Combat.damageObject() to do the damage.

The attack results in a single message each to the attacker and defender; it's chosen based on whichever DamageType resulted in the most damage this round. The total of all damages is used for the magnitude of the message, so a flaming sword that does some cut damage ("hit") and some burn damage ("burn") might say "burned badly" on one round, and "hit hard" on another round, depending on which damage type was greater.

Parameters:
agent - the attacker
defender - the attackee
dtype - the damage type used by the attack
hitLoc - the hit location on the attacker, or null if it was a whole-body or unspecified attack.
attack - the weapon or attack
Returns:
a DamageEvent with the target set to the defender.

createDamageEvent

public DamageEvent createDamageEvent(Commandable agent,
                                     GameObject defender,
                                     DamageType[] dtypes,
                                     BodyPart hitLoc,
                                     Attack attack)
Utility method for creating a damage event suitable for placement in the agent's queue. If you don't have a Commandable attacker handy, you can use Combat.damageMonster() or Combat.damageObject() to do the damage.

Parameters:
agent - the attacker
defender - the attackee
dtypes - the damages that are done in the attack. For instance, a flaming sword might do some cut and some fire damage.
hitLoc - the hit location on the attacker, null if it was a whole-body or unspecified attack.
Returns:
a DamageEvent with the target set to the defender.

execute

public boolean execute(CommandEvent event)
Executes the damage for a DamageEvent, which could have been from a spell, a monster attack, a trap, or just about anything else.

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

addHitLocation

public java.lang.String addHitLocation(java.lang.String msg,
                                       DamageEvent e)
Appends the hit-location, if any, to the defender message.


damageWeapon

public void damageWeapon(DamageEvent e)
Figures out how much damage to to do the weapon, if any. We don't do this in the createEvent() phase because someone in one of the hooks may have modified the total damage for the event, and weapon damage is proportional to the total actual damage done.


damageArmor

public void damageArmor(DamageEvent e)
Figures out how much damage to do to the armor, if any. We don't do this in the createEvent() phase because someone in one of the hooks may have modified the total damage for the event, and armor damage is proportional to the total actual damage done.