Compare commits
No commits in common. "4c5a650a1ac12bc3d2e6abe2d5b7e30cf20fe008" and "23af12d258f6c0f039f9e8b02ce3291caa78e94c" have entirely different histories.
4c5a650a1a
...
23af12d258
11 changed files with 12 additions and 707 deletions
31
Cargo.lock
generated
31
Cargo.lock
generated
|
|
@ -1687,35 +1687,6 @@ dependencies = [
|
|||
"ui_range_indicator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "building_ramtower"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"avian3d",
|
||||
"bevy",
|
||||
"building",
|
||||
"combat",
|
||||
"combat_damagers",
|
||||
"inhabitant_endrake",
|
||||
"resources",
|
||||
"state",
|
||||
"upgrade",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "building_suncannon"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"avian3d",
|
||||
"bevy",
|
||||
"building",
|
||||
"combat",
|
||||
"combat_damagers",
|
||||
"resources",
|
||||
"state",
|
||||
"upgrade",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.0"
|
||||
|
|
@ -2034,8 +2005,6 @@ dependencies = [
|
|||
"building_core",
|
||||
"building_impaler",
|
||||
"building_placement",
|
||||
"building_ramtower",
|
||||
"building_suncannon",
|
||||
"camera",
|
||||
"combat",
|
||||
"combat_damagers",
|
||||
|
|
|
|||
|
|
@ -61,6 +61,4 @@ ui_range_indicator = { path = "crates/ui_range_indicator" }
|
|||
inhabitant_simbert = { path = "crates/inhabitant_simbert" }
|
||||
inhabitant_endrake = { path = "crates/inhabitant_endrake" }
|
||||
resource_soul_spot = { path = "crates/resource_soul_spot" }
|
||||
building_ramtower = { path = "crates/building_ramtower" }
|
||||
building_suncannon = { path = "crates/building_suncannon" }
|
||||
#new internal crates go here
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@
|
|||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
],
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
],
|
||||
KeyCode(ShiftLeft): [
|
||||
MultiPlaceTower,
|
||||
],
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
],
|
||||
MouseScroll: [
|
||||
CameraZoom,
|
||||
],
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
],
|
||||
MouseMovementX: [
|
||||
CameraYaw,
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
[package]
|
||||
name = "building_ramtower"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
avian3d = { workspace = true }
|
||||
|
||||
state = { path = "../state" }
|
||||
combat = { path = "../combat" }
|
||||
building = { path = "../building" }
|
||||
resources = { path = "../resources" }
|
||||
combat_damagers = { path = "../combat_damagers" }
|
||||
upgrade = { path = "../upgrade" }
|
||||
inhabitant_endrake = { path = "../inhabitant_endrake" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
@ -1,286 +0,0 @@
|
|||
//bevy system signatures often violate these rules
|
||||
#![allow(clippy::type_complexity)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use std::{cmp::Ordering, f32, time::Duration};
|
||||
|
||||
use avian3d::prelude::{Collider, GravityScale, LinearVelocity, RigidBody};
|
||||
use bevy::prelude::*;
|
||||
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{
|
||||
Defense, Health, Range, Team,
|
||||
projectiles::{Fire, Projectile, ProjectileLauncher},
|
||||
};
|
||||
use combat_damagers::ContactDamage;
|
||||
use inhabitant_endrake::Endrake;
|
||||
use resources::{Cost, Quantity};
|
||||
use upgrade::{Upgrade, UpgradeApplied, UpgradeTree};
|
||||
|
||||
pub struct BuildingRamtowerPlugin;
|
||||
|
||||
impl Plugin for BuildingRamtowerPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, register).add_observer(populate);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Ramtower {
|
||||
pub prioritize_endrakes: bool,
|
||||
pub shot_velocity: f32,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct BuildingResources {
|
||||
mesh: Handle<Mesh>,
|
||||
material: Handle<StandardMaterial>,
|
||||
projectile_mesh: Handle<Mesh>,
|
||||
projectile_material: Handle<StandardMaterial>,
|
||||
projectile_collider: Collider,
|
||||
info_entity: Entity,
|
||||
}
|
||||
|
||||
const SIZE: UVec3 = UVec3::new(1, 4, 1);
|
||||
const PROJ_SIZE: Vec3 = Vec3::new(0.5, 0.5, 2.0);
|
||||
|
||||
fn register(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let mesh = meshes.add(Cuboid::from_size(SIZE.as_vec3()));
|
||||
let base_material = StandardMaterial {
|
||||
base_color: Color::srgb_u8(152, 174, 174),
|
||||
metallic: 0.2,
|
||||
perceptual_roughness: 0.6,
|
||||
..default()
|
||||
};
|
||||
let material = materials.add(base_material.clone());
|
||||
let preview_material = materials.add(StandardMaterial {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
base_color: base_material.base_color.with_alpha(PREVIEW_ALPHA),
|
||||
..base_material
|
||||
});
|
||||
let projectile_material = materials.add(StandardMaterial {
|
||||
base_color: Color::srgb_u8(86, 106, 106),
|
||||
metallic: 1.0,
|
||||
perceptual_roughness: 0.0,
|
||||
emissive: Color::srgb_u8(86, 106, 106).to_linear() * 0.3,
|
||||
..default()
|
||||
});
|
||||
|
||||
let info = commands.spawn_empty().id();
|
||||
let test_unlocks = vec![
|
||||
commands
|
||||
.spawn((
|
||||
Name::new("Endrake Assassain"),
|
||||
Upgrade {
|
||||
description:
|
||||
"Ramtower will prioritize destroying Endrakes. Deals even more damage."
|
||||
.to_string(),
|
||||
cost: Quantity {
|
||||
souls: 50,
|
||||
bones: 20,
|
||||
},
|
||||
unlocks: vec![],
|
||||
},
|
||||
))
|
||||
.observe(
|
||||
|trigger: Trigger<UpgradeApplied>,
|
||||
mut query: Query<(&mut Ramtower, &mut ProjectileLauncher)>| {
|
||||
if let Ok((mut ramtower, mut launcher)) =
|
||||
query.get_mut(trigger.event().building)
|
||||
{
|
||||
ramtower.prioritize_endrakes = true;
|
||||
launcher.damage *= 1.5;
|
||||
}
|
||||
},
|
||||
)
|
||||
.id(),
|
||||
commands
|
||||
.spawn((
|
||||
Name::new("Fortification"),
|
||||
Upgrade {
|
||||
description: "Fortified battering rams significantly more damage. Defense increases as well.".to_string(),
|
||||
cost: Quantity {
|
||||
souls: 50,
|
||||
bones: 10,
|
||||
},
|
||||
unlocks: vec![],
|
||||
},
|
||||
))
|
||||
.observe(
|
||||
|trigger: Trigger<UpgradeApplied>, mut query: Query<(&mut ProjectileLauncher, &mut Defense)>| {
|
||||
if let Ok((mut launcher, mut defense)) = query.get_mut(trigger.event().building) {
|
||||
launcher.damage *= 2.;
|
||||
defense.amount += 5.;
|
||||
}
|
||||
},
|
||||
)
|
||||
.id(),
|
||||
];
|
||||
let upgrades = vec![
|
||||
commands
|
||||
.spawn((
|
||||
Name::new("More Force"),
|
||||
Upgrade {
|
||||
description: "Battering rams move faster and can be launched farther."
|
||||
.to_string(),
|
||||
cost: Quantity {
|
||||
souls: 25,
|
||||
bones: 10,
|
||||
},
|
||||
unlocks: test_unlocks,
|
||||
},
|
||||
))
|
||||
.observe(
|
||||
|trigger: Trigger<UpgradeApplied>,
|
||||
mut query: Query<(&mut Ramtower, &mut Range)>| {
|
||||
if let Ok((mut ramtower, mut range)) = query.get_mut(trigger.event().building) {
|
||||
ramtower.shot_velocity += 20.;
|
||||
range.0 *= 1.5;
|
||||
}
|
||||
},
|
||||
)
|
||||
.id(),
|
||||
];
|
||||
let preview = commands
|
||||
.spawn((
|
||||
BuildingPreview { info },
|
||||
Visibility::Hidden,
|
||||
Mesh3d(mesh.clone()),
|
||||
MeshMaterial3d(preview_material),
|
||||
))
|
||||
.id();
|
||||
commands.entity(info).insert((
|
||||
BuildingInfo {
|
||||
preview,
|
||||
size: SIZE,
|
||||
unlocked: true,
|
||||
},
|
||||
Range(10.0),
|
||||
Health::new(10.0),
|
||||
Defense::new(4.0),
|
||||
UpgradeTree { upgrades },
|
||||
Cost(Quantity {
|
||||
souls: 5,
|
||||
bones: 15,
|
||||
}),
|
||||
Name::new("Ramtower"),
|
||||
));
|
||||
commands.insert_resource(BuildingResources {
|
||||
mesh: mesh,
|
||||
material: material.clone(),
|
||||
projectile_material: projectile_material,
|
||||
projectile_mesh: meshes.add(Cuboid::from_size(PROJ_SIZE)),
|
||||
projectile_collider: Collider::cuboid(PROJ_SIZE.x, PROJ_SIZE.y, PROJ_SIZE.z),
|
||||
info_entity: info,
|
||||
});
|
||||
}
|
||||
|
||||
fn populate(
|
||||
trigger: Trigger<PopulatePlacedBuilding>,
|
||||
mut commands: Commands,
|
||||
res: Res<BuildingResources>,
|
||||
) {
|
||||
if trigger.event().info != res.info_entity {
|
||||
return;
|
||||
}
|
||||
commands
|
||||
.entity(trigger.target())
|
||||
.insert((
|
||||
Ramtower {
|
||||
prioritize_endrakes: false,
|
||||
shot_velocity: 20.,
|
||||
},
|
||||
ContactDamage::new(2.0),
|
||||
ProjectileLauncher {
|
||||
custom_targeting: true,
|
||||
..ProjectileLauncher::new(
|
||||
Duration::from_secs(1),
|
||||
50.0,
|
||||
Vec3::Y * (SIZE.y as f32 + 0.5),
|
||||
Duration::from_secs(10),
|
||||
0.,
|
||||
)
|
||||
},
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
))
|
||||
.observe(on_fire);
|
||||
}
|
||||
|
||||
fn on_fire(
|
||||
trigger: Trigger<Fire>,
|
||||
query: Query<(&GlobalTransform, &Team, &Ramtower)>,
|
||||
mut commands: Commands,
|
||||
res: Res<BuildingResources>,
|
||||
enemy_query: Query<(&Team, &GlobalTransform, Option<&Endrake>)>,
|
||||
) {
|
||||
let Ok((
|
||||
gtf,
|
||||
team,
|
||||
Ramtower {
|
||||
prioritize_endrakes: prioritize_endrake,
|
||||
shot_velocity,
|
||||
},
|
||||
)) = query.get(trigger.target())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Some((target_pos, _endrake)) = trigger
|
||||
.event()
|
||||
.enemies_in_range
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
enemy_query
|
||||
.get(*e)
|
||||
.ok()
|
||||
.and_then(|(enemy_team, enemy_gtf, opt_endrake)| {
|
||||
if enemy_team != team {
|
||||
Some((enemy_gtf.translation(), opt_endrake))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
.min_by(|(a, a_e), (b, b_e)| {
|
||||
if *prioritize_endrake {
|
||||
// put endrakes first
|
||||
if a_e.is_some() && b_e.is_none() {
|
||||
Ordering::Less
|
||||
} else if a_e.is_none() && b_e.is_some() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
// default to distance if both are endrakes
|
||||
gtf.translation()
|
||||
.distance_squared(*a)
|
||||
.total_cmp(>f.translation().distance_squared(*b))
|
||||
}
|
||||
} else {
|
||||
// default to closest by distance
|
||||
gtf.translation()
|
||||
.distance_squared(*a)
|
||||
.total_cmp(>f.translation().distance_squared(*b))
|
||||
}
|
||||
})
|
||||
else {
|
||||
info!("no closest enemy, is someone on the wrong physics layer for their team?");
|
||||
return;
|
||||
};
|
||||
let delta = (target_pos - trigger.event().spawn_pos).normalize_or_zero();
|
||||
commands.spawn((
|
||||
RigidBody::Dynamic,
|
||||
trigger.event().team,
|
||||
Health::new(1.0),
|
||||
GravityScale(0.0),
|
||||
ContactDamage::projectile(trigger.event().damage, f32::INFINITY),
|
||||
Transform::from_translation(trigger.event().spawn_pos).looking_at(target_pos, Vec3::Y),
|
||||
Projectile::from(&trigger.event().launcher),
|
||||
Projectile::collision_layers(trigger.event().team),
|
||||
LinearVelocity(delta * shot_velocity),
|
||||
res.projectile_collider.clone(),
|
||||
MeshMaterial3d(res.projectile_material.clone()),
|
||||
Mesh3d(res.projectile_mesh.clone()),
|
||||
));
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
[package]
|
||||
name = "building_suncannon"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
avian3d = { workspace = true }
|
||||
|
||||
state = { path = "../state" }
|
||||
combat = { path = "../combat" }
|
||||
building = { path = "../building" }
|
||||
resources = { path = "../resources" }
|
||||
combat_damagers = { path = "../combat_damagers" }
|
||||
upgrade = { path = "../upgrade" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
@ -1,312 +0,0 @@
|
|||
//bevy system signatures often violate these rules
|
||||
#![allow(clippy::type_complexity)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use std::{
|
||||
f32::{self, consts::PI},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{
|
||||
Attacked, Defense, Died, Health, Range, Team,
|
||||
projectiles::{Fire, Projectile, ProjectileLauncher, get_launch_vector},
|
||||
};
|
||||
use combat_damagers::ContactDamage;
|
||||
use resources::{Cost, Quantity};
|
||||
use upgrade::{Upgrade, UpgradeApplied, UpgradeTree};
|
||||
|
||||
pub struct BuildingSuncannonPlugin;
|
||||
|
||||
impl Plugin for BuildingSuncannonPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, register).add_observer(populate);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
pub struct Suncannon {
|
||||
pub explosion_radius: f32,
|
||||
pub explosion_damage: f32,
|
||||
pub explosion_knockback: f32,
|
||||
pub pellet_count: u32,
|
||||
pub pellet_damage: f32,
|
||||
pub pellet_speed: f32,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct SuncannonProjectile(Suncannon);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct BuildingResources {
|
||||
mesh: Handle<Mesh>,
|
||||
material: Handle<StandardMaterial>,
|
||||
projectile_mesh: Handle<Mesh>,
|
||||
projectile_material: Handle<StandardMaterial>,
|
||||
projectile_collider: Collider,
|
||||
info_entity: Entity,
|
||||
}
|
||||
|
||||
const SIZE: UVec3 = UVec3::new(3, 1, 3);
|
||||
const PROJ_SIZE: Vec3 = Vec3::new(1.0, 1.0, 1.0);
|
||||
|
||||
fn register(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let mesh = meshes.add(Cuboid::from_size(SIZE.as_vec3()));
|
||||
let base_material = StandardMaterial {
|
||||
base_color: Color::srgb_u8(173, 114, 57),
|
||||
metallic: 0.8,
|
||||
perceptual_roughness: 0.0,
|
||||
emissive: Color::srgb_u8(173, 114, 57).to_linear(),
|
||||
..default()
|
||||
};
|
||||
let material = materials.add(base_material.clone());
|
||||
let preview_material = materials.add(StandardMaterial {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
base_color: base_material.base_color.with_alpha(PREVIEW_ALPHA),
|
||||
..base_material
|
||||
});
|
||||
let projectile_material = materials.add(StandardMaterial {
|
||||
base_color: Color::srgb_u8(242, 151, 70),
|
||||
metallic: 0.8,
|
||||
perceptual_roughness: 0.0,
|
||||
emissive: Color::srgb_u8(250, 211, 150).to_linear() * 5.,
|
||||
..default()
|
||||
});
|
||||
|
||||
let info = commands.spawn_empty().id();
|
||||
let tier3 = vec![
|
||||
commands
|
||||
.spawn((
|
||||
Name::new("Sun Geyser"),
|
||||
Upgrade {
|
||||
description: "I AM THE SUN!".to_string(),
|
||||
cost: Quantity {
|
||||
souls: 1000,
|
||||
bones: 0,
|
||||
},
|
||||
unlocks: vec![],
|
||||
},
|
||||
))
|
||||
.observe(
|
||||
|trigger: Trigger<UpgradeApplied>,
|
||||
mut query: Query<(&mut Range, &mut ProjectileLauncher, &mut Suncannon)>| {
|
||||
if let Ok((mut range, mut launcher, mut suncannon)) = query.get_mut(trigger.event().building) {
|
||||
range.0 += 10.;
|
||||
let new_duration = launcher.fire_timer.duration() / 4;
|
||||
launcher.set_interval(new_duration);
|
||||
suncannon.pellet_damage *= 2.;
|
||||
}
|
||||
},
|
||||
)
|
||||
.id(),
|
||||
];
|
||||
let tier2 = vec![
|
||||
commands
|
||||
.spawn((
|
||||
Name::new("Solar Power"),
|
||||
Upgrade {
|
||||
description: "I WILL PUSH THEM ALL BACK. (WITH FORCE)".to_string(),
|
||||
cost: Quantity {
|
||||
souls: 500,
|
||||
bones: 0,
|
||||
},
|
||||
unlocks: tier3,
|
||||
},
|
||||
))
|
||||
.observe(
|
||||
|trigger: Trigger<UpgradeApplied>,
|
||||
mut query: Query<(&mut ProjectileLauncher, &mut Suncannon)>| {
|
||||
if let Ok((mut launcher, mut suncannon)) =
|
||||
query.get_mut(trigger.event().building)
|
||||
{
|
||||
launcher.damage *= 1.5;
|
||||
suncannon.explosion_damage *= 2.;
|
||||
suncannon.explosion_knockback *= 2.;
|
||||
suncannon.pellet_damage *= 2.;
|
||||
}
|
||||
},
|
||||
)
|
||||
.id(),
|
||||
];
|
||||
let upgrades = vec![
|
||||
commands
|
||||
.spawn((
|
||||
Name::new("Sun Pellets"),
|
||||
Upgrade {
|
||||
description: "THEY WILL EAT THIS! AND NOT LIKE IT!".to_string(),
|
||||
cost: Quantity {
|
||||
souls: 200,
|
||||
bones: 0,
|
||||
},
|
||||
unlocks: tier2,
|
||||
},
|
||||
))
|
||||
.observe(
|
||||
|trigger: Trigger<UpgradeApplied>, mut query: Query<&mut Suncannon>| {
|
||||
if let Ok(mut suncannon) = query.get_mut(trigger.event().building) {
|
||||
suncannon.pellet_count += 5;
|
||||
}
|
||||
},
|
||||
)
|
||||
.id(),
|
||||
];
|
||||
let preview = commands
|
||||
.spawn((
|
||||
BuildingPreview { info },
|
||||
Visibility::Hidden,
|
||||
Mesh3d(mesh.clone()),
|
||||
MeshMaterial3d(preview_material),
|
||||
))
|
||||
.id();
|
||||
commands.entity(info).insert((
|
||||
BuildingInfo {
|
||||
preview,
|
||||
size: SIZE,
|
||||
unlocked: true,
|
||||
},
|
||||
Range(20.0),
|
||||
Health::new(50.0),
|
||||
Defense::new(6.0),
|
||||
UpgradeTree { upgrades },
|
||||
Cost(Quantity {
|
||||
souls: 100,
|
||||
bones: 15,
|
||||
}),
|
||||
Name::new("Suncannon"),
|
||||
));
|
||||
commands.insert_resource(BuildingResources {
|
||||
mesh: mesh,
|
||||
material: material.clone(),
|
||||
projectile_material: projectile_material,
|
||||
projectile_mesh: meshes.add(Cuboid::from_size(PROJ_SIZE)),
|
||||
projectile_collider: Collider::cuboid(PROJ_SIZE.x, PROJ_SIZE.y, PROJ_SIZE.z),
|
||||
info_entity: info,
|
||||
});
|
||||
}
|
||||
|
||||
fn populate(
|
||||
trigger: Trigger<PopulatePlacedBuilding>,
|
||||
mut commands: Commands,
|
||||
res: Res<BuildingResources>,
|
||||
) {
|
||||
if trigger.event().info != res.info_entity {
|
||||
return;
|
||||
}
|
||||
commands
|
||||
.entity(trigger.target())
|
||||
.insert((
|
||||
Suncannon {
|
||||
explosion_radius: 10.0,
|
||||
explosion_damage: 20.0,
|
||||
explosion_knockback: 5.0,
|
||||
pellet_count: 0,
|
||||
pellet_damage: 10.,
|
||||
pellet_speed: 50.,
|
||||
},
|
||||
ContactDamage::new(2.0),
|
||||
ProjectileLauncher::new(
|
||||
Duration::from_secs(3),
|
||||
50.0,
|
||||
Vec3::Y * (SIZE.y as f32 + 0.5),
|
||||
Duration::from_secs(10),
|
||||
0.,
|
||||
),
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
))
|
||||
.observe(on_fire);
|
||||
}
|
||||
|
||||
fn on_fire(
|
||||
trigger: Trigger<Fire>,
|
||||
query: Query<&Suncannon>,
|
||||
mut commands: Commands,
|
||||
res: Res<BuildingResources>,
|
||||
) {
|
||||
let Ok(suncannon) = query.get(trigger.target()) else {
|
||||
return;
|
||||
};
|
||||
let v = get_launch_vector(
|
||||
trigger.event().spawn_pos,
|
||||
trigger.event().target_pos,
|
||||
100.0,
|
||||
0.0,
|
||||
);
|
||||
commands
|
||||
.spawn((
|
||||
RigidBody::Dynamic,
|
||||
trigger.event().team,
|
||||
Health::new(1.0),
|
||||
ContactDamage::projectile(trigger.event().damage, f32::INFINITY),
|
||||
Transform::from_translation(trigger.event().spawn_pos),
|
||||
Projectile::from(&trigger.event().launcher),
|
||||
Projectile::collision_layers(trigger.event().team),
|
||||
SuncannonProjectile(suncannon.clone()),
|
||||
LinearVelocity(v),
|
||||
res.projectile_collider.clone(),
|
||||
MeshMaterial3d(res.projectile_material.clone()),
|
||||
Mesh3d(res.projectile_mesh.clone()),
|
||||
))
|
||||
.observe(on_projectile_explode);
|
||||
}
|
||||
|
||||
fn on_projectile_explode(
|
||||
trigger: Trigger<Died>,
|
||||
proj_query: Query<(&GlobalTransform, &Team, &SuncannonProjectile)>,
|
||||
spatial_query: SpatialQuery,
|
||||
res: Res<BuildingResources>,
|
||||
mut enemy_query: Query<(&Team, &GlobalTransform, &mut ExternalImpulse)>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let Ok((gtf, team, projectile)) = proj_query.get(trigger.target()) else {
|
||||
return;
|
||||
};
|
||||
let enemies = spatial_query.shape_intersections(
|
||||
&Collider::sphere(projectile.0.explosion_radius),
|
||||
gtf.translation(),
|
||||
Quat::default(),
|
||||
&SpatialQueryFilter::from_mask(team.enemy_layers()),
|
||||
);
|
||||
for enemy in enemies {
|
||||
let Ok((enemy_team, enemy_gtf, mut enemy_v)) = enemy_query.get_mut(enemy) else {
|
||||
continue;
|
||||
};
|
||||
if enemy_team == team {
|
||||
continue;
|
||||
}
|
||||
let knockback = (enemy_gtf.translation() - gtf.translation()).normalize_or_zero()
|
||||
* projectile.0.explosion_knockback;
|
||||
enemy_v.apply_impulse(knockback);
|
||||
commands.entity(enemy).trigger(Attacked {
|
||||
attacker: Some(trigger.target()),
|
||||
amount: projectile.0.explosion_damage,
|
||||
skip_invulnerability: true,
|
||||
});
|
||||
}
|
||||
for pellet in 0..projectile.0.pellet_count {
|
||||
let angle = 2. * PI / (projectile.0.pellet_count as f32) * pellet as f32;
|
||||
let v = Vec3::new(angle.sin(), 0., angle.cos()) * projectile.0.pellet_speed;
|
||||
commands.spawn((
|
||||
RigidBody::Dynamic,
|
||||
team.clone(),
|
||||
Health::new(1.0),
|
||||
ContactDamage::projectile(projectile.0.pellet_damage, f32::INFINITY),
|
||||
Transform::from_translation(gtf.translation() + Vec3::Y * 0.1)
|
||||
.with_scale(Vec3::splat(0.25)),
|
||||
Projectile {
|
||||
lifetime: Duration::from_secs(1),
|
||||
},
|
||||
Projectile::collision_layers(*team),
|
||||
LinearVelocity(v),
|
||||
res.projectile_collider.clone(),
|
||||
MeshMaterial3d(res.projectile_material.clone()),
|
||||
Mesh3d(res.projectile_mesh.clone()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -59,8 +59,6 @@ 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 {
|
||||
|
|
@ -77,7 +75,6 @@ impl ProjectileLauncher {
|
|||
damage,
|
||||
fire_offset,
|
||||
lifetime,
|
||||
custom_targeting: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +86,6 @@ 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,
|
||||
|
|
@ -128,22 +123,6 @@ 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| {
|
||||
|
|
@ -172,8 +151,6 @@ 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(),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use building::Core;
|
||||
use combat::{Defense, Health, Team};
|
||||
use combat::{Health, Team};
|
||||
use combat_damagers::ContactDamage;
|
||||
use inhabitant::Inhabitant;
|
||||
use inhabitant_simbert::SpawnSimbert;
|
||||
|
|
@ -85,7 +85,6 @@ fn spawn(
|
|||
},
|
||||
transform.clone(),
|
||||
Health::new(2000.0 + 100. * phase.get().phase_count() as f32),
|
||||
Defense::new(5.),
|
||||
// todo: change enemy health bar color to differentiate from buildings
|
||||
BarSettings {
|
||||
offset: HEIGHT + 0.5,
|
||||
|
|
|
|||
|
|
@ -149,8 +149,7 @@ fn setup(
|
|||
}
|
||||
|
||||
fn spawn_enemies(
|
||||
mut simbert_writer: EventWriter<SpawnSimbert>,
|
||||
mut endrake_writer: EventWriter<SpawnEndrake>,
|
||||
mut writer: EventWriter<SpawnSimbert>,
|
||||
core_query: Single<(&GlobalTransform, &Range), With<Core>>,
|
||||
phase_state: Res<State<BasePhaseState>>,
|
||||
time: Res<Time>,
|
||||
|
|
@ -184,7 +183,7 @@ fn spawn_enemies(
|
|||
safe_axes.push(Vec3::ZERO);
|
||||
}
|
||||
|
||||
// endrake_writer.write(SpawnEndrake {
|
||||
// writer.write(SpawnEndrake {
|
||||
// transform: Transform::from_xyz(safe_axes[0].x, 2.0, safe_axes[0].z),
|
||||
// });
|
||||
|
||||
|
|
@ -199,7 +198,7 @@ fn spawn_enemies(
|
|||
spawn_origin = safe_axes[rng.gen_range(0..safe_axes.len())];
|
||||
}
|
||||
for y in 0..clump_size {
|
||||
simbert_writer.write(SpawnSimbert {
|
||||
writer.write(SpawnSimbert {
|
||||
transform: Transform::from_xyz(
|
||||
spawn_origin.x,
|
||||
2.0 + y as f32 * 0.5,
|
||||
|
|
|
|||
|
|
@ -44,8 +44,6 @@ fn main() {
|
|||
inhabitant_endrake::InhabitantEndrakePlugin,
|
||||
resource_soul_spot::ResourceSoulSpotPlugin,
|
||||
),
|
||||
building_ramtower::BuildingRamtowerPlugin,
|
||||
building_suncannon::BuildingSuncannonPlugin,
|
||||
// new internal crates go here
|
||||
));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue