Class Creature

All Implemented Interfaces:
Killer, Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
ArenaCreature, AttackableCreature, DeathMatchCreature, DomesticAnimal, ItemChangeGuardCreature, ItemGuardCreature, RaidCreature

public class Creature extends NPC
Server-side representation of a creature.

A creature is defined as an entity which can move with certain speed, has life points (HP) and can die.

Not all creatures have to be hostile, but at the moment the default behavior is to attack the player.

  • Field Details

    • dropsItems

      protected List<DropItem> dropsItems
      This list of item names this creature may drop Note; per default this list is shared with all creatures of that class.
    • dropItemInstances

      protected List<Item> dropItemInstances
      This list of item instances this creature may drop for use in quests. This is always creature specific.
    • noises

      protected LinkedHashMap<String,​LinkedList<String>> noises
      List of things this creature should say.
  • Constructor Details

    • Creature

      public Creature(RPObject object)
      creates a new Creature
      Parameters:
      object - serialized creature
    • Creature

      public Creature(Creature copy)
      creates a new Creature
      Parameters:
      copy - template to copy
    • Creature

      public Creature()
      creates a new creature without properties. These must be set in the deriving class
    • Creature

      public Creature(String clazz, String subclass, String name, int hp, int atk, int ratk, int def, int level, int xp, int width, int height, double baseSpeed, List<DropItem> dropItems, Map<String,​String> aiProfiles, LinkedHashMap<String,​LinkedList<String>> noises, int respawnTime, String description)
      Creates a new creature with the given properties.

      Creatures created with this function will share their dropItems with any other creature of that kind. If you want individual dropItems, use clearDropItemList first!

      Parameters:
      clazz - The creature's class, e.g. "golem".
      subclass - The creature's subclass, e.g. "wooden_golem".
      name - Typically the same as clazz, except for NPCs.
      hp - The creature's maximum health points.
      atk - The creature's attack strength.
      ratk - The creature's ranged attack strength.
      def - The creature's attack strength.
      level - The creature's level.
      xp - The creature's experience.
      width - The creature's width, in squares.
      height - The creature's height, in squares.
      baseSpeed - The normal speed at which the creature moves.
      dropItems - List of items that the creature drops on death.
      aiProfiles - Creature's behaviours.
      noises - . Sound effects used by the client when player is near creature.
      respawnTime - How often creature respawns, in turns.
      description - String description displayed when player examines creature.
  • Method Details

    • getNewInstance

      public Creature getNewInstance()
      creates a new instance, using this creature as template
      Returns:
      a new creature
    • setDeathSound

      public final void setDeathSound(String sound)
      Sets the sound played at creature's death
      Overrides:
      setDeathSound in class RPEntity
      Parameters:
      sound - Name of sound
    • setMovementSound

      public final void setMovementSound(String sound)
      Set looped sound to be played while creature is walking
      Parameters:
      sound - sound effect file name
    • setNoises

      public void setNoises(LinkedHashMap<String,​LinkedList<String>> creatureNoises)
      Override noises for changes.
      Parameters:
      creatureNoises - noises to be used instead of the defaults for the creature
    • registerObjectsForNotification

      public void registerObjectsForNotification(Observer observer)
      sets new observer
      Parameters:
      observer - - observer, which will get info about creature death.
    • registerObjectsForNotification

      public void registerObjectsForNotification(List<Observer> observers)
      sets new observer
      Parameters:
      observers - - observers, which will get info about creature death.
    • unregisterObjectsForNotification

      public void unregisterObjectsForNotification(Observer observer)
      unset observer
      Parameters:
      observer - - observer to remove.
    • unregisterObjectsForNotification

      public void unregisterObjectsForNotification(List<Observer> observers)
      unset observer
      Parameters:
      observers - - observers to remove.
    • notifyRegisteredObjects

      public void notifyRegisteredObjects()
      Will notify observers when event will occurred (death).
    • isSpawned

      public boolean isSpawned()
    • setRespawned

      public void setRespawned(boolean isRespawned)
    • getAttackTurn

      public int getAttackTurn()
    • isAttackTurn

      public boolean isAttackTurn(int turn)
    • generateRPClass

      public static void generateRPClass()
    • setAIProfiles

      public final void setAIProfiles(Map<String,​String> aiProfiles)
      sets the aiProfile of this creature
      Parameters:
      aiProfiles - aiProfile
    • getAIProfiles

      public Map<String,​String> getAIProfiles()
      gets the aiProfile of this creature
      Returns:
      aiProfile
    • setRespawnPoint

      public void setRespawnPoint(CreatureRespawnPoint point)
    • getRespawnPoint

      public CreatureRespawnPoint getRespawnPoint()
      gets the respan point of this create
      Returns:
      CreatureRespawnPoint
    • getRespawnTime

      public int getRespawnTime()
      Get the respawn time of the creature.
      Returns:
      respawn time in turns
    • setCorpse

      public final void setCorpse(String name, String harmless, int width, int height)
    • getCorpseName

      public String getCorpseName()
      Description copied from class: RPEntity
      Get the corpse image name to be used for the entity. Defaults to a player corpse.
      Overrides:
      getCorpseName in class RPEntity
      Returns:
      Identification string for corpse. This is the corpse image shown by the client without the path or file extension.
    • getHarmlessCorpseName

      public String getHarmlessCorpseName()
      Overrides:
      getHarmlessCorpseName in class RPEntity
    • getCorpseWidth

      public int getCorpseWidth()
      Overrides:
      getCorpseWidth in class RPEntity
    • getCorpseHeight

      public int getCorpseHeight()
      Overrides:
      getCorpseHeight in class RPEntity
    • clearDropItemList

      public void clearDropItemList()
      clears the list of predefined dropItems and creates an empty list specific to this creature.
    • addDropItem

      public void addDropItem(String name, double probability, int min, int max)
      adds a named item to the List of Items that will be dropped on dead if clearDropItemList hasn't been called first, this will change all creatures of this kind.
      Parameters:
      name -
      probability -
      min -
      max -
    • addDropItem

      public void addDropItem(String name, double probability, int amount)
      adds a named item to the List of Items that will be dropped on dead if clearDropItemList hasn't been called first, this will change all creatures of this kind.
      Parameters:
      name -
      probability -
      amount -
    • addDropItem

      public void addDropItem(Item item)
      adds a specific item to the List of Items that will be dropped on dead with 100 % probability. this is always for that specific creature only.
      Parameters:
      item -
    • isAttackable

      public boolean isAttackable()
      Returns true if this RPEntity is attackable.
      Overrides:
      isAttackable in class NPC
      Returns:
      true if this RPEntity is attackable.
    • onDead

      public void onDead(Killer killer, boolean remove)
      Description copied from class: RPEntity
      This method is called when this entity has been killed (hp == 0).
      Overrides:
      onDead in class RPEntity
      Parameters:
      killer - The entity who caused the death, i.e. who did the last hit.
      remove - true iff this entity should be removed from the world. For almost everything remove is true, but not for the players, who are instead moved to afterlife ("reborn").
    • dropItemsOn

      protected void dropItemsOn(Corpse corpse)
      Overrides:
      dropItemsOn in class NPC
    • getEnemyList

      public List<RPEntity> getEnemyList()
      Returns a list of enemies. One of it will be attacked.
      Returns:
      list of enemies
    • getNearestEnemy

      public RPEntity getNearestEnemy(double range)
      Returns the nearest enemy, which is reachable or otherwise attackable.
      Parameters:
      range - attack radius
      Returns:
      chosen enemy or null if no enemy was found.
    • isEnemyNear

      public boolean isEnemyNear(double range)
    • isBoss

      public boolean isBoss()
      Check if the entity is a "boss". Bosses have higher capacity corpses.
    • isRare

      public boolean isRare()
      Check if the creature has a rare profile, and thus should not appear in DeathMatch, or the daily quest.
      Returns:
      true if the creature is rare, false otherwise
    • isAbnormal

      public boolean isAbnormal()
      Checks if the creature has "abnormal" or "rare" profile.
      Returns:
      true if creature is abnormal or rare.
    • equip

      public void equip(List<EquipItem> items)
    • getMaxRangeForArcher

      public int getMaxRangeForArcher()
      Description copied from class: RPEntity
      Get the maximum distance attack range.
      Overrides:
      getMaxRangeForArcher in class RPEntity
      Returns:
      maximum range, or 0 if the entity can't attack from distance
    • getAIProfile

      public String getAIProfile(String key)
      returns the value of an ai profile.
      Parameters:
      key - as defined in creatures.xml
      Returns:
      value or null if undefined
    • init

      public void init()
      is called after the Creature is added to the zone.
    • logic

      public void logic()
      Description copied from class: RPEntity
      Perform cycle logic.
      Overrides:
      logic in class NPC
    • makeNoise

      public void makeNoise(String state)
      Random sound noises.
      Parameters:
      state - - state for noises
    • makeNoiseChance

      public void makeNoiseChance(int prob, String state)
      wrapper around makeNoise to simplify a code
      Parameters:
      prob - - 1/chance of make noise
      state - - state for noises
    • stopMovementSound

      public void stopMovementSound()
      Stops the looped sound
    • isPlayingMovementSound

      public boolean isPlayingMovementSound()
      Returns:
      true if looped sound is currently playing
    • hasTargetMoved

      public boolean hasTargetMoved()
    • setIdle

      public void setIdle()
    • setBusy

      public void setBusy()
    • setAttackStrategy

      public void setAttackStrategy(Map<String,​String> aiProfiles)
      Set the fighting strategy used by the creature.
      Parameters:
      aiProfiles - AI profiles to be used when deciding the strategy
    • getAttackStrategy

      public AttackStrategy getAttackStrategy()
      Get the fighting strategy used by the creature.
      Returns:
      strategy
    • setHealer

      public void setHealer(String aiprofile)
    • getItemAtk

      public float getItemAtk()
      Description copied from class: RPEntity
      Retrieves total ATK value of held weapons.
      Overrides:
      getItemAtk in class RPEntity
    • getItemRatk

      public float getItemRatk()
      Description copied from class: RPEntity
      Retrieves total range attack value of held weapon & ammunition.
      Overrides:
      getItemRatk in class RPEntity
    • setSusceptibilities

      public void setSusceptibilities(Map<Nature,​Double> susceptibilities)
      Set the susceptibility mapping of a creature. The mapping is not copied.
      Parameters:
      susceptibilities - The susceptibilities of the creature
    • getSusceptibility

      protected double getSusceptibility(Nature type)
      Description copied from class: RPEntity
      Get a multiplier for a given damage type when this entity is damaged.
      Overrides:
      getSusceptibility in class RPEntity
      Parameters:
      type - Type of the damage
      Returns:
      damage multiplier
    • getDamageType

      protected Nature getDamageType()
      Description copied from class: RPEntity
      Get the type of the damage this entity inflicts
      Overrides:
      getDamageType in class RPEntity
      Returns:
      type of damage
    • getRangedDamageType

      protected Nature getRangedDamageType()
      Description copied from class: RPEntity
      Get the nature of the damage the entity inflicts in ranged attacks.
      Overrides:
      getRangedDamageType in class RPEntity
      Returns:
      type of damage
    • setDamageTypes

      public final void setDamageTypes(Nature type, Nature rangedType)
      Set the damage natures the creature inflicts.
      Parameters:
      type - Damage nature.
      rangedType - Damage nature for ranged attacks, or null if the creature uses the same type as for the melee.
    • attack

      public boolean attack()
      Description copied from class: RPEntity
      Lets the attacker attack its target.
      Overrides:
      attack in class RPEntity
      Returns:
      true iff the attacker has done damage to the defender.
    • getCorpseDeserver

      public String getCorpseDeserver()
      gets the name of the player who deserves the corpse
      Overrides:
      getCorpseDeserver in class RPEntity
      Returns:
      name of player who deserves the corpse or null.