wyvern.kernel.combat
Class HitCommand

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

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

This special Command deals with the to-hit event. The to-hit phase of an attack is encapsulated as a separate event so that hook callbacks can easily manipulate the outcome.

If the to-hit calculations are successful, then the hit will be translated into a DamageEvent.

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

Method Summary
 void addCommands(java.util.Map map, CommandList list)
          Adds the commands we handle to a player's dictionary.
 int computeAccuracy(HitEvent event, Commandable agent, Attack attack, AttackType attackType)
          Computes the net accuracy for a given attack.
static int computeDodge(Monster defender, Commandable attacker)
          Computes the net dodge for the attack, based on the defender's level, dodge skill, encumbrance, and magical dodge bonuses.
 void computeToHit(Commandable agent, GameObject defender, Attack attack, HitEvent event)
          Performs the to-hit computation after the event is created.
 CommandEvent createEvent(CommandEvent initialInfo)
          Creates a CommandEvent that encapsulates the to-hit check.
 CommandEvent createHitEvent(Commandable agent, GameObject defender, Attack weapon)
          Utility method for creating a to-hit event suitable for placement in the agent's queue.
 boolean execute(CommandEvent ev)
          Executes the HitEvent by creating a DamageEvent if the hit was successful.
static HitCommand 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 HitCommand getImpl()

addCommands

public void addCommands(java.util.Map map,
                        CommandList list)
Adds the commands we handle to a player's dictionary.

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)
Returns true if this Command wants to handle 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 initialInfo)
Creates a CommandEvent that encapsulates the to-hit check.

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

createHitEvent

public CommandEvent createHitEvent(Commandable agent,
                                   GameObject defender,
                                   Attack weapon)
Utility method for creating a to-hit event suitable for placement in the agent's queue. If you already know the attacker, attackee and weapon, it's faster to do this than saying agent.commandNow("hit {monster} with {weapon}"), as it skips the parsing phase.

Parameters:
agent - the attacker
defender - the attackee
weapon - the thing being used to attack
Returns:
a TargetedEvent with the target set to the defender. The event contains the additional property "attack", with the property value set to the weapon.

computeToHit

public void computeToHit(Commandable agent,
                         GameObject defender,
                         Attack attack,
                         HitEvent event)
Performs the to-hit computation after the event is created.

The percent chance to hit is accuracy * (1 - dodge/100), so as dodge approaches 100, the chance goes to zero. Accuracy is explained in computeAccuracy(), and dodge is explained in computeDodge().

The event is vetoed (with a "You missed" failure message) if the agent misses.

Parameters:
agent - the attacker
defender - the defender
attack - the attack (such as a body part, melee weapon, range weapon, or hurled weapon)
event - the event

computeAccuracy

public int computeAccuracy(HitEvent event,
                           Commandable agent,
                           Attack attack,
                           AttackType attackType)
Computes the net accuracy for a given attack. Computed as: (base accuracy) + (attacker level) + (weapon-skill to-hit bonus) + (weapon to-hit bonus)


computeDodge

public static int computeDodge(Monster defender,
                               Commandable attacker)
Computes the net dodge for the attack, based on the defender's level, dodge skill, encumbrance, and magical dodge bonuses.

Parameters:
defender - the thing being attacked
attacker - the agent doing the attacking
Returns:
the defender's net dodge for this attack

execute

public boolean execute(CommandEvent ev)
Executes the HitEvent by creating a DamageEvent if the hit was successful. Invokes DamageCommand.getImpl().createDamageEvent() to create the damage event. Sets the current HitEvent as a property of the damage event, under the key "tohit-event", in case anyone needs to see it during the damage phase.

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