de.adom.jade.beings
Class Being

java.lang.Object
  extended by de.adom.jade.kernel.GUIDCarrier
      extended by de.adom.jade.kernel.DefaultActor
          extended by de.adom.jade.beings.Being
All Implemented Interfaces:
Actor, java.io.Serializable
Direct Known Subclasses:
NPC, PC

public abstract class Being
extends DefaultActor

Implements an autonomous being in JADE. This is the base class for both monsters and the PC.

By definition all commands a being can execute (either requested by the monster AI or by external commands) must be named in such a way that they start with the word do... followed by a verb.

Some of the method names in this class violate all coding standards by starting with capital letters, omitting the get prefix, etc. This is done for all methods used in building sentence structures to make the sentences look as readable as possible. This was necessary because both the PC and all NPCs use the same message texts and some tricks had to be used.

Particular care needs to be exercised when displaying messages caused by a being or his actions. There are three types of messages to differentiate:

See Also:
Serialized Form

Constructor Summary
Being(Map map)
          Initializes the basic data of this being.
 
Method Summary
 void act()
          Executes the next action of this being.
protected abstract  void doAct()
          Implements a atual action for this being.
 boolean doMove(int direction)
          Moves this being one step into a given direction.
 void doWait()
          The "wait" action.
 boolean enterLocation()
          Enters the location at the current position of the being.
 boolean enterLocation(Connection connection)
          Enters the location at the current position of the being.
protected  boolean executeRepeatedCommand(Command command)
          Executes a command that is executed repetitively.
 int getAttribute(int attributeIndex)
          Returns an attribute value of the being.
 int getAttributeModifier(int attributeIndex)
          Returns an attribute modifier of the being.
 int getCurrentHitPoints()
          Returns the current number of hit points of this being.
 int getCurrentPowerPoints()
          Returns the current number of power points of this being.
 int getDV()
          Returns the current defense value of this being.
 long getExperiencePoints()
          Returns the current experience points of the being.
 Gender getGender()
          Returns the gender of this being.
 Command getLastUsedCommand()
          Returns the most recent command used by this being.
 int getLastX()
          Returns the last x position of this being.
 int getLastY()
          Returns the last y position of this being.
 int getLevel()
          Returns the current level of the being.
abstract  java.lang.String getLogicalName()
          Returns the logical name for tbis being.
 Map getMap()
          Returns the map this being dwells upon.
 int getMaximumHitPoints()
          Returns the maximum number of hit points for this being.
 int getMaximumPowerPoints()
          Returns the maximum number of power points for this being.
 long getMoves()
          Returns the current number of moves points of the being.
 java.lang.String getName()
          Returns the name of this being.
protected  int getNextActionEnergy()
          Returns the energy (in ticks) required for the next action.
 int getPV()
          Returns the current protection value of this being.
 Race getRace()
          Returns the race of this being.
 int getSightRange()
          Returns the basic sight range for this being.
 int getSpeed()
          Returns the speed score of the being.
 int getX()
          Returns the x position of this being.
 int getY()
          Returns the y position of this being.
protected  void handleTimedStuff()
          Handles all the timers that can run on a being.
 void inform(java.lang.String information)
          Displays messages meant only for this being.
 void initialize()
          Initializes a being so that all core values have been set.
static void initializeWordForms()
          Initializes all the word forms for all beings.
 void install()
          Installs the being as a new being on its map.
 boolean isAlive()
          Checks if this being is still alive.
 boolean isBlind()
          Checks whether this being has been blinded.
protected abstract  boolean isFirstPerson()
          Determines whether messages originating from this being use first person singular or third person singular word form.
protected  boolean isLastCommandRepeated()
          Determines whether the last executed command should be repeated.
 boolean isOpenTile(Tile tile)
          Checks whether a given tile is open for this being.
protected  boolean isReadyToAct()
          Determines whether the being can act.
 boolean isValid()
          Determines whether this action still is going to happen when the time has come.
 boolean isVisible()
          Determines whether this being currently is visible to the PC.
 boolean isVisibleTo(Being being)
          Determines whether this being currently is visible to the given being.
protected abstract  boolean isVisibleToImpl(Being being)
          Determines whether this being currently is visible to the given being.
 void message(java.lang.String message)
          Displays a message meant for everyone on the map.
 void modifyCurrentHitPoints(int modifier)
          Modifies the current number of hit points by a given value.
 void modifyCurrentPowerPoints(int modifier)
          Modifies the current number of hit points by a given value.
 void modifyMaximumHitPoints(int modifier)
          Modifies the maximum number of hit points for this being.
 void modifyMaximumPowerPoints(int modifier)
          Modifies the maximum number of power points for this being.
protected  void modifyNextActionEnergy(int percentageModifier)
          Modifies the energy required for the next action by a certain percentage.
 boolean moveTo(int newX, int newY)
          Moves the being to a new position.
 void observe(java.lang.String observation)
          Displays a message to the user if this being is visible to the PC.
protected  void resetNextActionEnergy()
          Resets the energy required for the next action.
 void setAttribute(int attributeIndex, int value)
          Sets the atribute value for a given attribute.
 void setCurrentHitPoints(int value)
          Sets the current number of hit points of this being.
 void setCurrentPowerPoints(int value)
          Sets the current number of power points of this being.
 void setGender(Gender theGender)
          Sets the gender of the being.
 void setLastUsedCommand(Command command)
          Stores the most recent command used by this being.
 void setMap(Map map)
          Sets the map this being dwells on.
 void setMaximumHitPoints(int maxHits)
          Sets the maximum number of hit points for this being.
 void setMaximumPowerPoints(int maxPower)
          Sets the maximum number of power points for this being.
 void setName(java.lang.String theName)
          Sets the name of this being.
 void setPosition(int xp, int yp)
          Sets the position of this being on the current map.
 void setRace(Race theRace)
          Sets the race for this being.
 void updateDisplay()
          Updates the visibility of the current map.
 java.lang.String word(java.lang.String word)
          Returns a given word in the appopriate form for this being (either first person or third person).
abstract  java.lang.String you()
          Returns a text describing this being as the actor.
 java.lang.String You()
          Returns a text describing this being as the actor with a capital letter at the start.
 void You(java.lang.String information)
          Informs the being of the results of its action.
 
Methods inherited from class de.adom.jade.kernel.DefaultActor
actAgainAfter, getActionPoint, setActionPoint
 
Methods inherited from class de.adom.jade.kernel.GUIDCarrier
getGUID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Being

public Being(Map map)
Initializes the basic data of this being.

Parameters:
map - the map upon which the being is movign right now; may be null, if the being is held in some kind of storage object; in that case no location-dependent methods may be called
Method Detail

initialize

public void initialize()
Initializes a being so that all core values have been set.


act

public final void act()
Executes the next action of this being. All kinds of checks are executed to see if the being really is allowed to act (e.g. it must not be paralyzed, asleep, ...). Then doAct (which needs to be overridden in derived classes) is called. Finally the next action will be prepared.

Specified by:
act in interface Actor
Specified by:
act in class DefaultActor

isLastCommandRepeated

protected boolean isLastCommandRepeated()
Determines whether the last executed command should be repeated. If that is possible it will be repeated.

Returns:
a boolean flag indicating if the last command could be repeated

executeRepeatedCommand

protected boolean executeRepeatedCommand(Command command)
Executes a command that is executed repetitively.

Parameters:
command - the command to execute

install

public void install()
Installs the being as a new being on its map. This basically inserts the being into the actor queue at the correct position. This method must be called after a being has been instantiated and before it can act on its own. Don't call this method before the being is initialized completely lest it will not act at the correct point of time.


doAct

protected abstract void doAct()
Implements a atual action for this being. This method needs to hold either the NPC AI or the interface for the player to execute the next command.


handleTimedStuff

protected void handleTimedStuff()
Handles all the timers that can run on a being. This includes taking care of poison, healing, various spells, paralyzation and so on.


resetNextActionEnergy

protected void resetNextActionEnergy()
Resets the energy required for the next action. The basic energy required is equal to ten times the speed of the being.


modifyNextActionEnergy

protected void modifyNextActionEnergy(int percentageModifier)
Modifies the energy required for the next action by a certain percentage. Percentages can be both positive and negative. They are added up until each call of getNextEnergyAction.

Parameters:
percentageModifier -
See Also:
#getNextEnergyAction

getNextActionEnergy

protected int getNextActionEnergy()
Returns the energy (in ticks) required for the next action.

Returns:
the energy required for the next action (in ticks)

isReadyToAct

protected boolean isReadyToAct()
Determines whether the being can act. Paralyzation magical sleep and other factors are taken into account.

Returns:
a boolean value determining whether the being is truly ready to act

getSpeed

public int getSpeed()
Returns the speed score of the being.

Returns:
the speed score of the being

getAttribute

public int getAttribute(int attributeIndex)
Returns an attribute value of the being.

Parameters:
attributeIndex - the index of the attribute
Returns:
the attribute score

setAttribute

public void setAttribute(int attributeIndex,
                         int value)
Sets the atribute value for a given attribute.

Parameters:
attributeIndex - the index of the attribute
value - teh value of the attribute

getAttributeModifier

public int getAttributeModifier(int attributeIndex)
Returns an attribute modifier of the being.

Parameters:
attributeIndex - the index of the attribute
Returns:
the attribute modifier; see the class Attribute for more details

isAlive

public boolean isAlive()
Checks if this being is still alive. "Alive" here has a special meaning. Basically it represens the notion of "this being can still act". Therefor undead can be alive, too.

Returns:
a boolean value determining whether this being is alive

isValid

public boolean isValid()
Determines whether this action still is going to happen when the time has come. Actions no longer might be necessary because e.g. the acting monster already has been killed.

Specified by:
isValid in interface Actor
Overrides:
isValid in class DefaultActor
Returns:
a boolean flag determining whether the next action of this actor still is valid

isBlind

public boolean isBlind()
Checks whether this being has been blinded.

TODO: this method needs to be implemented in a meaningful way.

Returns:
a boolean value determining whether this being is blind or not

doWait

public void doWait()
The "wait" action. Passes one game turn without doing anything.


setGender

public void setGender(Gender theGender)
Sets the gender of the being.

Parameters:
theGender - the new gender

getGender

public Gender getGender()
Returns the gender of this being.

Returns:
the gender of this being

getCurrentHitPoints

public int getCurrentHitPoints()
Returns the current number of hit points of this being.

Returns:
the current number of hit points for this being

setCurrentHitPoints

public void setCurrentHitPoints(int value)
Sets the current number of hit points of this being.

Parameters:
value - the new value for the current number of hit points

modifyCurrentHitPoints

public void modifyCurrentHitPoints(int modifier)
Modifies the current number of hit points by a given value. The maximum number of hit points can be surpassed.


getMaximumHitPoints

public int getMaximumHitPoints()
Returns the maximum number of hit points for this being.

Returns:
the maximum number of hit points for this being

setMaximumHitPoints

public void setMaximumHitPoints(int maxHits)
Sets the maximum number of hit points for this being. The maximum number can't be reduced below 1. The current number of hit points will be adjusted appropriately.

Parameters:
maxHits - the maximum number of hit points for this being

modifyMaximumHitPoints

public void modifyMaximumHitPoints(int modifier)
Modifies the maximum number of hit points for this being.

Parameters:
modifier - the modifier for the maximum number of hit points

getCurrentPowerPoints

public int getCurrentPowerPoints()
Returns the current number of power points of this being.

Returns:
the current number of power points for this being

setCurrentPowerPoints

public void setCurrentPowerPoints(int value)
Sets the current number of power points of this being.

Parameters:
value - the new value for the current number of power points

modifyCurrentPowerPoints

public void modifyCurrentPowerPoints(int modifier)
Modifies the current number of hit points by a given value. The maximum number of hit points can be surpassed.


getMaximumPowerPoints

public int getMaximumPowerPoints()
Returns the maximum number of power points for this being.

Returns:
the maximum number of power points for this being

setMaximumPowerPoints

public void setMaximumPowerPoints(int maxPower)
Sets the maximum number of power points for this being. The maximum number can't be reduced below 0. The current number of power points will be adjusted appropriately.

Parameters:
maxPower - the maximum number of hit points for this being

modifyMaximumPowerPoints

public void modifyMaximumPowerPoints(int modifier)
Modifies the maximum number of power points for this being.

Parameters:
modifier - the modifier for the maximum number of power points

getX

public int getX()
Returns the x position of this being.

Returns:
the x position of this being

getY

public int getY()
Returns the y position of this being.

Returns:
the y position of this being

getLastX

public int getLastX()
Returns the last x position of this being.

Returns:
the last x position of this being

getLastY

public int getLastY()
Returns the last y position of this being.

Returns:
the last y position of this being

setPosition

public void setPosition(int xp,
                        int yp)
Sets the position of this being on the current map.

Parameters:
xp - the x coordinate of the position
yp - the y coordinate of the position

updateDisplay

public final void updateDisplay()
Updates the visibility of the current map. This method should always be called if this being does something that changes the line of sight for the current map.


getSightRange

public int getSightRange()
Returns the basic sight range for this being.

Returns:
the sight rage for this being

isOpenTile

public boolean isOpenTile(Tile tile)
Checks whether a given tile is open for this being. Open tiles are such tiles that the being can look and move through.

Parameters:
tile - the tile to check
Returns:
a boolean value determining whether the tile is open or not

setMap

public void setMap(Map map)
Sets the map this being dwells on.

Parameters:
map - the map this being dwells on

getMap

public Map getMap()
Returns the map this being dwells upon.

Returns:
the map this being dwells on

isVisible

public boolean isVisible()
Determines whether this being currently is visible to the PC.

Returns:
a boolean flag determing whether this being is visible to the PC or not

isVisibleTo

public boolean isVisibleTo(Being being)
Determines whether this being currently is visible to the given being.

Parameters:
being - the being that tries to discern this being
Returns:
a boolean flag determing whether this being is visible to the given being or not

isVisibleToImpl

protected abstract boolean isVisibleToImpl(Being being)
Determines whether this being currently is visible to the given being.

Parameters:
being - the being that tries to discern this being
Returns:
a boolean flag determing whether this being is visible to the given being or not

doMove

public boolean doMove(int direction)
Moves this being one step into a given direction. This method checks whether the move is legal. If it is legal, the method moveTo will be called to execute the actual move with all consequences resulting from it.

Parameters:
direction - the direction to move one step to
Returns:
a boolean value indicating if the move was successful
See Also:
moveTo(int, int)

moveTo

public boolean moveTo(int newX,
                      int newY)
Moves the being to a new position. To check the validity of a move, doMove should be called with a given direction if the being is moved but one step in a non-standard way (e.g. out of its own will).

Parameters:
newX - the new x coordinate for this being
newY - the new y coordinate for this being
Returns:
a boolean value indicating if the move was successful
See Also:
doMove(int)

getLogicalName

public abstract java.lang.String getLogicalName()
Returns the logical name for tbis being. The logical name is intended to be used by the specific UI implementation to look up the correct graphical representation for the being in question.

Returns:
the logical name of this being

message

public void message(java.lang.String message)
Displays a message meant for everyone on the map.


observe

public void observe(java.lang.String observation)
Displays a message to the user if this being is visible to the PC. This method should be used for all information that can be noticed by anyone observing this being.

Parameters:
observation - the observation to display if the being is visible to the PC

You

public void You(java.lang.String information)
Informs the being of the results of its action. Messages of the form "You..." are displayed.

Parameters:
information - the personal information to display

inform

public void inform(java.lang.String information)
Displays messages meant only for this being. Usually such messages will only be displayed if the PC is the acting being. By default the implementation of this method does nothing. This method should be used to convey information to a being if the information can not be noticed by other beings observing this being.

Parameters:
information - the personal information to display

word

public final java.lang.String word(java.lang.String word)
Returns a given word in the appopriate form for this being (either first person or third person). Note that this method does not adhere to Suns coding standard in order to make the text pieces build with it more readable. This is a conscious design decision.
For each word requested from this method the file /data/dictionary.dat needs a correct entry with the word form in both first and third person singular.

Parameters:
word - the word in first person singular
Returns:
the word in first or third person singular

isFirstPerson

protected abstract boolean isFirstPerson()
Determines whether messages originating from this being use first person singular or third person singular word form.

Returns:
a boolean flag determining whether messages originating from this being use first operson singular or not

you

public abstract java.lang.String you()
Returns a text describing this being as the actor.

Returns:
a text describing this being as the actor

You

public java.lang.String You()
Returns a text describing this being as the actor with a capital letter at the start.

Returns:
a text describing this being as the actor

initializeWordForms

public static void initializeWordForms()
Initializes all the word forms for all beings.


setRace

public void setRace(Race theRace)
Sets the race for this being.

Parameters:
theRace - the race of this being

getRace

public Race getRace()
Returns the race of this being.

Returns:
the race of this being

setName

public void setName(java.lang.String theName)
Sets the name of this being.

Parameters:
theName - the name of this being

getName

public java.lang.String getName()
Returns the name of this being.

Returns:
the name of this being

getLevel

public int getLevel()
Returns the current level of the being.

Returns:
the current level of the being

getExperiencePoints

public long getExperiencePoints()
Returns the current experience points of the being.

Returns:
the current experience points of the being

getMoves

public long getMoves()
Returns the current number of moves points of the being.

Returns:
the current number of moves of the being

getPV

public int getPV()
Returns the current protection value of this being.

Returns:
the current protection value

getDV

public int getDV()
Returns the current defense value of this being.

Returns:
the current defense value

enterLocation

public boolean enterLocation()
Enters the location at the current position of the being.

Returns:
a boolean value indicating whether the location could be entered

enterLocation

public boolean enterLocation(Connection connection)
Enters the location at the current position of the being.

Parameters:
connection - the connection by which to enter the next location
Returns:
a boolean value indicating whether the location could be entered

setLastUsedCommand

public void setLastUsedCommand(Command command)
Stores the most recent command used by this being.

Parameters:
command - the command to store

getLastUsedCommand

public Command getLastUsedCommand()
Returns the most recent command used by this being.

Returns:
the most recent command used