From c2b99f3a626cb18b4866c438e62479aa085c46d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilbert=20R=C3=B6hrbein?= Date: Sun, 12 Jan 2020 21:06:32 +0100 Subject: [PATCH 1/3] Fix panic in case no default audio device found when audio off --- voxygen/src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index c06abd440a..7898cc2f83 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -116,13 +116,13 @@ fn main() { panic!("Failed to save settings: {:?}", err); } - let mut audio = if settings.audio.audio_on { - let audio_device = match &settings.audio.audio_device { - Some(d) => d.to_string(), - None => audio::get_default_device(), - }; + let audio_device = || match &settings.audio.audio_device { + Some(d) => d.to_string(), + None => audio::get_default_device(), + }; - AudioFrontend::new(audio_device, 16) + let mut audio = if settings.audio.audio_on { + AudioFrontend::new(audio_device(), 16) } else { AudioFrontend::no_audio() }; From 4f90e6325e033ebce196b0245145edac2de440bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilbert=20R=C3=B6hrbein?= Date: Mon, 13 Jan 2020 23:49:46 +0100 Subject: [PATCH 2/3] feat: add endurance fitness willpower to stats --- common/src/comp/stats.rs | 27 +++++++++++++++++++++++++-- common/src/sys/stats.rs | 2 +- server/src/cmd.rs | 7 ++++++- server/src/lib.rs | 16 +++++++--------- server/src/sys/terrain.rs | 9 ++++++--- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index af4f9a9ac5..50dd0340b5 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -1,3 +1,4 @@ +use crate::comp::{body::humanoid::Race, Body}; use crate::{comp, sync::Uid}; use specs::{Component, FlaggedStorage}; use specs_idvs::IDVStorage; @@ -135,7 +136,7 @@ impl Level { } pub fn change_by(&mut self, level: u32) { - self.amount = self.amount + level; + self.amount += level; } } @@ -146,6 +147,9 @@ pub struct Stats { pub level: Level, pub exp: Exp, pub equipment: Equipment, + pub endurance: u32, + pub fitness: u32, + pub willpower: u32, pub is_dead: bool, } @@ -166,7 +170,23 @@ impl Stats { } impl Stats { - pub fn new(name: String, main: Option) -> Self { + pub fn new(name: String, body: Body, main: Option) -> Self { + let race = if let comp::Body::Humanoid(hbody) = body { + Some(hbody.race) + } else { + None + }; + + let (endurance, fitness, willpower) = match race { + Some(Race::Danari) => (0, 1, 2), + Some(Race::Dwarf) => (1, 2, 0), + Some(Race::Elf) => (2, 1, 0), + Some(Race::Human) => (1, 0, 2), + Some(Race::Orc) => (0, 2, 1), + Some(Race::Undead) => (2, 0, 1), + None => (0, 0, 0), + }; + let mut stats = Self { name, health: Health { @@ -186,6 +206,9 @@ impl Stats { maximum: 50, }, equipment: Equipment { main, alt: None }, + endurance, + fitness, + willpower, is_dead: false, }; diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 0564fd8bf2..9836402f05 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -69,7 +69,7 @@ impl<'a> System<'a> for Sys { stat.update_max_hp(); stat.health - .set_to(stat.health.maximum(), HealthSource::LevelUp) + .set_to(stat.health.maximum(), HealthSource::LevelUp); } // Accelerate recharging energy if not wielding. diff --git a/server/src/cmd.rs b/server/src/cmd.rs index ae79ae6215..dcd21129ce 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -484,9 +484,14 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C ); let body = kind_to_body(id); + let new_entity = server .state - .create_npc(pos, comp::Stats::new(get_npc_name(id), None), body) + .create_npc( + pos, + comp::Stats::new(get_npc_name(id), body, None), + body, + ) .with(comp::Vel(vel)) .with(comp::MountState::Unmounted) .with(agent.clone()) diff --git a/server/src/lib.rs b/server/src/lib.rs index bc49da988f..d71c67b025 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -257,7 +257,7 @@ impl Server { let spawn_point = state.ecs().read_resource::().0; state.write_component(entity, body); - state.write_component(entity, comp::Stats::new(name, main)); + state.write_component(entity, comp::Stats::new(name, body, main)); state.write_component(entity, comp::Energy::new(1000)); state.write_component(entity, comp::Controller::default()); state.write_component(entity, comp::Pos(spawn_point)); @@ -501,11 +501,10 @@ impl Server { .get(entity) .map(|inv| !inv.is_full()) .unwrap_or(false) + && state.try_set_block(pos, Block::empty()).is_some() { - if state.try_set_block(pos, Block::empty()).is_some() { - comp::Item::try_reclaim_from_block(block) - .map(|item| state.give_item(entity, item)); - } + comp::Item::try_reclaim_from_block(block) + .map(|item| state.give_item(entity, item)); } } } @@ -517,8 +516,8 @@ impl Server { .get_mut(entity) .and_then(|inv| inv.remove(slot)); - match item_opt { - Some(item) => match item.kind { + if let Some(item) = item_opt { + match item.kind { comp::ItemKind::Tool { .. } => { if let Some(stats) = state .ecs() @@ -548,8 +547,7 @@ impl Server { .get_mut(entity) .map(|inv| inv.insert(slot, item)); } - }, - _ => {} + } } state.write_component(entity, comp::InventoryUpdate); diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index c6ca4ab53e..283a429329 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -97,15 +97,16 @@ impl<'a> System<'a> for Sys { // Handle chunk supplement for npc in supplement.npcs { let (mut stats, mut body) = if rand::random() { + let body = comp::Body::Humanoid(comp::humanoid::Body::random()); let stats = comp::Stats::new( "Traveler".to_string(), + body, Some(assets::load_expect_cloned("common.items.weapons.staff_1")), ); - let body = comp::Body::Humanoid(comp::humanoid::Body::random()); (stats, body) } else { - let stats = comp::Stats::new("Wolf".to_string(), None); let body = comp::Body::QuadrupedMedium(comp::quadruped_medium::Body::random()); + let stats = comp::Stats::new("Wolf".to_string(), body, None); (stats, body) }; let mut scale = 1.0; @@ -115,11 +116,13 @@ impl<'a> System<'a> for Sys { if npc.boss { if rand::random::() < 0.8 { + let hbody = comp::humanoid::Body::random(); + body = comp::Body::Humanoid(hbody); stats = comp::Stats::new( "Fearless Wanderer".to_string(), + body, Some(assets::load_expect_cloned("common.items.weapons.hammer_1")), ); - body = comp::Body::Humanoid(comp::humanoid::Body::random()); } stats.level.set_level(rand::thread_rng().gen_range(8, 15)); scale = 2.0 + rand::random::(); From 28fe73825dc343acad25a6bd81c367bccfd8deee Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 21 Jan 2020 19:24:09 +0100 Subject: [PATCH 3/3] feat: fitness stat effects movement speed --- common/src/comp/stats.rs | 12 +++++------ common/src/sys/movement.rs | 41 +++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 50dd0340b5..67d8f335d9 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -178,12 +178,12 @@ impl Stats { }; let (endurance, fitness, willpower) = match race { - Some(Race::Danari) => (0, 1, 2), - Some(Race::Dwarf) => (1, 2, 0), - Some(Race::Elf) => (2, 1, 0), - Some(Race::Human) => (1, 0, 2), - Some(Race::Orc) => (0, 2, 1), - Some(Race::Undead) => (2, 0, 1), + Some(Race::Danari) => (0, 2, 3), // Small, flexible, intelligent, physically weak + Some(Race::Dwarf) => (2, 2, 1), // phyiscally strong, intelligent, slow reflexes + Some(Race::Elf) => (1, 2, 2), // Intelligent, quick, physically weak + Some(Race::Human) => (2, 1, 2), // Perfectly balanced + Some(Race::Orc) => (3, 2, 0), // Physically strong, non intelligent, medium reflexes + Some(Race::Undead) => (1, 3, 1), // Very good reflexes, equally intelligent and strong None => (0, 0, 0), }; diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index e7c93e3bbf..ffd6334255 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -15,13 +15,13 @@ use vek::*; pub const ROLL_DURATION: Duration = Duration::from_millis(600); -const HUMANOID_ACCEL: f32 = 100.0; -const HUMANOID_SPEED: f32 = 120.0; -const HUMANOID_AIR_ACCEL: f32 = 15.0; -const HUMANOID_AIR_SPEED: f32 = 100.0; -const HUMANOID_WATER_ACCEL: f32 = 70.0; -const HUMANOID_WATER_SPEED: f32 = 120.0; -const HUMANOID_CLIMB_ACCEL: f32 = 10.0; +const BASE_HUMANOID_ACCEL: f32 = 100.0; +const BASE_HUMANOID_SPEED: f32 = 120.0; +const BASE_HUMANOID_AIR_ACCEL: f32 = 15.0; +const BASE_HUMANOID_AIR_SPEED: f32 = 100.0; +const BASE_HUMANOID_WATER_ACCEL: f32 = 70.0; +const BASE_HUMANOID_WATER_SPEED: f32 = 120.0; +const BASE_HUMANOID_CLIMB_ACCEL: f32 = 10.0; const ROLL_SPEED: f32 = 17.0; const CHARGE_SPEED: f32 = 20.0; const GLIDE_ACCEL: f32 = 15.0; @@ -142,24 +142,33 @@ impl<'a> System<'a> for Sys { vel.0 += Vec2::broadcast(dt.0) * inputs.move_dir * match (physics.on_ground, &character.movement) { - (true, Run) if vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) => { - HUMANOID_ACCEL + (true, Run) + if vel.0.magnitude_squared() + < (BASE_HUMANOID_SPEED + stats.fitness as f32 * 50.0).powf(2.0) => + { + BASE_HUMANOID_ACCEL } - (false, Climb) if vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) => { - HUMANOID_CLIMB_ACCEL + (false, Climb) + if vel.0.magnitude_squared() < BASE_HUMANOID_SPEED.powf(2.0) => + { + BASE_HUMANOID_CLIMB_ACCEL } (false, Glide) if vel.0.magnitude_squared() < GLIDE_SPEED.powf(2.0) => { GLIDE_ACCEL } (false, Fall) | (false, Jump) - if vel.0.magnitude_squared() < HUMANOID_AIR_SPEED.powf(2.0) => + if vel.0.magnitude_squared() + < (BASE_HUMANOID_AIR_SPEED + stats.fitness as f32 * 10.0) + .powf(2.0) => { - HUMANOID_AIR_ACCEL + BASE_HUMANOID_AIR_ACCEL } (false, Swim) - if vel.0.magnitude_squared() < HUMANOID_WATER_SPEED.powf(2.0) => + if vel.0.magnitude_squared() + < (BASE_HUMANOID_WATER_SPEED + stats.fitness as f32 * 30.0) + .powf(2.0) => { - HUMANOID_WATER_ACCEL + BASE_HUMANOID_WATER_ACCEL + stats.fitness as f32 * 10.0 } _ => 0.0, }; @@ -228,7 +237,7 @@ impl<'a> System<'a> for Sys { } if character.movement == Swim && inputs.jump.is_pressed() { - vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(HUMANOID_WATER_SPEED); + vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(BASE_HUMANOID_WATER_SPEED); } } }