Skip to main content

Item

Struct Item 

Source
pub struct Item {
Show 15 fields pub id: ItemId, pub symbol: String, pub name: String, pub description: String, pub location: Location, pub visibility: ItemVisibility, pub visible_when: Option<EventCondition>, pub aliases: Vec<String>, pub movability: Movability, pub container_state: Option<ContainerState>, pub contents: HashSet<ItemId>, pub abilities: HashSet<ItemAbility>, pub interaction_requires: HashMap<ItemInteractionType, ItemAbility>, pub text: Option<String>, pub consumable: Option<ConsumableOpts>,
}
Expand description

Anything in ‘AmbleWorld’ that can be inspected or manipulated apart from NPCs.

Some ‘Items’ can also act as containers for other items, if ‘container_state’ is ‘Some(_)’. symbol and id refer to the same string – a holdover from a previous engine version where they differed.

movability specifies whether the Item can change location, and why not if it can’t.

‘abilities’ are special things you can do with this item (e.g. read, smash, ignite, clean)

interaction_requires’ maps a type of interaction (a thing that can be done to this item using another item) to an ability. e.g. ItemInteractionType::Burn => ItemAbility::Ignite

Combined with an appropriate ActOnItem-based trigger, this would mean any Item with ItemAbility::Ignite can be used to Burn this item – and importantly only items with that ability can be used to Burn it.

‘consumable’ makes an item consumable if present, with number of uses and what to do when all uses are expended defined in ConsumableOpts.

Fields§

§id: ItemId

The stable id of this item.

§symbol: String

The symbol used to refer to this item in world data.

§name: String

The display name of the item.

§description: String

A general description of the item.

§location: Location

The current Location of the item.

§visibility: ItemVisibility

Determines whether the item appears in listings or is discoverable.

§visible_when: Option<EventCondition>

Optional condition gating visibility.

§aliases: Vec<String>

Alternate names that can match this item in parser searches.

§movability: Movability

Determines whether the item can be moved from its current location.

§container_state: Option<ContainerState>

Some state (open, locked, etc) for the item as a container, or None if it is not a container.

§contents: HashSet<ItemId>

Set of ids of other items contained by this one.

§abilities: HashSet<ItemAbility>

Set of capabilities ItemAbility for this item.

§interaction_requires: HashMap<ItemInteractionType, ItemAbility>

Relates interactions to abilities. (Ex: to perform the “burn” interaction targeting this item, the other item must have the “ignite” capability.)

§text: Option<String>

Any legible detail text on the item. Also used as the detail text for the “examine” command.

§consumable: Option<ConsumableOpts>

Some consumable parameters ConsumableOpts, or None it the item isn’t consumable.

Implementations§

Source§

impl Item

Source

pub fn is_consumed(&self) -> bool

Returns true if item is consumable and has been consumed.

Source

pub fn is_accessible(&self) -> bool

Returns true if item’s contents can be accessed directly.

Source

pub fn is_transparent(&self) -> bool

Returns true if the item is a container and its contents are visible even when closed or locked.

Source

pub fn set_location_room(&mut self, room_id: RoomId)

Set location to a Room by id.

Source

pub fn set_location_item(&mut self, container_id: ItemId)

Set location to inside another container Item by id.

Source

pub fn set_location_inventory(&mut self)

Set location to player inventory

Source

pub fn set_location_npc(&mut self, npc_id: NpcId)

Set location to NPC inventory by id.

Source

pub fn show(&self, world: &AmbleWorld, view: &mut View)

Show item description (and any contents if a container and open).

Source

pub fn requires_capability_for( &self, inter: ItemInteractionType, ) -> Option<ItemAbility>

Determine what ability is required for certain interactions with this item.

In <verb> <target> with <tool> commands, this returns whatever ability the <tool> must have in order to successfully <verb> the <target> (this item).

Example – if this item is candle, then:

candle.requires_capability_for(ItemInteractionType::Burn) might return Some(ItemAbility::Ignite).

Source

pub fn access_denied_reason(&self) -> Option<String>

Returns the reason the item can’t be accessed (as a container), if any

Source

pub fn take_denied_reason(&self) -> Option<String>

Returns the reason an item can’t be taken into inventory, if any

Trait Implementations§

Source§

impl Clone for Item

Source§

fn clone(&self) -> Item

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Item

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Item

Source§

fn default() -> Item

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Item

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl ItemHolder for Item

Source§

fn add_item(&mut self, item_id: ItemId)

Insert an item into the holder’s contents.
Source§

fn remove_item(&mut self, item_id: ItemId)

Remove an item from the holder’s contents.
Source§

fn contains_item(&self, item_id: ItemId) -> bool

Return true when the holder already contains the given item.
Source§

impl Serialize for Item

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl WorldObject for Item

Source§

fn id(&self) -> Id

Stable id assigned to the object.
Source§

fn symbol(&self) -> &str

Symbol used in world data to refer to the object.
Source§

fn name(&self) -> &str

Display-friendly name.
Source§

fn description(&self) -> &str

Long-form description shown to players.
Source§

fn location(&self) -> &Location

Current location of the object within the world.

Auto Trait Implementations§

§

impl Freeze for Item

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnsafeUnpin for Item

§

impl UnwindSafe for Item

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,