StendhalAPI

From Arianne
Jump to: navigation, search


this page is a work-in progress

Description

This page is intended to be a description of the common usable methods for adding or altering the world of Stendhal.

Entities

Base Classes

Entity

This is the base entity class for all entities in Stendhal.

Public methods:

Entity()
Default constructor.
Entity(object)
Copy constructor.
object: Object to be copied.
setDescription(text)
Sets the description text for the entity.
text: String to be used for description.
setEntityClass(clazz)
Sets the "class" attribute which is used to determine an image to be used as a representation of this entity.
clazz: (String) Class name.
setEntitySubclass(subclazz)
Sets the "subclass" attribute which is used to determine an image to be used as a representation of this entity.
subclazz: (String) Sub-class name.
setSize(width, height)
Sets the entity's size.
width: (int)
height: (int)
setPosition(x, y)
Sets the entity's horizontal & vertical position.
x: (int) The horizontal position.
y: (int) The vertical position.
setResistance(resistance)
Sets the resistance this has with other entities.
resistance: (int) Amount of resistance to set (0-100).
setVisibility(visibility)
Sets the entity's visibility level.
visibility: (int) 0 = completely transparent, 100 = completely opaque.
setMenu(menu)
Sets the context menu to use for the entity.
menu: (String) The menu to display in the client in the format:
  Display name 1|action1,
  Display name 2|action2
setCursor(cursor)
Sets the name of the mouse cursor that should be used for this entity.
cursor: (String)
getTitle()
Retrieves the entity's nicely formatted title/name.
returns: (String) The entity's formatted name.
getName()
Retrieves the name of this entity.
returns: (String) The entity's name.
getDescription()
Retrieves the entity's description text.
returns: (string) The entity's description text.
getDescriptionName(definite)
Retrieves the name or something that can be used to identify the entity to the player.
definite: (bool) Determines article to be used as prefix. true for "the" & false for "a/an" in case the entity has no name.
returns: (String) Entity name including article.
getHeight()
Retrieves the entity's height.
returns: (double)
getWidth()
Retrieves the entity's width.
returns: (double)
getZone()
returns: (StendhalRPZone) The current zone where the entity is located.
getX()
returns: (int) The horizontal coordinate of the entity's position.
getY()
returns: (int) The vertical coordinate of the entity's position.
getResistance(entity)
Retrieves the resistance this entity has on other entities.
entity: (optional) If set, returned value is combined resistance.
returns: (int) Value between 0-100 (0 = no resistance, 100 = non-traversable).
getAdjacentNodes()
Retrieves horizontal & vertical nodes immediately adjacent to entity's current position.
NOTE: This does not compensate for the entity's size. It is only meant to determine the positions the entity could potentially move to.
returns: (List<Node>) All nodes next to entity.
getArea()
Retrieves the area this entity currently occupies.
returns: (Rectangle2D)
getArea(ex, ey)
ex: (double)
ey: (double)
returns: (Rectangle2D)
getOrigin()
Retrieves the initial position of the entity.
returns: (Point)
getEntitySlot(name)
Retrieve's a slot identified by name.
name: (String) Name of slot.
returns: (EntitySlot) EntitySlot instance or null if the entity does not have such slot.
getCursor()
Retrieves the name of the mouse cursor that should be used for this entity.
returns: (String) Cursor name or null.
stopped()
returns: (bool) true if the entity is not moving.
hasDescription()
Checks if the entity has a description.
returns: (bool) true if the "description" attribute is set.
isObstacle(entity)
Determine if this is an obstacle for another entity.
entity: The entity to check against.
returns: (bool) true if combined resistance is above 95.
isInSight(other)
Checks if another entity is close enough to be detected by this entity.
other: (Entity) The entity to gauge distance to.
returns: (boolean) true if near enough.
squaredDistance(other)
Retrieves the square distance between this entity & the given one.
other: (Entity) The entity to which the distance should be calculated.
returns: (double) Representation of the squared distance.
squaredDistance(x, y)
Retrieves the square distance between this entity & a given point.
x: (int) The horizontal position to which distance should be calculated.
y: (int) The vertical position to which distance should be calculated.
returns: (double) Representation of the squared distance.
nextTo(entity, step)
Checks whether the given entity is next to this one.
entity: (Entity) The entity to compare distance to.
step: (double) (default: 0.25) Maximum distance at which is required to determine if next to.
returns: (bool) true if entity is next to this one.
onAdded(zone)
Called when this entity is added to a zone.
zone: (StendhalRPZone) The zone this was added to.
onRemoved(zone)
Called when this entity is being removed from a zone.
zone: (StendhalRPZone) The zone this will be removed from.
notifyWorldAboutChanges()
Notifies the StendhalRPWorld that this entity's attributes have changed.
describe()
Describes then entity (commonly used for when a player "looks" at an entity).
returns: (string) Description from the player's point-of-view.
slotIterator(slotTypes)
slotTypes: (Slots) Slot types to include in the iteration.
returns: (Iterator<RPSlot>)
slots(slotTypes)
slotTypes: (Slots) Slot types to include in the iteration.
returns: (Iterable<RPSlot>)

Public static methods:

generateRPClass()
Initializes the RPClass for this entity (initialized from games.stendhal.server.core.engine.RPClassGenerator).

ActiveEntity

Public methods:

ActiveEntity()
Default constructor.
ActiveEntity(object)
Copy constructor.
object: (RPObject) Object to be copied.
setSpeed(speed)
Sets the entity's current movement speed.
speed: (double)
setDirection(dir)
Sets the entity's facing direction.
dir: (Direction) Direction to face.
setIgnoresCollision(ignore)
Sets whether or not the entity should be able to traverse collision tiles.
ignore: (boolean) If true sets the "ignore_collision" attribute, otherwise removes it.
applyMovement()
getDirection()
Retrieves the entities current facing direction.
returns: (Direction)
getSpeed()
Retrieves the speed at which the entity is currently moving.
returns: (double)
getStepsTaken()
Retrieves the number of steps the entity has taken during the current session.
returns: (int)
getDirectionToward(entity)
Retrieves the direction from this entity to another.
entity: (Entity) Entity from which to gauge direction.
returns: (Direction)
getDirectionToward(area)
area: (Rectangle2D)
returns: (Direction)
isGhost()
Checks whether an entity is a ghost (not physically interactive).
returns: (boolean) true if "ghostmode" attribute is set (players only).
stop()
Stops the entity's movement.
isFacingToward(entity)
Determines if this entity is facing toward another entity.
entity: (Entity) Target entity.
returns: (boolean) true if facing other entity.
faceto(x, y)
Face toward a specific point on the map.
x: (int) Horizontal position of point to face.
y: (int) Vertical position of point to face.
faceToward(entity)
Face toward a specific entity.
entity: (Entity) Entity to face toward.
canMoveTo(x, y)
Predicts if entity can move to a position.
x: (int) Horizontal position of the target point.
y: (int) Vertical position of the target point.
returns: (boolean) true if nothing is preventing entity from moving to target point.
canMoveTo(pos)
Predicts if entity can move to a position.
pos: (Point) Target point.
returns: (boolean) true if nothing is preventing entity from moving to target point.
ignoresCollision()
Checks if the entity can pass through collision tiles.
returns: (boolean) true if the "ignore_collision" attribute is set.

Public static methods:

generateRPClass()
Initializes the RPClass for this entity (initialized from games.stendhal.server.core.engine.RPClassGenerator).

GuidedEntity

Public methods:

GuidedEntity ()
Default constructor.
GuidedEntity (object)
object : (RPObject) Object to be copied.
setBaseSpeed (bs)
Set entity's normal movement speed.
bs : (double) New normal speed for moving.
setPath (path, position)
Set a path for this entity to follow.
path : (FixedPath) Path to follow.
position : (int) (optional) The position of the path where the entity should start (this is not the same as setPosition()).
setPathAndPosition (path)
Set path & starting position for entity.
path : (FixedPath) Path to follow.
setPathPosition (pathPos)
Sets the entity's position in its path.
pathPos : (int) Position to set.
retracePath ()
Causes entity to retrace its path backwards when it reaches the end.
setCollisionAction (action)
Set action type to take when entity collides.
action : (CollisionAction) Behavior type after collision.
getBaseSpeed ()
Retreives entity's normal movement speed.
returns: (double)
getPath ()
Retrieves the entity's current path.
returns: (FixedPath)
getPathPosition ()
Retrieves the entity's current position in its path.
returns: (int)
getGuide ()
returns: (EntityGuide)
getCollisionAction ()
returns: (CollisionAction)
hasPath ()
Checks if the entity has a path set.
returns: (boolean)
isPathLoop ()
Checks if the entity's path loops.
returns: (boolean)
clearPath ()
Removes the entity's path.
reroute ()
Plan a new path to destination.
followPath ()
returns: (boolean)
addSuspend (duration, dir, pos...)
Add a suspension to the entity's path.
duration : (in)
dir : (Direction) (optional)
pos... : (int[])
NOTE: this method is experimental.
removeSuspend (pos...)
Removes a suspension from path.
pos... : (int[])
NOTE: this method is experimental.
onFinishedPath ()
updateModifedAttributes ()
atMovementRadius ()
returns: (boolean)
onOutsideMovementRadius ()
setRandomMovementRadius (radius, ret)
radius : (int)
ret : (boolean) (optional)

RPEntity

Public methods:

RPEntity ()
Default constructor.
RPEntity (object)
Copy constructor.
object : (RPObject) Object to be copied.
setName (name)
Sets the entity's name attribute.
name : (String) String to be used as name.
setLevel (level)
Sets the entity's level.
level : (int)
addKarma (karma)
Adds good or bad karma (players only).
karma : (double) Amount to be added (negative amount represents "bad" karma).
getLevel ()
Retrieves the entity's current level.
returns: (int)
getKarma ()
Retrieves current karma level.
returns: (double)

Static public methods:

generateRPClass ()

DressedEntity

NPC

PassiveNPC

SpeakerNPC

SilentNPC

See Also