Struct veloren_common_net::synced_components::Inventory
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
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 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
pub fn slots_with_id(&self) -> impl Iterator<Item = (InvSlotId, &Option<Item>)>
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
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)
pub fn sort(&mut self)
Sorts the inventory using the next sort order
pub 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
pub fn push(&mut self, item: Item) -> Result<(), (Item, Option<NonZero<u32>>)>
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>
pub fn push_all<I>(&mut self, items: I) -> Result<(), Error>
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>
pub fn push_all_unique<I>(&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.
pub 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.
pub 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
pub 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.
pub 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
pub 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>
pub fn get_overflow(&self, overflow: usize) -> Option<&Item>
pub fn get_overflow(&self, overflow: usize) -> Option<&Item>
Get content of an overflow slot
pub 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
pub 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
pub 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>)>
pub 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)
pub 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
pub 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
pub 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
pub 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
pub fn take_amount(
&mut self,
inv_slot_id: InvSlotId,
amount: NonZero<u32>,
ability_map: &AbilityMap,
msm: &MaterialStatManifest,
) -> Option<Item>
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>
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>
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 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.
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
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>
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>
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
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>>)>
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>
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
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>
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
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>
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
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,
)
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,
)
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,
)
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)
pub fn persistence_push_overflow_items<I>(&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
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>)
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<'de> Deserialize<'de> for Inventory
impl<'de> Deserialize<'de> for Inventory
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Inventory, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Inventory, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl From<Inventory> for EcsCompPacket
impl From<Inventory> for EcsCompPacket
source§fn from(other: Inventory) -> EcsCompPacket
fn from(other: Inventory) -> EcsCompPacket
source§impl NetSync for Inventory
impl NetSync for Inventory
source§const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity
const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity
source§fn pre_insert(&mut self, world: &World)
fn pre_insert(&mut self, world: &World)
source§fn pre_modify(&mut self, world: &World)
fn pre_modify(&mut self, world: &World)
§impl Serialize for Inventory
impl Serialize for Inventory
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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