pub struct SkillSet {
    skill_groups: HashMap<SkillGroupKind, SkillGroup>,
    skills: HashMap<Skill, u16>,
}
Expand description

Contains all of a player’s skill groups and skills. Provides methods for manipulating assigned skills and skill groups including unlocking skills, refunding skills etc.

Fields§

§skill_groups: HashMap<SkillGroupKind, SkillGroup>§skills: HashMap<Skill, u16>

Implementations§

source§

impl SkillSet

source

pub fn initial_skills() -> HashMap<Skill, u16>

source

pub fn load_from_database( skill_groups: HashMap<SkillGroupKind, SkillGroup>, all_skills: HashMap<SkillGroupKind, Result<Vec<Skill>, SkillsPersistenceError>> ) -> (Self, Option<SkillsPersistenceError>)

NOTE: This does not return an error on failure, since we can partially recover from some failures. Instead, it returns the error in the second return value; make sure to handle it if present!

source

fn skill_group_accessible_if_exists( &self, skill_group_kind: SkillGroupKind ) -> bool

Check if a particular skill group is accessible for an entity, if it exists.

source

pub fn skill_group_accessible(&self, skill_group_kind: SkillGroupKind) -> bool

Checks if a particular skill group is accessible for an entity

source

fn unlock_skill_group(&mut self, skill_group_kind: SkillGroupKind)

Unlocks a skill group for a player. It starts with 0 exp and 0 skill points.

source

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

Returns an iterator over skill groups

source

fn skill_group(&self, skill_group: SkillGroupKind) -> Option<&SkillGroup>

Returns a reference to a particular skill group in a skillset

source

fn skill_group_mut( &mut self, skill_group: SkillGroupKind ) -> Option<&mut SkillGroup>

Returns a mutable reference to a particular skill group in a skillset Requires that skillset contains skill that unlocks the skill group

source

pub fn add_experience( &mut self, skill_group_kind: SkillGroupKind, amount: u32 ) -> Option<u16>

Adds experience to the skill group within an entity’s skill set, will attempt to earn a skill point while doing so. If a skill point was earned, returns the number of earned skill points in the skill group.

source

pub fn available_experience(&self, skill_group: SkillGroupKind) -> u32

Gets the available experience for a particular skill group

source

pub fn skill_point_cost(&self, skill_group: SkillGroupKind) -> u32

Checks how much experience is needed for the next skill point in a tree

source

pub fn add_skill_points( &mut self, skill_group_kind: SkillGroupKind, number_of_skill_points: u16 )

Adds skill points to a skill group as long as the player has that skill group type.

source

pub fn available_sp(&self, skill_group: SkillGroupKind) -> u16

Gets the available points for a particular skill group

source

pub fn earned_sp(&self, skill_group: SkillGroupKind) -> u16

Gets the total earned points for a particular skill group

source

pub fn prerequisites_met(&self, skill: Skill) -> bool

Checks that the skill set contains all prerequisite skills of the required level for a particular skill

source

pub fn skill_cost(&self, skill: Skill) -> u16

Gets skill point cost to purchase skill of next level

source

pub fn sufficient_skill_points(&self, skill: Skill) -> bool

Checks if player has sufficient skill points to purchase a skill

source

fn next_skill_level(&self, skill: Skill) -> u16

Checks the next level of a skill

source

pub fn unlock_skill_cow<'a, B, C>( this_: &'a mut B, skill: Skill, to_mut: impl FnOnce(&'a mut B) -> &'a mut C ) -> Result<(), SkillUnlockError>
where B: Borrow<SkillSet>, C: BorrowMut<SkillSet> + 'a,

Unlocks a skill for a player, assuming they have the relevant skill group unlocked and available SP in that skill group.

NOTE: Please don’t use pathological or clever implementations of to_mut here.

source

pub fn unlock_skill(&mut self, skill: Skill) -> Result<(), SkillUnlockError>

Convenience function for the case where you have mutable access to the skill.

source

pub fn has_available_sp(&self) -> bool

Checks if the player has available SP to spend

source

pub fn is_at_max_level(&self, skill: Skill) -> bool

Checks if the skill is at max level in a skill set

source

pub fn has_skill(&self, skill: Skill) -> bool

Checks if skill set contains a skill

source

pub fn skill_level(&self, skill: Skill) -> Result<u16, SkillError>

Returns the level of the skill

Trait Implementations§

source§

impl Clone for SkillSet

source§

fn clone(&self) -> SkillSet

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 SkillSet

§

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

Associated storage type for this component.
source§

impl Debug for SkillSet

source§

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

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

impl Default for SkillSet

source§

fn default() -> Self

Instantiate a new skill set with the default skill groups with no unlocked skills in them - used when adding a skill set to a new player

source§

impl<'de> Deserialize<'de> for SkillSet

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 PartialEq for SkillSet

source§

fn eq(&self, other: &SkillSet) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for SkillSet

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

impl Eq for SkillSet

source§

impl StructuralEq for SkillSet

source§

impl StructuralPartialEq for SkillSet

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
§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

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
§

impl<T> TryDefault for T
where T: Default,

§

fn try_default() -> Result<T, String>

Tries to create the default.
§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
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,