Class CreatureRespawnPoint
java.lang.Object
games.stendhal.server.entity.mapstuff.spawner.CreatureRespawnPoint
- All Implemented Interfaces:
TurnListener
RespawnPoints are points at which creatures can appear. Several creatures can
be spawned, until a maximum has been reached (note that this maximum is
usually 1); then the RespawnPoint will stop spawning creatures until at least
one of the creatures has died. It will then continue to spawn creatures. A
certain time must pass between respawning creatures; this respawn time is
usually dependent of the type of the creatures that are spawned.
Each respawn point can only spawn one type of creature. The Prototype design
pattern is used; the prototypeCreature will be copied to create new
creatures.
-
Field Summary
Modifier and TypeFieldDescriptionAll creatures that were spawned here and that are still alive.protected Creature
This is the prototype; it will be copied to create new creatures that will be spawned here.protected boolean
Stores if this respawn point is currently waiting for a creature to respawn.protected int
protected int
protected StendhalRPZone
-
Constructor Summary
ConstructorDescriptionCreatureRespawnPoint(StendhalRPZone zone, int x, int y, Creature creature, int maximum)
Creates a new RespawnPoint.CreatureRespawnPoint(StendhalRPZone zone, int x, int y, Creature creature, int maximum, Observer observer)
Creates a new RespawnPoint. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver(Observer observer)
add observer to observers listprotected int
Calculates a randomized respawn time.int
getX()
function returns X coord of this respawn pointint
getY()
function returns Y coord of this respawn pointgetZone()
return zone where respawn point placedvoid
notifyDead(Creature dead)
Notifies this respawn point about the death of a creature that was spawned here.void
onTurnReached(int currentTurn)
Is called when a new creature is ready to pop up.void
removeObserver(Observer observer)
remove observer from listprotected void
respawn()
Pops up a new creature.void
setPrototypeCreature(Creature creature)
Set the prototype creature for the spawner.void
setRespawnTime(int respawnTime)
Sets the time it takes to respawn a creature.int
size()
Checks how many creatures which were spawned here are currently alive.void
spawnNow()
Pops up a new creature.
-
Field Details
-
zone
-
x
protected final int x -
y
protected final int y -
prototypeCreature
This is the prototype; it will be copied to create new creatures that will be spawned here. -
creatures
All creatures that were spawned here and that are still alive. -
respawning
protected boolean respawningStores if this respawn point is currently waiting for a creature to respawn.
-
-
Constructor Details
-
CreatureRespawnPoint
Creates a new RespawnPoint.- Parameters:
zone
-x
-y
-creature
- The prototype creaturemaximum
- The number of creatures spawned here that can exist at the same time
-
CreatureRespawnPoint
public CreatureRespawnPoint(StendhalRPZone zone, int x, int y, Creature creature, int maximum, Observer observer)Creates a new RespawnPoint.- Parameters:
zone
-x
-y
-creature
- The prototype creaturemaximum
- The number of creatures spawned here that can exist at the same timeobserver
-
-
-
Method Details
-
getPrototypeCreature
-
setRespawnTime
public void setRespawnTime(int respawnTime)Sets the time it takes to respawn a creature. Note that this value defaults to the creature's default respawn time.- Parameters:
respawnTime
- the middled delay between spawns in turns
-
notifyDead
Notifies this respawn point about the death of a creature that was spawned here.- Parameters:
dead
- The creature that has died
-
onTurnReached
public void onTurnReached(int currentTurn)Is called when a new creature is ready to pop up.- Specified by:
onTurnReached
in interfaceTurnListener
- Parameters:
currentTurn
- current turn number- See Also:
TurnListener.onTurnReached(int)
-
calculateNextRespawnTurn
protected int calculateNextRespawnTurn()Calculates a randomized respawn time.- Returns:
- the amount of turns calculated
-
size
public int size()Checks how many creatures which were spawned here are currently alive.- Returns:
- amount of living creatures
-
getX
public int getX()function returns X coord of this respawn point- Returns:
- - x coord
-
getY
public int getY()function returns Y coord of this respawn point- Returns:
- - y coord
-
setPrototypeCreature
Set the prototype creature for the spawner.- Parameters:
creature
- prototype creature
-
addObserver
add observer to observers list- Parameters:
observer
- - observer to add
-
removeObserver
remove observer from list- Parameters:
observer
- - observer to remove
-
getZone
return zone where respawn point placed- Returns:
- - zone where respawn point placed
-
respawn
protected void respawn()Pops up a new creature. -
spawnNow
public void spawnNow()Pops up a new creature.
-