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
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
sourcepub fn overflow_items(&self) -> impl Iterator<Item = &Item>
pub fn overflow_items(&self) -> impl Iterator<Item = &Item>
An iterator of all overflow slots in the inventory
sourcefn slots_mut(&mut self) -> impl Iterator<Item = &mut InvSlot>
fn slots_mut(&mut self) -> impl Iterator<Item = &mut InvSlot>
A mutable iterator of all inventory slots
fn slots_mut_with_mutable_recently_unequipped_items( &mut self, ) -> (impl Iterator<Item = &mut InvSlot>, &mut HashMap<ItemDefinitionIdOwned, (Time, u8)>)
sourcepub fn slots_with_id(&self) -> impl Iterator<Item = (InvSlotId, &InvSlot)>
pub fn slots_with_id(&self) -> impl Iterator<Item = (InvSlotId, &InvSlot)>
An iterator of all inventory slots and their position
sourcepub fn order_by_custom(
custom_order: &[CustomOrder],
a: &Item,
b: &Item,
) -> Ordering
pub fn order_by_custom( custom_order: &[CustomOrder], a: &Item, b: &Item, ) -> Ordering
If custom_order is empty, it will always return Ordering::Equal
sourcepub fn next_sort_order(&self) -> InventorySortOrder
pub fn next_sort_order(&self) -> InventorySortOrder
Returns the sort order that will be used when Inventory::sort() is next called
sourcepub fn push(&mut self, item: Item) -> Result<(), (Item, Option<NonZeroU32>)>
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.
sourcepub fn push_all<I: Iterator<Item = Item>>(
&mut self,
items: I,
) -> Result<(), Error>
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.
sourcepub fn push_all_unique<I: Iterator<Item = Item>>(
&mut self,
items: I,
) -> Result<(), Error>
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.
sourcepub fn insert_at(
&mut self,
inv_slot_id: InvSlotId,
item: Item,
) -> Result<Option<Item>, Item>
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.
sourcepub fn merge_stack_into(&mut self, src: InvSlotId, dst: InvSlotId) -> bool
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
sourcepub fn insert_or_stack_at(
&mut self,
inv_slot_id: InvSlotId,
item: Item,
) -> Result<Option<Item>, Item>
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.
sourcepub fn try_equip(&mut self, item: Item) -> Result<(), Item>
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
sourcepub fn get_slot_of_item(&self, item: &Item) -> Option<InvSlotId>
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>
sourcepub fn get_overflow(&self, overflow: usize) -> Option<&Item>
pub fn get_overflow(&self, overflow: usize) -> Option<&Item>
Get content of an overflow slot
sourcepub fn get_by_hash(&self, item_hash: u64) -> Option<&Item>
pub fn get_by_hash(&self, item_hash: u64) -> Option<&Item>
Get item from inventory
sourcepub fn get_slot_from_hash(&self, item_hash: u64) -> Option<InvSlotId>
pub fn get_slot_from_hash(&self, item_hash: u64) -> Option<InvSlotId>
Get slot from hash
sourcefn get_mut(&mut self, inv_slot_id: InvSlotId) -> Option<&mut Item>
fn get_mut(&mut self, inv_slot_id: InvSlotId) -> Option<&mut Item>
Mutably get content of a slot
sourcepub fn equipped(&self, equip_slot: EquipSlot) -> Option<&Item>
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>)>
sourcepub fn get_slot_range_for_equip_slot(
&self,
equip_slot: EquipSlot,
) -> Option<Range<usize>>
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)
sourcepub fn swap_slots(&mut self, a: InvSlotId, b: InvSlotId)
pub fn swap_slots(&mut self, a: InvSlotId, b: InvSlotId)
Swap the items inside of two slots
sourcepub fn move_overflow_item(&mut self, overflow: usize, inv_slot: InvSlotId)
pub fn move_overflow_item(&mut self, overflow: usize, inv_slot: InvSlotId)
Moves an item from an overflow slot to an inventory slot
sourcepub fn overflow_remove(&mut self, overflow_slot: usize) -> Option<Item>
pub fn overflow_remove(&mut self, overflow_slot: usize) -> Option<Item>
Remove an item from an overflow slot
sourcepub fn take(
&mut self,
inv_slot_id: InvSlotId,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
) -> Option<Item>
pub fn take( &mut self, inv_slot_id: InvSlotId, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Option<Item>
Remove just one item from the slot
sourcepub fn take_amount(
&mut self,
inv_slot_id: InvSlotId,
amount: NonZeroU32,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
) -> Option<Item>
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.
sourcepub fn take_half(
&mut self,
inv_slot_id: InvSlotId,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
) -> Option<Item>
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
sourcepub fn overflow_take_half(
&mut self,
overflow_slot: usize,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
) -> Option<Item>
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
sourcepub fn item_count(&self, item_def: &ItemDef) -> u64
pub fn item_count(&self, item_def: &ItemDef) -> u64
Determine how many of a particular item there is in the inventory.
sourcefn insert(&mut self, item: Item) -> Result<(), Item>
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.
pub fn slot(&self, inv_slot_id: InvSlotId) -> Option<&InvSlot>
pub fn slot_mut(&mut self, inv_slot_id: InvSlotId) -> Option<&mut InvSlot>
sourcepub fn free_slots_minus_equipped_item(&self, equip_slot: EquipSlot) -> usize
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)>
sourcepub fn replace_loadout_item(
&mut self,
equip_slot: EquipSlot,
replacement_item: Option<Item>,
time: Time,
) -> Option<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.
sourcepub fn equip(&mut self, inv_slot: InvSlotId, time: Time) -> Vec<Item>
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.
sourcepub fn free_after_equip(&self, inv_slot: InvSlotId) -> i32
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)
sourcepub fn pickup_item(
&mut self,
item: Item,
) -> Result<(), (Item, Option<NonZeroU32>)>
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
sourcepub fn unequip(
&mut self,
equip_slot: EquipSlot,
time: Time,
) -> Result<Option<Vec<Item>>, SlotError>
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.
sourcepub fn free_after_unequip(&self, equip_slot: EquipSlot) -> i32
pub fn free_after_unequip(&self, equip_slot: EquipSlot) -> i32
Determines how many free inventory slots will be left after unequipping an item
sourcepub fn swap(&mut self, slot_a: Slot, slot_b: Slot, time: Time) -> Vec<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.
sourcepub fn free_after_swap(&self, equip_slot: EquipSlot, inv_slot: InvSlotId) -> i32
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
sourcepub fn swap_inventory_loadout(
&mut self,
inv_slot_id: InvSlotId,
equip_slot: EquipSlot,
time: Time,
) -> Vec<Item>
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.
sourcepub fn can_swap(&self, inv_slot_id: InvSlotId, equip_slot: EquipSlot) -> bool
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)
sourcepub fn persistence_update_all_item_states(
&mut self,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
)
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.
sourcepub fn damage_items(
&mut self,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
time: Time,
)
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
sourcepub fn repair_item_at_slot(
&mut self,
slot: Slot,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
)
pub fn repair_item_at_slot( &mut self, slot: Slot, ability_map: &AbilityMap, msm: &MaterialStatManifest, )
Resets durability of item in specified slot
sourcepub fn persistence_push_overflow_items<I: Iterator<Item = Item>>(
&mut self,
overflow_items: I,
)
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
pub fn recipes_iter(&self) -> impl ExactSizeIterator<Item = &String>
pub fn recipe_groups_iter(&self) -> impl ExactSizeIterator<Item = &Item>
pub fn available_recipes_iter<'a>( &'a self, rbm: &'a RecipeBookManifest, ) -> impl Iterator<Item = (&String, &Recipe)> + '_
pub fn recipe_book_len(&self) -> usize
pub fn get_recipe<'a>( &'a self, recipe_key: &str, rbm: &'a RecipeBookManifest, ) -> Option<&Recipe>
pub fn push_recipe_group(&mut self, recipe_group: Item) -> Result<(), Item>
sourcepub fn can_craft_recipe(
&self,
recipe_key: &str,
amount: u32,
rbm: &RecipeBookManifest,
) -> (bool, Option<SpriteKind>)
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§
source§impl<'de> Deserialize<'de> for Inventory
impl<'de> Deserialize<'de> for Inventory
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Inventory
impl RefUnwindSafe for Inventory
impl Send for Inventory
impl Sync for Inventory
impl Unpin for Inventory
impl UnwindSafe for Inventory
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<C, M> ConvertSaveload<M> for C
impl<C, M> ConvertSaveload<M> for C
§type Error = Infallible
type Error = Infallible
§fn convert_into<F>(
&self,
_: F,
) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
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>
fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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