From 41d3322fb20f98b3e31af0a2f0ce88fe4d5a33e2 Mon Sep 17 00:00:00 2001 From: jiminycrick Date: Sat, 14 Nov 2020 16:14:15 -0800 Subject: [PATCH] Initial work to move combat sfx to outcomes --- assets/voxygen/audio/sfx.ron | 60 ++++++++++++++-------------- common/src/event.rs | 2 + common/src/outcome.rs | 18 +++++---- common/src/state.rs | 25 ++++++++++++ common/src/sys/melee.rs | 3 +- server/src/events/entity_creation.rs | 5 +++ voxygen/src/audio/sfx/mod.rs | 59 ++++++++++++++++++++++++++- 7 files changed, 132 insertions(+), 40 deletions(-) diff --git a/assets/voxygen/audio/sfx.ron b/assets/voxygen/audio/sfx.ron index a2a2b9f168..959d1913a1 100644 --- a/assets/voxygen/audio/sfx.ron +++ b/assets/voxygen/audio/sfx.ron @@ -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 diff --git a/common/src/event.rs b/common/src/event.rs index fee8baf6a0..3b07c7be38 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -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` diff --git a/common/src/outcome.rs b/common/src/outcome.rs index bf6002aa63..3fab916ada 100644 --- a/common/src/outcome.rs +++ b/common/src/outcome.rs @@ -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, }, - Swing { + Attack { pos: Vec3, - ability: CharacterAbilityType, - tool: ToolKind, + character_state: CharacterState, + loadout: Loadout, }, LevelUp { pos: Vec3, }, + Beam { + pos: Vec3, + 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), } } } diff --git a/common/src/state.rs b/common/src/state.rs index aeb90bca02..4c4e64b5d0 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -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::::new()); + ecs } @@ -388,7 +392,28 @@ impl State { for event in events { let mut velocities = self.ecs.write_storage::(); let mut controllers = self.ecs.write_storage::(); + let positions = self.ecs.read_storage::(); + let character_states = self.ecs.read_storage::(); + let loadouts = self.ecs.read_storage::(); match event { + LocalEvent::Attack(entity) => { + self.ecs + .write_resource::>() + .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; diff --git a/common/src/sys/melee.rs b/common/src/sys/melee.rs index f284cb390d..60c120ab6e 100644 --- a/common/src/sys/melee.rs +++ b/common/src/sys/melee.rs @@ -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 ( diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 6ff0943886..6d8aa4b1de 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -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::>().push(Outcome::Beam { + pos: pos.0, + heal: properties.lifesteal_eff > 0.0, + }); state.create_beam(properties, pos, ori).build(); } diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index dcbc958e0f..c77cd7bb93 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -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, + ); + }, + _ => {}, + } + } + } + } + }, } }