Struct veloren_common::comp::energy::Energy
source · pub struct Energy {
current: u32,
base_max: u32,
maximum: u32,
regen_rate: f32,
}
Expand description
Energy is represented by u32s within the module, but treated as a float by the rest of the game.
Fields§
§current: u32
Current energy is how much energy the entity currently has
base_max: u32
Base max is the amount of energy the entity has without considering temporary modifiers such as buffs
maximum: u32
Maximum is the amount of energy the entity has after temporary modifiers are considered
regen_rate: f32
Rate of regeneration per tick. Starts at zero and accelerates.
Implementations§
source§impl Energy
impl Energy
sourcepub const ENERGY_EPSILON: f32 = 2.98032319E-8f32
pub const ENERGY_EPSILON: f32 = 2.98032319E-8f32
Used when comparisons to energy are needed outside this module.
sourceconst MAX_ENERGY: u16 = 65_534u16
const MAX_ENERGY: u16 = 65_534u16
Maximum value allowed for energy before scaling
sourceconst MAX_SCALED_ENERGY: u32 = 16_776_704u32
const MAX_SCALED_ENERGY: u32 = 16_776_704u32
The maximum value allowed for current and maximum energy Maximum value is (u16:MAX - 1) * 256, which only requires 24 bits. This can fit into an f32 with no loss to precision
sourceconst SCALING_FACTOR_FLOAT: f32 = 256f32
const SCALING_FACTOR_FLOAT: f32 = 256f32
The amount energy is scaled by within this module
const SCALING_FACTOR_INT: u32 = 256u32
sourcepub fn needs_maximum_update(&self, modifiers: StatsModifier) -> Option<u32>
pub fn needs_maximum_update(&self, modifiers: StatsModifier) -> Option<u32>
Calculates a new maximum value and returns it if the value differs from the current maximum.
Note: The returned value uses an internal format so don’t expect it to
be useful for anything other than a parameter to
[Self::update_maximum
].
sourcepub fn update_internal_integer_maximum(&mut self, maximum: u32)
pub fn update_internal_integer_maximum(&mut self, maximum: u32)
Updates the maximum value for energy.
Note: The accepted u32
value is in the internal format of this type.
So attempting to pass values that weren’t returned from
Self::needs_maximum_update
can produce strange or unexpected
results.
pub fn new(body: Body) -> Self
sourcepub fn needs_regen(&self) -> bool
pub fn needs_regen(&self) -> bool
Returns true
if the current value is less than the maximum
sourcepub fn regen(&mut self, accel: f32, dt: f32)
pub fn regen(&mut self, accel: f32, dt: f32)
Regenerates energy based on the provided acceleration
sourcepub fn needs_regen_rate_reset(&self) -> bool
pub fn needs_regen_rate_reset(&self) -> bool
Checks whether the regen_rate
is zero or not. Returns true if the
value is anything other than 0.0
.
sourcepub fn reset_regen_rate(&mut self)
pub fn reset_regen_rate(&mut self)
Resets the energy regeneration rate to zero
pub fn change_by(&mut self, change: f32)
pub fn try_change_by(&mut self, change: f32) -> Result<(), ()>
pub fn refresh(&mut self)
Trait Implementations§
source§impl<'de> Deserialize<'de> for Energy
impl<'de> Deserialize<'de> for Energy
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 Energy
impl PartialEq for Energy
impl Copy for Energy
impl StructuralPartialEq for Energy
Auto Trait Implementations§
impl Freeze for Energy
impl RefUnwindSafe for Energy
impl Send for Energy
impl Sync for Energy
impl Unpin for Energy
impl UnwindSafe for Energy
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
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
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