Struct veloren_common::comp::skillset::SkillSet
source · 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
impl SkillSet
pub fn initial_skills() -> HashMap<Skill, u16>
sourcepub fn load_from_database(
skill_groups: HashMap<SkillGroupKind, SkillGroup>,
all_skills: HashMap<SkillGroupKind, Result<Vec<Skill>, SkillsPersistenceError>>,
) -> (Self, Option<SkillsPersistenceError>)
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!
sourcefn skill_group_accessible_if_exists(
&self,
skill_group_kind: SkillGroupKind,
) -> bool
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.
sourcepub fn skill_group_accessible(&self, skill_group_kind: SkillGroupKind) -> bool
pub fn skill_group_accessible(&self, skill_group_kind: SkillGroupKind) -> bool
Checks if a particular skill group is accessible for an entity
sourcefn unlock_skill_group(&mut self, skill_group_kind: SkillGroupKind)
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.
sourcepub fn skill_groups(&self) -> impl Iterator<Item = &SkillGroup>
pub fn skill_groups(&self) -> impl Iterator<Item = &SkillGroup>
Returns an iterator over skill groups
sourcefn skill_group(&self, skill_group: SkillGroupKind) -> Option<&SkillGroup>
fn skill_group(&self, skill_group: SkillGroupKind) -> Option<&SkillGroup>
Returns a reference to a particular skill group in a skillset
sourcefn skill_group_mut(
&mut self,
skill_group: SkillGroupKind,
) -> Option<&mut SkillGroup>
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
sourcepub fn add_experience(
&mut self,
skill_group_kind: SkillGroupKind,
amount: u32,
) -> Option<u16>
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.
sourcepub fn available_experience(&self, skill_group: SkillGroupKind) -> u32
pub fn available_experience(&self, skill_group: SkillGroupKind) -> u32
Gets the available experience for a particular skill group
sourcepub fn skill_point_cost(&self, skill_group: SkillGroupKind) -> u32
pub fn skill_point_cost(&self, skill_group: SkillGroupKind) -> u32
Checks how much experience is needed for the next skill point in a tree
sourcepub fn add_skill_points(
&mut self,
skill_group_kind: SkillGroupKind,
number_of_skill_points: u16,
)
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.
sourcepub fn available_sp(&self, skill_group: SkillGroupKind) -> u16
pub fn available_sp(&self, skill_group: SkillGroupKind) -> u16
Gets the available points for a particular skill group
sourcepub fn earned_sp(&self, skill_group: SkillGroupKind) -> u16
pub fn earned_sp(&self, skill_group: SkillGroupKind) -> u16
Gets the total earned points for a particular skill group
sourcepub fn prerequisites_met(&self, skill: Skill) -> bool
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
sourcepub fn skill_cost(&self, skill: Skill) -> u16
pub fn skill_cost(&self, skill: Skill) -> u16
Gets skill point cost to purchase skill of next level
sourcepub fn sufficient_skill_points(&self, skill: Skill) -> bool
pub fn sufficient_skill_points(&self, skill: Skill) -> bool
Checks if player has sufficient skill points to purchase a skill
sourcefn next_skill_level(&self, skill: Skill) -> u16
fn next_skill_level(&self, skill: Skill) -> u16
Checks the next level of a skill
sourcepub 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>
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>
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.
sourcepub fn unlock_skill(&mut self, skill: Skill) -> Result<(), SkillUnlockError>
pub fn unlock_skill(&mut self, skill: Skill) -> Result<(), SkillUnlockError>
Convenience function for the case where you have mutable access to the skill.
sourcepub fn has_available_sp(&self) -> bool
pub fn has_available_sp(&self) -> bool
Checks if the player has available SP to spend
sourcepub fn is_at_max_level(&self, skill: Skill) -> bool
pub fn is_at_max_level(&self, skill: Skill) -> bool
Checks if the skill is at max level in a skill set
sourcepub fn skill_level(&self, skill: Skill) -> Result<u16, SkillError>
pub fn skill_level(&self, skill: Skill) -> Result<u16, SkillError>
Returns the level of the skill
Trait Implementations§
source§impl<'de> Deserialize<'de> for SkillSet
impl<'de> Deserialize<'de> for SkillSet
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>,
source§impl PartialEq for SkillSet
impl PartialEq for SkillSet
impl Eq for SkillSet
impl StructuralPartialEq for SkillSet
Auto Trait Implementations§
impl Freeze for SkillSet
impl RefUnwindSafe for SkillSet
impl Send for SkillSet
impl Sync for SkillSet
impl Unpin for SkillSet
impl UnwindSafe for SkillSet
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§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§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.