Initial work to move combat sfx to outcomes

This commit is contained in:
jiminycrick 2020-11-14 16:14:15 -08:00
parent 77d624f640
commit b3aa454f8e
7 changed files with 132 additions and 40 deletions

View File

@ -181,24 +181,24 @@
],
threshold: 0.5,
),
Attack(ComboMelee(Swing, 1), Sword): (
files: [
"voxygen.audio.sfx.abilities.swing_sword",
],
threshold: 0.7,
),
Attack(ComboMelee(Swing, 2), Sword): (
files: [
"voxygen.audio.sfx.abilities.separated_second_swing",
],
threshold: 0.7,
),
Attack(ComboMelee(Swing, 3), Sword): (
files: [
"voxygen.audio.sfx.abilities.separated_third_swing",
],
threshold: 0.7,
),
//Attack(ComboMelee(Swing, 1), Sword): (
// files: [
// "voxygen.audio.sfx.abilities.swing_sword",
// ],
// threshold: 0.7,
//),
//Attack(ComboMelee(Swing, 2), Sword): (
// files: [
// "voxygen.audio.sfx.abilities.separated_second_swing",
// ],
// threshold: 0.7,
//),
//Attack(ComboMelee(Swing, 3), Sword): (
// files: [
// "voxygen.audio.sfx.abilities.separated_third_swing",
// ],
// threshold: 0.7,
//),
Attack(DashMelee(Swing), Sword): (
files: [
"voxygen.audio.sfx.abilities.sword_dash",
@ -319,12 +319,12 @@
],
threshold: 0.5,
),
Attack(BasicBeam, Staff): (
files: [
"voxygen.audio.sfx.abilities.flame_thrower",
],
threshold: 0.2,
),
//Attack(BasicBeam, Staff): (
// files: [
// "voxygen.audio.sfx.abilities.flame_thrower",
// ],
// threshold: 0.2,
//),
Attack(BasicRanged, Staff): (
files: [
// "voxygen.audio.sfx.abilities.staff_channeling",
@ -381,12 +381,12 @@
],
threshold: 0.5,
),
Attack(BasicBeam, Sceptre): (
files: [
"voxygen.audio.sfx.abilities.staff_channeling",
],
threshold: 0.6,
),
//Attack(BasicBeam, Sceptre): (
// files: [
// "voxygen.audio.sfx.abilities.staff_channeling",
// ],
// threshold: 0.6,
//),
//
// Dagger

View File

@ -9,6 +9,8 @@ use std::{collections::VecDeque, ops::DerefMut};
use vek::*;
pub enum LocalEvent {
/// An attack for use with particles and sfx
Attack(EcsEntity),
/// Applies upward force to entity's `Vel`
Jump(EcsEntity),
/// Applies the `impulse` to `entity`'s `Vel`

View File

@ -1,8 +1,5 @@
use crate::comp;
use comp::{
item::{tool::ToolKind, Reagent},
CharacterAbilityType,
};
use comp::{item::Reagent, CharacterState, Loadout};
use serde::{Deserialize, Serialize};
use vek::*;
@ -25,14 +22,18 @@ pub enum Outcome {
body: comp::Body,
vel: Vec3<f32>,
},
Swing {
Attack {
pos: Vec3<f32>,
ability: CharacterAbilityType,
tool: ToolKind,
character_state: CharacterState,
loadout: Loadout,
},
LevelUp {
pos: Vec3<f32>,
},
Beam {
pos: Vec3<f32>,
heal: bool,
},
}
impl Outcome {
@ -40,8 +41,9 @@ impl Outcome {
match self {
Outcome::Explosion { pos, .. } => Some(*pos),
Outcome::ProjectileShot { pos, .. } => Some(*pos),
Outcome::Swing { pos, .. } => Some(*pos),
Outcome::Attack { pos, .. } => Some(*pos),
Outcome::LevelUp { pos } => Some(*pos),
Outcome::Beam { pos, .. } => Some(*pos),
}
}
}

View File

@ -2,6 +2,7 @@ use crate::{
comp,
event::{EventBus, LocalEvent, ServerEvent},
metrics::{PhysicsMetrics, SysMetrics},
outcome::Outcome,
region::RegionMap,
sync::WorldSyncExt,
sys,
@ -187,6 +188,9 @@ impl State {
ecs.insert(SysMetrics::default());
ecs.insert(PhysicsMetrics::default());
// Register outcomes
ecs.insert(Vec::<Outcome>::new());
ecs
}
@ -388,7 +392,28 @@ impl State {
for event in events {
let mut velocities = self.ecs.write_storage::<comp::Vel>();
let mut controllers = self.ecs.write_storage::<comp::Controller>();
let positions = self.ecs.read_storage::<comp::Pos>();
let character_states = self.ecs.read_storage::<comp::CharacterState>();
let loadouts = self.ecs.read_storage::<comp::Loadout>();
match event {
LocalEvent::Attack(entity) => {
self.ecs
.write_resource::<Vec<Outcome>>()
.push(Outcome::Attack {
pos: positions
.get(entity)
.expect("Failed to fetch attacking entity")
.0,
character_state: character_states
.get(entity)
.expect("Failed to get the character state of the attacking entity")
.clone(),
loadout: loadouts
.get(entity)
.expect("Failed to get attacking entity's loadout")
.clone(),
});
},
LocalEvent::Jump(entity) => {
if let Some(vel) = velocities.get_mut(entity) {
vel.0.z = HUMANOID_JUMP_ACCEL;

View File

@ -56,7 +56,7 @@ impl<'a> System<'a> for Sys {
let start_time = std::time::Instant::now();
span!(_guard, "run", "melee::Sys::run");
let mut server_emitter = server_bus.emitter();
let mut _local_emitter = local_bus.emitter();
let mut local_emitter = local_bus.emitter();
// Attacks
for (entity, uid, pos, ori, scale_maybe, attack) in (
&entities,
@ -72,6 +72,7 @@ impl<'a> System<'a> for Sys {
continue;
}
attack.applied = true;
local_emitter.emit(LocalEvent::Attack(entity));
// Go through all other entities
for (b, pos_b, scale_b_maybe, health_b, body_b, char_state_b_maybe) in (

View File

@ -145,6 +145,11 @@ pub fn handle_shockwave(
pub fn handle_beam(server: &mut Server, properties: beam::Properties, pos: Pos, ori: Ori) {
let state = server.state_mut();
let ecs = state.ecs();
ecs.write_resource::<Vec<Outcome>>().push(Outcome::Beam {
pos: pos.0,
heal: properties.lifesteal_eff > 0.0,
});
state.create_beam(properties, pos, ori).build();
}

View File

@ -97,6 +97,7 @@ use common::{
event::EventBus,
outcome::Outcome,
state::State,
states::utils::StageSection,
terrain::{BlockKind, TerrainChunk},
vol::ReadVol,
};
@ -382,7 +383,63 @@ impl SfxMgr {
let file_ref = "voxygen.audio.sfx.character.level_up_sound_-_shorter_wind_up";
audio.play_sfx(file_ref, *pos, None);
},
_ => {},
Outcome::Beam { pos, heal } => {
if *heal {
let file_ref = "voxygen.audio.sfx.abilities.staff_channeling";
audio.play_sfx(file_ref, *pos, None);
} else {
let file_ref = "voxygen.audio.sfx.abilities.flame_thrower";
audio.play_sfx(file_ref, *pos, None);
}
},
Outcome::Attack {
pos,
character_state,
loadout,
} => {
if let Some(item_config) = &loadout.active_item {
if let ItemKind::Tool(data) = item_config.item.kind() {
if character_state.is_attack() {
match (
CharacterAbilityType::from(character_state),
data.kind.clone(),
) {
(
CharacterAbilityType::ComboMelee(StageSection::Swing, 1),
ToolKind::Sword,
) => {
audio.play_sfx(
"voxygen.audio.sfx.abilities.swing_sword",
*pos,
None,
);
},
(
CharacterAbilityType::ComboMelee(StageSection::Swing, 2),
ToolKind::Sword,
) => {
audio.play_sfx(
"voxygen.audio.sfx.abilities.separated_second_swing",
*pos,
None,
);
},
(
CharacterAbilityType::ComboMelee(StageSection::Swing, 3),
ToolKind::Sword,
) => {
audio.play_sfx(
"voxygen.audio.sfx.abilities.separated_third_swing",
*pos,
None,
);
},
_ => {},
}
}
}
}
},
}
}