mdh.hephaestus2
Class Entity

java.lang.Object
  |
  +--mdh.hephaestus2.Stuff
        |
        +--mdh.hephaestus2.Thing
              |
              +--mdh.hephaestus2.Statted
                    |
                    +--mdh.hephaestus2.Entity
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Creature, Player

public abstract class Entity
extends Statted

Common code of any mobile entity - Creature and Player.

Author:
Copyright © 2001 by Mark Hughes <kamikaze@kuoi.asui.uidaho.edu>
See Also:
Serialized Form

Method Summary
 boolean checkAlive(Stuff killer)
          Returns true if you're still alive, calls and returns die() if not.
 Entity chooseTarget(ArrayList targets)
          Selects a single Entity from a list of targets.
 boolean die(Stuff killer)
          The Entity dies and is removed.
 boolean doAttack()
          The Entity attacks a target ahead of it.
 boolean doMagic(String magicname)
          Casts a "magic spell" (magic is also used for skills and other special abilities).
 boolean doMagicAttack(Entity target, int dmg, String youmsg, String tarmsg)
          Performs a magical attack.
 boolean doMove(int dir)
          Tries to move the Entity in direction 'dir' with a speed equal to its current Speed score.
 boolean doMove(int dir, int speed)
          Tries to move the Entity in direction 'dir' with a given speed.
 boolean doTrigger()
          Tries to trigger something in the same grid, and returns the callback result.
 String getAttackCallback()
          Returns the callback that the Entity will call after every attack.
 String getAttackName()
          Returns the name of the Entity's attack, shown as "foo attacks you with ATTACKNAME".
 String getDefeatCallback()
          Returns the function called when the Creature is killed by a Player.
 int getExp()
          Returns the experience total of this Entity.
abstract  int getFaction()
          Returns which faction the Entity belongs to.
 String getMagic(String name)
          Returns the callback assigned to the magic spell named 'name'.
 int getNMagic()
          Returns the number of "magic abilities" defined.
 String getTurnCallback()
          Returns the callback called on every turn.
 boolean isFriendlyTo(Entity en)
          Returns true if you are friendly to Entity 'en'.
 boolean isType(int type)
          Returns true if this class or any of its superclasses is of 'type', one of Global.TYPE_*.
 Iterator listMagic()
          Returns an iterator over the list of "magic abilities".
 ArrayList listTargets(boolean friendlyTarget, int range)
          Returns a list of visible targets in a direct line forward, out to 'range' squares.
 void output(String text)
          Displays output, if you're a player, does nothing if you're a Creature.
 void output(String iconfile, Color fore, Color back, String text)
          Displays output, if you're a player, does nothing if you're a Creature.
 void output(String iconfile, String text)
          Displays output, if you're a player, does nothing if you're a Creature.
 void playSound(String filename)
          Plays a sound, if you're a player, does nothing if you're a Creature.
 void removeMagic(String name)
          Removes a "magic ability" named 'name' from the Entity.
 void setAttackCallback(String a)
          Returns the callback that the Entity will call after every attack.
 void setAttackName(String a)
          Sets the attack name.
 void setDefeatCallback(String d)
          Sets the function called when the Creature is killed by a Player.
 void setExp(int e)
          Sets the experience total of this Entity.
 void setMagic(String name, String magicCallback)
          Sets the callback for a "magic ability" named 'name'.
 void setTurnCallback(String t)
          Sets the callback called on every turn.
 void takeDamage(int dmg)
          'dmg' points are subtracted from the Entity's current HitPoints.
 
Methods inherited from class mdh.hephaestus2.Statted
calcSecondary, getGold, getStat, getStatMax, setGold, setStat, setStatBoth, setStatMax
 
Methods inherited from class mdh.hephaestus2.Thing
findGrid, findMap, getIconFilename, getNPoses, getOpacity, getPose, getProps, getTile, initProps, loc, moveto, moveto, setFacing, setOpacity, setPose, setTile
 
Methods inherited from class mdh.hephaestus2.Stuff
destroy, getBlocking, getName, getTriggerCallback, getType, id, setBlocking, setName, setTriggerCallback, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

checkAlive

public boolean checkAlive(Stuff killer)
                   throws HephaestusException
Returns true if you're still alive, calls and returns die() if not. Adventure code that modifies stats should call checkAlive() when it's done. An Entity will die if its current Body, Speed, Mind, Charm, or HitPoints are 0 and the maximum stat for that score is more than 0.

HephaestusException

chooseTarget

public Entity chooseTarget(ArrayList targets)
                    throws HephaestusException
Selects a single Entity from a list of targets.

HephaestusException

die

public boolean die(Stuff killer)
            throws HephaestusException
The Entity dies and is removed. The defeatCallback, if defined, is called, and if it returns MoveResult.BLOCKED, die() immediately returns true, indicating that you're not dead after all. Otherwise the killer gets killersReward(), this Entity is removed, and false is returned.

Returns:
true if you're still alive after all, false if you're really dead.
HephaestusException

doAttack

public boolean doAttack()
                 throws HephaestusException
The Entity attacks a target ahead of it. Creatures will just pick one available target at random, Players get to choose from a menu.

Returns:
true if the attack was attempted, even if it misses.
HephaestusException

doMagic

public boolean doMagic(String magicname)
                throws HephaestusException
Casts a "magic spell" (magic is also used for skills and other special abilities).

HephaestusException

doMagicAttack

public boolean doMagicAttack(Entity target,
                             int dmg,
                             String youmsg,
                             String tarmsg)
                      throws HephaestusException
Performs a magical attack.

Parameters:
target - The target Entity.
dmg - HP of damage to inflict if the attack hits - unlike physical attacks, this is NOT affected by result quality.
youmsg - Base message to display to you; your name will be prepended.
tarmsg - Base message to display to the target; target's name will be prepended.
Returns:
true if the attack hit, even if it did no damage.
HephaestusException

doMove

public boolean doMove(int dir)
               throws HephaestusException
Tries to move the Entity in direction 'dir' with a speed equal to its current Speed score.

Returns:
true if the move succeeded, false if it failed.
HephaestusException

doMove

public boolean doMove(int dir,
                      int speed)
               throws HephaestusException
Tries to move the Entity in direction 'dir' with a given speed. The Entity is lined up with the grid along the minor axis of the move, so you can always pass through doorways, hit triggers, etc. If the move is blocked by a barrier or Entity, this Entity is moved up to the blocking point and stops, and the blocking object's trigger function is called and the result returned. If the move is into the outer border of the map, the move will fail but the map's border callback will be called and the result returned.

Returns:
true if the move succeeded, false if it failed.
HephaestusException

doTrigger

public boolean doTrigger()
                  throws HephaestusException
Tries to trigger something in the same grid, and returns the callback result. Use doMove to trigger things around you.

HephaestusException

getAttackCallback

public String getAttackCallback()
                         throws HephaestusException
Returns the callback that the Entity will call after every attack. The id of this Entity will be in "actorid", the target will be in "targetid", and the amount the attack succeeded or failed by will be in "attackresult".

HephaestusException

getAttackName

public String getAttackName()
Returns the name of the Entity's attack, shown as "foo attacks you with ATTACKNAME". If null, the "with ATTACKNAME" is left off.


getDefeatCallback

public String getDefeatCallback()
                         throws HephaestusException
Returns the function called when the Creature is killed by a Player.

HephaestusException

getExp

public int getExp()
           throws HephaestusException
Returns the experience total of this Entity.

HephaestusException

getFaction

public abstract int getFaction()
                        throws HephaestusException
Returns which faction the Entity belongs to. Every faction is hostile to every other faction. Faction 0 is the player's faction. Faction -1 is neutral to everyone.

HephaestusException

getNMagic

public int getNMagic()
              throws HephaestusException
Returns the number of "magic abilities" defined.

HephaestusException

getMagic

public String getMagic(String name)
                throws HephaestusException
Returns the callback assigned to the magic spell named 'name'.

HephaestusException

getTurnCallback

public String getTurnCallback()
                       throws HephaestusException
Returns the callback called on every turn.

HephaestusException

isFriendlyTo

public boolean isFriendlyTo(Entity en)
                     throws HephaestusException
Returns true if you are friendly to Entity 'en'.

HephaestusException

isType

public boolean isType(int type)
Description copied from class: Stuff
Returns true if this class or any of its superclasses is of 'type', one of Global.TYPE_*.

Overrides:
isType in class Statted

listMagic

public Iterator listMagic()
                   throws HephaestusException
Returns an iterator over the list of "magic abilities".

HephaestusException

listTargets

public ArrayList listTargets(boolean friendlyTarget,
                             int range)
                      throws HephaestusException
Returns a list of visible targets in a direct line forward, out to 'range' squares.

Parameters:
friendlyTarget - if true, only friendly targets are selected; if false, only hostile targets are selected.
HephaestusException

output

public final void output(String text)
Displays output, if you're a player, does nothing if you're a Creature.

See Also:
Game.output(java.lang.String)

output

public final void output(String iconfile,
                         String text)
Displays output, if you're a player, does nothing if you're a Creature.

See Also:
Game.output(java.lang.String)

output

public void output(String iconfile,
                   Color fore,
                   Color back,
                   String text)
Displays output, if you're a player, does nothing if you're a Creature.

See Also:
Game.output(java.lang.String)

playSound

public void playSound(String filename)
Plays a sound, if you're a player, does nothing if you're a Creature.


removeMagic

public void removeMagic(String name)
                 throws HephaestusException
Removes a "magic ability" named 'name' from the Entity.

HephaestusException

setAttackCallback

public void setAttackCallback(String a)
                       throws HephaestusException
Returns the callback that the Entity will call after every attack.

HephaestusException
See Also:
getAttackCallback()

setAttackName

public void setAttackName(String a)
Sets the attack name.

See Also:
getAttackName()

setDefeatCallback

public void setDefeatCallback(String d)
                       throws HephaestusException
Sets the function called when the Creature is killed by a Player.

HephaestusException

setExp

public void setExp(int e)
            throws HephaestusException
Sets the experience total of this Entity.

HephaestusException

setMagic

public void setMagic(String name,
                     String magicCallback)
              throws HephaestusException
Sets the callback for a "magic ability" named 'name'. Magic is used for spells, skills, and any natural abilities.

HephaestusException

setTurnCallback

public void setTurnCallback(String t)
                     throws HephaestusException
Sets the callback called on every turn.

HephaestusException

takeDamage

public void takeDamage(int dmg)
                throws HephaestusException
'dmg' points are subtracted from the Entity's current HitPoints. You should always call checkAlive(killer) after this.

HephaestusException