address comments

This commit is contained in:
Vincent Foulon 2021-03-20 22:56:54 +01:00
parent 7dad972632
commit 8b01abde67
4 changed files with 65 additions and 58 deletions

View File

@ -1072,46 +1072,39 @@ impl CharacterAbility {
_ => {},
}
},
None => {
use skills::{
ClimbSkill::{self, *},
RollSkill::{self, *},
};
match self {
CharacterAbility::Roll {
ref mut immune_melee,
ref mut energy_cost,
ref mut roll_strength,
ref mut movement_duration,
..
} => {
*immune_melee = skillset.has_skill(Skill::Roll(ImmuneMelee));
if let Ok(Some(level)) = skillset.skill_level(Skill::Roll(RollSkill::Cost))
{
*energy_cost *= 0.8_f32.powi(level.into());
}
if let Ok(Some(level)) = skillset.skill_level(Skill::Roll(Strength)) {
*roll_strength *= 1.2_f32.powi(level.into());
}
if let Ok(Some(level)) = skillset.skill_level(Skill::Roll(Duration)) {
*movement_duration *= 1.2_f32.powi(level.into());
}
},
CharacterAbility::Climb {
ref mut energy_cost,
ref mut movement_speed,
} => {
if let Ok(Some(level)) =
skillset.skill_level(Skill::Climb(ClimbSkill::Cost))
{
*energy_cost *= 0.8_f32.powi(level.into());
}
if let Ok(Some(level)) = skillset.skill_level(Skill::Climb(Speed)) {
*movement_speed *= 1.2_f32.powi(level.into());
}
},
_ => {},
}
None => match self {
CharacterAbility::Roll {
ref mut immune_melee,
ref mut energy_cost,
ref mut roll_strength,
ref mut movement_duration,
..
} => {
use skills::RollSkill::*;
*immune_melee = skillset.has_skill(Skill::Roll(ImmuneMelee));
if let Ok(Some(level)) = skillset.skill_level(Skill::Roll(Cost)) {
*energy_cost *= 0.8_f32.powi(level.into());
}
if let Ok(Some(level)) = skillset.skill_level(Skill::Roll(Strength)) {
*roll_strength *= 1.2_f32.powi(level.into());
}
if let Ok(Some(level)) = skillset.skill_level(Skill::Roll(Duration)) {
*movement_duration *= 1.2_f32.powi(level.into());
}
},
CharacterAbility::Climb {
ref mut energy_cost,
ref mut movement_speed,
} => {
use skills::ClimbSkill::*;
if let Ok(Some(level)) = skillset.skill_level(Skill::Climb(Cost)) {
*energy_cost *= 0.8_f32.powi(level.into());
}
if let Ok(Some(level)) = skillset.skill_level(Skill::Climb(Speed)) {
*movement_speed *= 1.2_f32.powi(level.into());
}
},
_ => {},
},
Some(_) => {},
}
@ -1253,8 +1246,10 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState {
energy_cost,
movement_speed,
} => CharacterState::Climb(climb::Data {
energy_cost: *energy_cost,
movement_speed: *movement_speed,
static_data: climb::StaticData {
energy_cost: *energy_cost,
movement_speed: *movement_speed,
},
}),
CharacterAbility::ComboMelee {
stage_data,

View File

@ -11,17 +11,27 @@ use crate::{
use serde::{Deserialize, Serialize};
use vek::*;
/// Separated out to condense update portions of character state
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
pub struct StaticData {
pub energy_cost: f32,
pub movement_speed: f32,
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
/// Struct containing data that does not change over the course of the
/// character state
pub static_data: StaticData,
}
impl Default for Data {
fn default() -> Self {
Data {
energy_cost: 5.0,
movement_speed: 5.0,
static_data: StaticData {
energy_cost: 5.0,
movement_speed: 5.0,
},
}
}
}
@ -50,15 +60,15 @@ impl CharacterBehavior for Data {
// Move player
update.vel.0 += Vec2::broadcast(data.dt.0)
* data.inputs.move_dir
* if update.vel.0.magnitude_squared() < self.movement_speed.powi(2) {
self.movement_speed.powi(2)
* if update.vel.0.magnitude_squared() < self.static_data.movement_speed.powi(2) {
self.static_data.movement_speed.powi(2)
} else {
0.0
};
// Expend energy if climbing
let energy_use = match climb {
Climb::Up => self.energy_cost as i32,
Climb::Up => self.static_data.energy_cost as i32,
Climb::Down => 1,
Climb::Hold => 1,
};
@ -82,8 +92,12 @@ impl CharacterBehavior for Data {
// Apply Vertical Climbing Movement
match climb {
Climb::Down => update.vel.0.z += data.dt.0 * (GRAVITY - self.movement_speed.powi(2)),
Climb::Up => update.vel.0.z += data.dt.0 * (GRAVITY + self.movement_speed.powi(2)),
Climb::Down => {
update.vel.0.z += data.dt.0 * (GRAVITY - self.static_data.movement_speed.powi(2))
},
Climb::Up => {
update.vel.0.z += data.dt.0 * (GRAVITY + self.static_data.movement_speed.powi(2))
},
Climb::Hold => update.vel.0.z += data.dt.0 * GRAVITY,
}

View File

@ -11,7 +11,6 @@ use common::{
consts::{FRIC_GROUND, GRAVITY},
event::{EventBus, ServerEvent},
resources::DeltaTime,
states::*,
terrain::{Block, TerrainGrid},
uid::Uid,
vol::{BaseVol, ReadVol},
@ -670,9 +669,8 @@ impl<'a> PhysicsData<'a> {
let was_on_ground = physics_state.on_ground;
let block_snap = body.map_or(false, |body| body.jump_impulse().is_some());
let climbing = character_state.map_or(false, |cs| {
matches!(cs, CharacterState::Climb(climb::Data { .. }))
});
let climbing =
character_state.map_or(false, |cs| matches!(cs, CharacterState::Climb(_)));
match &collider {
Collider::Voxel { .. } => {

View File

@ -134,8 +134,8 @@ pub fn skill_to_db_string(skill: comp::skills::Skill) -> String {
Roll(RollSkill::Cost) => "Roll Cost",
Roll(RollSkill::Strength) => "Roll Strength",
Roll(RollSkill::Duration) => "Roll Duration",
Climb(ClimbSkill::Cost) => "Climbing Cost",
Climb(ClimbSkill::Speed) => "Climbing Speed",
Climb(ClimbSkill::Cost) => "Climb Cost",
Climb(ClimbSkill::Speed) => "Climb Speed",
UnlockGroup(SkillGroupKind::Weapon(ToolKind::Sword)) => "Unlock Weapon Sword",
UnlockGroup(SkillGroupKind::Weapon(ToolKind::Axe)) => "Unlock Weapon Axe",
UnlockGroup(SkillGroupKind::Weapon(ToolKind::Hammer)) => "Unlock Weapon Hammer",
@ -259,8 +259,8 @@ pub fn db_string_to_skill(skill_string: &str) -> comp::skills::Skill {
"Roll Cost" => Roll(RollSkill::Cost),
"Roll Strength" => Roll(RollSkill::Strength),
"Roll Duration" => Roll(RollSkill::Duration),
"Climbing Cost" => Climb(ClimbSkill::Cost),
"Climbing Speed" => Climb(ClimbSkill::Speed),
"Climb Cost" => Climb(ClimbSkill::Cost),
"Climb Speed" => Climb(ClimbSkill::Speed),
"Unlock Weapon Sword" => UnlockGroup(SkillGroupKind::Weapon(ToolKind::Sword)),
"Unlock Weapon Axe" => UnlockGroup(SkillGroupKind::Weapon(ToolKind::Axe)),
"Unlock Weapon Hammer" => UnlockGroup(SkillGroupKind::Weapon(ToolKind::Hammer)),