//! 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
    }
}
