pub struct Inventory {
    next_sort_order: InventorySortOrder,
    loadout: Loadout,
    slots: Vec<Option<Item>>,
    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<Option<Item>>§overflow_items: Vec<Item>§recipe_book: RecipeBook

Implementations§

§

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

pub fn with_empty() -> Inventory

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

pub fn with_loadout_humanoid(loadout: Loadout) -> Inventory

pub fn with_loadout_animal(loadout: Loadout) -> Inventory

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

pub fn capacity(&self) -> usize

Total number of slots in in the inventory.

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

An iterator of all inventory slots

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

An iterator of all overflow slots in the inventory

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

An iterator of all inventory slots and their position

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

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

pub fn sort(&mut self)

Sorts the inventory using the next sort order

pub fn next_sort_order(&self) -> InventorySortOrder

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

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

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.

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

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

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

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.

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.

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

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.

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.

pub fn populated_slots(&self) -> usize

pub fn free_slots(&self) -> usize

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

Check if an item is in this inventory.

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

Return the first slot id containing the item

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

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

Get content of a slot

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

Get content of an overflow slot

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

Get content of any kind of slot

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

Get item from inventory

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

Get slot from hash

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

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

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

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)

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

Swap the items inside of two slots

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

Moves an item from an overflow slot to an inventory slot

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

Remove an item from the slot

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

Remove an item from an overflow slot

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

Remove just one item from the slot

pub fn take_amount( &mut self, inv_slot_id: InvSlotId, amount: NonZero<u32>, 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.

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

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

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

Takes all items from the inventory

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

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

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

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

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.

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

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

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.

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.

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)

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

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

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.

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

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

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.

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

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.

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.

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

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

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.

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

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

Resets durability of item in specified slot

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

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

pub fn recipes_iter(&self) -> impl ExactSizeIterator

pub fn recipe_groups_iter(&self) -> impl ExactSizeIterator

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

pub fn recipe_book_len(&self) -> usize

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

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

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.

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

pub fn reset_recipes(&mut self)

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

Trait Implementations§

§

impl Clone for Inventory

§

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
§

impl Component for Inventory

§

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

Associated storage type for this component.
§

impl Debug for Inventory

§

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

Formats the value using the given formatter. Read more
§

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

§

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

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

impl From<Inventory> for EcsCompPacket

source§

fn from(other: Inventory) -> EcsCompPacket

Converts to this type from the input type.
source§

impl NetSync for Inventory

source§

const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity

Determines what for entities this component is synced to the client. Read more
source§

fn pre_insert(&mut self, world: &World)

Allows making modifications before the synced component is inserted on the client.
source§

fn pre_modify(&mut self, world: &World)

Allows making modifications before the synced component is overwritten with this version on the client.
§

impl Serialize for Inventory

§

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

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

impl TryFrom<EcsCompPacket> for Inventory

§

type Error = InvalidType

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

fn try_from(other: EcsCompPacket) -> Result<Inventory, Self::Error>

Performs the conversion.

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
§

impl<Context> SubContext<Context> for Context

§

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,