wyvern.lib.skills
Class NagaShift

java.lang.Object
  extended bywyvern.lib.skills.NagaShift
All Implemented Interfaces:
AddRemoveNotify, Command, HookCallback, MethodHookCallback, MutableProperty, Timed

public class NagaShift
extends java.lang.Object
implements Command, AddRemoveNotify, HookCallback, MethodHookCallback, Timed, MutableProperty

Handles the "shift" command for Nagas, allowing them to polymorph into various predefined shapes.

Version:
1.0, Dec 30, 2000
Author:
Steve Yegge

Field Summary
static java.lang.String[] ARCHETYPES
          The archetypes for the shapes, from which we can determine a bunch of other information like HP, SP and so on.
static java.lang.String[] IMAGES
          The images to use for each shape if the naga is facing east or west.
static int[] LEVELS
          These are the levels at which nagas can become their shapes.
static java.lang.String[] SHAPE_NAMES
           
static java.lang.String[] SHAPES
          These are all the shapes nagas can become.
static int[] SIZES
          The sizes of the shapes. 1 means 1x1, 2 means 1x2 or 2x1 depending on direction, and 4 means 2x2.
 
Constructor Summary
NagaShift()
           
 
Method Summary
 void computeEncumbrance(Commandable agent)
          Recomputes the agent's encumbrance
 void computeShiftedHP(Commandable agent, Archetype arch)
          Figures out how many HP the agent should have in the new form, and sets their transient HP value accordingly.
 void computeShiftedWC(Commandable agent, Archetype arch)
          Figures out the new WC for the shape.
 java.lang.Object createClone()
          Produces a clone of the property for the caller.
 CommandEvent createEvent(CommandEvent initial)
          Creates the command event.
 boolean equals(java.lang.Object o)
           
 boolean execute(CommandEvent event)
          Executes the event.
 Rectangle findSpace(Commandable agent, int index)
          Locates a spot to put the agent after the polymorph.
 int hashCode()
           
 void hookEvent(java.lang.String hookName, CommandEvent event)
          Turns "turn" into "move" if they're in a long form.
 void killTimer()
          Kills the sp-drain timer.
 boolean knowsCommand(java.lang.String command)
          Returns true if we want to handle this command.
 void methodCalled(java.lang.String hookName, MethodHookable target, java.lang.Object data)
          Called when the player is done initializing.
 void notifyAdd(PropertyList obj)
          Notifies the property that it's being added.
 void notifyRemove(PropertyList obj)
          Notifies the property that it's being removed.
 boolean restore(Commandable agent)
          Restores the naga to natural form.
 void restoreBodyParts(Commandable agent)
          Changes the agent back to their original form.
 void restoreStats(Commandable agent)
          Restores the agent's stats to the non-shifted versions.
 void rewearArmor(Commandable agent)
          Removes any worn armor and tries to wear it again.
 void rewieldWeapon(Commandable agent)
          Unwields any weapon and tries to wield it again.
 void setBodyParts(Commandable agent, PartsList body)
          Changes the agent's body parts to those of the new shape.
 void setTimer()
          Starts the sp-drain timer.
 boolean shift(Commandable agent, CommandEvent event)
          Shifts the naga into the specified shape.
 boolean shift(Commandable agent, java.lang.String shape)
          Shifts the naga into a specific shape.
 void timerExpired()
          Spell-drain timer went off.
 java.lang.String toString()
           
 void unshift()
          Forces a shift back into a naga, or failing that, a frog.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SHAPES

public static final java.lang.String[] SHAPES
These are all the shapes nagas can become.


SHAPE_NAMES

public static final java.lang.String[] SHAPE_NAMES

LEVELS

public static final int[] LEVELS
These are the levels at which nagas can become their shapes. Each entry corresponds to an entry at the same index in the SHAPES list.


IMAGES

public static final java.lang.String[] IMAGES
The images to use for each shape if the naga is facing east or west.


SIZES

public static final int[] SIZES
The sizes of the shapes. 1 means 1x1, 2 means 1x2 or 2x1 depending on direction, and 4 means 2x2.


ARCHETYPES

public static final java.lang.String[] ARCHETYPES
The archetypes for the shapes, from which we can determine a bunch of other information like HP, SP and so on.

Constructor Detail

NagaShift

public NagaShift()
Method Detail

knowsCommand

public boolean knowsCommand(java.lang.String command)
Returns true if we want to handle this command.

Specified by:
knowsCommand in interface Command
Parameters:
command - the command the player typed
Returns:
true if we're handling it

createEvent

public CommandEvent createEvent(CommandEvent initial)
Creates the command event.

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.

execute

public boolean execute(CommandEvent event)
Executes the event.

Specified by:
execute in interface Command
Parameters:
event - the event
Returns:
true if the event executed successfully

shift

public boolean shift(Commandable agent,
                     CommandEvent event)
Shifts the naga into the specified shape.

Parameters:
event - the command event
Returns:
true if successful

shift

public boolean shift(Commandable agent,
                     java.lang.String shape)
Shifts the naga into a specific shape. Has to be one of the shapes in the SHAPES list.

Parameters:
agent - the player
shape - the shape to shift into

findSpace

public Rectangle findSpace(Commandable agent,
                           int index)
Locates a spot to put the agent after the polymorph. Issues no messages to the agent, even if it fails.

Parameters:
agent - the agent to shift
index - the index into the shape tables
Returns:
the rectangle into which to place the agent after doing the shape-shift (i.e. their new reference location, width and height). Returns null if there was no space available.

setBodyParts

public void setBodyParts(Commandable agent,
                         PartsList body)
Changes the agent's body parts to those of the new shape. Unwears any armor that can no longer be worn, issuing messages to the agent as appropriate.

Parameters:
agent - the player
body - the new body to use

rewearArmor

public void rewearArmor(Commandable agent)
Removes any worn armor and tries to wear it again.

Parameters:
agent - the player

rewieldWeapon

public void rewieldWeapon(Commandable agent)
Unwields any weapon and tries to wield it again.

Parameters:
agent - the player

restoreBodyParts

public void restoreBodyParts(Commandable agent)
Changes the agent back to their original form. Transfers all possible worn armor to the new body, and unwears any armor that can no longer be worn. Issues appropriate messages to the agent.

Parameters:
agent - the player. Their old body is set in the permanent property "body-parts".

computeShiftedHP

public void computeShiftedHP(Commandable agent,
                             Archetype arch)
Figures out how many HP the agent should have in the new form, and sets their transient HP value accordingly.

Parameters:
agent - the player
arch - the polymorph archetype

computeShiftedWC

public void computeShiftedWC(Commandable agent,
                             Archetype arch)
Figures out the new WC for the shape.


restore

public boolean restore(Commandable agent)
Restores the naga to natural form.

Parameters:
agent - the naga to restore
Returns:
true if successful

restoreStats

public void restoreStats(Commandable agent)
Restores the agent's stats to the non-shifted versions.


computeEncumbrance

public void computeEncumbrance(Commandable agent)
Recomputes the agent's encumbrance


notifyAdd

public void notifyAdd(PropertyList obj)
Notifies the property that it's being added. Registers the "shift" command with the player.

Specified by:
notifyAdd in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being added to (in this case, the naga player)

notifyRemove

public void notifyRemove(PropertyList obj)
Notifies the property that it's being removed. Unregisters the "shift" command from the player.

Specified by:
notifyRemove in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being removed from (in this case, the naga player)

methodCalled

public void methodCalled(java.lang.String hookName,
                         MethodHookable target,
                         java.lang.Object data)
Called when the player is done initializing.

Specified by:
methodCalled in interface MethodHookCallback
Parameters:
hookName - the name of the hook being run
target - the object on which the method was invoked: a GameMap or GameObject.
data - a method-specific data object; can be null. Check the documentation for the method hook to see if any data is passed to the callbacks.

hookEvent

public void hookEvent(java.lang.String hookName,
                      CommandEvent event)
Turns "turn" into "move" if they're in a long form.

Specified by:
hookEvent in interface HookCallback
Parameters:
hookName - the name of the hook, such as "movePreHook".
event - the CommandEvent encapsulating the event parameters

timerExpired

public void timerExpired()
Spell-drain timer went off.

Specified by:
timerExpired in interface Timed

unshift

public void unshift()
Forces a shift back into a naga, or failing that, a frog.


killTimer

public void killTimer()
Kills the sp-drain timer.


setTimer

public void setTimer()
Starts the sp-drain timer.


toString

public java.lang.String toString()

createClone

public java.lang.Object createClone()
Description copied from interface: MutableProperty
Produces a clone of the property for the caller. Note: it's called createClone, not makeClone, because GameObject already has a makeClone. Some GameObjects can be properties (e.g inventories) and we can't do overloaded methods based only on the return type.

Specified by:
createClone in interface MutableProperty

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()