pub struct EffectSet<const N: usize> { /* private fields */ }Implementations§
Source§impl<const N: usize> EffectSet<N>
impl<const N: usize> EffectSet<N>
pub fn new() -> Result<EffectSet<N>, AttributeError>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of active effect keys (not the sum of their stacks), at most N.
Sourcepub fn status(&self, key: u32) -> Option<EffectStatus>
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.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator + FusedIterator
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.
Sourcepub fn apply(
&mut self,
spec: EffectSpec,
immune_tags: u64,
) -> Result<bool, AttributeError>
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.
Sourcepub fn refresh_duration(
&mut self,
key: u32,
seconds: f32,
) -> Result<bool, AttributeError>
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));Sourcepub fn advance(&mut self, dt: f32) -> Result<[Option<Pulse>; N], AttributeError>
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.
Sourcepub fn value(
&self,
attribute: u16,
base: f32,
min: f32,
max: f32,
) -> Result<f32, AttributeError>
pub fn value( &self, attribute: u16, base: f32, min: f32, max: f32, ) -> Result<f32, AttributeError>
Additive-then-multiplicative evaluation, clamped to host bounds.
pub fn remaining(&self, key: u32) -> f32
Sourcepub fn take(&mut self, key: u32) -> Option<EffectStatus>
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);Sourcepub fn remove(&mut self, key: u32) -> bool
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.