StendhalAPI: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>AntumDeluge Page for common public Stendhal server API |
imported>AntumDeluge →Entity: add more public methods |
||
| Line 12: | Line 12: | ||
=== Entity === |
=== Entity === |
||
This is the base entity class for all entities in Stendhal. |
|||
* Class: {{StendhalFile|master|src/games/stendhal/server/entity/Entity.java|games.stendhal.server.entity.Entity}} |
* Class: {{StendhalFile|master|src/games/stendhal/server/entity/Entity.java|games.stendhal.server.entity.Entity}} |
||
| Line 17: | Line 19: | ||
* Implements: |
* Implements: |
||
** {{StendhalFile|master|src/games/stendhal/server/entity/Killer.java|games.stendhal.server.entity.Killer}} |
** {{StendhalFile|master|src/games/stendhal/server/entity/Killer.java|games.stendhal.server.entity.Killer}} |
||
This is the base entity class for all entities in Stendhal. |
|||
Public methods: |
Public methods: |
||
| Line 28: | Line 28: | ||
: Copy constructor. |
: Copy constructor. |
||
: '''''object:''''' Object to be copied. |
: '''''object:''''' Object to be copied. |
||
; ''<span style="color:green;">generateRPClass</span>()'' |
|||
: Initializes the RPClass for this entity (initialized from {{StendhalFile|master|src/games/stendhal/server/core/engine/RPClassGenerator.java|games.stendhal.server.core.engine.RPClassGenerator}}). |
|||
; ''<span style="color:green;">setDescription</span>(text)'' |
; ''<span style="color:green;">setDescription</span>(text)'' |
||
: Sets the description text for the entity. |
: Sets the description text for the entity. |
||
: '''''text:''''' String to be used for description. |
: '''''text:''''' String to be used for description. |
||
; ''<span style="color:green;">setEntityClass</span>(clazz)'' |
|||
: Sets the "class" attribute which is used to determine an image to be used as a representation of this entity. |
|||
: '''''clazz:''''' (<code>String</code>) Class name. |
|||
; ''<span style="color:green;">setEntitySubclass</span>(subclazz)'' |
|||
: Sets the "subclass" attribute which is used to determine an image to be used as a representation of this entity. |
|||
: '''''subclazz:''''' (<code>String</code>) Sub-class name. |
|||
; ''<span style="color:green;">setSize</span>(width, height)'' |
|||
: Sets the entity's size. |
|||
: '''''width:''''' (<code>int</code>) |
|||
: '''''height:''''' (<code>int</code>) |
|||
; ''<span style="color:green;">setPosition</span>(x, y)'' |
|||
: Sets the entity's horizontal & vertical position. |
|||
: '''''x:''''' (<code>int</code>) The horizontal position. |
|||
: '''''y:''''' (<code>int</code>) The vertical position. |
|||
; ''<span style="color:green;">setResistance</span>(resistance)'' |
|||
: Sets the resistance this has with other entities. |
|||
: '''''resistance:''''' (<code>int</code>) Amount of resistance to set (0-100). |
|||
; ''<span style="color:green;">setVisibility</span>(visibility)'' |
|||
: Sets the entity's visibility level. |
|||
: '''''visibility:''''' (<code>int</code>) <code>0</code> = completely transparent, <code>100</code> = completely opaque. |
|||
; ''<span style="color:green;">setMenu</span>(menu)'' |
|||
: Sets the context menu to use for the entity. |
|||
: '''''menu:''''' (<code>String</code>) The menu to display in the client in the format: |
|||
<blockquote> |
|||
<pre> |
|||
Display name 1|action1, |
|||
Display name 2|action2 |
|||
</pre> |
|||
</blockquote> |
|||
; ''<span style="color:green;">setCursor</span>(cursor)'' |
|||
: Sets the name of the mouse cursor that should be used for this entity. |
|||
: '''''cursor:''''' (<code>String</code>) |
|||
; ''<span style="color:green;">getTitle</span>()'' |
; ''<span style="color:green;">getTitle</span>()'' |
||
: Retrieves the entity's title/name |
: Retrieves the entity's nicely formatted title/name. |
||
: ''returns:'' (<code> |
: ''returns:'' (<code>String</code>) The entity's formatted name. |
||
; ''<span style="color:green;">getName</span>()'' |
|||
: Retrieves the name of this entity. |
|||
: ''returns:'' (<code>String</code>) The entity's name. |
|||
; ''<span style="color:green;">getDescription</span>()'' |
; ''<span style="color:green;">getDescription</span>()'' |
||
: Retrieves the entity's description text. |
: Retrieves the entity's description text. |
||
: ''returns:'' (<code>string</code>) The entity's description text. |
: ''returns:'' (<code>string</code>) The entity's description text. |
||
; ''<span style="color:green;">getDescriptionName</span>(definite)'' |
|||
: Retrieves the name or something that can be used to identify the entity to the player. |
|||
: '''''definite:''''' (<code>bool</code>) Determines article to be used as prefix. <code>true</code> for "the" & <code>false</code> for "a/an" in case the entity has no name. |
|||
: ''returns:'' (<code>String</code>) Entity name including article. |
|||
; ''<span style="color:green;">getHeight</span>()'' |
|||
: Retrieves the entity's height. |
|||
: ''returns:'' (<code>double</code>) |
|||
; ''<span style="color:green;">getWidth</span>()'' |
|||
: Retrieves the entity's width. |
|||
: ''returns:'' (<code>double</code>) |
|||
; ''<span style="color:green;">getZone</span>()'' |
; ''<span style="color:green;">getZone</span>()'' |
||
| Line 57: | Line 117: | ||
: '''''entity:''''' (optional) If set, returned value is combined resistance. |
: '''''entity:''''' (optional) If set, returned value is combined resistance. |
||
: ''returns:'' (<code>int</code>) Value between 0-100 (0 = no resistance, 100 = non-traversable). |
: ''returns:'' (<code>int</code>) Value between 0-100 (0 = no resistance, 100 = non-traversable). |
||
; ''<span style="color:green;">getAdjacentNodes</span>()'' |
|||
: 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:'' (<code>List<Node></code>) All nodes next to entity. |
|||
; ''<span style="color:green;">getArea</span>()'' |
|||
: Retrieves the area this entity currently occupies. |
|||
: ''returns:'' (<code>Rectangle2D</code>) |
|||
; ''<span style="color:green;">getArea</span>(ex, ey)'' |
|||
: |
|||
: '''''ex:''''' (<code>double</code>) |
|||
: '''''ey:''''' (<code>double</code>) |
|||
: ''returns:'' (<code>Rectangle2D</code>) |
|||
; ''<span style="color:green;">getOrigin</span>()'' |
|||
: Retrieves the initial position of the entity. |
|||
: ''returns:'' (<code>Point</code>) |
|||
; ''<span style="color:green;">getEntitySlot</span>(name)'' |
|||
: Retrieve's a slot identified by <code>name</code>. |
|||
: '''''name:''''' (<code>String</code>) Name of slot. |
|||
: ''returns:'' (<code>EntitySlot</code>) EntitySlot instance or <code>null</code> if the entity does not have such slot. |
|||
; ''<span style="color:green;">getCursor</span>()'' |
|||
: Retrieves the name of the mouse cursor that should be used for this entity. |
|||
: ''returns:'' (<code>String</code>) Cursor name or </code>null</code>. |
|||
; ''<span style="color:green;">stopped</span>()'' |
; ''<span style="color:green;">stopped</span>()'' |
||
| Line 70: | Line 158: | ||
: '''''entity:''''' The entity to check against. |
: '''''entity:''''' The entity to check against. |
||
: ''returns:'' (<code>bool</code>) <code>true</code> if combined resistance is above 95. |
: ''returns:'' (<code>bool</code>) <code>true</code> if combined resistance is above 95. |
||
; ''<span style="color:green;">isInSight</span>(other)'' |
|||
: Checks if another entity is close enough to be detected by this entity. |
|||
: '''''other:''''' (<code>Entity</code>) The entity to gauge distance to. |
|||
: ''returns:'' (<code>boolean</code>) <code>true</code> if near enough. |
|||
; ''<span style="color:green;">squaredDistance</span>(other)'' |
|||
: Retrieves the square distance between this entity & the given one. |
|||
: '''''other:''''' (<code>Entity</code>) The entity to which the distance should be calculated. |
|||
: ''returns:'' (<code>double</code>) Representation of the squared distance. |
|||
; ''<span style="color:green;">squaredDistance</span>(x, y)'' |
|||
: Retrieves the square distance between this entity & a given point. |
|||
: '''''x:''''' (<code>int</code>) The horizontal position to which distance should be calculated. |
|||
: '''''y:''''' (<code>int</code>) The vertical position to which distance should be calculated. |
|||
: ''returns:'' (<code>double</code>) Representation of the squared distance. |
|||
; ''<span style="color:green;">nextTo</span>(entity, step)'' |
|||
: Checks whether the given entity is next to this one. |
|||
: '''''entity:''''' (<code>Entity</code>) The entity to compare distance to. |
|||
: '''''step:''''' (<code>double</code>) (default: ''0.25'') Maximum distance at which is required to determine if next to. |
|||
: ''returns:'' (<code>bool</code>) <code>true</code> if '''''entity''''' is next to this one. |
|||
; ''<span style="color:green;">onAdded</span>(zone)'' |
|||
: Called when this entity is added to a zone. |
|||
: '''''zone:''''' (<code>StendhalRPZone</code>) The zone this was added to. |
|||
; ''<span style="color:green;">onRemoved</span>(zone)'' |
|||
: Called when this entity is being removed from a zone. |
|||
: '''''zone:''''' (<code>StendhalRPZone</code>) The zone this will be removed from. |
|||
; ''<span style="color:green;">notifyWorldAboutChanges</span>()'' |
|||
: Notifies the <code>StendhalRPWorld</code> that this entity's attributes have changed. |
|||
; ''<span style="color:green;">describe</span>()'' |
|||
: Describes then entity (commonly used for when a player "looks" at an entity). |
|||
: ''returns:'' (<code>string</code>) Description from the player's point-of-view. |
|||
; ''<span style="color:green;">slotIterator</span>(slotTypes)'' |
|||
: |
|||
: '''''slotTypes:''''' (<code>Slots</code>) Slot types to include in the iteration. |
|||
: ''returns:'' (<code>Iterator<RPSlot></code>) |
|||
; ''<span style="color:green;">slots</span>(slotTypes)'' |
|||
: |
|||
: '''''slotTypes:''''' (<code>Slots</code>) Slot types to include in the iteration. |
|||
: ''returns:'' (<code>Iterable<RPSlot></code>) |
|||
=== ActiveEntity === |
=== ActiveEntity === |
||
Revision as of 22:28, 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
GuidedEntity
- Class: games.stendhal.server.entity.GuidedEntity
- Inherits: ActiveEntity
RPEntity
- Class: games.stendhal.server.entity.RPEntity
- Inherits: GuidedEntity