wyvern.kernel.combat
Class WearCommand

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

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

This command handles donning & doffing armor and wearable magic items like rings & amulets.

Version:
1.0, Jun 08, 1998
Author:
Steve Yegge

Nested Class Summary
 class WearCommand.UnwearEvent
          Event class to encapsulate removing some armor.
 
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.
static void addDefense(Commandable agent, Armor armor)
          Adds the armor to the agent's @defense-list, for clients that need to know what armor the agent is wearing at the moment.
static boolean canUsePart(BodyPart part, java.lang.Class type, Armor armor, java.util.List parts, WearEvent event)
          Checks the slots for the passed BodyPart to see if any of them are slots we need for wearing the armor.
 boolean checkBlocked(Armor armor, java.util.List parts, Monster agent)
          See if the passed armor cannot be removed because of a cursed piece of armor (or weapon) covering it.
 GameObject checkSlotBlocked(ItemSlot slot, ItemSlot[] slots)
          Checks if the passed slot is blocked on the same body part by a nonempty outer layer.
 CommandEvent createEvent(CommandEvent initial)
          Creates a CommandEvent that encapsulates all the state necessary to perform the command.
 CommandEvent createRemoveEvent(CommandEvent initial)
          Creates an event to encapsulate removing a piece of armor.
 CommandEvent createWearEvent(CommandEvent e)
           
static WearEvent createWearEvent(WearEvent event, Armor armor, int delay, boolean quiet)
          A function to create a wear event as if the user had typed "wear ", but you can pass in more parameters, such as whether there's a delay, and whether to print messages.
static boolean ensureCorrectSize(Monster monster, Armor armor, WearEvent event)
          Makes sure they can actually wear the armor.
 boolean execute(CommandEvent event)
          Executes the specified CommandEvent.
 void executeRemove(WearCommand.UnwearEvent event)
          Performs the UnwearEvent
 boolean executeRemoveAll(WearCommand.UnwearEvent event)
          Attempts to remove all the agent's worn armor.
 void executeWear(WearEvent event)
          Wears the armor.
static void findBodyParts(Monster agent, Armor armor, WearEvent event)
          Searches the monster's parts-list for enough available body parts to wear the armor.
static java.util.List findPartsUsed(Armor armor, Monster agent)
          If for some reason the armor lost track of its list of body-parts that were used to wear the armor, we need to sniff around the agent's body to see where the armor is worn.
static WearCommand getImpl()
           
 boolean knowsCommand(java.lang.String command)
          Returns true if this Command wants to handle the command.
static void removeDefense(Commandable agent, Armor armor)
          Removes the armor from the agent's @defense-list
static void removeForce(Armor armor, java.util.List parts, Monster agent)
          Forces the passed armor to be removed from the wearer.
static void rewearInventory(Commandable agent)
          Handles re-wearing armor and re-wielding weapons that were worn when the inventory was saved out.
 boolean tryRemove(Armor armor, Monster agent, WearCommand.UnwearEvent event)
          Attempts to remove the passed piece of armor from the passed agent.
static boolean wearArmor(Commandable agent, java.util.List parts, Armor armor)
          Puts the armor on the agent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static WearCommand 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.

createWearEvent

public CommandEvent createWearEvent(CommandEvent e)

createWearEvent

public static WearEvent createWearEvent(WearEvent event,
                                        Armor armor,
                                        int delay,
                                        boolean quiet)
A function to create a wear event as if the user had typed "wear ", but you can pass in more parameters, such as whether there's a delay, and whether to print messages.

This method does various checks to see if the armor can be worn: whether it's the right size, whether there are enough body parts, whether it's already worn or not, etc.

This method is used by the Player object to re-wear armor after a player logs in. It's better than just commanding the Player to "wear ", since there's no delay.

Parameters:
event - a WearEvent with the original text and agent already set up. Just call new WearEvent("wear whatever", agent) and pass it to this method.
armor - the piece of armor to wear
delay - the delay to use for the event. Set a nonzero delay if the player is putting the armor on; you can use zero if you want it to go on instantaneously.
quiet - true not to print any messages to the player if the event is successful.

findBodyParts

public static void findBodyParts(Monster agent,
                                 Armor armor,
                                 WearEvent event)
Searches the monster's parts-list for enough available body parts to wear the armor. Stuffs this information in the event.

Parameters:
agent - the Monster trying to wear something
armor - the armor to wear
event - the event

ensureCorrectSize

public static boolean ensureCorrectSize(Monster monster,
                                        Armor armor,
                                        WearEvent event)
Makes sure they can actually wear the armor. Vetoes the event with a message if not.

Returns:
true if size OK, false if not

canUsePart

public static boolean canUsePart(BodyPart part,
                                 java.lang.Class type,
                                 Armor armor,
                                 java.util.List parts,
                                 WearEvent event)
Checks the slots for the passed BodyPart to see if any of them are slots we need for wearing the armor.

Side effect: adds the part to the passed parts list if usable

Parameters:
part - the BodyPart to examine
type - the slot-type to look for
parts - the list of body-parts we've already chosen
armor - the armor to wear
event - the event
Returns:
true if the part had a slot of the required type

createRemoveEvent

public CommandEvent createRemoveEvent(CommandEvent initial)
Creates an event to encapsulate removing a piece of armor.


execute

public boolean execute(CommandEvent event)
Description copied from interface: Command
Executes the specified CommandEvent. The CommandEvent contains all the parameters and state required to execute the command; the parameters have been filtered through hook objects, so they may not be the same as when the event was created.

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

executeWear

public void executeWear(WearEvent event)
Wears the armor.

Parameters:
event - the event encapsulating the command parameters

wearArmor

public static boolean wearArmor(Commandable agent,
                                java.util.List parts,
                                Armor armor)
Puts the armor on the agent.

Parameters:
agent - the monster
parts - a list of the agent's body parts (hashcodes)
Returns:
true if we were able to get the agent to wear the armor

executeRemove

public void executeRemove(WearCommand.UnwearEvent event)
Performs the UnwearEvent

Parameters:
event - the command event

findPartsUsed

public static java.util.List findPartsUsed(Armor armor,
                                           Monster agent)
If for some reason the armor lost track of its list of body-parts that were used to wear the armor, we need to sniff around the agent's body to see where the armor is worn.

Parameters:
armor - the armor to check
agent - the agent to check
Returns:
the list of parts that we found the armor on (hashcodes)

executeRemoveAll

public boolean executeRemoveAll(WearCommand.UnwearEvent event)
Attempts to remove all the agent's worn armor.

Parameters:
event - the event containing the command context
Returns:
true if we succeeded

tryRemove

public boolean tryRemove(Armor armor,
                         Monster agent,
                         WearCommand.UnwearEvent event)
Attempts to remove the passed piece of armor from the passed agent.

Parameters:
agent - the monster/player wearing the armor
armor - the armor to try to remove
event - the command event, for messages
Returns:
true if we were successful. If not, we issue a message to the agent telling them why they can't remove it.

removeForce

public static void removeForce(Armor armor,
                               java.util.List parts,
                               Monster agent)
Forces the passed armor to be removed from the wearer. Issues no message to the wearer, but notifies the armor that it's been removed.

Parameters:
armor - the armor to remove
parts - the body parts the armor is being worn on
agent - the agent wearing the armor

checkBlocked

public boolean checkBlocked(Armor armor,
                            java.util.List parts,
                            Monster agent)
See if the passed armor cannot be removed because of a cursed piece of armor (or weapon) covering it.

Parameters:
armor - the armor to check
parts - the body parts the armor is being worn on (hashcodes)
agent - the agent wearing the armor
Returns:
true if the armor is blocked. If so, issues a message to the agent explaining why it's blocked. If false, no message is issued.

checkSlotBlocked

public GameObject checkSlotBlocked(ItemSlot slot,
                                   ItemSlot[] slots)
Checks if the passed slot is blocked on the same body part by a nonempty outer layer.

Parameters:
slot - the slot to check
slots - the list of slots for the body part
Returns:
the first piece of armor (or cursed weapon) we find blocking removal of the slot, or null if there was nothing found blocking.

addDefense

public static void addDefense(Commandable agent,
                              Armor armor)
Adds the armor to the agent's @defense-list, for clients that need to know what armor the agent is wearing at the moment.

Parameters:
agent - the wearer
armor - the thing being worn

removeDefense

public static void removeDefense(Commandable agent,
                                 Armor armor)
Removes the armor from the agent's @defense-list

Parameters:
agent - the wearer
armor - the thing being removed

rewearInventory

public static void rewearInventory(Commandable agent)
Handles re-wearing armor and re-wielding weapons that were worn when the inventory was saved out. Goes through the agent's inventory and looks for armor with the property "worn" and weapons with the property "wielded", and wears/wields them. Puts a command in the agent's queue directly, so make sure their event queue is instantiated. If you get a null-pointer exception, try commanding them with "wait 0" first to create their queue.

Parameters:
agent - the player to set up