···2626struct MovementSpeed(Stat);
27272828/// Applies a speed boost, which decreases throughout its duration.
2929-#[derive(Component, Default)]
2929+#[derive(Component, Default, Clone)]
3030struct DecayingSpeed {
3131 start_speed_boost: Modifier,
3232}
···4848 return;
4949 }
50505151- commands.entity(*target).with_effect(EffectBundle {
5252- mode: EffectMode::Insert, // Block having multiple of effect stacked on a single target.
5353- bundle: (
5454- Lifetime::from_seconds(2.0), // The duration of the effect.
5555- DecayingSpeed {
5656- start_speed_boost: Modifier {
5757- bonus: 10,
5858- multiplier: 2.0,
5959- },
5151+ commands.entity(*target).with_effect((
5252+ EffectMode::Insert, // Block having multiple of effect stacked on a single target.
5353+ Lifetime::from_seconds(2.0), // The duration of the effect.
5454+ DecayingSpeed {
5555+ start_speed_boost: Modifier {
5656+ bonus: 10,
5757+ multiplier: 2.0,
6058 },
6161- ),
6262- ..default()
6363- });
5959+ },
6060+ ));
6461}
65626663/// Applies the effect to the target. Because of how Immediate Stats works, this needs to run every frame.
···2828struct MovementSpeed(Stat);
29293030/// Applies a speed boost, which decreases throughout its duration.
3131-#[derive(Component, Default)]
3131+#[derive(Component, Default, Clone)]
3232struct DecayingSpeed {
3333 start_speed_boost: Modifier,
3434}
···5252 return;
5353 }
54545555- commands.entity(*target).with_effect(EffectBundle {
5656- mode: EffectMode::Insert, // Block having multiple of effect stacked on a single target.
5757- bundle: (
5858- Lifetime::from_seconds(2.0), // The duration of the effect.
5959- DecayingSpeed {
6060- start_speed_boost: Modifier {
6161- bonus: 10,
6262- multiplier: 2.0,
6363- },
5555+ commands.entity(*target).with_effect((
5656+ EffectMode::Insert, // Block having multiple of effect stacked on a single target.
5757+ Lifetime::from_seconds(2.0), // The duration of the effect.
5858+ DecayingSpeed {
5959+ start_speed_boost: Modifier {
6060+ bonus: 10,
6161+ multiplier: 2.0,
6462 },
6565- ),
6666- ..default()
6767- });
6363+ },
6464+ ));
6865}
69667067/// Applies the effect to the target. Because of how Immediate Stats works, this needs to run every frame.
+8-13
examples/poison.rs
···55//! The `poison_falloff` example shows a different way to handle effect stacking.
6677use bevy::prelude::*;
88-use bevy_alchemy::{
99- AlchemyPlugin, Delay, EffectBundle, EffectCommandsExt, EffectTimer, Effecting, Lifetime,
1010-};
88+use bevy_alchemy::{AlchemyPlugin, Delay, EffectCommandsExt, EffectTimer, Effecting, Lifetime};
1191210fn main() {
1311 App::new()
···2220struct Health(i32);
23212422/// Deals damage over time to the target entity.
2525-#[derive(Component, Default)]
2323+#[derive(Component, Default, Clone)]
2624struct Poison {
2725 damage: i32,
2826}
···4442 return;
4543 }
46444747- commands.entity(*target).with_effect(EffectBundle {
4848- bundle: (
4949- Lifetime::from_seconds(3.0), // The duration of the effect.
5050- Delay::from_seconds(1.0) // The time between damage ticks.
5151- .trigger_immediately(), // Make damage tick immediately when the effect is applied.
5252- Poison { damage: 1 }, // The amount of damage to apply per tick.
5353- ),
5454- ..default()
5555- });
4545+ commands.entity(*target).with_effect((
4646+ Lifetime::from_seconds(3.0), // The duration of the effect.
4747+ Delay::from_seconds(1.0) // The time between damage ticks.
4848+ .trigger_immediately(), // Make damage tick immediately when the effect is applied.
4949+ Poison { damage: 1 }, // The amount of damage to apply per tick.
5050+ ));
5651}
57525853/// Runs every frame and deals the poison damage.
+11-14
examples/poison_falloff.rs
···991010use bevy::prelude::*;
1111use bevy_alchemy::{
1212- AlchemyPlugin, Delay, EffectBundle, EffectCommandsExt, EffectMode, EffectStacks, EffectTimer,
1313- Effecting, Lifetime,
1212+ AlchemyPlugin, Delay, EffectCommandsExt, EffectMode, EffectStacks, EffectTimer, Effecting,
1313+ Lifetime,
1414};
15151616fn main() {
···2626struct Health(i32);
27272828/// Deals damage over time to the target entity.
2929-#[derive(Component, Default)]
2929+#[derive(Component, Default, Clone)]
3030struct Poison {
3131 damage: i32,
3232}
···4848 return;
4949 }
50505151- commands.entity(*target).with_effect(EffectBundle {
5252- mode: EffectMode::Merge, // Stack tracking requires effect merging.
5353- bundle: (
5454- EffectStacks::default(), // Enable stack tracking.
5555- Lifetime::from_seconds(3.0), // The duration of the effect.
5656- Delay::from_seconds(1.0) // The time between damage ticks.
5757- .trigger_immediately(), // Make damage tick immediately when the effect is applied.
5858- Poison { damage: 5 }, // The amount of damage to apply per tick.
5959- ),
6060- ..default()
6161- });
5151+ commands.entity(*target).with_effect((
5252+ EffectMode::Merge, // Stack tracking requires effect merging.
5353+ EffectStacks::default(), // Enable stack tracking.
5454+ Lifetime::from_seconds(3.0), // The duration of the effect.
5555+ Delay::from_seconds(1.0) // The time between damage ticks.
5656+ .trigger_immediately(), // Make damage tick immediately when the effect is applied.
5757+ Poison { damage: 5 }, // The amount of damage to apply per tick.
5858+ ));
6259}
63606461/// Runs every frame and deals the poison damage.