Struct EffectSet

Source
pub struct EffectSet<const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const N: usize> EffectSet<N>

Source

pub fn new() -> Result<EffectSet<N>, AttributeError>

Source

pub fn len(&self) -> usize

Number of active effect keys (not the sum of their stacks), at most N.

Source

pub fn is_empty(&self) -> bool

Whether there are no active effects.

Source

pub fn status(&self, key: u32) -> Option<EffectStatus>

Copies the active status for key; missing, expired and zero keys yield None. See the module example for the view’s fields.

Source

pub fn iter(&self) -> impl DoubleEndedIterator + FusedIterator

Iterates over copied statuses without allocation, scanning at most N slots. Order is stable slot order, not key or application order: removal leaves a vacancy and a new key reuses the first vacancy. Refreshes retain their slot. Holding a copied status does not borrow or track the set.

Source

pub fn apply( &mut self, spec: EffectSpec, immune_tags: u64, ) -> Result<bool, AttributeError>

Applies a specification without changing any effect on error or immunity rejection. Compatible reapplications preserve periodic phase and never shorten remaining time. A weaker Strongest application returns true but leaves the active effect unchanged, including its duration.

Source

pub fn refresh_duration( &mut self, key: u32, seconds: f32, ) -> Result<bool, AttributeError>

Ensures an existing effect has at least seconds remaining, without changing its specification, stacks or periodic phase. This never adds an effect and works at capacity. It does not recheck immunity: the host decides whether to refresh an already active effect.

Zero keys and nonfinite durations or durations outside 0.0001..=3600.0 return AttributeError::Invalid before any change, even for missing keys. Valid missing keys return Ok(false); present keys return Ok(true) even if their remaining duration already meets the requested minimum.

use ferravex_play::attributes::{AttributeError, EffectSet, EffectSpec, Stacking};
let mut effects = EffectSet::<1>::new().unwrap();
let mut slow = EffectSpec::modifier(1, 0, 0.5, 1.0);
slow.stacking = Stacking::Stack(3);
effects.apply(slow, 0).unwrap();
effects.advance(0.5).unwrap();
assert_eq!(effects.refresh_duration(1, 2.0), Ok(true));
let status = effects.status(1).unwrap();
assert_eq!(status.remaining_seconds, 2.0);
assert_eq!(status.stacks, 1);
assert_eq!(status.spec, slow);
assert_eq!(effects.refresh_duration(1, f32::NAN), Err(AttributeError::Invalid));
assert_eq!(effects.status(1), Some(status));
assert_eq!(effects.refresh_duration(2, 1.0), Ok(false));
Source

pub fn advance(&mut self, dt: f32) -> Result<[Option<Pulse>; N], AttributeError>

At most N pulse reports regardless of dt; elapsed periodic ticks aggregate. Refreshing an effect preserves its pulse phase, preventing refresh starvation.

Source

pub fn value( &self, attribute: u16, base: f32, min: f32, max: f32, ) -> Result<f32, AttributeError>

Additive-then-multiplicative evaluation, clamped to host bounds.

Source

pub fn tags(&self) -> u64

Source

pub fn remaining(&self, key: u32) -> f32

Source

pub fn take(&mut self, key: u32) -> Option<EffectStatus>

Removes all stacks for key and returns their final status in one operation. Missing, expired and zero keys return None without changes. Other effects retain their slots and state; removal emits no pulse. Reapplying a removed key starts at one stack with a fresh pulse phase.

use ferravex_play::attributes::{EffectSet, EffectSpec};
let mut effects = EffectSet::<1>::new().unwrap();
effects.apply(EffectSpec::modifier(7, 0, 0.5, 2.0), 0).unwrap();
effects.advance(0.5).unwrap();
let removed = effects.take(7).unwrap();
assert_eq!(removed.remaining_seconds, 1.5);
assert_eq!(removed.periodic_progress(), None);
assert!(effects.is_empty());
assert_eq!(effects.take(7), None);
Source

pub fn remove(&mut self, key: u32) -> bool

Removes all stacks for key, returning whether it was present. Use Self::take to also inspect the removed status.

Source

pub fn clear(&mut self)

Trait Implementations§

Source§

impl<const N: usize> Clone for EffectSet<N>

Source§

fn clone(&self) -> EffectSet<N>

Returns a duplicate 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<const N: usize> Debug for EffectSet<N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for EffectSet<N>

§

impl<const N: usize> RefUnwindSafe for EffectSet<N>

§

impl<const N: usize> Send for EffectSet<N>

§

impl<const N: usize> Sync for EffectSet<N>

§

impl<const N: usize> Unpin for EffectSet<N>

§

impl<const N: usize> UnwindSafe for EffectSet<N>

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.