From 0f201c5e09dc6c8ecfecfe33185b3e18aba483a7 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 21 Mar 2021 20:09:59 +0000 Subject: [PATCH] Outcome for block destruction, take select_pos from ControllerInputs --- assets/common/items/tool/pick.ron | 2 +- assets/common/recipe_book.ron | 9 ++++++++ common/src/comp/character_state.rs | 2 -- common/src/comp/controller.rs | 2 ++ common/src/outcome.rs | 5 ++++ common/src/states/basic_melee.rs | 5 ++-- common/src/states/behavior.rs | 1 - common/src/states/charged_melee.rs | 5 ++-- common/src/states/combo_melee.rs | 5 ++-- common/src/states/dash_melee.rs | 5 ++-- common/src/states/leap_melee.rs | 5 ++-- common/src/states/spin_melee.rs | 5 ++-- common/src/states/utils.rs | 37 +++++++++++------------------- server/src/events/interaction.rs | 9 ++++++++ voxygen/src/audio/sfx/mod.rs | 4 ++++ voxygen/src/scene/particle.rs | 11 +++++++++ voxygen/src/session.rs | 1 + 17 files changed, 68 insertions(+), 45 deletions(-) diff --git a/assets/common/items/tool/pick.ron b/assets/common/items/tool/pick.ron index cf9fae385a..ee303546f2 100644 --- a/assets/common/items/tool/pick.ron +++ b/assets/common/items/tool/pick.ron @@ -1,5 +1,5 @@ ItemDef( - name: "Stone Pickaxe", + name: "Iron Pickaxe", description: "Strike the earth!", kind: Tool(( kind: Pick, diff --git a/assets/common/recipe_book.ron b/assets/common/recipe_book.ron index abe8561486..305a796504 100644 --- a/assets/common/recipe_book.ron +++ b/assets/common/recipe_book.ron @@ -375,6 +375,15 @@ (Item("common.items.crafting_tools.sewing_set"), 0), ], ), + "pickaxe": ( + ("common.items.tool.pick", 1), + [ + (Item("common.items.crafting_ing.wool"), 1), // TODO: Replace with plant fiber when obtainable + (Item("common.items.crafting_ing.stones"), 5), // TODO: Replace with iron ingots when obtainable + (Item("common.items.crafting_ing.twigs"), 4), + (Item("common.items.crafting_tools.craftsman_hammer"), 0), + ], + ), "cloth_scraps": ( ("common.items.crafting_ing.cloth_scraps", 1), [ diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 2d3f1f5674..cac86218c4 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -22,7 +22,6 @@ pub struct StateUpdate { pub removed_inputs: Vec, pub local_events: VecDeque, pub server_events: VecDeque, - pub select_pos: Option>, } impl From<&JoinData<'_>> for StateUpdate { @@ -38,7 +37,6 @@ impl From<&JoinData<'_>> for StateUpdate { removed_inputs: Vec::new(), local_events: VecDeque::new(), server_events: VecDeque::new(), - select_pos: None, } } } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 7b2fa468f4..f0a32840aa 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -163,6 +163,7 @@ pub struct ControllerInputs { pub move_z: f32, /* z axis (not combined with move_dir because they may have independent * limits) */ pub look_dir: Dir, + pub select_pos: Option>, } #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] @@ -181,6 +182,7 @@ impl ControllerInputs { self.move_dir = new.move_dir; self.move_z = new.move_z; self.look_dir = new.look_dir; + self.select_pos = new.select_pos; } } diff --git a/common/src/outcome.rs b/common/src/outcome.rs index f46bc3874b..56cc92979c 100644 --- a/common/src/outcome.rs +++ b/common/src/outcome.rs @@ -41,6 +41,10 @@ pub enum Outcome { uid: Uid, combo: u32, }, + BreakBlock { + pos: Vec3, + color: Option>, + }, } impl Outcome { @@ -50,6 +54,7 @@ impl Outcome { | Outcome::ProjectileShot { pos, .. } | Outcome::Beam { pos, .. } | Outcome::SkillPointGain { pos, .. } => Some(*pos), + Outcome::BreakBlock { pos, .. } => Some(pos.map(|e| e as f32 + 0.5)), Outcome::ExpChange { .. } | Outcome::ComboChange { .. } => None, } } diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 3eeaa21e19..78719faec7 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -122,9 +122,8 @@ impl CharacterBehavior for Data { max_angle: self.static_data.max_angle, applied: false, hit_count: 0, - break_block: self - .static_data - .ability_info + break_block: data + .inputs .select_pos .map(|p| { ( diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index 2e81b5d927..90e1e98cc6 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -38,7 +38,6 @@ pub trait CharacterBehavior { select_pos: Option>, ) -> StateUpdate { let mut update = StateUpdate::from(data); - update.select_pos = select_pos; update.queued_inputs.insert(input, InputAttr { select_pos }); update } diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index f75d13278c..049b7374e8 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -187,9 +187,8 @@ impl CharacterBehavior for Data { max_angle: self.static_data.max_angle.to_radians(), applied: false, hit_count: 0, - break_block: self - .static_data - .ability_info + break_block: data + .inputs .select_pos .map(|p| { ( diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index 37c2da82a8..ccb26f20bf 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -213,9 +213,8 @@ impl CharacterBehavior for Data { max_angle: self.static_data.stage_data[stage_index].angle.to_radians(), applied: false, hit_count: 0, - break_block: self - .static_data - .ability_info + break_block: data + .inputs .select_pos .map(|p| { ( diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 4c40c58726..4fa754889e 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -164,9 +164,8 @@ impl CharacterBehavior for Data { max_angle: self.static_data.angle.to_radians(), applied: false, hit_count: 0, - break_block: self - .static_data - .ability_info + break_block: data + .inputs .select_pos .map(|p| { ( diff --git a/common/src/states/leap_melee.rs b/common/src/states/leap_melee.rs index e0035ec747..50735eaf74 100644 --- a/common/src/states/leap_melee.rs +++ b/common/src/states/leap_melee.rs @@ -177,9 +177,8 @@ impl CharacterBehavior for Data { max_angle: self.static_data.max_angle.to_radians(), applied: false, hit_count: 0, - break_block: self - .static_data - .ability_info + break_block: data + .inputs .select_pos .map(|p| { ( diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index b3fff6a28d..4dce57dff4 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -141,9 +141,8 @@ impl CharacterBehavior for Data { max_angle: 180_f32.to_radians(), applied: false, hit_count: 0, - break_block: self - .static_data - .ability_info + break_block: data + .inputs .select_pos .map(|p| { ( diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index e800a3d3e3..9e40c195b8 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -5,8 +5,7 @@ use crate::{ item::{Hands, ItemKind, Tool, ToolKind}, quadruped_low, quadruped_medium, quadruped_small, ship, skills::Skill, - theropod, Body, CharacterAbility, CharacterState, InputAttr, InputKind, InventoryAction, - StateUpdate, + theropod, Body, CharacterAbility, CharacterState, InputKind, InventoryAction, StateUpdate, }, consts::{FRIC_GROUND, GRAVITY}, event::{LocalEvent, ServerEvent}, @@ -512,16 +511,7 @@ fn handle_ability(data: &JoinData, update: &mut StateUpdate, input: InputKind) { { update.character = ( &ability, - AbilityInfo::from_input( - data, - matches!(equip_slot, EquipSlot::Offhand), - input, - data.controller - .queued_inputs - .get(&input) - .cloned() - .unwrap_or_default(), - ), + AbilityInfo::from_input(data, matches!(equip_slot, EquipSlot::Offhand), input), ) .into(); } @@ -575,7 +565,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { if let CharacterState::ComboMelee(c) = data.character { update.character = ( &ability, - AbilityInfo::from_input(data, false, InputKind::Roll, InputAttr::default()), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -585,7 +575,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else if data.character.is_wield() { update.character = ( &ability, - AbilityInfo::from_input(data, false, InputKind::Roll, InputAttr::default()), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -594,7 +584,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else if data.character.is_stealthy() { update.character = ( &ability, - AbilityInfo::from_input(data, false, InputKind::Roll, InputAttr::default()), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -603,7 +593,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else { update.character = ( &ability, - AbilityInfo::from_input(data, false, InputKind::Roll, InputAttr::default()), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); } @@ -705,12 +695,7 @@ pub struct AbilityInfo { } impl AbilityInfo { - pub fn from_input( - data: &JoinData, - from_offhand: bool, - input: InputKind, - input_attr: InputAttr, - ) -> Self { + pub fn from_input(data: &JoinData, from_offhand: bool, input: InputKind) -> Self { let tool_data = if from_offhand { unwrap_tool_data(data, EquipSlot::Offhand) } else { @@ -729,7 +714,13 @@ impl AbilityInfo { tool, hand, input, - select_pos: input_attr.select_pos, + select_pos: data + .controller + .queued_inputs + .get(&input) + .cloned() + .unwrap_or_default() + .select_pos, } } } diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index 277b528716..17bb66a046 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -8,6 +8,7 @@ use common::{ Inventory, Pos, }, consts::MAX_MOUNT_RANGE, + outcome::Outcome, uid::Uid, vol::ReadVol, }; @@ -265,6 +266,7 @@ pub fn handle_mine_block(server: &mut Server, pos: Vec3, tool: Option, tool: Option>() + .push(Outcome::BreakBlock { + pos, + color: block.get_color(), + }); } } } diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 75fed8efb6..b86acfa1b6 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -365,6 +365,10 @@ impl SfxMgr { }, }, Outcome::ExpChange { .. } | Outcome::ComboChange { .. } => {}, + Outcome::BreakBlock { pos, .. } => { + let file_ref = "voxygen.audio.sfx.footsteps.stone_step_1"; + audio.play_sfx(file_ref, pos.map(|e| e as f32 + 0.5), Some(3.0)); + }, } } diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index eb8a8c7fee..b8235ad889 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -156,6 +156,17 @@ impl ParticleMgr { } }, Outcome::ProjectileShot { .. } => {}, + Outcome::BreakBlock { pos, .. } => { + // TODO: Use color field when particle colors are a thing + self.particles.resize_with(self.particles.len() + 30, || { + Particle::new( + Duration::from_millis(100), + time, + ParticleMode::Shrapnel, + pos.map(|e| e as f32 + 0.5), + ) + }); + }, _ => {}, } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 0b96ce2e15..879d440d4e 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -328,6 +328,7 @@ impl PlayState for SessionState { b.is_collectible() } }); + self.inputs.select_pos = select_pos; // Throw out distance info, it will be useful in the future self.target_entity = target_entity.map(|x| x.0);