Outcome for block destruction, take select_pos from ControllerInputs

This commit is contained in:
Joshua Barretto 2021-03-21 20:09:59 +00:00
parent f342be71a1
commit fb3980e273
17 changed files with 68 additions and 45 deletions

View File

@ -1,5 +1,5 @@
ItemDef(
name: "Stone Pickaxe",
name: "Iron Pickaxe",
description: "Strike the earth!",
kind: Tool((
kind: Pick,

View File

@ -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),
[

View File

@ -22,7 +22,6 @@ pub struct StateUpdate {
pub removed_inputs: Vec<InputKind>,
pub local_events: VecDeque<LocalEvent>,
pub server_events: VecDeque<ServerEvent>,
pub select_pos: Option<Vec3<f32>>,
}
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,
}
}
}

View File

@ -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<Vec3<f32>>,
}
#[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;
}
}

View File

@ -41,6 +41,10 @@ pub enum Outcome {
uid: Uid,
combo: u32,
},
BreakBlock {
pos: Vec3<i32>,
color: Option<Rgb<u8>>,
},
}
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,
}
}

View File

@ -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| {
(

View File

@ -38,7 +38,6 @@ pub trait CharacterBehavior {
select_pos: Option<Vec3<f32>>,
) -> StateUpdate {
let mut update = StateUpdate::from(data);
update.select_pos = select_pos;
update.queued_inputs.insert(input, InputAttr { select_pos });
update
}

View File

@ -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| {
(

View File

@ -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| {
(

View File

@ -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| {
(

View File

@ -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| {
(

View File

@ -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| {
(

View File

@ -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,
}
}
}

View File

@ -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<i32>, tool: Option<ToolK
if state.can_set_block(pos) {
let block = state.terrain().get(pos).ok().copied();
if let Some(block) = block.filter(|b| b.mine_tool().map_or(true, |t| Some(t) == tool)) {
// Drop item if one is recoverable from the block
if let Some(item) = comp::Item::try_reclaim_from_block(block) {
state
.create_object(Default::default(), comp::object::Body::Pouch)
@ -274,6 +276,13 @@ pub fn handle_mine_block(server: &mut Server, pos: Vec3<i32>, tool: Option<ToolK
}
state.set_block(pos, block.into_vacant());
state
.ecs()
.write_resource::<Vec<Outcome>>()
.push(Outcome::BreakBlock {
pos,
color: block.get_color(),
});
}
}
}

View File

@ -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));
},
}
}

View File

@ -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),
)
});
},
_ => {},
}
}

View File

@ -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);