pub struct AttributeInstance {
attribute: AttributeRef,
base_value: f64,
modifiers: Vec<AttributeModifier>,
persistent: Vec<bool>,
cached_value: f64,
}Expand description
Runtime state for a single attribute on an entity
Fields§
§attribute: AttributeRef§base_value: f64§modifiers: Vec<AttributeModifier>§persistent: Vec<bool>Parallel to modifiers true means the modifier survives serialization
cached_value: f64Implementations§
Source§impl AttributeInstance
impl AttributeInstance
const fn new(attribute: AttributeRef, base_value: f64) -> Self
Sourcepub const fn base_value(&self) -> f64
pub const fn base_value(&self) -> f64
Returns the base value before modifiers
Sourcepub fn set_base_value(&mut self, value: f64) -> bool
pub fn set_base_value(&mut self, value: f64) -> bool
Sets the base value and recalculates. Returns true if changed
Sourcepub const fn value(&self) -> f64
pub const fn value(&self) -> f64
Returns the final calculated value (base + modifiers, clamped)
Sourcepub fn add_modifier(
&mut self,
modifier: AttributeModifier,
persistent: bool,
) -> bool
pub fn add_modifier( &mut self, modifier: AttributeModifier, persistent: bool, ) -> bool
Adds a modifier. Returns false if a modifier with this ID already exists
Sourcepub fn has_modifier(&self, id: &Identifier) -> bool
pub fn has_modifier(&self, id: &Identifier) -> bool
Returns whether a modifier with the given ID exists.
Sourcepub fn set_modifier(
&mut self,
modifier: AttributeModifier,
persistent: bool,
) -> bool
pub fn set_modifier( &mut self, modifier: AttributeModifier, persistent: bool, ) -> bool
Adds or replaces a modifier. Returns true if the value actually changed.
Sourcepub fn remove_modifier(&mut self, id: &Identifier) -> bool
pub fn remove_modifier(&mut self, id: &Identifier) -> bool
Removes a modifier by ID, Returns true if it existed
Sourcepub fn permanent_modifiers(&self) -> impl Iterator<Item = &AttributeModifier>
pub fn permanent_modifiers(&self) -> impl Iterator<Item = &AttributeModifier>
Returns an iterator over permanent modifiers (for serialization)
Sourcefn remove_transient_modifiers(&mut self) -> bool
fn remove_transient_modifiers(&mut self) -> bool
Removes all transient (non-persistent) modifiers. Returns true if any were removed
Sourcefn recalculate(&mut self)
fn recalculate(&mut self)
Three-phase vanilla calculation:
ADD_VALUEADD_MULTIPLIED_BASEADD_MULTIPLIED_TOTAL
Sourcefn to_snapshot(&self, attribute_id: i32) -> AttributeSnapshot
fn to_snapshot(&self, attribute_id: i32) -> AttributeSnapshot
Builds a network snapshot for CUpdateAttributes
Auto Trait Implementations§
impl Freeze for AttributeInstance
impl RefUnwindSafe for AttributeInstance
impl Send for AttributeInstance
impl Sync for AttributeInstance
impl Unpin for AttributeInstance
impl UnsafeUnpin for AttributeInstance
impl UnwindSafe for AttributeInstance
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreArc<SyncMutex<>>