diff --git a/Cargo.lock b/Cargo.lock index 7069f42f18..a62f45c156 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -682,9 +682,9 @@ dependencies = [ [[package]] name = "const-tweaker" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe948a728bf50e79be7b41b197587318fbc17da0106e5d0f435e3a6b2b42226" +checksum = "b51e91181af416a58123da1cebf00d2e600296f358d0d69aa14df63956d2753e" dependencies = [ "anyhow", "async-std", @@ -698,9 +698,9 @@ dependencies = [ [[package]] name = "const-tweaker-attribute" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c22ff357be06ddb217d230a62c3f3ed8ebd305e87df53789d27450f48c40f6a" +checksum = "55cef233d59741e1a93f0363145fe412bd13f64df1827c6c5d709c9403e081fc" dependencies = [ "darling", "proc-macro2 1.0.9", @@ -2002,9 +2002,9 @@ dependencies = [ [[package]] name = "horrorshow" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad517632123d9c856735b04b02031b04dfb5ab1e69695bcfb96dee5e8804f0df" +checksum = "87ce7e0a1bc8e4489896abc94e5664e811a502a151bebfe113b3214fa181d3fb" [[package]] name = "hound" @@ -4022,18 +4022,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8" dependencies = [ "proc-macro2 1.0.9", "quote 1.0.3", diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 80d17119af..af44b056d5 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -17,11 +17,13 @@ pub enum CharacterAbility { max_angle: f32, }, BasicRanged { + prepare_duration: Duration, recover_duration: Duration, projectile: Projectile, projectile_body: Body, }, CastFireball { + prepare_duration: Duration, recover_duration: Duration, projectile: Projectile, projectile_body: Body, @@ -121,23 +123,26 @@ impl From<&CharacterAbility> for CharacterState { max_angle: *max_angle, }), CharacterAbility::BasicRanged { + prepare_duration, recover_duration, projectile, projectile_body, } => CharacterState::BasicRanged(basic_ranged::Data { exhausted: false, prepare_timer: Duration::default(), + prepare_duration: *prepare_duration, recover_duration: *recover_duration, projectile: projectile.clone(), projectile_body: *projectile_body, }), CharacterAbility::CastFireball { + prepare_duration, recover_duration, projectile, projectile_body, } => CharacterState::CastFireball(cast_fireball::Data { exhausted: false, - prepare_timer: Duration::default(), + prepare_duration: *prepare_duration, recover_duration: *recover_duration, projectile: projectile.clone(), projectile_body: *projectile_body, diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index a74d0738fb..8aa2cda5b1 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -89,6 +89,8 @@ impl ToolData { max_angle: 60.0, }], Bow(_) => vec![BasicRanged { + prepare_duration: Duration::from_millis(100), + recover_duration: Duration::from_millis(300), projectile: Projectile { hit_ground: vec![projectile::Effect::Stick], hit_wall: vec![projectile::Effect::Stick], @@ -104,7 +106,6 @@ impl ToolData { owner: None, }, projectile_body: Body::Object(object::Body::Arrow), - recover_duration: Duration::from_millis(300), }], Dagger(_) => vec![BasicMelee { buildup_duration: Duration::from_millis(100), @@ -126,6 +127,8 @@ impl ToolData { max_angle: 45.0, }, BasicRanged { + prepare_duration: Duration::from_millis(300), + recover_duration: Duration::from_millis(100), projectile: Projectile { hit_ground: vec![projectile::Effect::Vanish], hit_wall: vec![projectile::Effect::Vanish], @@ -141,9 +144,10 @@ impl ToolData { owner: None, }, projectile_body: Body::Object(object::Body::BoltFire), - recover_duration: Duration::from_millis(500), }, CastFireball { + prepare_duration: Duration::from_millis(800), + recover_duration: Duration::from_millis(300), projectile: Projectile { hit_ground: vec![ projectile::Effect::Explode { power: 1.4 }, @@ -161,7 +165,6 @@ impl ToolData { owner: None, }, projectile_body: Body::Object(object::Body::BoltFire), - recover_duration: Duration::from_millis(800), }, ], Shield(_) => vec![BasicBlock], @@ -177,6 +180,8 @@ impl ToolData { }, ], Possess => vec![BasicRanged { + prepare_duration: Duration::from_millis(300), + recover_duration: Duration::from_millis(300), projectile: Projectile { hit_ground: vec![projectile::Effect::Stick], hit_wall: vec![projectile::Effect::Stick], @@ -185,7 +190,6 @@ impl ToolData { owner: None, }, projectile_body: Body::Object(object::Body::ArrowSnake), - recover_duration: Duration::from_millis(300), }], }, Empty => vec![], diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index 9b219e8ca4..4301d0668b 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -8,6 +8,8 @@ use std::time::Duration; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Data { + /// How long we have to prepare the weapon + pub prepare_duration: Duration, /// How long we prepared the weapon already pub prepare_timer: Duration, /// How long the state has until exiting @@ -27,10 +29,13 @@ impl CharacterBehavior for Data { handle_move(data, &mut update); handle_jump(data, &mut update); - if !self.exhausted && data.inputs.holding_ability_key() { + if self.prepare_timer < self.prepare_duration + || !self.exhausted && data.inputs.holding_ability_key() + { // Prepare (draw the bow) update.character = CharacterState::BasicRanged(Data { prepare_timer: self.prepare_timer + Duration::from_secs_f32(data.dt.0), + prepare_duration: self.prepare_duration, recover_duration: self.recover_duration, projectile: self.projectile.clone(), projectile_body: self.projectile_body, @@ -51,6 +56,7 @@ impl CharacterBehavior for Data { update.character = CharacterState::BasicRanged(Data { prepare_timer: self.prepare_timer, + prepare_duration: self.prepare_duration, recover_duration: self.recover_duration, projectile: self.projectile.clone(), projectile_body: self.projectile_body, @@ -60,6 +66,7 @@ impl CharacterBehavior for Data { // Recovery update.character = CharacterState::BasicRanged(Data { prepare_timer: self.prepare_timer, + prepare_duration: self.prepare_duration, recover_duration: self .recover_duration .checked_sub(Duration::from_secs_f32(data.dt.0)) diff --git a/common/src/states/cast_fireball.rs b/common/src/states/cast_fireball.rs index 50f5a5d5f6..7ebb9b28d8 100644 --- a/common/src/states/cast_fireball.rs +++ b/common/src/states/cast_fireball.rs @@ -8,8 +8,8 @@ use std::time::Duration; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Data { - /// How long we prepared the weapon already - pub prepare_timer: Duration, + /// How long we need to wait before we fire + pub prepare_duration: Duration, /// How long the state has until exiting pub recover_duration: Duration, /// Projectile @@ -27,10 +27,13 @@ impl CharacterBehavior for Data { handle_move(data, &mut update); handle_jump(data, &mut update); - if !self.exhausted && data.inputs.holding_ability_key() { + if self.prepare_duration != Duration::default() { // Prepare update.character = CharacterState::CastFireball(Data { - prepare_timer: self.prepare_timer + Duration::from_secs_f32(data.dt.0), + prepare_duration: self + .prepare_duration + .checked_sub(Duration::from_secs_f32(data.dt.0)) + .unwrap_or_default(), recover_duration: self.recover_duration, projectile: self.projectile.clone(), projectile_body: self.projectile_body, @@ -53,7 +56,7 @@ impl CharacterBehavior for Data { }); update.character = CharacterState::CastFireball(Data { - prepare_timer: self.prepare_timer, + prepare_duration: Duration::default(), recover_duration: self.recover_duration, projectile: self.projectile.clone(), projectile_body: self.projectile_body, @@ -62,7 +65,7 @@ impl CharacterBehavior for Data { } else if self.recover_duration != Duration::default() { // Recovery update.character = CharacterState::CastFireball(Data { - prepare_timer: self.prepare_timer, + prepare_duration: Duration::default(), recover_duration: self .recover_duration .checked_sub(Duration::from_secs_f32(data.dt.0))