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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds anItem
to the bag (container).void
void
void
close()
boolean
Tells you if this item contains other items, for example if it is a bag.boolean
destroyItem
(Item item) Physically destroys an item instance.void
void
Specialty method for the creation of new items in a room.Returns items this entity has, based on description provided.void
getAttribute
(String name) Retrieves an attribute, returns null if not found.Will return the person that owns this item.getBody()
The body to be displayed on the screen.abstract ItemCategory
Returns the category of the item.Retrieves the item that contains this item (if possible).Description of the item, for example "a white, cloth pants".Provides the description of what happens when you try to drink it.Provides the description of what happens when you try to eat it.getId()
getImage()
Returns an url pointing to an image.getItems()
Indicates the items that are contained (if possible) inside this item.The title as visible on the screen.getOwner()
Retrieves the owner, the administrator, of this object.getRead()
getRoom()
Will return the room in which this item can be found.getTitle()
void
boolean
hasLid()
Returns true if the container has a lid, if the container can be opened.boolean
hasLock()
Returns whether or not the container has a lock.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.boolean
Items are buyable by default, unless attribute "notbuyable" is set.boolean
boolean
isDescribedBy
(List<String> parsed) boolean
Returns true if the item can be drunk.boolean
Whether or not you are able to drop this item.boolean
Returns true if the item can be eaten.boolean
Whether or not you are able to retrieve this item from the floor of the room.boolean
Verifies that the key provided can open this container.boolean
isLocked()
Returns whether or not the container is locked.boolean
isOpen()
Indicates if the container is open or closed.boolean
Returns true if the container has a lid, if the container can be opened.boolean
boolean
Items are sellable by default, unless attribute "notsellable" is set.boolean
boolean
isWearable
(Wearing position) boolean
isWieldable
(Wielding position) void
lock()
void
open()
boolean
removeAttribute
(String name) Removes an attribute by name.void
setAttribute
(String name, String value) Set the value of the attribute, creates the attribute if the attribute does not exist.void
setContainer
(Item container) void
setCreation
(LocalDateTime creation) void
void
setItemDefinition
(ItemDefinition itemDefinition) void
void
Sets the owner, the administrator, of this object.toString()
void
unlock()
boolean
verifyAttribute
(String name, String value) Verify if the attribute exists, and has the proper value.
-
Constructor Details
-
Item
public Item()Constructor. Creates a completely empty item. Usually required by ORM. -
Item
Constructor.- Parameters:
id
- the item definition used as a template of this (new) item.
-
-
Method Details
-
getDiscriminator
-
getId
-
setId
-
getCreation
-
setCreation
-
getItems
Indicates the items that are contained (if possible) inside this item. Will in most cases return an empty list.- Specified by:
getItems
in interfaceItemWrangler
- Returns:
- set of items.
-
setItems
-
getContainer
Retrieves the item that contains this item (if possible). Might be null.- Returns:
- the container
- See Also:
-
isContainer
public boolean isContainer() -
setContainer
-
getItemDefinition
-
setItemDefinition
-
getOwner
-
setOwner
Description copied from interface:Ownage
Sets the owner, the administrator, of this object. -
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
Will return the person that owns this item. Might be null.- Returns:
- the person who owns this item.
- See Also:
-
toString
-
getDescription
Description of the item, for example "a white, cloth pants".- Returns:
- a description of the item.
-
isDescribedBy
-
getTitle
- Throws:
MudException
-
getMainTitle
Description copied from interface:DisplayInterface
The title as visible on the screen.- Specified by:
getMainTitle
in interfaceDisplayInterface
- Returns:
- Throws:
MudException
-
getImage
Description copied from interface:DisplayInterface
Returns an url pointing to an image.- Specified by:
getImage
in interfaceDisplayInterface
- Returns:
- Throws:
MudException
-
getLongDescription
-
getBody
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 interfaceDisplayInterface
- Returns:
- Throws:
MudException
-
getCopper
-
removeAttribute
Description copied from interface:AttributeWrangler
Removes an attribute by name.- Specified by:
removeAttribute
in interfaceAttributeWrangler
- Parameters:
name
- the name of the attribute, for example "guildwish".- Returns:
- false if not found, true if removed.
-
getAttribute
Description copied from interface:AttributeWrangler
Retrieves an attribute, returns null if not found.- Specified by:
getAttribute
in interfaceAttributeWrangler
- Parameters:
name
- the name of the attribute- Returns:
- an attribute
-
setAttribute
Description copied from interface:AttributeWrangler
Set the value of the attribute, creates the attribute if the attribute does not exist.- Specified by:
setAttribute
in interfaceAttributeWrangler
- Parameters:
name
- the name of the attributevalue
- the value of the attribute
-
verifyAttribute
Description copied from interface:AttributeWrangler
Verify if the attribute exists, and has the proper value.- Specified by:
verifyAttribute
in interfaceAttributeWrangler
- Parameters:
name
- the name of the attributevalue
- 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
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
Description copied from interface:ItemWrangler
Returns items this entity has, based on description provided.- Specified by:
findItems
in interfaceItemWrangler
- Parameters:
parsed
- the parsed description of the item, for example {"light-green", "leather", "pants"}.- Returns:
- list of found items, empty if not found.
-
destroyItem
Description copied from interface:ItemWrangler
Physically destroys an item instance.- Specified by:
destroyItem
in interfaceItemWrangler
- 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
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
-
isWieldable
-
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
-
drop
Specialty method for the creation of new items in a room. Only used byinvalid reference
Room#createItem(mmud.database.entities.items.ItemDefinition)
- Parameters:
room
- the room to drop the new item into.
-
get
-
give
-
isReadable
public boolean isReadable() -
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
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
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
Adds anItem
to the bag (container).- Specified by:
addItem
in interfaceItemWrangler
- Parameters:
item
- the new item. May not be null.- Returns:
- the new item, null if unable to add.
-
assignTo
-
assignTo
-