Class Item

Object
Item
All Implemented Interfaces:
Serializable, AttributeWrangler, DisplayInterface, ItemWrangler, Ownage
Direct Known Subclasses:
NormalItem, ShopkeeperList

@Entity public abstract class Item extends Object implements Serializable, DisplayInterface, AttributeWrangler, ItemWrangler, Ownage
An item. To be more precise an instance of an item definition. An item can either reside in a room, on a person or in another item.
Author:
maartenl
See Also:
  • Constructor Details

    • Item

      public Item()
      Constructor. Creates a completely empty item. Usually required by ORM.
    • Item

      public Item(ItemDefinition id)
      Constructor.
      Parameters:
      id - the item definition used as a template of this (new) item.
  • Method Details

    • getDiscriminator

      public Integer getDiscriminator()
    • getId

      public Integer getId()
    • setId

      public void setId(Integer id)
    • getCreation

      public LocalDateTime getCreation()
    • setCreation

      public void setCreation(LocalDateTime creation)
    • getItems

      public Set<Item> getItems()
      Indicates the items that are contained (if possible) inside this item. Will in most cases return an empty list.
      Specified by:
      getItems in interface ItemWrangler
      Returns:
      set of items.
    • setItems

      public void setItems(Set<Item> items)
    • getContainer

      public Item getContainer()
      Retrieves the item that contains this item (if possible). Might be null.
      Returns:
      the container
      See Also:
    • isContainer

      public boolean isContainer()
    • setContainer

      public void setContainer(@Nonnull Item container)
    • getItemDefinition

      public ItemDefinition getItemDefinition()
    • setItemDefinition

      public void setItemDefinition(ItemDefinition itemDefinition)
    • getOwner

      public Admin getOwner()
      Description copied from interface: Ownage
      Retrieves the owner, the administrator, of this object. In case this is null, anyone can edit the object.
      Specified by:
      getOwner in interface Ownage
      Returns:
    • setOwner

      public void setOwner(Admin owner)
      Description copied from interface: Ownage
      Sets the owner, the administrator, of this object.
      Specified by:
      setOwner in interface Ownage
      Parameters:
      owner - the owner/administrator of the object. In case this is null, which is allowed, any administrator can edit this object. This is what happens when an object is "disowned".
    • getRoom

      public Room getRoom()
      Will return the room in which this item can be found. Might be null.
      Returns:
      the room which contains this item.
      See Also:
    • getBelongsTo

      public Person getBelongsTo()
      Will return the person that owns this item. Might be null.
      Returns:
      the person who owns this item.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDescription

      public String getDescription()
      Description of the item, for example "a white, cloth pants".
      Returns:
      a description of the item.
    • isDescribedBy

      public boolean isDescribedBy(List<String> parsed)
      Parameters:
      parsed -
      Returns:
      true if the item is properly described.
      See Also:
      • ItemDefinition.isDescribedBy(java.util.List)
    • getTitle

      public String getTitle() throws MudException
      Throws:
      MudException
    • getMainTitle

      public String getMainTitle() throws MudException
      Description copied from interface: DisplayInterface
      The title as visible on the screen.
      Specified by:
      getMainTitle in interface DisplayInterface
      Returns:
      Throws:
      MudException
    • getImage

      public String getImage() throws MudException
      Description copied from interface: DisplayInterface
      Returns an url pointing to an image.
      Specified by:
      getImage in interface DisplayInterface
      Returns:
      Throws:
      MudException
    • getLongDescription

      public String getLongDescription()
    • getBody

      public String getBody() throws MudException
      Description copied from interface: DisplayInterface
      The body to be displayed on the screen. In general the first letter of the body is converted to an image on the client side.
      Specified by:
      getBody in interface DisplayInterface
      Returns:
      Throws:
      MudException
    • getCopper

      public Integer getCopper()
    • removeAttribute

      public boolean removeAttribute(String name)
      Description copied from interface: AttributeWrangler
      Removes an attribute by name.
      Specified by:
      removeAttribute in interface AttributeWrangler
      Parameters:
      name - the name of the attribute, for example "guildwish".
      Returns:
      false if not found, true if removed.
    • getAttribute

      public Attribute getAttribute(String name)
      Description copied from interface: AttributeWrangler
      Retrieves an attribute, returns null if not found.
      Specified by:
      getAttribute in interface AttributeWrangler
      Parameters:
      name - the name of the attribute
      Returns:
      an attribute
    • setAttribute

      public void setAttribute(String name, String value)
      Description copied from interface: AttributeWrangler
      Set the value of the attribute, creates the attribute if the attribute does not exist.
      Specified by:
      setAttribute in interface AttributeWrangler
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
    • verifyAttribute

      public boolean verifyAttribute(String name, String value)
      Description copied from interface: AttributeWrangler
      Verify if the attribute exists, and has the proper value.
      Specified by:
      verifyAttribute in interface AttributeWrangler
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      true if it exists, false otherwise.
    • isOpen

      public boolean isOpen()
      Indicates if the container is open or closed. Only makes sense if this item is in fact a container.
      Returns:
      true if there is an attribute named "isopen".
    • hasLid

      public boolean hasLid()
      Returns true if the container has a lid, if the container can be opened.
      Returns:
      boolean true if the container has a lid.
    • isOpenable

      public boolean isOpenable()
      Returns true if the container has a lid, if the container can be opened.
      Returns:
      boolean true if the container has a lid.
    • isLocked

      public boolean isLocked()
      Returns whether or not the container is locked. If it can be locked, it needs a key.
      Returns:
      boolean true if the container is locked.
      See Also:
    • open

      public void open()
    • close

      public void close()
    • isEatable

      public boolean isEatable()
      Returns true if the item can be eaten. This is better than just using a compare on the getEatable.
      Returns:
      true if eatable, false otherwise
      See Also:
    • getEatable

      public String getEatable()
      Provides the description of what happens when you try to eat it. Can be null or empty, for example if the item cannot be eaten. Eating an item will always destroy that item.
      Returns:
    • findItems

      public List<Item> findItems(List<String> parsed)
      Description copied from interface: ItemWrangler
      Returns items this entity has, based on description provided.
      Specified by:
      findItems in interface ItemWrangler
      Parameters:
      parsed - the parsed description of the item, for example {"light-green", "leather", "pants"}.
      Returns:
      list of found items, empty if not found.
    • destroyItem

      public boolean destroyItem(Item item)
      Description copied from interface: ItemWrangler
      Physically destroys an item instance.
      Specified by:
      destroyItem in interface ItemWrangler
      Parameters:
      item - the item to be destroyed
      Returns:
      returns true, if the item was found and destroyed. False if the item was not found.
    • isDrinkable

      public boolean isDrinkable()
      Returns true if the item can be drunk. This is better than just using a compare on the getDrinkable.
      Returns:
      true if drinkable, false otherwise
      See Also:
    • getDrinkable

      public String getDrinkable()
      Provides the description of what happens when you try to drink it. Can be null or empty, for example if the item cannot be drunk. Drinking an item will always destroy that item.
      Returns:
    • isWearable

      public boolean isWearable(Wearing position)
    • isWieldable

      public boolean isWieldable(Wielding position)
    • isDroppable

      public boolean isDroppable()
      Whether or not you are able to drop this item.
      Returns:
      true, in case you can, false otherwise.
    • isBound

      public boolean isBound()
      Whether or not you are able to drop this item or give this item, or in some other way dispose of this item, besides selling it to a vendor or just destroying it.
      Returns:
      true, in case you cannot, false otherwise.
    • isGetable

      public boolean isGetable()
      Whether or not you are able to retrieve this item from the floor of the room.
      Returns:
      true, in case you can, false otherwise.
    • drop

      public void drop(Person person, Room room)
    • drop

      public void drop(Room room)
      Specialty method for the creation of new items in a room. Only used by
      invalid reference
      Room#createItem(mmud.database.entities.items.ItemDefinition)
      Parameters:
      room - the room to drop the new item into.
    • get

      public void get(Person person, Room room)
    • give

      public void give(Person toperson)
    • isReadable

      public boolean isReadable()
    • getRead

      public DisplayInterface getRead()
    • hasLock

      public boolean hasLock()
      Returns whether or not the container has a lock. Meaning whether or not the container can be unlocked/locked.
      Returns:
      boolean true if the container can be locked/unlocked.
    • isKey

      public boolean isKey(Item key)
      Verifies that the key provided can open this container.
      Parameters:
      key - the key to hopefully open this container.
      Returns:
      true, if it is possible to open this container with the key provided.
    • lock

      public void lock()
    • unlock

      public void unlock()
    • isVisible

      public boolean isVisible()
    • getCategory

      public abstract ItemCategory getCategory()
      Returns the category of the item.
      Returns:
      the category of the item.
    • isSellable

      public boolean isSellable()
      Items are sellable by default, unless attribute "notsellable" is set.
      Returns:
      can the item be sold.
      See Also:
    • isBuyable

      public boolean isBuyable()
      Items are buyable by default, unless attribute "notbuyable" is set.
      Returns:
      See Also:
    • containsItems

      public boolean containsItems()
      Tells you if this item contains other items, for example if it is a bag.
      Returns:
    • addItem

      public Item addItem(Item item)
      Adds an Item to the bag (container).
      Specified by:
      addItem in interface ItemWrangler
      Parameters:
      item - the new item. May not be null.
      Returns:
      the new item, null if unable to add.
    • assignTo

      public void assignTo(Room room)
    • assignTo

      public void assignTo(Room room, Person belongsto, Item container)