StendhalAPI: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>AntumDeluge →Entity: add more public methods |
imported>AntumDeluge →ActiveEntity: add public methods |
||
| Line 210: | Line 210: | ||
* Class: {{StendhalFile|master|src/games/stendhal/server/entity/ActiveEntity.java|games.stendhal.server.entity.ActiveEntity}} |
* Class: {{StendhalFile|master|src/games/stendhal/server/entity/ActiveEntity.java|games.stendhal.server.entity.ActiveEntity}} |
||
* Inherits: [[StendhalAPI#Entity|Entity]] |
* Inherits: [[StendhalAPI#Entity|Entity]] |
||
'''Public methods:''' |
|||
; ''<span style="color:green;">ActiveEntity</span>()'' |
|||
: Default constructor. |
|||
; ''<span style="color:green;">ActiveEntity</span>(object)'' |
|||
: Copy constructor. |
|||
: '''''object:''''' (<code>RPObject</code>) Object to be copied. |
|||
; ''<span style="color:green;">setSpeed</span>(speed)'' |
|||
: Sets the entity's current movement speed. |
|||
: '''''speed:''''' (<code>double</code>) |
|||
; ''<span style="color:green;">setDirection</span>(dir)'' |
|||
: Sets the entity's facing direction. |
|||
: '''''dir:''''' (<code>Direction</code>) Direction to face. |
|||
; ''<span style="color:green;">setIgnoresCollision</span>(ignore)'' |
|||
: Sets whether or not the entity should be able to traverse collision tiles. |
|||
: '''''ignore:''''' (<code>boolean</code>) If <code>true</code> sets the "ignore_collision" attribute, otherwise removes it. |
|||
; ''<span style="color:green;">applyMovement</span>()'' |
|||
: |
|||
; ''<span style="color:green;">getDirection</span>()'' |
|||
: Retrieves the entities current facing direction. |
|||
: ''returns:'' (<code>Direction</code>) |
|||
; ''<span style="color:green;">getSpeed</span>()'' |
|||
: Retrieves the speed at which the entity is currently moving. |
|||
: ''returns:'' (<code>double</code>) |
|||
; ''<span style="color:green;">getStepsTaken</span>()'' |
|||
: Retrieves the number of steps the entity has taken during the current session. |
|||
: ''returns:'' (<code>int</code>) |
|||
; ''<span style="color:green;">getDirectionToward</span>(entity)'' |
|||
: Retrieves the direction from this entity to another. |
|||
: '''''entity:''''' (<code>Entity</code>) Entity from which to gauge direction. |
|||
: ''returns:'' (<code>Direction</code>) |
|||
; ''<span style="color:green;">getDirectionToward</span>(area)'' |
|||
: |
|||
: '''''area:''''' (<code>Rectangle2D</code>) |
|||
: ''returns:'' (<code>Direction</code>) |
|||
; ''<span style="color:green;">isGhost</span>()'' |
|||
: Checks whether an entity is a ghost (not physically interactive). |
|||
: ''returns:'' (<code>boolean</code>) <code>true</code> if "ghostmode" attribute is set (players only). |
|||
; ''<span style="color:green;">stop</span>()'' |
|||
: Stops the entity's movement. |
|||
; ''<span style="color:green;">isFacingToward</span>(entity)'' |
|||
: Determines if this entity is facing toward another entity. |
|||
: '''''entity:''''' (<code>Entity</code>) Target entity. |
|||
: ''returns:'' (<code>boolean</code>) <code>true</code> if facing other entity. |
|||
; ''<span style="color:green;">faceto</span>(x, y)'' |
|||
: Face toward a specific point on the map. |
|||
: '''''x:''''' (<code>int</code>) Horizontal position of point to face. |
|||
: '''''y:''''' (<code>int</code>) Vertical position of point to face. |
|||
; ''<span style="color:green;">faceToward</span>(entity)'' |
|||
: Face toward a specific entity. |
|||
: '''''entity:''''' (<code>Entity</code>) Entity to face toward. |
|||
; ''<span style="color:green;">canMoveTo</span>(x, y)'' |
|||
: Predicts if entity can move to a position. |
|||
: '''''x:''''' (<code>int</code>) Horizontal position of the target point. |
|||
: '''''y:''''' (<code>int</code>) Vertical position of the target point. |
|||
: ''returns:'' (<code>boolean</code>) <code>true</code> if nothing is preventing entity from moving to target point. |
|||
; ''<span style="color:green;">canMoveTo</span>(pos)'' |
|||
: Predicts if entity can move to a position. |
|||
: '''''pos:''''' (<code>Point</code>) Target point. |
|||
: ''returns:'' (<code>boolean</code>) <code>true</code> if nothing is preventing entity from moving to target point. |
|||
; ''<span style="color:green;">ignoresCollision</span>()'' |
|||
: Checks if the entity can pass through collision tiles. |
|||
: ''returns:'' (<code>boolean</code>) <code>true</code> if the "ignore_collision" attribute is set. |
|||
'''Public static methods:''' |
|||
; ''<span style="color:green;">generateRPClass</span>()'' |
|||
: |
|||
=== GuidedEntity === |
=== GuidedEntity === |
||
Revision as of 22:55, 19 April 2020
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.
- Class: games.stendhal.server.entity.Entity
- Inherits: marauroa.common.game.RPObject
- Implements:
Public methods:
- Entity()
- Default constructor.
- Entity(object)
- Copy constructor.
- object: Object to be copied.
- generateRPClass()
- Initializes the RPClass for this entity (initialized from games.stendhal.server.core.engine.RPClassGenerator).
- 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.truefor "the" &falsefor "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 ornullif 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)trueif the entity is not moving.
- hasDescription()
- Checks if the entity has a description.
- returns: (
bool)trueif the "description" attribute is set.
- isObstacle(entity)
- Determine if this is an obstacle for another entity.
- entity: The entity to check against.
- returns: (
bool)trueif 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)trueif 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)trueif 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
StendhalRPWorldthat 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>)
ActiveEntity
- Class: games.stendhal.server.entity.ActiveEntity
- Inherits: Entity
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) Iftruesets 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)trueif "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)trueif 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)trueif 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)trueif nothing is preventing entity from moving to target point.
- ignoresCollision()
- Checks if the entity can pass through collision tiles.
- returns: (
boolean)trueif the "ignore_collision" attribute is set.
Public static methods:
- generateRPClass()
GuidedEntity
- Class: games.stendhal.server.entity.GuidedEntity
- Inherits: ActiveEntity
RPEntity
- Class: games.stendhal.server.entity.RPEntity
- Inherits: GuidedEntity