td

Artifact [cdeb3efc4a]
Login

Artifact [cdeb3efc4a]

Artifact cdeb3efc4a001b9d3c9a5d736b1c39d590591e1e461da3e552c2366a5d827a39:


//! Impact — the base hit. Seeded as the tower's default loadout; reads the `HitContext`
//! damage accumulator so modifiers that ran earlier in the pipeline scale its damage.

use crate::{
    animations::{AnimationSet, VisualPriority, visual_slots},
    behavior::projectile::{BehaviorPriority, HitResponse, ProjectileBehavior},
    context::HitContext,
    enemy::Enemy,
    registry::{AnimationID, DamageID},
    world::Projectile,
};

#[derive(Clone)]
pub struct TowerBaseWeapon {
    tier: u32,
    base_damage: f32,
    pct_bonus: f32,
    damage_type: DamageID,
    end_animation: AnimationID,
}

impl TowerBaseWeapon {
    pub fn create(
        tier: u32,
        damage_type: DamageID,
        end_animation: AnimationID,
    ) -> Box<dyn ProjectileBehavior> {
        Box::new(Self {
            tier,
            base_damage: tier as f32,
            pct_bonus: 0.11 * (tier - 1) as f32,
            damage_type,
            end_animation,
        })
    }
}

impl ProjectileBehavior for TowerBaseWeapon {
    fn contribute_animations(&self, animations: &mut AnimationSet) {
        animations.insert(
            visual_slots::END,
            self.end_animation,
            VisualPriority::DEFAULT,
        );
    }

    fn priority(&self) -> i32 {
        BehaviorPriority::IMPACT
    }
    fn on_hit_enemy(
        &mut self,
        _p: &mut Projectile,
        _e: &mut Enemy,
        c: &mut HitContext,
    ) -> HitResponse {
        c.damage.flat(self.damage_type, self.base_damage);
        c.damage.increased(self.damage_type, self.pct_bonus);
        HitResponse::PASS
    }
}