mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add dash ability to sword M2
This commit is contained in:
parent
81591fcaf7
commit
d5db1f6ca0
@ -22,6 +22,11 @@ pub enum CharacterAbility {
|
||||
duration: Duration,
|
||||
only_up: bool,
|
||||
},
|
||||
DashMelee {
|
||||
buildup_duration: Duration,
|
||||
recover_duration: Duration,
|
||||
base_damage: u32,
|
||||
},
|
||||
BasicBlock,
|
||||
Roll,
|
||||
ChargeAttack,
|
||||
@ -86,6 +91,16 @@ impl From<&CharacterAbility> for CharacterState {
|
||||
duration: *duration,
|
||||
only_up: *only_up,
|
||||
}),
|
||||
CharacterAbility::DashMelee {
|
||||
buildup_duration,
|
||||
recover_duration,
|
||||
base_damage,
|
||||
} => CharacterState::DashMelee(dash_melee::Data {
|
||||
exhausted: false,
|
||||
buildup_duration: *buildup_duration,
|
||||
recover_duration: *recover_duration,
|
||||
base_damage: *base_damage,
|
||||
}),
|
||||
CharacterAbility::BasicBlock => CharacterState::BasicBlock,
|
||||
CharacterAbility::Roll => CharacterState::Roll(roll::Data {
|
||||
remaining_duration: Duration::from_millis(600),
|
||||
|
@ -40,6 +40,8 @@ pub enum CharacterState {
|
||||
BasicRanged(basic_ranged::Data),
|
||||
/// A force will boost you into a direction for some duration
|
||||
Boost(boost::Data),
|
||||
/// Dash forward and then attack
|
||||
DashMelee(dash_melee::Data),
|
||||
/// A three-stage attack where play must click at appropriate times
|
||||
/// to continue attack chain.
|
||||
TimedCombo(timed_combo::Data),
|
||||
|
@ -42,11 +42,18 @@ impl ToolData {
|
||||
use ToolKind::*;
|
||||
|
||||
match self.kind {
|
||||
Sword(_) => vec![BasicMelee {
|
||||
buildup_duration: Duration::from_millis(100),
|
||||
recover_duration: Duration::from_millis(500),
|
||||
base_damage: 60,
|
||||
}],
|
||||
Sword(_) => vec![
|
||||
BasicMelee {
|
||||
buildup_duration: Duration::from_millis(100),
|
||||
recover_duration: Duration::from_millis(500),
|
||||
base_damage: 60,
|
||||
},
|
||||
DashMelee {
|
||||
buildup_duration: Duration::from_millis(500),
|
||||
recover_duration: Duration::from_millis(500),
|
||||
base_damage: 200,
|
||||
},
|
||||
],
|
||||
Axe => vec![BasicMelee {
|
||||
buildup_duration: Duration::from_millis(700),
|
||||
recover_duration: Duration::from_millis(100),
|
||||
|
95
common/src/states/dash_melee.rs
Normal file
95
common/src/states/dash_melee.rs
Normal file
@ -0,0 +1,95 @@
|
||||
use crate::{
|
||||
comp::{Attacking, CharacterState, EnergySource, StateUpdate},
|
||||
states::utils::*,
|
||||
sys::character_behavior::*,
|
||||
};
|
||||
use std::{collections::VecDeque, time::Duration};
|
||||
use vek::Vec3;
|
||||
|
||||
const DASH_SPEED: f32 = 19.0;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||||
pub struct Data {
|
||||
/// How long until state should deal damage
|
||||
pub buildup_duration: Duration,
|
||||
/// How long the state has until exiting
|
||||
pub recover_duration: Duration,
|
||||
/// Base damage
|
||||
pub base_damage: u32,
|
||||
/// Whether the attack can deal more damage
|
||||
pub exhausted: bool,
|
||||
}
|
||||
|
||||
impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate {
|
||||
pos: *data.pos,
|
||||
vel: *data.vel,
|
||||
ori: *data.ori,
|
||||
energy: *data.energy,
|
||||
character: data.character.clone(),
|
||||
local_events: VecDeque::new(),
|
||||
server_events: VecDeque::new(),
|
||||
};
|
||||
|
||||
if self.buildup_duration != Duration::default() && data.physics.touch_entity.is_none() {
|
||||
// Build up (this will move you forward)
|
||||
update.vel.0 = Vec3::new(0.0, 0.0, update.vel.0.z)
|
||||
+ (update.vel.0 * Vec3::new(1.0, 1.0, 0.0)
|
||||
+ 1.5 * data.inputs.move_dir.try_normalized().unwrap_or_default())
|
||||
.try_normalized()
|
||||
.unwrap_or_default()
|
||||
* DASH_SPEED;
|
||||
|
||||
update.character = CharacterState::DashMelee(Data {
|
||||
buildup_duration: self
|
||||
.buildup_duration
|
||||
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
||||
.unwrap_or_default(),
|
||||
recover_duration: self.recover_duration,
|
||||
base_damage: self.base_damage,
|
||||
exhausted: false,
|
||||
});
|
||||
} else if !self.exhausted {
|
||||
// Hit attempt
|
||||
data.updater.insert(data.entity, Attacking {
|
||||
base_damage: self.base_damage,
|
||||
applied: false,
|
||||
hit_count: 0,
|
||||
});
|
||||
|
||||
update.character = CharacterState::DashMelee(Data {
|
||||
buildup_duration: Duration::default(),
|
||||
recover_duration: self.recover_duration,
|
||||
base_damage: self.base_damage,
|
||||
exhausted: true,
|
||||
});
|
||||
} else if self.recover_duration != Duration::default() {
|
||||
// Recovery
|
||||
update.character = CharacterState::DashMelee(Data {
|
||||
buildup_duration: self.buildup_duration,
|
||||
recover_duration: self
|
||||
.recover_duration
|
||||
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
||||
.unwrap_or_default(),
|
||||
base_damage: self.base_damage,
|
||||
exhausted: true,
|
||||
});
|
||||
} else {
|
||||
// Done
|
||||
update.character = CharacterState::Wielding;
|
||||
// Make sure attack component is removed
|
||||
data.updater.remove::<Attacking>(data.entity);
|
||||
}
|
||||
|
||||
// Grant energy on successful hit
|
||||
if let Some(attack) = data.attacking {
|
||||
if attack.applied && attack.hit_count > 0 {
|
||||
data.updater.remove::<Attacking>(data.entity);
|
||||
update.energy.change_by(100, EnergySource::HitEnemy);
|
||||
}
|
||||
}
|
||||
|
||||
update
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ pub mod basic_ranged;
|
||||
pub mod boost;
|
||||
pub mod charge_attack;
|
||||
pub mod climb;
|
||||
pub mod dash_melee;
|
||||
pub mod equipping;
|
||||
pub mod glide;
|
||||
pub mod idle;
|
||||
|
@ -185,6 +185,7 @@ impl<'a> System<'a> for Sys {
|
||||
CharacterState::BasicMelee(data) => data.behavior(&j),
|
||||
CharacterState::BasicRanged(data) => data.behavior(&j),
|
||||
CharacterState::Boost(data) => data.behavior(&j),
|
||||
CharacterState::DashMelee(data) => data.behavior(&j),
|
||||
CharacterState::TimedCombo(data) => data.behavior(&j),
|
||||
|
||||
// Do not use default match.
|
||||
|
@ -495,6 +495,15 @@ impl FigureMgr {
|
||||
skeleton_attr,
|
||||
)
|
||||
},
|
||||
CharacterState::DashMelee(_) => {
|
||||
anim::character::AttackAnimation::update_skeleton(
|
||||
&target_base,
|
||||
(active_tool_kind, time),
|
||||
state.state_time,
|
||||
&mut state_animation_rate,
|
||||
skeleton_attr,
|
||||
)
|
||||
},
|
||||
CharacterState::TimedCombo(s) => match s.stage {
|
||||
0 | 2 => anim::character::AttackAnimation::update_skeleton(
|
||||
&target_base,
|
||||
|
Loading…
Reference in New Issue
Block a user