Class Item

All Implemented Interfaces:
EquipListener, TurnListener, UseListener, Killer, Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
AreaUseItem, Box, BreakableItem, CaptureTheFlagFlag, Container, Dice, DummyWeapon, FoodMill, GateKey, HouseKey, ItemInformation, LifeSupportGear, NecroStaff, OwnedItem, RingOfLife, SlotActivatedItem, StackableItem, Token, WeddingRing

public class Item extends PassiveEntity implements TurnListener, EquipListener, UseListener
This is an item.
  • Field Details

  • Constructor Details

    • Item

      public Item(String name, String clazz, String subclass, Map<String,​String> attributes)
      Creates a new Item.
      Parameters:
      name - name of item
      clazz - class (or type) of item
      subclass - subclass of this item
      attributes - attributes (like attack). may be empty or null
    • Item

      public Item(Item item)
      copy constructor.
      Parameters:
      item - item to copy
  • Method Details

    • generateRPClass

      public static void generateRPClass()
    • setEquipableSlots

      public void setEquipableSlots(List<String> slots)
      on which slots may this item be equipped.
      Parameters:
      slots - list of allowed slots
    • setPlantGrower

      public void setPlantGrower(PassiveEntityRespawnPoint plantGrower)
      If this item is created by a PlantGrower, the item will notify it when picked from the ground.
      Parameters:
      plantGrower - a plant grower
    • getPlantGrower

      public PassiveEntityRespawnPoint getPlantGrower()
      returns the PlantGrower which created this item or null if no plantgrower was involved.
      Returns:
      PlantGrower or null
    • getAttack

      public int getAttack()
      Returns the attack points of this item. Positive and negative values are allowed. If this item doesn't modify the attack it should return '0'.
      Returns:
      attack points
    • getDefense

      public int getDefense()
      Returns the defense points of this item. Positive and negative values are allowed. If this item doesn't modify the defense it should return '0'.
      Returns:
      defense points
    • getRangedAttack

      public int getRangedAttack()
      Returns the ranged attack points of this item. Positive and negative values are allowed. If this item doesn't modify the ranged attack it should return '0'.
      Returns:
      ranged attack points
    • getAttackRate

      public int getAttackRate()
      Returns each how many turns this item can attack.
      Returns:
      each how many turns this item can attack.
    • getAttackRate

      public int getAttackRate(boolean meleeDistance)
      Returns turn delay for this item's attack.
      Parameters:
      meleeDistance - true if the entity is standing next to its attack target.
      Returns:
      Turn delay for this items attack.
    • getDefaultAttackRate

      public static int getDefaultAttackRate()
      Retrieves default attack rate for items.
    • getDeterioration

      public int getDeterioration()
      Each Item is subject to deterioration that weakens the item
      Returns:
      the current degree of deterioration
    • deteriorate

      public void deteriorate()
      Propose increase the degree of deterioration. If degree increases is decided by random
    • deteriorate

      public void deteriorate(RPEntity user)
      Can be overridden to handle actions on user entity.
      Parameters:
      user - Entity using the item.
    • repair

      public void repair()
      repair this item
    • isPersistent

      public boolean isPersistent()
      Returns if the item is persistent. Persistent items do not update their stats from the item database and thus can have individual stats
      Returns:
      true if item is persistent
    • setPersistent

      public void setPersistent(boolean persistent)
      Set the item's persistence.
      Parameters:
      persistent - If the item's stats are persistent.
    • isOfClass

      public boolean isOfClass(String clazz)
      Checks if the item is of type type .
      Parameters:
      clazz - the class to check
      Returns:
      true if the type matches, else false
    • getItemClass

      public String getItemClass()
      Returns:
      the type of the item
    • getItemSubclass

      public String getItemSubclass()
      Returns:
      the subclass of the item
    • getName

      public String getName()
      Gets the name of the item.
      Specified by:
      getName in interface Killer
      Overrides:
      getName in class Entity
      Returns:
      The programmatic item name.
    • getQuantity

      public int getQuantity()
      Get item count.
      Returns:
      1.
    • getPossibleSlots

      public List<String> getPossibleSlots()
      Returns:
      the list of possible slots for this item
    • getBoundTo

      public String getBoundTo()
      Get the player this is bound to. A bound item can only be used by that player.
      Returns:
      The player name, or null.
    • isBound

      public boolean isBound()
      Check if the item is bound to a player
      Returns:
      true if the item is bound, otherwise false
    • autobind

      public void autobind(String player)
      Bind the item to a player, if the item is one that should be automatically bound, and the item is not already bound.
      Parameters:
      player - player name
    • getInfoString

      public String getInfoString()
      Get the item's infoString. The infoString contains context specific information that is used by the implementation.
      Returns:
      The infoString.
    • setBoundTo

      public void setBoundTo(String name)
      Bind this item to a player. A bound item can only be used by that player.
      Parameters:
      name - The player name, or null.
    • isUndroppableOnDeath

      public boolean isUndroppableOnDeath()
      Is the item undroppable. On player death items carried may be dropped into the players corpse. unless this method returns true.
      Returns:
      true if item may not be dropped on death of players.
    • setUndroppableOnDeath

      public void setUndroppableOnDeath(boolean unDroppableOnDeath)
      Set is the item undroppable when player dies.
      Parameters:
      unDroppableOnDeath - If true, the item won't be dropped if the player dies.
    • setUseBehavior

      public void setUseBehavior(UseBehavior behavior)
      Set behavior to follow when the item is used.
      Parameters:
      behavior - new behavior
    • setInfoString

      public void setInfoString(String infostring)
      Set the item's infostring. The infostring contains context specific information that is used by the implementation.
      Parameters:
      infostring - The item's infostring.
    • getDamageType

      public Nature getDamageType()
      Get the type of damage inflicted by this item.
      Returns:
      type of damage
    • setDamageType

      public void setDamageType(Nature type)
      Set the type of damage inflicted by this item
      Parameters:
      type - type of damage
    • getSusceptibility

      public double getSusceptibility(Nature type)
      Get this item's contribution to susceptibility to a type of damage.
      Parameters:
      type - type of damage to be checked
      Returns:
      susceptibility to damage of type type
    • setSusceptibilities

      public void setSusceptibilities(Map<Nature,​Double> susceptibilities)
      Set the susceptibility data of this item.
      Parameters:
      susceptibilities - susceptibilities to be used
    • initializeActiveSlotsList

      public void initializeActiveSlotsList(List<String> slotList)
      Override in SlotActivatedItem sub-class.
    • initializeStatusResistancesList

      public void initializeStatusResistancesList(Map<StatusType,​Double> resistanceList)
      Override in StatusResistantItem sub-class.
    • getWeaponType

      public String getWeaponType()
      Get a weapon type identifier that can be used in attack events, so that the client can draw an appropriate item image for the attack.
      Returns:
      weapon identifier
    • toString

      public String toString()
      Description copied from class: RPObject
      This method returns a String that represent the object
      Overrides:
      toString in class RPObject
      Returns:
      a string representing the object.
    • onPutOnGround

      public void onPutOnGround(Player player)
      Is called when the item is moved to the ground.
      Parameters:
      player - the player who drops the Item.
    • onPutOnGround

      public void onPutOnGround(boolean expire)
      Is called when the item is created.
      Parameters:
      expire - Set true if the item should expire normally, false otherwise.
    • onRemoveFromGround

      public void onRemoveFromGround()
    • onPickedUp

      public void onPickedUp(Player player)
    • onTurnReached

      public void onTurnReached(int currentTurn)
      Description copied from interface: TurnListener
      This method is called when the turn number is reached.
      Specified by:
      onTurnReached in interface TurnListener
      Parameters:
      currentTurn - current turn number
    • describe

      public String describe()
      Description copied from class: Entity
      Describes the entity (if a players looks at it).
      Overrides:
      describe in class Entity
      Returns:
      description from the players point of view
    • removeOne

      public void removeOne()
      Removes the item. In case of StackableItems only one is removed.
    • canBeEquippedIn

      public boolean canBeEquippedIn(String slot)
      Description copied from interface: EquipListener
      Checks whether this object can be equipped in the given slot.
      Specified by:
      canBeEquippedIn in interface EquipListener
      Parameters:
      slot - name of slot
      Returns:
      true, if it can be equipped; false otherwise
    • removeFromWorld

      public void removeFromWorld()
    • getDescriptionName

      public String getDescriptionName(boolean definite)
      Returns the name or something that can be used to identify the entity for the player.
      Overrides:
      getDescriptionName in class Entity
      Parameters:
      definite - true for "the", and false for "a/an" in case the entity has no name.
      Returns:
      The description name.
    • getTitle

      public String getTitle()
      Get the nicely formatted entity title/name.
      Overrides:
      getTitle in class Entity
      Returns:
      The title, or null if unknown.
    • setFromCorpse

      public void setFromCorpse(boolean fromCorpse)
    • isFromCorpse

      public boolean isFromCorpse()
    • getMinLevel

      public int getMinLevel()
      gets the min level
      Returns:
      minLevel
    • onEquipped

      public boolean onEquipped(RPEntity equipper, String slot)
      opportunity to affect the player when equipped currently returns boolean, to indicate whether it made any change TODO: should this return some sort of undoable thing (if it can be undone?)
      Parameters:
      equipper - entity equipping the item
      slot - slot where the item is equipped
      Returns:
      unknown, see the note above
    • onUnequipped

      public boolean onUnequipped()
      item is about to be removed from owner. at this time, we are still owned by the original owner. opportunity to affect the player when equipped note: use this.getContainerOwner(), rather than the equipper param TODO: i don't think the parameters are necessary. can get owner and slot from Item api
      Returns:
      needs documenting
    • onUsed

      public boolean onUsed(RPEntity user)
      Description copied from interface: UseListener
      Invoked when the object is used.
      Specified by:
      onUsed in interface UseListener
      Parameters:
      user - the RPEntity who uses the object
      Returns:
      true if successful