From f516c041c5823c35cd03b8371b953eb6868417a6 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Sat, 22 May 2021 15:50:29 -0400 Subject: [PATCH] Make the camera zoom as the bow is charging. --- common/src/states/charged_ranged.rs | 11 ++++++--- voxygen/src/session/mod.rs | 35 +++++++++++++++++++---------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 2b8de1ac42..9f8be59235 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -61,6 +61,13 @@ pub struct Data { pub exhausted: bool, } +impl Data { + /// How complete the charge is, on a scale of 0.0 to 1.0 + pub fn charge_frac(&self) -> f32 { + (self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()).min(1.0) + } +} + impl CharacterBehavior for Data { fn behavior(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); @@ -91,9 +98,7 @@ impl CharacterBehavior for Data { }, StageSection::Charge => { if !input_is_pressed(data, self.static_data.ability_info.input) && !self.exhausted { - let charge_frac = (self.timer.as_secs_f32() - / self.static_data.charge_duration.as_secs_f32()) - .min(1.0); + let charge_frac = self.charge_frac(); let arrow = ProjectileConstructor::Arrow { damage: self.static_data.initial_damage as f32 + charge_frac * self.static_data.scaled_damage as f32, diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 86a33f669a..95c5ca9530 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -285,6 +285,22 @@ impl PlayState for SessionState { camera.set_orientation(cam_dir); } + let client = self.client.borrow(); + let player_entity = client.entity(); + + let fov_scaling = { + if let Some(comp::CharacterState::ChargedRanged(cr)) = client + .state() + .read_storage::() + .get(player_entity) + { + 1.0 - 3.0 * cr.charge_frac() / 4.0 + } else { + 1.0 + } + }; + camera.set_fov((global_state.settings.graphics.fov as f32 * fov_scaling).to_radians()); + // Compute camera data camera.compute_dependents(&*self.client.borrow().state().terrain()); let camera::Dependents { @@ -295,18 +311,17 @@ impl PlayState for SessionState { let cam_pos = cam_pos + focus_off; let (is_aiming, aim_dir_offset) = { - let client = self.client.borrow(); let is_aiming = client .state() .read_storage::() - .get(client.entity()) + .get(player_entity) .map(|cs| cs.is_aimed()) .unwrap_or(false); ( is_aiming, if is_aiming && self.scene.camera().get_mode() == CameraMode::ThirdPerson { - Vec3::unit_z() * 0.05 + Vec3::unit_z() * 0.025 } else { Vec3::zero() }, @@ -314,25 +329,21 @@ impl PlayState for SessionState { }; self.is_aiming = is_aiming; - let player_entity = self.client.borrow().entity(); - - let can_build = self - .client - .borrow() + let can_build = client .state() .read_storage::() .get(player_entity) .map_or_else(|| false, |cb| cb.enabled); - let is_mining = self - .client - .borrow() + let is_mining = client .inventories() .get(player_entity) .and_then(|inv| inv.equipped(EquipSlot::ActiveMainhand)) .and_then(|item| item.tool()) .map_or(false, |tool| tool.kind == ToolKind::Pick) - && self.client.borrow().is_wielding() == Some(true); + && client.is_wielding() == Some(true); + + drop(client); // Check to see whether we're aiming at anything let (build_pos, select_pos, target_entity) =