Struct veloren_common::comp::inventory::Inventory

source ·
pub struct Inventory {
    next_sort_order: InventorySortOrder,
    loadout: Loadout,
    slots: Vec<InvSlot>,
    overflow_items: Vec<Item>,
    recipe_book: RecipeBook,
}
Expand description

NOTE: Do not add a PartialEq instance for Inventory; that’s broken!

Fields§

§next_sort_order: InventorySortOrder§loadout: Loadout§slots: Vec<InvSlot>

The “built-in” slots belonging to the inventory itself, all other slots are provided by equipped items

§overflow_items: Vec<Item>

For when slot amounts are rebalanced or the inventory otherwise does not have enough space to hold all the items after loading from database. These slots are “remove-only” meaning that during normal gameplay items can only be removed from these slots and never entered.

§recipe_book: RecipeBook

Recipes that are available for use

Implementations§

source§

impl Inventory

Represents the Inventory of an entity. The inventory has 18 “built-in” slots, with further slots being provided by items equipped in the Loadout sub-struct. Inventory slots are indexed by InvSlotId which is comprised of loadout_idx - the index of the loadout item that provides the slot, 0 being the built-in inventory slots, and slot_idx - the index of the slot within that loadout item.

Currently, it is not supported for inventories to contain items that have items inside them. This is due to both game balance purposes, and the lack of a UI to show such items. Because of this, any action that would result in such an item being put into the inventory (item pickup, unequipping an item that contains items etc) must first ensure items are unloaded from the item. This is handled in inventory\slot.rs

source

pub fn with_empty() -> Inventory

source

pub fn with_loadout(loadout: Loadout, body: Body) -> Inventory

source

pub fn with_loadout_humanoid(loadout: Loadout) -> Inventory

source

pub fn with_loadout_animal(loadout: Loadout) -> Inventory

source

pub fn with_recipe_book(self, recipe_book: RecipeBook) -> Inventory

source

pub fn capacity(&self) -> usize

Total number of slots in in the inventory.

source

pub fn slots(&self) -> impl Iterator<Item = &InvSlot>

An iterator of all inventory slots

source

pub fn overflow_items(&self) -> impl Iterator<Item = &Item>

An iterator of all overflow slots in the inventory

source

fn slots_mut(&mut self) -> impl Iterator<Item = &mut InvSlot>

A mutable iterator of all inventory slots

source

fn slots_mut_with_mutable_recently_unequipped_items( &mut self, ) -> (impl Iterator<Item = &mut InvSlot>, &mut HashMap<ItemDefinitionIdOwned, (Time, u8)>)

source

pub fn slots_with_id(&self) -> impl Iterator<Item = (InvSlotId, &InvSlot)>

An iterator of all inventory slots and their position

source

pub fn order_by_custom( custom_order: &[CustomOrder], a: &Item, b: &Item, ) -> Ordering

If custom_order is empty, it will always return Ordering::Equal

source

pub fn sort(&mut self)

Sorts the inventory using the next sort order

source

pub fn next_sort_order(&self) -> InventorySortOrder

Returns the sort order that will be used when Inventory::sort() is next called

source

pub fn push(&mut self, item: Item) -> Result<(), (Item, Option<NonZeroU32>)>

Adds a new item to the fitting slots of the inventory or starts a new group. Returns the item in an error if no space was found.

WARNING: This may make inventory modifications if Err(item) is returned. The second tuple field in the error is the number of items that were successfully inserted into the inventory.

source

pub fn push_all<I: Iterator<Item = Item>>( &mut self, items: I, ) -> Result<(), Error>

Add a series of items to inventory, returning any which do not fit as an error.

source

pub fn push_all_unique<I: Iterator<Item = Item>>( &mut self, items: I, ) -> Result<(), Error>

Add a series of items to an inventory without giving duplicates. (n * m complexity)

Error if inventory cannot contain the items (is full), returning the un-added items. This is a lazy inefficient implementation, as it iterates over the inventory more times than necessary (n^2) and with the proper structure wouldn’t need to iterate at all, but because this should be fairly cold code, clarity has been favored over efficiency.

source

pub fn insert_at( &mut self, inv_slot_id: InvSlotId, item: Item, ) -> Result<Option<Item>, Item>

Replaces an item in a specific slot of the inventory. Returns the old item or the same item again if that slot was not found.

source

pub fn merge_stack_into(&mut self, src: InvSlotId, dst: InvSlotId) -> bool

Merge the stack of items at src into the stack at dst if the items are compatible and stackable, and return whether anything was changed

source

pub fn insert_or_stack_at( &mut self, inv_slot_id: InvSlotId, item: Item, ) -> Result<Option<Item>, Item>

Checks if inserting item exists in given cell. Inserts an item if it exists.

source

pub fn try_equip(&mut self, item: Item) -> Result<(), Item>

Attempts to equip the item into a compatible, unpopulated loadout slot. If no slot is available the item is returned.

source

pub fn populated_slots(&self) -> usize

source

pub fn free_slots(&self) -> usize

source

pub fn contains(&self, item: &Item) -> bool

Check if an item is in this inventory.

source

pub fn get_slot_of_item(&self, item: &Item) -> Option<InvSlotId>

Return the first slot id containing the item

source

pub fn get_slot_of_item_by_def_id( &self, item_def_id: &ItemDefinitionIdOwned, ) -> Option<InvSlotId>

source

pub fn get(&self, inv_slot_id: InvSlotId) -> Option<&Item>

Get content of a slot

source

pub fn get_overflow(&self, overflow: usize) -> Option<&Item>

Get content of an overflow slot

source

pub fn get_slot(&self, slot: Slot) -> Option<&Item>

Get content of any kind of slot

source

pub fn get_by_hash(&self, item_hash: u64) -> Option<&Item>

Get item from inventory

source

pub fn get_slot_from_hash(&self, item_hash: u64) -> Option<InvSlotId>

Get slot from hash

source

fn get_mut(&mut self, inv_slot_id: InvSlotId) -> Option<&mut Item>

Mutably get content of a slot

source

pub fn equipped(&self, equip_slot: EquipSlot) -> Option<&Item>

Returns a reference to the item (if any) equipped in the given EquipSlot

source

pub fn loadout_items_with_persistence_key( &self, ) -> impl Iterator<Item = (&str, Option<&Item>)>

source

pub fn get_slot_range_for_equip_slot( &self, equip_slot: EquipSlot, ) -> Option<Range<usize>>

Returns the range of inventory slot indexes that a particular equipped item provides (used for UI highlighting of inventory slots when hovering over a loadout item)

source

pub fn swap_slots(&mut self, a: InvSlotId, b: InvSlotId)

Swap the items inside of two slots

source

pub fn move_overflow_item(&mut self, overflow: usize, inv_slot: InvSlotId)

Moves an item from an overflow slot to an inventory slot

source

pub fn remove(&mut self, inv_slot_id: InvSlotId) -> Option<Item>

Remove an item from the slot

source

pub fn overflow_remove(&mut self, overflow_slot: usize) -> Option<Item>

Remove an item from an overflow slot

source

pub fn take( &mut self, inv_slot_id: InvSlotId, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Option<Item>

Remove just one item from the slot

source

pub fn take_amount( &mut self, inv_slot_id: InvSlotId, amount: NonZeroU32, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Option<Item>

Takes an amount of items from a slot. If the amount to take is larger than the item amount, the item amount will be returned instead.

source

pub fn take_half( &mut self, inv_slot_id: InvSlotId, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Option<Item>

Takes half of the items from a slot in the inventory

source

pub fn overflow_take_half( &mut self, overflow_slot: usize, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Option<Item>

Takes half of the items from an overflow slot

source

pub fn drain(&mut self) -> impl Iterator<Item = Item> + '_

Takes all items from the inventory

source

pub fn item_count(&self, item_def: &ItemDef) -> u64

Determine how many of a particular item there is in the inventory.

source

fn insert(&mut self, item: Item) -> Result<(), Item>

Adds a new item to the first empty slot of the inventory. Returns the item again in an Err if no free slot was found, otherwise returns a reference to the item.

source

pub fn slot(&self, inv_slot_id: InvSlotId) -> Option<&InvSlot>

source

pub fn slot_mut(&mut self, inv_slot_id: InvSlotId) -> Option<&mut InvSlot>

source

pub fn free_slots_minus_equipped_item(&self, equip_slot: EquipSlot) -> usize

Returns the number of free slots in the inventory ignoring any slots granted by the item (if any) equipped in the provided EquipSlot.

source

pub fn equipped_items(&self) -> impl Iterator<Item = &Item>

source

pub fn equipped_items_with_slot( &self, ) -> impl Iterator<Item = (EquipSlot, &Item)>

source

pub fn replace_loadout_item( &mut self, equip_slot: EquipSlot, replacement_item: Option<Item>, time: Time, ) -> Option<Item>

Replaces the loadout item (if any) in the given EquipSlot with the provided item, returning the item that was previously in the slot.

source

pub fn equip(&mut self, inv_slot: InvSlotId, time: Time) -> Vec<Item>

Equip an item from a slot in inventory. The currently equipped item will go into inventory. If the item is going to mainhand, put mainhand in offhand and place offhand into inventory.

source

pub fn free_after_equip(&self, inv_slot: InvSlotId) -> i32

Determines how many free inventory slots will be left after equipping an item (because it could be swapped with an already equipped item that provides more inventory slots than the item being equipped)

source

pub fn pickup_item( &mut self, item: Item, ) -> Result<(), (Item, Option<NonZeroU32>)>

Handles picking up an item, unloading any items inside the item being picked up and pushing them to the inventory to ensure that items containing items aren’t inserted into the inventory as this is not currently supported.

WARNING: The Err(_) variant may still cause inventory modifications, note on Inventory::push

source

pub fn unequip( &mut self, equip_slot: EquipSlot, time: Time, ) -> Result<Option<Vec<Item>>, SlotError>

Unequip an item from slot and place into inventory. Will leave the item equipped if inventory has no slots available.

source

pub fn free_after_unequip(&self, equip_slot: EquipSlot) -> i32

Determines how many free inventory slots will be left after unequipping an item

source

pub fn swap(&mut self, slot_a: Slot, slot_b: Slot, time: Time) -> Vec<Item>

Swaps items from two slots, regardless of if either is inventory or loadout.

source

pub fn free_after_swap(&self, equip_slot: EquipSlot, inv_slot: InvSlotId) -> i32

Determines how many free inventory slots will be left after swapping two item slots

source

pub fn swap_inventory_loadout( &mut self, inv_slot_id: InvSlotId, equip_slot: EquipSlot, time: Time, ) -> Vec<Item>

Swap item in an inventory slot with one in a loadout slot.

source

pub fn can_swap(&self, inv_slot_id: InvSlotId, equip_slot: EquipSlot) -> bool

Determines if an inventory and loadout slot can be swapped, taking into account whether there will be free space in the inventory for the loadout item once any slots that were provided by it have been removed.

source

pub fn equipped_items_replaceable_by<'a>( &'a self, item_kind: &'a ItemKind, ) -> impl Iterator<Item = &'a Item>

source

pub fn swap_equipped_weapons(&mut self, time: Time)

source

pub fn persistence_update_all_item_states( &mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest, )

Update internal computed state of all top level items in this loadout. Used only when loading in persistence code.

source

pub fn damage_items( &mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest, time: Time, )

Increments durability lost for all valid items equipped in loadout and recently unequipped from loadout by 1

source

pub fn repair_item_at_slot( &mut self, slot: Slot, ability_map: &AbilityMap, msm: &MaterialStatManifest, )

Resets durability of item in specified slot

source

pub fn persistence_push_overflow_items<I: Iterator<Item = Item>>( &mut self, overflow_items: I, )

When loading a character from the persistence system, pushes any items to overflow_items that were not able to be loaded into or pushed to the inventory

source

pub fn recipes_iter(&self) -> impl ExactSizeIterator<Item = &String>

source

pub fn recipe_groups_iter(&self) -> impl ExactSizeIterator<Item = &Item>

source

pub fn available_recipes_iter<'a>( &'a self, rbm: &'a RecipeBookManifest, ) -> impl Iterator<Item = (&String, &Recipe)> + '_

source

pub fn recipe_book_len(&self) -> usize

source

pub fn get_recipe<'a>( &'a self, recipe_key: &str, rbm: &'a RecipeBookManifest, ) -> Option<&Recipe>

source

pub fn push_recipe_group(&mut self, recipe_group: Item) -> Result<(), Item>

source

pub fn can_craft_recipe( &self, recipe_key: &str, amount: u32, rbm: &RecipeBookManifest, ) -> (bool, Option<SpriteKind>)

Returns whether the specified recipe can be crafted and the sprite, if any, that is required to do so.

source

pub fn recipe_is_known(&self, recipe_key: &str) -> bool

source

pub fn reset_recipes(&mut self)

source

pub fn persistence_recipes_iter_with_index( &self, ) -> impl Iterator<Item = (usize, &Item)>

Trait Implementations§

source§

impl Clone for Inventory

source§

fn clone(&self) -> Inventory

Returns a copy 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 Component for Inventory

§

type Storage = DerefFlaggedStorage<Inventory, VecStorage<Inventory>>

Associated storage type for this component.
source§

impl Debug for Inventory

source§

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

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

impl<'de> Deserialize<'de> for Inventory

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 Serialize for Inventory

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

Auto Trait Implementations§

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<C, M> ConvertSaveload<M> for C

§

type Data = C

(De)Serializable data representation for data type
§

type Error = Infallible

Error may occur during serialization or deserialization of component
§

fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
where F: FnMut(Entity) -> Option<M>,

Convert this data type into serializable form (Data) using entity to marker mapping function
§

fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
where F: FnMut(M) -> Option<Entity>,

Convert this data from a deserializable form (Data) using entity to marker mapping function
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<Context> SubContext<Context> for Context

source§

fn sub_context(self) -> Context

source§

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

§

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>,

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

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

§

impl<T> Event for T
where T: Send + Sync + 'static,

§

impl<T> Resource for T
where T: Any + Send + Sync,

§

impl<T> Storable for T
where T: Send + Sync + 'static,