From 3bfff6cf180d6f4affb4ed7a0eedb300138bacd4 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Oct 2021 15:42:11 -0400 Subject: [PATCH] Added min fall off to explosions. --- .../common/abilities/custom/asp/firebomb.ron | 1 + .../custom/birdlargebreathe/firebomb.ron | 1 + .../custom/birdlargefire/firebomb.ron | 1 + .../abilities/custom/claygolem/rocket.ron | 1 + .../custom/harvester/explodingpumpkin.ron | 1 + .../abilities/custom/maneater/poisonball.ron | 1 + .../custom/mindflayer/necroticsphere.ron | 1 + .../custom/quadlowranged/firebomb.ron | 1 + .../custom/wendigomagic/frostbomb.ron | 1 + .../common/abilities/custom/yeti/snowball.ron | 1 + assets/common/abilities/staff/firebomb.ron | 1 + .../common/abilities/staffsimple/firebomb.ron | 1 + common/src/comp/projectile.rs | 34 +++++++++++++++++-- common/src/explosion.rs | 1 + server/src/cmd.rs | 1 + server/src/events/entity_manipulation.rs | 22 ++++++++++-- server/src/sys/object.rs | 2 ++ 17 files changed, 66 insertions(+), 6 deletions(-) diff --git a/assets/common/abilities/custom/asp/firebomb.ron b/assets/common/abilities/custom/asp/firebomb.ron index 738fb4c3f3..02b54ed7f3 100644 --- a/assets/common/abilities/custom/asp/firebomb.ron +++ b/assets/common/abilities/custom/asp/firebomb.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 13.0, radius: 5.0, energy_regen: 0, + min_falloff: 0.5, ), projectile_body: Object(BoltFire), /*projectile_light: Some(LightEmitter { diff --git a/assets/common/abilities/custom/birdlargebreathe/firebomb.ron b/assets/common/abilities/custom/birdlargebreathe/firebomb.ron index f3d118976c..a3708e2740 100644 --- a/assets/common/abilities/custom/birdlargebreathe/firebomb.ron +++ b/assets/common/abilities/custom/birdlargebreathe/firebomb.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 10.0, radius: 5.0, energy_regen: 5.0, + min_falloff: 0.5, ), projectile_body: Object(BoltFire), /*projectile_light: Some(LightEmitter { diff --git a/assets/common/abilities/custom/birdlargefire/firebomb.ron b/assets/common/abilities/custom/birdlargefire/firebomb.ron index f3d118976c..a3708e2740 100644 --- a/assets/common/abilities/custom/birdlargefire/firebomb.ron +++ b/assets/common/abilities/custom/birdlargefire/firebomb.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 10.0, radius: 5.0, energy_regen: 5.0, + min_falloff: 0.5, ), projectile_body: Object(BoltFire), /*projectile_light: Some(LightEmitter { diff --git a/assets/common/abilities/custom/claygolem/rocket.ron b/assets/common/abilities/custom/claygolem/rocket.ron index a5b2a230c6..5b5a87cc02 100644 --- a/assets/common/abilities/custom/claygolem/rocket.ron +++ b/assets/common/abilities/custom/claygolem/rocket.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 50.0, knockback: 18.0, radius: 5.0, + min_falloff: 0.75, ), projectile_body: Object(ClayRocket), projectile_light: None, diff --git a/assets/common/abilities/custom/harvester/explodingpumpkin.ron b/assets/common/abilities/custom/harvester/explodingpumpkin.ron index 5d76172c15..f302ab8c43 100644 --- a/assets/common/abilities/custom/harvester/explodingpumpkin.ron +++ b/assets/common/abilities/custom/harvester/explodingpumpkin.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 20.0, knockback: 25.0, radius: 5.0, + min_falloff: 0.6, ), projectile_body: Object(Pumpkin), projectile_light: None, diff --git a/assets/common/abilities/custom/maneater/poisonball.ron b/assets/common/abilities/custom/maneater/poisonball.ron index 8b171eba68..8b13e59ecf 100644 --- a/assets/common/abilities/custom/maneater/poisonball.ron +++ b/assets/common/abilities/custom/maneater/poisonball.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 26.0, radius: 5.0, energy_regen: 0, + min_falloff: 0.5, ), projectile_body: Object(FireworkPurple), /*projectile_light: Some(LightEmitter { diff --git a/assets/common/abilities/custom/mindflayer/necroticsphere.ron b/assets/common/abilities/custom/mindflayer/necroticsphere.ron index 52004b1bbf..e353fd46fe 100644 --- a/assets/common/abilities/custom/mindflayer/necroticsphere.ron +++ b/assets/common/abilities/custom/mindflayer/necroticsphere.ron @@ -5,6 +5,7 @@ BasicRanged( projectile: NecroticSphere( damage: 45.0, radius: 5.0, + min_falloff: 0.9, ), projectile_body: Object(FireworkPurple), projectile_speed: 100.0, diff --git a/assets/common/abilities/custom/quadlowranged/firebomb.ron b/assets/common/abilities/custom/quadlowranged/firebomb.ron index 27f0381ad8..7b4fe7b0f0 100644 --- a/assets/common/abilities/custom/quadlowranged/firebomb.ron +++ b/assets/common/abilities/custom/quadlowranged/firebomb.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 13.0, radius: 5.0, energy_regen: 0, + min_falloff: 0.5, ), projectile_body: Object(FireworkPurple), /*projectile_light: Some(LightEmitter { diff --git a/assets/common/abilities/custom/wendigomagic/frostbomb.ron b/assets/common/abilities/custom/wendigomagic/frostbomb.ron index 732f397d76..55e0e0f542 100644 --- a/assets/common/abilities/custom/wendigomagic/frostbomb.ron +++ b/assets/common/abilities/custom/wendigomagic/frostbomb.ron @@ -5,6 +5,7 @@ BasicRanged( projectile: Frostball( damage: 12.0, radius: 5.0, + min_falloff: 0.5, ), projectile_body: Object(BoltFire), // TODO: Get ice projectile model /*projectile_light: Some(LightEmitter { diff --git a/assets/common/abilities/custom/yeti/snowball.ron b/assets/common/abilities/custom/yeti/snowball.ron index 3a53ac3d5b..e437a73f7a 100644 --- a/assets/common/abilities/custom/yeti/snowball.ron +++ b/assets/common/abilities/custom/yeti/snowball.ron @@ -5,6 +5,7 @@ BasicRanged( projectile: Snowball( damage: 20.0, radius: 5.0, + min_falloff: 0.7, ), projectile_body: Object(Snowball), projectile_speed: 60.0, diff --git a/assets/common/abilities/staff/firebomb.ron b/assets/common/abilities/staff/firebomb.ron index 21638365c7..2d9345ff77 100644 --- a/assets/common/abilities/staff/firebomb.ron +++ b/assets/common/abilities/staff/firebomb.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 9.0, radius: 4.0, energy_regen: 6.0, + min_falloff: 0.5, ), projectile_body: Object(BoltFire), projectile_speed: 60.0, diff --git a/assets/common/abilities/staffsimple/firebomb.ron b/assets/common/abilities/staffsimple/firebomb.ron index 1c8278e077..5a0a996df2 100644 --- a/assets/common/abilities/staffsimple/firebomb.ron +++ b/assets/common/abilities/staffsimple/firebomb.ron @@ -6,6 +6,7 @@ BasicRanged( damage: 6.0, radius: 5.0, energy_regen: 5.0, + min_falloff: 0.5, ), projectile_body: Object(BoltFire), /*projectile_light: Some(LightEmitter { diff --git a/common/src/comp/projectile.rs b/common/src/comp/projectile.rs index 22c1a398c3..6dd5587711 100644 --- a/common/src/comp/projectile.rs +++ b/common/src/comp/projectile.rs @@ -54,29 +54,35 @@ pub enum ProjectileConstructor { damage: f32, radius: f32, energy_regen: f32, + min_falloff: f32, }, Frostball { damage: f32, radius: f32, + min_falloff: f32, }, NecroticSphere { damage: f32, radius: f32, + min_falloff: f32, }, Possess, ClayRocket { damage: f32, radius: f32, knockback: f32, + min_falloff: f32, }, Snowball { damage: f32, radius: f32, + min_falloff: f32, }, ExplodingPumpkin { damage: f32, radius: f32, knockback: f32, + min_falloff: f32, }, } @@ -141,6 +147,7 @@ impl ProjectileConstructor { damage, radius, energy_regen, + min_falloff, } => { let energy = AttackEffect::new(None, CombatEffect::EnergyReward(energy_regen)) .with_requirement(CombatRequirement::AnyDamage); @@ -164,6 +171,7 @@ impl ProjectileConstructor { ], radius, reagent: Some(Reagent::Red), + min_falloff, }; Projectile { hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], @@ -175,7 +183,11 @@ impl ProjectileConstructor { is_point: true, } }, - Frostball { damage, radius } => { + Frostball { + damage, + radius, + min_falloff, + } => { let damage = AttackDamage::new( Damage { source: DamageSource::Explosion, @@ -192,6 +204,7 @@ impl ProjectileConstructor { effects: vec![RadiusEffect::Attack(attack)], radius, reagent: Some(Reagent::White), + min_falloff, }; Projectile { hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], @@ -203,7 +216,11 @@ impl ProjectileConstructor { is_point: true, } }, - NecroticSphere { damage, radius } => { + NecroticSphere { + damage, + radius, + min_falloff, + } => { let damage = AttackDamage::new( Damage { source: DamageSource::Explosion, @@ -220,6 +237,7 @@ impl ProjectileConstructor { effects: vec![RadiusEffect::Attack(attack)], radius, reagent: Some(Reagent::Purple), + min_falloff, }; Projectile { hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], @@ -244,6 +262,7 @@ impl ProjectileConstructor { damage, radius, knockback, + min_falloff, } => { let knockback = AttackEffect::new( Some(GroupTarget::OutOfGroup), @@ -272,6 +291,7 @@ impl ProjectileConstructor { ], radius, reagent: Some(Reagent::Red), + min_falloff, }; Projectile { hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], @@ -283,7 +303,11 @@ impl ProjectileConstructor { is_point: true, } }, - Snowball { damage, radius } => { + Snowball { + damage, + radius, + min_falloff, + } => { let damage = AttackDamage::new( Damage { source: DamageSource::Explosion, @@ -299,6 +323,7 @@ impl ProjectileConstructor { effects: vec![RadiusEffect::Attack(attack)], radius, reagent: Some(Reagent::White), + min_falloff, }; Projectile { hit_solid: vec![], @@ -314,6 +339,7 @@ impl ProjectileConstructor { damage, radius, knockback, + min_falloff, } => { let knockback = AttackEffect::new( Some(GroupTarget::OutOfGroup), @@ -353,6 +379,7 @@ impl ProjectileConstructor { ], radius, reagent: Some(Reagent::Red), + min_falloff, }; Projectile { hit_solid: vec![Effect::Explode(explosion.clone()), Effect::Vanish], @@ -417,6 +444,7 @@ impl ProjectileConstructor { Snowball { ref mut damage, ref mut radius, + .. } => { *damage *= power; *radius *= range; diff --git a/common/src/explosion.rs b/common/src/explosion.rs index ac5790b976..ff02365cf5 100644 --- a/common/src/explosion.rs +++ b/common/src/explosion.rs @@ -6,6 +6,7 @@ pub struct Explosion { pub effects: Vec, pub radius: f32, pub reagent: Option, + pub min_falloff: f32, } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 375e4ccc08..ba1d9c3c37 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -2033,6 +2033,7 @@ fn handle_explosion( ], radius: 3.0 * power, reagent: None, + min_falloff: 0.0, }, owner, }); diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 24de925db5..592039e7c0 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -546,6 +546,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o fn cylinder_sphere_strength( sphere_pos: Vec3, radius: f32, + min_falloff: f32, cyl_pos: Vec3, cyl_body: Body, ) -> f32 { @@ -559,7 +560,10 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o // Compare both checks, take whichever gives weaker effect, sets minimum of 0 so // 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? @@ -714,7 +718,13 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o { // Check if it is a hit 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 { let distance_squared = pos.distance_squared(pos_b.0); 1.0 - distance_squared / explosion.radius.powi(2) @@ -801,7 +811,13 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o .join() { 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 { let distance_squared = pos.distance_squared(pos_b.0); 1.0 - distance_squared / explosion.radius.powi(2) diff --git a/server/src/sys/object.rs b/server/src/sys/object.rs index 9736d157cc..44533ce8e1 100644 --- a/server/src/sys/object.rs +++ b/server/src/sys/object.rs @@ -61,6 +61,7 @@ impl<'a> System<'a> for Sys { ], radius: 12.0, reagent: None, + min_falloff: 0.75, }, owner: *owner, }); @@ -153,6 +154,7 @@ impl<'a> System<'a> for Sys { ], radius: 12.0, reagent: Some(*reagent), + min_falloff: 0.0, }, owner: *owner, });