pub struct Health {
current: u32,
base_max: u32,
maximum: u32,
pub last_change: HealthChange,
pub is_dead: bool,
pub can_have_death_protection: bool,
pub death_protection: bool,
damage_contributors: HashMap<DamageContributor, (u64, Time)>,
}Expand description
Health is represented by u32s within the module, but treated as a float by the rest of the game.
Fields§
§current: u32§base_max: u32§maximum: u32§last_change: HealthChangeThe last change to health
is_dead: bool§can_have_death_protection: boolIf this entity supports having death protection.
death_protection: boolIf death protection is true, any damage that would kill instead leaves the entity at 1 health.
damage_contributors: HashMap<DamageContributor, (u64, Time)>Implementations§
Source§impl Health
impl Health
Sourcepub const HEALTH_EPSILON: f32
pub const HEALTH_EPSILON: f32
Used when comparisons to health are needed outside this module.
Sourcepub fn set_fraction(&mut self, fraction: f32)
pub fn set_fraction(&mut self, fraction: f32)
Instantly set the health fraction.
pub fn set_amount(&mut self, amount: f32)
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_internal_integer_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 health.
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) -> Health
Sourcepub fn change_by(&mut self, change: HealthChange) -> bool
pub fn change_by(&mut self, change: HealthChange) -> bool
Returns a boolean if the delta was not zero.
pub fn damage_contributions( &self, ) -> impl Iterator<Item = (&DamageContributor, &u64)>
pub fn recent_damagers(&self) -> impl Iterator<Item = (Uid, Time)>
pub fn should_die(&self) -> bool
pub fn kill(&mut self)
pub fn revive(&mut self)
pub fn consume_death_protection(&mut self)
pub fn refresh_death_protection(&mut self)
pub fn has_consumed_death_protection(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Health
impl<'de> Deserialize<'de> for Health
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Health, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Health, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<Health> for EcsCompPacket
impl From<Health> for EcsCompPacket
Source§fn from(other: Health) -> EcsCompPacket
fn from(other: Health) -> EcsCompPacket
Source§impl NetSync for Health
impl NetSync for Health
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)
Source§impl Serialize for Health
impl Serialize for Health
Source§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 Health
impl RefUnwindSafe for Health
impl Send for Health
impl Sync for Health
impl Unpin for Health
impl UnsafeUnpin for Health
impl UnwindSafe for Health
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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 functionimpl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> Event for T
§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