Class CreatureRespawnPoint

java.lang.Object
games.stendhal.server.entity.mapstuff.spawner.CreatureRespawnPoint
All Implemented Interfaces:
TurnListener

public class CreatureRespawnPoint extends Object implements 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 Details

    • zone

      protected final StendhalRPZone zone
    • x

      protected final int x
    • y

      protected final int y
    • prototypeCreature

      protected Creature prototypeCreature
      This is the prototype; it will be copied to create new creatures that will be spawned here.
    • creatures

      protected final List<Creature> creatures
      All creatures that were spawned here and that are still alive.
    • respawning

      protected boolean respawning
      Stores if this respawn point is currently waiting for a creature to respawn.
  • Constructor Details

    • CreatureRespawnPoint

      public CreatureRespawnPoint(StendhalRPZone zone, int x, int y, Creature creature, int maximum)
      Creates a new RespawnPoint.
      Parameters:
      zone -
      x -
      y -
      creature - The prototype creature
      maximum - 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 creature
      maximum - The number of creatures spawned here that can exist at the same time
      observer -
  • Method Details

    • getPrototypeCreature

      public Creature 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

      public void notifyDead(Creature dead)
      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 interface TurnListener
      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

      public void setPrototypeCreature(Creature creature)
      Set the prototype creature for the spawner.
      Parameters:
      creature - prototype creature
    • addObserver

      public void addObserver(Observer observer)
      add observer to observers list
      Parameters:
      observer - - observer to add
    • removeObserver

      public void removeObserver(Observer observer)
      remove observer from list
      Parameters:
      observer - - observer to remove
    • getZone

      public StendhalRPZone 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.