add ramtower

This commit is contained in:
Jim 2025-09-02 15:04:01 -04:00
parent 23af12d258
commit 3e42fb6cf1
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
9 changed files with 356 additions and 7 deletions

View file

@ -59,6 +59,8 @@ pub struct ProjectileLauncher {
pub spread: f32,
pub lifetime: Duration,
pub damage: f32,
/// will set fields in the fire event to be defaults, responsiblity of the building to set them up
pub custom_targeting: bool,
}
impl ProjectileLauncher {
@ -75,6 +77,7 @@ impl ProjectileLauncher {
damage,
fire_offset,
lifetime,
custom_targeting: false,
}
}
@ -86,6 +89,8 @@ impl ProjectileLauncher {
#[derive(Event)]
pub struct Fire {
pub target: Entity,
pub damage: f32,
pub enemies_in_range: Vec<Entity>,
pub target_pos: Vec3,
pub spawn_pos: Vec3,
pub launcher: ProjectileLauncher,
@ -123,6 +128,22 @@ fn fire_launcher(
if enemies.is_empty() {
continue;
}
if launcher.custom_targeting {
launcher.fire_timer.reset();
commands.trigger_targets(
Fire {
target: Entity::PLACEHOLDER,
damage: launcher.damage,
target_pos: Vec3::ZERO,
enemies_in_range: enemies,
spawn_pos: gtf.translation() + launcher.fire_offset,
launcher: launcher.clone(),
team: team.clone(),
},
[launcher_entity],
);
continue;
}
let Some((closest_enemy, enemy_pos)) = enemies
.iter()
.filter_map(|e| {
@ -151,6 +172,8 @@ fn fire_launcher(
Fire {
target: closest_enemy,
target_pos: enemy_pos,
damage: launcher.damage,
enemies_in_range: enemies,
spawn_pos: gtf.translation() + launcher.fire_offset,
launcher: launcher.clone(),
team: team.clone(),