Struct Lootr

Source
pub struct Lootr<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Lootr<'a>

Source

pub fn new() -> Self

Create a new lootbag

Source

pub fn from(items: Vec<Item<'a>>) -> Self

Create a new lootbag from given items

Source

pub fn branchs(&self) -> &BTreeMap<&str, Lootr<'a>>

Return this lootbag branchs

Source

pub fn items(&self) -> &Vec<Item<'_>>

Return this lootbag items (at this level)

Source

pub fn self_count(&self) -> usize

Return this lootbag items count (at this level)

Source

pub fn all_count(&self) -> usize

Return this lootbag items count (including any sublevel)

Source

pub fn add(&mut self, item: Item<'a>) -> &mut Self

Add an item at this level

Returns the current lootbag

Source

pub fn add_in(&mut self, item: Item<'a>, path: &'a str) -> &mut Self

Add an item in the given branch

Returns the current lootbag

Source

pub fn branch_mut(&mut self, path: &'a str) -> Option<&mut Lootr<'a>>

Returns the branch at the given path.

Source

pub fn branch(&self, path: &'a str) -> Option<&Lootr<'a>>

Returns the branch at the given path. If the branch does not exit yet, None is returned

Source

pub fn add_branch(&mut self, path: &'a str, branch: Lootr<'a>) -> &mut Self

Add a branch, return self (the owner)

Source

pub fn all_items(&self) -> Vec<Item<'_>>

Return all items in the current and nested branchs

Source

pub fn add_modifier(&mut self, modifier: Modifier) -> &mut Self

Add a modifier

Source

pub fn roll( &self, catalog_path: Option<&'a str>, nesting: i16, threshold: f32, ) -> Option<&Item<'_>>

Pick a random item from the specified branch

Returns Some(Item) or None

Source

pub fn roll_seeded<R>( &self, catalog_path: Option<&'a str>, nesting: i16, threshold: f32, rng: &mut R, ) -> Option<&Item<'a>>
where R: Rng + ?Sized,

Pick a random item from the specified branch, given a PRNG

Returns Some(Item) or None

Source

pub fn roll_any(&self) -> Option<&Item<'_>>

Pick a random item anywhere in that branch

Returns Some(Item) or None

Source

pub fn loot(&self, drops: &[Drop]) -> Vec<Item<'_>>

Roll against a looting table

Returns a vec of Item

Source

pub fn loot_seeded<R>(&self, drops: &[Drop], rng: &mut R) -> Vec<Item<'_>>
where R: Rng + ?Sized,

Roll against a looting table, given a PRNG

Returns a vec of Item

Trait Implementations§

Source§

impl<'a> Display for Lootr<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Lootr<'a>

§

impl<'a> RefUnwindSafe for Lootr<'a>

§

impl<'a> Send for Lootr<'a>

§

impl<'a> Sync for Lootr<'a>

§

impl<'a> Unpin for Lootr<'a>

§

impl<'a> UnwindSafe for Lootr<'a>

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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