Added min fall off to explosions.

This commit is contained in:
Sam 2021-10-27 15:42:11 -04:00
parent 098c10eb39
commit 2b447852fd
17 changed files with 66 additions and 6 deletions

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 13.0, damage: 13.0,
radius: 5.0, radius: 5.0,
energy_regen: 0, energy_regen: 0,
min_falloff: 0.5,
), ),
projectile_body: Object(BoltFire), projectile_body: Object(BoltFire),
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 10.0, damage: 10.0,
radius: 5.0, radius: 5.0,
energy_regen: 5.0, energy_regen: 5.0,
min_falloff: 0.5,
), ),
projectile_body: Object(BoltFire), projectile_body: Object(BoltFire),
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 10.0, damage: 10.0,
radius: 5.0, radius: 5.0,
energy_regen: 5.0, energy_regen: 5.0,
min_falloff: 0.5,
), ),
projectile_body: Object(BoltFire), projectile_body: Object(BoltFire),
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 50.0, damage: 50.0,
knockback: 18.0, knockback: 18.0,
radius: 5.0, radius: 5.0,
min_falloff: 0.75,
), ),
projectile_body: Object(ClayRocket), projectile_body: Object(ClayRocket),
projectile_light: None, projectile_light: None,

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 20.0, damage: 20.0,
knockback: 25.0, knockback: 25.0,
radius: 5.0, radius: 5.0,
min_falloff: 0.6,
), ),
projectile_body: Object(Pumpkin), projectile_body: Object(Pumpkin),
projectile_light: None, projectile_light: None,

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 26.0, damage: 26.0,
radius: 5.0, radius: 5.0,
energy_regen: 0, energy_regen: 0,
min_falloff: 0.5,
), ),
projectile_body: Object(FireworkPurple), projectile_body: Object(FireworkPurple),
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -5,6 +5,7 @@ BasicRanged(
projectile: NecroticSphere( projectile: NecroticSphere(
damage: 45.0, damage: 45.0,
radius: 5.0, radius: 5.0,
min_falloff: 0.9,
), ),
projectile_body: Object(FireworkPurple), projectile_body: Object(FireworkPurple),
projectile_speed: 100.0, projectile_speed: 100.0,

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 13.0, damage: 13.0,
radius: 5.0, radius: 5.0,
energy_regen: 0, energy_regen: 0,
min_falloff: 0.5,
), ),
projectile_body: Object(FireworkPurple), projectile_body: Object(FireworkPurple),
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -5,6 +5,7 @@ BasicRanged(
projectile: Frostball( projectile: Frostball(
damage: 12.0, damage: 12.0,
radius: 5.0, radius: 5.0,
min_falloff: 0.5,
), ),
projectile_body: Object(BoltFire), // TODO: Get ice projectile model projectile_body: Object(BoltFire), // TODO: Get ice projectile model
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -5,6 +5,7 @@ BasicRanged(
projectile: Snowball( projectile: Snowball(
damage: 20.0, damage: 20.0,
radius: 5.0, radius: 5.0,
min_falloff: 0.7,
), ),
projectile_body: Object(Snowball), projectile_body: Object(Snowball),
projectile_speed: 60.0, projectile_speed: 60.0,

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 9.0, damage: 9.0,
radius: 4.0, radius: 4.0,
energy_regen: 6.0, energy_regen: 6.0,
min_falloff: 0.5,
), ),
projectile_body: Object(BoltFire), projectile_body: Object(BoltFire),
projectile_speed: 60.0, projectile_speed: 60.0,

View File

@ -6,6 +6,7 @@ BasicRanged(
damage: 6.0, damage: 6.0,
radius: 5.0, radius: 5.0,
energy_regen: 5.0, energy_regen: 5.0,
min_falloff: 0.5,
), ),
projectile_body: Object(BoltFire), projectile_body: Object(BoltFire),
/*projectile_light: Some(LightEmitter { /*projectile_light: Some(LightEmitter {

View File

@ -54,29 +54,35 @@ pub enum ProjectileConstructor {
damage: f32, damage: f32,
radius: f32, radius: f32,
energy_regen: f32, energy_regen: f32,
min_falloff: f32,
}, },
Frostball { Frostball {
damage: f32, damage: f32,
radius: f32, radius: f32,
min_falloff: f32,
}, },
NecroticSphere { NecroticSphere {
damage: f32, damage: f32,
radius: f32, radius: f32,
min_falloff: f32,
}, },
Possess, Possess,
ClayRocket { ClayRocket {
damage: f32, damage: f32,
radius: f32, radius: f32,
knockback: f32, knockback: f32,
min_falloff: f32,
}, },
Snowball { Snowball {
damage: f32, damage: f32,
radius: f32, radius: f32,
min_falloff: f32,
}, },
ExplodingPumpkin { ExplodingPumpkin {
damage: f32, damage: f32,
radius: f32, radius: f32,
knockback: f32, knockback: f32,
min_falloff: f32,
}, },
} }
@ -141,6 +147,7 @@ impl ProjectileConstructor {
damage, damage,
radius, radius,
energy_regen, energy_regen,
min_falloff,
} => { } => {
let energy = AttackEffect::new(None, CombatEffect::EnergyReward(energy_regen)) let energy = AttackEffect::new(None, CombatEffect::EnergyReward(energy_regen))
.with_requirement(CombatRequirement::AnyDamage); .with_requirement(CombatRequirement::AnyDamage);
@ -164,6 +171,7 @@ impl ProjectileConstructor {
], ],
radius, radius,
reagent: Some(Reagent::Red), reagent: Some(Reagent::Red),
min_falloff,
}; };
Projectile { Projectile {
hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish],
@ -175,7 +183,11 @@ impl ProjectileConstructor {
is_point: true, is_point: true,
} }
}, },
Frostball { damage, radius } => { Frostball {
damage,
radius,
min_falloff,
} => {
let damage = AttackDamage::new( let damage = AttackDamage::new(
Damage { Damage {
source: DamageSource::Explosion, source: DamageSource::Explosion,
@ -192,6 +204,7 @@ impl ProjectileConstructor {
effects: vec![RadiusEffect::Attack(attack)], effects: vec![RadiusEffect::Attack(attack)],
radius, radius,
reagent: Some(Reagent::White), reagent: Some(Reagent::White),
min_falloff,
}; };
Projectile { Projectile {
hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish],
@ -203,7 +216,11 @@ impl ProjectileConstructor {
is_point: true, is_point: true,
} }
}, },
NecroticSphere { damage, radius } => { NecroticSphere {
damage,
radius,
min_falloff,
} => {
let damage = AttackDamage::new( let damage = AttackDamage::new(
Damage { Damage {
source: DamageSource::Explosion, source: DamageSource::Explosion,
@ -220,6 +237,7 @@ impl ProjectileConstructor {
effects: vec![RadiusEffect::Attack(attack)], effects: vec![RadiusEffect::Attack(attack)],
radius, radius,
reagent: Some(Reagent::Purple), reagent: Some(Reagent::Purple),
min_falloff,
}; };
Projectile { Projectile {
hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish],
@ -244,6 +262,7 @@ impl ProjectileConstructor {
damage, damage,
radius, radius,
knockback, knockback,
min_falloff,
} => { } => {
let knockback = AttackEffect::new( let knockback = AttackEffect::new(
Some(GroupTarget::OutOfGroup), Some(GroupTarget::OutOfGroup),
@ -272,6 +291,7 @@ impl ProjectileConstructor {
], ],
radius, radius,
reagent: Some(Reagent::Red), reagent: Some(Reagent::Red),
min_falloff,
}; };
Projectile { Projectile {
hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish],
@ -283,7 +303,11 @@ impl ProjectileConstructor {
is_point: true, is_point: true,
} }
}, },
Snowball { damage, radius } => { Snowball {
damage,
radius,
min_falloff,
} => {
let damage = AttackDamage::new( let damage = AttackDamage::new(
Damage { Damage {
source: DamageSource::Explosion, source: DamageSource::Explosion,
@ -299,6 +323,7 @@ impl ProjectileConstructor {
effects: vec![RadiusEffect::Attack(attack)], effects: vec![RadiusEffect::Attack(attack)],
radius, radius,
reagent: Some(Reagent::White), reagent: Some(Reagent::White),
min_falloff,
}; };
Projectile { Projectile {
hit_solid: vec![], hit_solid: vec![],
@ -314,6 +339,7 @@ impl ProjectileConstructor {
damage, damage,
radius, radius,
knockback, knockback,
min_falloff,
} => { } => {
let knockback = AttackEffect::new( let knockback = AttackEffect::new(
Some(GroupTarget::OutOfGroup), Some(GroupTarget::OutOfGroup),
@ -353,6 +379,7 @@ impl ProjectileConstructor {
], ],
radius, radius,
reagent: Some(Reagent::Red), reagent: Some(Reagent::Red),
min_falloff,
}; };
Projectile { Projectile {
hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish],
@ -417,6 +444,7 @@ impl ProjectileConstructor {
Snowball { Snowball {
ref mut damage, ref mut damage,
ref mut radius, ref mut radius,
..
} => { } => {
*damage *= power; *damage *= power;
*radius *= range; *radius *= range;

View File

@ -6,6 +6,7 @@ pub struct Explosion {
pub effects: Vec<RadiusEffect>, pub effects: Vec<RadiusEffect>,
pub radius: f32, pub radius: f32,
pub reagent: Option<Reagent>, pub reagent: Option<Reagent>,
pub min_falloff: f32,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]

View File

@ -2033,6 +2033,7 @@ fn handle_explosion(
], ],
radius: 3.0 * power, radius: 3.0 * power,
reagent: None, reagent: None,
min_falloff: 0.0,
}, },
owner, owner,
}); });

View File

@ -546,6 +546,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
fn cylinder_sphere_strength( fn cylinder_sphere_strength(
sphere_pos: Vec3<f32>, sphere_pos: Vec3<f32>,
radius: f32, radius: f32,
min_falloff: f32,
cyl_pos: Vec3<f32>, cyl_pos: Vec3<f32>,
cyl_body: Body, cyl_body: Body,
) -> f32 { ) -> f32 {
@ -559,7 +560,10 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
// Compare both checks, take whichever gives weaker effect, sets minimum of 0 so // Compare both checks, take whichever gives weaker effect, sets minimum of 0 so
// that explosions reach a max strength on edge of entity // that explosions reach a max strength on edge of entity
((horiz_dist.max(vert_distance).max(0.0) / radius).min(1.0) - 1.0).abs() let fall_off = ((horiz_dist.max(vert_distance).max(0.0) / radius).min(1.0) - 1.0).abs();
// Clamp min_falloff so that it doesn't produce absurd values or NaNs
let min_falloff = min_falloff.clamp(0.0, 0.99);
min_falloff + fall_off * (1.0 - min_falloff)
} }
// TODO: Faster RNG? // TODO: Faster RNG?
@ -714,7 +718,13 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
{ {
// Check if it is a hit // Check if it is a hit
let strength = if let Some(body) = body_b_maybe { let strength = if let Some(body) = body_b_maybe {
cylinder_sphere_strength(pos, explosion.radius, pos_b.0, *body) cylinder_sphere_strength(
pos,
explosion.radius,
explosion.min_falloff,
pos_b.0,
*body,
)
} else { } else {
let distance_squared = pos.distance_squared(pos_b.0); let distance_squared = pos.distance_squared(pos_b.0);
1.0 - distance_squared / explosion.radius.powi(2) 1.0 - distance_squared / explosion.radius.powi(2)
@ -801,7 +811,13 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
.join() .join()
{ {
let strength = if let Some(body) = body_b_maybe { let strength = if let Some(body) = body_b_maybe {
cylinder_sphere_strength(pos, explosion.radius, pos_b.0, *body) cylinder_sphere_strength(
pos,
explosion.radius,
explosion.min_falloff,
pos_b.0,
*body,
)
} else { } else {
let distance_squared = pos.distance_squared(pos_b.0); let distance_squared = pos.distance_squared(pos_b.0);
1.0 - distance_squared / explosion.radius.powi(2) 1.0 - distance_squared / explosion.radius.powi(2)

View File

@ -61,6 +61,7 @@ impl<'a> System<'a> for Sys {
], ],
radius: 12.0, radius: 12.0,
reagent: None, reagent: None,
min_falloff: 0.75,
}, },
owner: *owner, owner: *owner,
}); });
@ -153,6 +154,7 @@ impl<'a> System<'a> for Sys {
], ],
radius: 12.0, radius: 12.0,
reagent: Some(*reagent), reagent: Some(*reagent),
min_falloff: 0.0,
}, },
owner: *owner, owner: *owner,
}); });