mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added keyframes to leap melee.
This commit is contained in:
@ -121,15 +121,16 @@ pub enum CharacterAbility {
|
|||||||
},
|
},
|
||||||
LeapMelee {
|
LeapMelee {
|
||||||
energy_cost: u32,
|
energy_cost: u32,
|
||||||
movement_duration: Duration,
|
|
||||||
buildup_duration: Duration,
|
buildup_duration: Duration,
|
||||||
|
movement_duration: Duration,
|
||||||
|
swing_duration: Duration,
|
||||||
recover_duration: Duration,
|
recover_duration: Duration,
|
||||||
base_damage: u32,
|
base_damage: u32,
|
||||||
range: f32,
|
range: f32,
|
||||||
max_angle: f32,
|
max_angle: f32,
|
||||||
knockback: f32,
|
knockback: f32,
|
||||||
leap_speed: f32,
|
forward_leap_strength: f32,
|
||||||
leap_vert_speed: f32,
|
vertical_leap_strength: f32,
|
||||||
},
|
},
|
||||||
SpinMelee {
|
SpinMelee {
|
||||||
buildup_duration: Duration,
|
buildup_duration: Duration,
|
||||||
@ -464,27 +465,32 @@ impl From<&CharacterAbility> for CharacterState {
|
|||||||
}),
|
}),
|
||||||
CharacterAbility::LeapMelee {
|
CharacterAbility::LeapMelee {
|
||||||
energy_cost: _,
|
energy_cost: _,
|
||||||
movement_duration,
|
|
||||||
buildup_duration,
|
buildup_duration,
|
||||||
|
movement_duration,
|
||||||
|
swing_duration,
|
||||||
recover_duration,
|
recover_duration,
|
||||||
base_damage,
|
base_damage,
|
||||||
|
knockback,
|
||||||
range,
|
range,
|
||||||
max_angle,
|
max_angle,
|
||||||
knockback,
|
forward_leap_strength,
|
||||||
leap_speed,
|
vertical_leap_strength,
|
||||||
leap_vert_speed,
|
|
||||||
} => CharacterState::LeapMelee(leap_melee::Data {
|
} => CharacterState::LeapMelee(leap_melee::Data {
|
||||||
initialize: true,
|
static_data: leap_melee::StaticData {
|
||||||
exhausted: false,
|
|
||||||
movement_duration: *movement_duration,
|
|
||||||
buildup_duration: *buildup_duration,
|
buildup_duration: *buildup_duration,
|
||||||
|
movement_duration: *movement_duration,
|
||||||
|
swing_duration: *swing_duration,
|
||||||
recover_duration: *recover_duration,
|
recover_duration: *recover_duration,
|
||||||
base_damage: *base_damage,
|
base_damage: *base_damage,
|
||||||
|
knockback: *knockback,
|
||||||
range: *range,
|
range: *range,
|
||||||
max_angle: *max_angle,
|
max_angle: *max_angle,
|
||||||
knockback: *knockback,
|
forward_leap_strength: *forward_leap_strength,
|
||||||
leap_speed: *leap_speed,
|
vertical_leap_strength: *vertical_leap_strength,
|
||||||
leap_vert_speed: *leap_vert_speed,
|
},
|
||||||
|
timer: Duration::default(),
|
||||||
|
stage_section: StageSection::Buildup,
|
||||||
|
exhausted: false,
|
||||||
}),
|
}),
|
||||||
CharacterAbility::SpinMelee {
|
CharacterAbility::SpinMelee {
|
||||||
buildup_duration,
|
buildup_duration,
|
||||||
|
@ -228,15 +228,16 @@ impl Tool {
|
|||||||
},
|
},
|
||||||
LeapMelee {
|
LeapMelee {
|
||||||
energy_cost: 450,
|
energy_cost: 450,
|
||||||
|
buildup_duration: Duration::from_millis(100),
|
||||||
movement_duration: Duration::from_millis(200),
|
movement_duration: Duration::from_millis(200),
|
||||||
buildup_duration: Duration::from_millis(1000),
|
swing_duration: Duration::from_millis(100),
|
||||||
recover_duration: Duration::from_millis(600),
|
recover_duration: Duration::from_millis(600),
|
||||||
base_damage: (160.0 * self.base_power()) as u32,
|
base_damage: (160.0 * self.base_power()) as u32,
|
||||||
|
knockback: 15.0,
|
||||||
range: 3.5,
|
range: 3.5,
|
||||||
max_angle: 100.0,
|
max_angle: 100.0,
|
||||||
knockback: 15.0,
|
forward_leap_strength: 16.0,
|
||||||
leap_speed: 16.0,
|
vertical_leap_strength: 6.0,
|
||||||
leap_vert_speed: 6.0,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
Hammer(_) => vec![
|
Hammer(_) => vec![
|
||||||
@ -264,15 +265,16 @@ impl Tool {
|
|||||||
},
|
},
|
||||||
LeapMelee {
|
LeapMelee {
|
||||||
energy_cost: 700,
|
energy_cost: 700,
|
||||||
|
buildup_duration: Duration::from_millis(100),
|
||||||
movement_duration: Duration::from_millis(500),
|
movement_duration: Duration::from_millis(500),
|
||||||
buildup_duration: Duration::from_millis(1000),
|
swing_duration: Duration::from_millis(100),
|
||||||
recover_duration: Duration::from_millis(100),
|
recover_duration: Duration::from_millis(100),
|
||||||
base_damage: (240.0 * self.base_power()) as u32,
|
base_damage: (240.0 * self.base_power()) as u32,
|
||||||
|
knockback: 25.0,
|
||||||
range: 4.5,
|
range: 4.5,
|
||||||
max_angle: 360.0,
|
max_angle: 360.0,
|
||||||
knockback: 25.0,
|
forward_leap_strength: 24.0,
|
||||||
leap_speed: 24.0,
|
vertical_leap_strength: 4.0,
|
||||||
leap_vert_speed: 4.0,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
Farming(_) => vec![BasicMelee {
|
Farming(_) => vec![BasicMelee {
|
||||||
|
@ -1,140 +1,184 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{Attacking, CharacterState, StateUpdate},
|
comp::{Attacking, CharacterState, StateUpdate},
|
||||||
states::utils::*,
|
states::utils::{StageSection, *},
|
||||||
sys::character_behavior::{CharacterBehavior, JoinData},
|
sys::character_behavior::{CharacterBehavior, JoinData},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use vek::Vec3;
|
use vek::Vec3;
|
||||||
|
|
||||||
|
/// Separated out to condense update portions of character state
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
//#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
pub struct StaticData {
|
||||||
pub struct Data {
|
|
||||||
/// How long the state is moving
|
/// How long the state is moving
|
||||||
pub movement_duration: Duration,
|
pub movement_duration: Duration,
|
||||||
/// How long until state should deal damage
|
/// How long until state should deal damage
|
||||||
pub buildup_duration: Duration,
|
pub buildup_duration: Duration,
|
||||||
|
/// How long the weapon swings
|
||||||
|
pub swing_duration: Duration,
|
||||||
/// How long the state has until exiting
|
/// How long the state has until exiting
|
||||||
pub recover_duration: Duration,
|
pub recover_duration: Duration,
|
||||||
/// Base damage
|
/// Base damage
|
||||||
pub base_damage: u32,
|
pub base_damage: u32,
|
||||||
/// Whether the attack can deal more damage
|
/// Knockback
|
||||||
pub exhausted: bool,
|
pub knockback: f32,
|
||||||
/// Max range
|
/// Max range
|
||||||
pub range: f32,
|
pub range: f32,
|
||||||
/// Max angle (45.0 will give you a 90.0 angle window)
|
/// Max angle (45.0 will give you a 90.0 angle window)
|
||||||
pub max_angle: f32,
|
pub max_angle: f32,
|
||||||
/// Knockback
|
/// Affects how far forward the player leaps
|
||||||
pub knockback: f32,
|
pub forward_leap_strength: f32,
|
||||||
/// Leap speed
|
/// Affects how high the player leaps
|
||||||
pub leap_speed: f32,
|
pub vertical_leap_strength: f32,
|
||||||
/// Leap vertical speed?
|
}
|
||||||
pub leap_vert_speed: f32,
|
|
||||||
pub initialize: bool,
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
//#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||||||
|
pub struct Data {
|
||||||
|
/// Struct containing data that does not change over the course of the
|
||||||
|
/// character state
|
||||||
|
pub static_data: StaticData,
|
||||||
|
/// Timer for each stage
|
||||||
|
pub timer: Duration,
|
||||||
|
/// What section the character stage is in
|
||||||
|
pub stage_section: StageSection,
|
||||||
|
/// Whether the attack can deal more damage
|
||||||
|
pub exhausted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharacterBehavior for Data {
|
impl CharacterBehavior for Data {
|
||||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
|
|
||||||
if self.initialize {
|
handle_move(data, &mut update, 0.3);
|
||||||
update.vel.0 = *data.inputs.look_dir * 20.0;
|
handle_jump(data, &mut update);
|
||||||
if let Some(dir) = Vec3::from(data.inputs.look_dir.xy()).try_normalized() {
|
|
||||||
update.ori.0 = dir.into();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.movement_duration != Duration::default() {
|
match self.stage_section {
|
||||||
|
StageSection::Buildup => {
|
||||||
|
if self.timer < self.static_data.buildup_duration {
|
||||||
|
// Buildup
|
||||||
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
stage_section: self.stage_section,
|
||||||
|
exhausted: self.exhausted,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Transitions to leap portion of state
|
||||||
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
timer: Duration::default(),
|
||||||
|
stage_section: StageSection::Movement,
|
||||||
|
exhausted: self.exhausted,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
StageSection::Movement => {
|
||||||
// Jumping
|
// Jumping
|
||||||
update.vel.0 = Vec3::new(
|
update.vel.0 = Vec3::new(
|
||||||
data.inputs.look_dir.x,
|
data.inputs.look_dir.x,
|
||||||
data.inputs.look_dir.y,
|
data.inputs.look_dir.y,
|
||||||
self.leap_vert_speed,
|
self.static_data.vertical_leap_strength,
|
||||||
) * (2.0)
|
) * 2.0
|
||||||
|
* (1.0
|
||||||
|
- self.timer.as_secs_f32()
|
||||||
|
/ self.static_data.movement_duration.as_secs_f32())
|
||||||
+ (update.vel.0 * Vec3::new(2.0, 2.0, 0.0)
|
+ (update.vel.0 * Vec3::new(2.0, 2.0, 0.0)
|
||||||
+ 0.25 * data.inputs.move_dir.try_normalized().unwrap_or_default())
|
+ 0.25 * data.inputs.move_dir.try_normalized().unwrap_or_default())
|
||||||
.try_normalized()
|
.try_normalized()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
* self.leap_speed
|
* self.static_data.forward_leap_strength
|
||||||
* (1.0 - data.inputs.look_dir.z.abs());
|
* (1.0 - data.inputs.look_dir.z.abs());
|
||||||
|
|
||||||
|
if self.timer < self.static_data.movement_duration {
|
||||||
|
// Movement duration
|
||||||
update.character = CharacterState::LeapMelee(Data {
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
movement_duration: self
|
static_data: self.static_data,
|
||||||
.movement_duration
|
timer: self
|
||||||
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
buildup_duration: self.buildup_duration,
|
stage_section: self.stage_section,
|
||||||
recover_duration: self.recover_duration,
|
exhausted: self.exhausted,
|
||||||
base_damage: self.base_damage,
|
|
||||||
exhausted: false,
|
|
||||||
range: self.range,
|
|
||||||
max_angle: self.max_angle,
|
|
||||||
knockback: self.knockback,
|
|
||||||
leap_speed: self.leap_speed,
|
|
||||||
leap_vert_speed: self.leap_vert_speed,
|
|
||||||
initialize: false,
|
|
||||||
});
|
});
|
||||||
} else if self.buildup_duration != Duration::default() && !data.physics.on_ground {
|
} else {
|
||||||
// Falling
|
// Transitions to swing portion of state
|
||||||
update.character = CharacterState::LeapMelee(Data {
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
movement_duration: Duration::default(),
|
static_data: self.static_data,
|
||||||
buildup_duration: self
|
timer: Duration::default(),
|
||||||
.buildup_duration
|
stage_section: StageSection::Swing,
|
||||||
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
exhausted: self.exhausted,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
StageSection::Swing => {
|
||||||
|
if self.timer < self.static_data.swing_duration {
|
||||||
|
// Swings weapons
|
||||||
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
recover_duration: self.recover_duration,
|
stage_section: self.stage_section,
|
||||||
base_damage: self.base_damage,
|
exhausted: self.exhausted,
|
||||||
exhausted: false,
|
});
|
||||||
range: self.range,
|
} else {
|
||||||
max_angle: self.max_angle,
|
// Transitions to recover portion
|
||||||
knockback: self.knockback,
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
leap_speed: self.leap_speed,
|
static_data: self.static_data,
|
||||||
leap_vert_speed: self.leap_vert_speed,
|
timer: Duration::default(),
|
||||||
initialize: false,
|
stage_section: StageSection::Recover,
|
||||||
|
exhausted: self.exhausted,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
StageSection::Recover => {
|
||||||
|
if !data.physics.on_ground {
|
||||||
|
// Falls
|
||||||
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
stage_section: self.stage_section,
|
||||||
|
exhausted: self.exhausted,
|
||||||
});
|
});
|
||||||
} else if !self.exhausted {
|
} else if !self.exhausted {
|
||||||
// Hit attempt
|
// Hit attempt
|
||||||
data.updater.insert(data.entity, Attacking {
|
data.updater.insert(data.entity, Attacking {
|
||||||
base_damage: self.base_damage,
|
base_damage: self.static_data.base_damage,
|
||||||
base_heal: 0,
|
base_heal: 0,
|
||||||
range: self.range,
|
range: self.static_data.range,
|
||||||
max_angle: self.max_angle.to_radians(),
|
max_angle: self.static_data.max_angle.to_radians(),
|
||||||
applied: false,
|
applied: false,
|
||||||
hit_count: 0,
|
hit_count: 0,
|
||||||
knockback: self.knockback,
|
knockback: self.static_data.knockback,
|
||||||
});
|
});
|
||||||
|
|
||||||
update.character = CharacterState::LeapMelee(Data {
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
movement_duration: self.movement_duration,
|
static_data: self.static_data,
|
||||||
buildup_duration: Duration::default(),
|
timer: self
|
||||||
recover_duration: self.recover_duration,
|
.timer
|
||||||
base_damage: self.base_damage,
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
exhausted: true,
|
|
||||||
range: self.range,
|
|
||||||
max_angle: self.max_angle,
|
|
||||||
knockback: self.knockback,
|
|
||||||
leap_speed: self.leap_speed,
|
|
||||||
leap_vert_speed: self.leap_vert_speed,
|
|
||||||
initialize: false,
|
|
||||||
});
|
|
||||||
} else if self.recover_duration != Duration::default() {
|
|
||||||
// Recovery
|
|
||||||
handle_move(data, &mut update, 0.7);
|
|
||||||
update.character = CharacterState::LeapMelee(Data {
|
|
||||||
movement_duration: self.movement_duration,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
recover_duration: self
|
|
||||||
.recover_duration
|
|
||||||
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
base_damage: self.base_damage,
|
stage_section: self.stage_section,
|
||||||
exhausted: true,
|
exhausted: true,
|
||||||
range: self.range,
|
});
|
||||||
max_angle: self.max_angle,
|
} else if self.timer < self.static_data.recover_duration {
|
||||||
knockback: self.knockback,
|
// Recovers
|
||||||
leap_speed: self.leap_speed,
|
update.character = CharacterState::LeapMelee(Data {
|
||||||
leap_vert_speed: self.leap_vert_speed,
|
static_data: self.static_data,
|
||||||
initialize: false,
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
stage_section: self.stage_section,
|
||||||
|
exhausted: self.exhausted,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Done
|
// Done
|
||||||
@ -142,6 +186,14 @@ impl CharacterBehavior for Data {
|
|||||||
// Make sure attack component is removed
|
// Make sure attack component is removed
|
||||||
data.updater.remove::<Attacking>(data.entity);
|
data.updater.remove::<Attacking>(data.entity);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// If it somehow ends up in an incorrect stage section
|
||||||
|
update.character = CharacterState::Wielding;
|
||||||
|
// Make sure attack component is removed
|
||||||
|
data.updater.remove::<Attacking>(data.entity);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,10 @@ impl CharacterBehavior for Data {
|
|||||||
// Lands
|
// Lands
|
||||||
update.character = CharacterState::RepeaterRanged(Data {
|
update.character = CharacterState::RepeaterRanged(Data {
|
||||||
static_data: self.static_data.clone(),
|
static_data: self.static_data.clone(),
|
||||||
timer: self.timer,
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
stage_section: self.stage_section,
|
stage_section: self.stage_section,
|
||||||
reps_remaining: self.reps_remaining,
|
reps_remaining: self.reps_remaining,
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user