mdh.hephaestus2
Class Player

java.lang.Object
  |
  +--mdh.hephaestus2.Stuff
        |
        +--mdh.hephaestus2.Thing
              |
              +--mdh.hephaestus2.Statted
                    |
                    +--mdh.hephaestus2.Entity
                          |
                          +--mdh.hephaestus2.Player
All Implemented Interfaces:
Serializable

public final class Player
extends Entity

A player character.

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

Field Summary
static int MAX_ITEMS
          Maximum number of items that may be carried.
static int SELECT_DROP
          select values for chooseItem()
static int SELECT_EQUIP
          select values for chooseItem()
static int SELECT_ITEM
          select values for chooseItem()
static int SELECT_USE
          select values for chooseItem()
 
Constructor Summary
Player(String name)
          Creates a new Player named 'name'.
 
Method Summary
 Item chooseItem(String title, int select)
          Pops up a menu letting the Player choose a single item from: inventory if select=SELECT_ITEM, equipment if select=SELECT_EQUIP, or usable inventory items if select=SELECT_USE.
 Entity chooseTarget(ArrayList targets)
          Selects a single Entity from a list of targets.
 int countItems()
          Returns the number of items carried, including equipment.
 boolean die(Stuff killer)
          The Entity dies and is removed.
 boolean doMagic()
           
 boolean doMove(int dir, int speed)
          Tries to move the Entity in direction 'dir' with a given speed.
 boolean dropItem(Item it)
          Drops an item from the Player's inventory, after calling it.dropCallback.
 boolean equipItem(Item it)
          Equips an item, after calling it.equipCallback.
 int getEquipid(int pos)
          Returns the id of the equipment at position 'pos', which is one of Global.EQ_*.
 int getFaction()
          Returns which faction the Entity belongs to.
 IntStackReadOnly getItems()
          Returns a list of ids of items carried.
 int getLevel()
          Returns the experience level of the Player.
 int getNItems()
          Returns the number of items carried.
 int getType()
          Returns the type constant for this object, one of Global.TYPE_*.
 boolean isType(int type)
          Returns true if this class or any of its superclasses is of 'type', one of Global.TYPE_*.
 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 playSound(String filename)
          Plays a sound, if you're a player, does nothing if you're a Creature.
 boolean removeEquip(Item it)
          Removes (unequips) an item, after calling it.removeCallback.
 void setEquipid(int pos, int e)
          Sets the equipment at position 'pos'.
 void setExp(int e)
          Sets the Player's experience point total, and the player levels up if exp reaches current level * Global.LEVEL_COST.
 void setGold(int g)
          Sets the gold value of the object.
 void setLevel(int l)
          Sets the Player's experience level.
 void setName(String n)
          Sets the name of this Stuff.
 void setStat(int i, int score)
          Sets the current score of stat 'i'.
 void setStatMax(int i, int score)
          Sets the maximum score of stat 'i'.
 void takeDamage(int dmg)
          'dmg' points are subtracted from the Entity's current HitPoints.
 boolean takeItem(Item it)
          Adds an item from the Player's inventory, after calling it.takeCallback.
 
Methods inherited from class mdh.hephaestus2.Entity
checkAlive, doAttack, doMagic, doMagicAttack, doMove, doTrigger, getAttackCallback, getAttackName, getDefeatCallback, getExp, getMagic, getNMagic, getTurnCallback, isFriendlyTo, listMagic, listTargets, output, output, removeMagic, setAttackCallback, setAttackName, setDefeatCallback, setMagic, setTurnCallback
 
Methods inherited from class mdh.hephaestus2.Statted
calcSecondary, getGold, getStat, getStatMax, setStatBoth
 
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, id, setBlocking, setTriggerCallback, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_ITEMS

public static final int MAX_ITEMS
Maximum number of items that may be carried.

See Also:
Constant Field Values

SELECT_ITEM

public static final int SELECT_ITEM
select values for chooseItem()

See Also:
Constant Field Values

SELECT_DROP

public static final int SELECT_DROP
select values for chooseItem()

See Also:
Constant Field Values

SELECT_EQUIP

public static final int SELECT_EQUIP
select values for chooseItem()

See Also:
Constant Field Values

SELECT_USE

public static final int SELECT_USE
select values for chooseItem()

See Also:
Constant Field Values
Constructor Detail

Player

public Player(String name)
       throws HephaestusException
Creates a new Player named 'name'. This gives the Player a new unique ID and adds it to the database.

Parameters:
name - Human-readable name to show in descriptions. Names do not have to be unique, but should be kept fairly short so they can fit in menus. Null names are not allowed.
Method Detail

chooseItem

public Item chooseItem(String title,
                       int select)
                throws HephaestusException
Pops up a menu letting the Player choose a single item from: inventory if select=SELECT_ITEM, equipment if select=SELECT_EQUIP, or usable inventory items if select=SELECT_USE.

Returns:
item selected, or null if the Player has no items or hit cancel.
HephaestusException

chooseTarget

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

Overrides:
chooseTarget in class Entity
HephaestusException

countItems

public int countItems()
Returns the number of items carried, including equipment. You can normally never have more than MAX_ITEMS.


die

public boolean die(Stuff killer)
            throws HephaestusException
Description copied from class: Entity
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.

Overrides:
die in class Entity
Returns:
true if you're still alive after all, false if you're really dead.
HephaestusException

doMagic

public boolean doMagic()
                throws HephaestusException
HephaestusException

doMove

public boolean doMove(int dir,
                      int speed)
               throws HephaestusException
Description copied from class: Entity
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.

Overrides:
doMove in class Entity
Returns:
true if the move succeeded, false if it failed.
HephaestusException

dropItem

public boolean dropItem(Item it)
                 throws HephaestusException
Drops an item from the Player's inventory, after calling it.dropCallback.

Returns:
true if successful.
HephaestusException

equipItem

public boolean equipItem(Item it)
                  throws HephaestusException
Equips an item, after calling it.equipCallback.

Returns:
true if successful.
HephaestusException

getEquipid

public int getEquipid(int pos)
               throws HephaestusException
Returns the id of the equipment at position 'pos', which is one of Global.EQ_*.

HephaestusException

getFaction

public int getFaction()
               throws HephaestusException
Description copied from class: Entity
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.

Specified by:
getFaction in class Entity
HephaestusException

getItems

public IntStackReadOnly getItems()
                          throws HephaestusException
Returns a list of ids of items carried.

HephaestusException

getNItems

public int getNItems()
              throws HephaestusException
Returns the number of items carried.

HephaestusException

getLevel

public int getLevel()
             throws HephaestusException
Returns the experience level of the Player.

HephaestusException

getType

public int getType()
Description copied from class: Stuff
Returns the type constant for this object, one of Global.TYPE_*.

Specified by:
getType in class Stuff

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 Entity

output

public void output(String iconfile,
                   Color fore,
                   Color back,
                   String text)
Description copied from class: Entity
Displays output, if you're a player, does nothing if you're a Creature.

Overrides:
output in class Entity
See Also:
Game.output(java.lang.String)

playSound

public void playSound(String filename)
Description copied from class: Entity
Plays a sound, if you're a player, does nothing if you're a Creature.

Overrides:
playSound in class Entity

removeEquip

public boolean removeEquip(Item it)
                    throws HephaestusException
Removes (unequips) an item, after calling it.removeCallback.

Returns:
true if successful.
HephaestusException

setEquipid

public void setEquipid(int pos,
                       int e)
                throws HephaestusException
Sets the equipment at position 'pos'.

HephaestusException

setExp

public void setExp(int e)
            throws HephaestusException
Sets the Player's experience point total, and the player levels up if exp reaches current level * Global.LEVEL_COST.

Overrides:
setExp in class Entity
HephaestusException

setGold

public void setGold(int g)
             throws HephaestusException
Description copied from class: Statted
Sets the gold value of the object.

Overrides:
setGold in class Statted
HephaestusException

setLevel

public void setLevel(int l)
              throws HephaestusException
Sets the Player's experience level. Generally you shouldn't use this - use setExp() instead, to give the Player the level increase bonuses.

HephaestusException

setName

public void setName(String n)
             throws HephaestusException
Description copied from class: Stuff
Sets the name of this Stuff.

Overrides:
setName in class Stuff
HephaestusException

setStat

public void setStat(int i,
                    int score)
             throws HephaestusException
Description copied from class: Statted
Sets the current score of stat 'i'. The current score may (temporarily) exceed the "maximum" stat score, but healing and levelling up will restore it to the normal maximum.

Overrides:
setStat in class Statted
Parameters:
i - index of the stat to modify
score - new score. The scores range from 1 to 20 for a normal human, and can go much higher; no score can go below 0. The maximum range of stat scores is -65536 to 65535; if you set outside that range, the value will wrap around.
HephaestusException
See Also:
Global.Body

setStatMax

public void setStatMax(int i,
                       int score)
                throws HephaestusException
Description copied from class: Statted
Sets the maximum score of stat 'i'.

Overrides:
setStatMax in class Statted
HephaestusException
See Also:
Statted.setStat(int, int)

takeDamage

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

Overrides:
takeDamage in class Entity
HephaestusException

takeItem

public boolean takeItem(Item it)
                 throws HephaestusException
Adds an item from the Player's inventory, after calling it.takeCallback.

Returns:
true if successful.
HephaestusException