feat: implemented extra status effect effectiveness and duration

This commit is contained in:
TotallyNot 2025-11-04 19:38:02 +01:00
parent 9b720facf8
commit 39c6714317
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
3 changed files with 68 additions and 12 deletions

View file

@ -562,7 +562,6 @@ fn use_damaging_weapon(
_ => 0.0,
})
.unwrap_or_default();
// TODO: special ammo
let mut dmg = dmg_intrinsic
* w_dmg.0

View file

@ -162,16 +162,54 @@ where
M: AdditiveStatusEffectMarker<N>,
{
marker: PhantomData<M>,
extra_effectiveness: f32,
extra_duration: f32,
}
impl<const N: usize, M: AdditiveStatusEffectMarker<N>> Default for AdditiveStatusEffect<N, M> {
fn default() -> Self {
Self {
marker: PhantomData,
extra_effectiveness: 0.0,
extra_duration: 0.0,
}
}
}
#[derive(Component)]
pub struct ExtraStatusEffectEffectiveness<const N: usize, M>
where
M: AdditiveStatusEffectMarker<N>,
{
marker: PhantomData<M>,
pub factor: f32,
}
impl<const N: usize, M> ExtraStatusEffectEffectiveness<N, M>
where
M: AdditiveStatusEffectMarker<N>,
{
pub fn new(factor: f32) -> Self {
Self {
marker: PhantomData,
factor,
}
}
}
#[derive(Component)]
pub struct ExtraStatusEffectDuration<const N: usize, M>
where
M: AdditiveStatusEffectMarker<N>,
{
marker: PhantomData<M>,
pub factor: f32,
}
impl<const N: usize, M> ExtraStatusEffectDuration<N, M>
where
M: AdditiveStatusEffectMarker<N>,
{
pub fn new(factor: f32) -> Self {
Self {
marker: PhantomData,
factor,
}
}
}
@ -383,30 +421,34 @@ impl DamageOverTimeMarker for Bleed {
fn apply_additive_status_effect<const N: usize, M: AdditiveStatusEffectMarker<N>>(
In(entities): In<Vec<Entity>>,
effect_q: Query<(Entity, &ChildOf, &AdditiveStatusEffect<N, M>)>,
mut parent_q: Query<Option<&mut StatusEffectStack<M>>>,
effect_q: Query<(Entity, &ChildOf)>,
mut parent_q: Query<(
Option<&mut StatusEffectStack<M>>,
Option<&ExtraStatusEffectDuration<N, M>>,
Option<&ExtraStatusEffectEffectiveness<N, M>>,
)>,
mut commands: Commands,
mut effects: Effects,
mut logger: Logger,
) {
for (entity, player, effect) in effect_q.iter_many(entities) {
for (entity, player) in effect_q.iter_many(entities) {
log!(logger, "apply_status_effect", {
recipient: player.parent(),
effect: std::any::type_name::<M>(),
});
let stack = parent_q.get_mut(player.parent()).unwrap();
let (stack, extra_duration, extra_effect) = parent_q.get_mut(player.parent()).unwrap();
let new_effects = <M::AffectedStats as Stats<N>>::spawn_additive_effects(
&mut effects,
player.parent(),
M::factor() * (1.0 + effect.extra_effectiveness),
M::factor() * extra_effect.map_or(1.0, |e| e.factor),
std::any::type_name::<M>(),
);
commands.entity(entity).insert((
LinkedComponents(new_effects),
TimeLimitedEffect(M::duration() * (1.0 + effect.extra_duration)),
TimeLimitedEffect(M::duration() * extra_duration.map_or(1.0, |e| e.factor)),
));
if let Some(mut stack) = stack {