mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Dash melee now works as desired.
This commit is contained in:
parent
744843d03f
commit
b79235b890
@ -334,22 +334,24 @@ impl From<&CharacterAbility> for CharacterState {
|
|||||||
swing_duration,
|
swing_duration,
|
||||||
recover_duration,
|
recover_duration,
|
||||||
} => CharacterState::DashMelee(dash_melee::Data {
|
} => CharacterState::DashMelee(dash_melee::Data {
|
||||||
base_damage: *base_damage,
|
static_data: dash_melee::StaticData {
|
||||||
max_damage: *max_damage,
|
base_damage: *base_damage,
|
||||||
base_knockback: *base_knockback,
|
max_damage: *max_damage,
|
||||||
max_knockback: *max_knockback,
|
base_knockback: *base_knockback,
|
||||||
range: *range,
|
max_knockback: *max_knockback,
|
||||||
angle: *angle,
|
range: *range,
|
||||||
energy_drain: *energy_drain,
|
angle: *angle,
|
||||||
forward_speed: *forward_speed,
|
energy_drain: *energy_drain,
|
||||||
buildup_duration: *buildup_duration,
|
forward_speed: *forward_speed,
|
||||||
charge_duration: *charge_duration,
|
infinite_charge: *infinite_charge,
|
||||||
charge_duration_attained: Duration::default(),
|
buildup_duration: *buildup_duration,
|
||||||
infinite_charge: *infinite_charge,
|
charge_duration: *charge_duration,
|
||||||
swing_duration: *swing_duration,
|
recover_duration: *recover_duration,
|
||||||
recover_duration: *recover_duration,
|
},
|
||||||
|
end_charge: false,
|
||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
stage_section: StageSection::Buildup,
|
stage_section: StageSection::Buildup,
|
||||||
|
exhausted: false,
|
||||||
}),
|
}),
|
||||||
CharacterAbility::BasicBlock => CharacterState::BasicBlock,
|
CharacterAbility::BasicBlock => CharacterState::BasicBlock,
|
||||||
CharacterAbility::Roll => CharacterState::Roll(roll::Data {
|
CharacterAbility::Roll => CharacterState::Roll(roll::Data {
|
||||||
|
@ -165,20 +165,19 @@ impl Tool {
|
|||||||
combo_duration: Duration::from_millis(10),
|
combo_duration: Duration::from_millis(10),
|
||||||
},
|
},
|
||||||
DashMelee {
|
DashMelee {
|
||||||
energy_cost: 100,
|
energy_cost: 200,
|
||||||
base_damage: (60.0 * self.base_power()) as u32,
|
base_damage: (60.0 * self.base_power()) as u32,
|
||||||
max_damage: (180.0 * self.base_power()) as u32,
|
max_damage: (180.0 * self.base_power()) as u32,
|
||||||
base_knockback: 5.0,
|
base_knockback: 5.0,
|
||||||
max_knockback: 10.0,
|
max_knockback: 10.0,
|
||||||
range: 5.0,
|
range: 5.0,
|
||||||
angle: 45.0,
|
angle: 45.0,
|
||||||
energy_drain: 100,
|
energy_drain: 500,
|
||||||
forward_speed: 2.5,
|
forward_speed: 4.0,
|
||||||
buildup_duration: Duration::from_millis(250),
|
buildup_duration: Duration::from_millis(200),
|
||||||
charge_duration: Duration::from_millis(2000),
|
charge_duration: Duration::from_millis(400),
|
||||||
infinite_charge: true,
|
infinite_charge: true,
|
||||||
swing_duration: Duration::from_millis(100),
|
recover_duration: Duration::from_millis(750),
|
||||||
recover_duration: Duration::from_millis(300),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
Axe(_) => vec![
|
Axe(_) => vec![
|
||||||
|
@ -6,8 +6,9 @@ use crate::{
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// Separated out to condense update portions of character state
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Data {
|
pub struct StaticData {
|
||||||
/// How much damage the attack initially does
|
/// How much damage the attack initially does
|
||||||
pub base_damage: u32,
|
pub base_damage: u32,
|
||||||
/// How much damage the attack does at max charge distance
|
/// How much damage the attack does at max charge distance
|
||||||
@ -24,22 +25,28 @@ pub struct Data {
|
|||||||
pub energy_drain: u32,
|
pub energy_drain: u32,
|
||||||
/// How quickly dasher moves forward
|
/// How quickly dasher moves forward
|
||||||
pub forward_speed: f32,
|
pub forward_speed: f32,
|
||||||
|
/// Whether state keeps charging after reaching max charge duration
|
||||||
|
pub infinite_charge: bool,
|
||||||
/// 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 state charges for until it reaches max damage
|
/// How long the state charges for until it reaches max damage
|
||||||
pub charge_duration: Duration,
|
pub charge_duration: Duration,
|
||||||
/// How high timer got while in charge potion
|
|
||||||
pub charge_duration_attained: Duration,
|
|
||||||
/// Whether state keeps charging after reaching max charge duration
|
|
||||||
pub infinite_charge: bool,
|
|
||||||
/// How long the state swings for
|
|
||||||
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
/// Whether the charge should end
|
||||||
|
pub end_charge: bool,
|
||||||
/// Timer for each stage
|
/// Timer for each stage
|
||||||
pub timer: Duration,
|
pub timer: Duration,
|
||||||
/// What section the character stage is in
|
/// What section the character stage is in
|
||||||
pub stage_section: StageSection,
|
pub stage_section: StageSection,
|
||||||
|
/// Whether the state should attempt attacking again
|
||||||
|
pub exhausted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharacterBehavior for Data {
|
impl CharacterBehavior for Data {
|
||||||
@ -49,195 +56,143 @@ impl CharacterBehavior for Data {
|
|||||||
handle_orientation(data, &mut update, 1.0);
|
handle_orientation(data, &mut update, 1.0);
|
||||||
handle_move(data, &mut update, 0.1);
|
handle_move(data, &mut update, 0.1);
|
||||||
|
|
||||||
if self.stage_section == StageSection::Buildup && self.timer < self.buildup_duration {
|
if self.stage_section == StageSection::Buildup && self.timer < self.static_data.buildup_duration {
|
||||||
// Build up
|
// Build up
|
||||||
update.character = CharacterState::DashMelee(Data {
|
update.character = CharacterState::DashMelee(Data {
|
||||||
base_damage: self.base_damage,
|
static_data: self.static_data,
|
||||||
max_damage: self.max_damage,
|
end_charge: self.end_charge,
|
||||||
base_knockback: self.base_knockback,
|
|
||||||
max_knockback: self.max_knockback,
|
|
||||||
range: self.range,
|
|
||||||
angle: self.angle,
|
|
||||||
energy_drain: self.energy_drain,
|
|
||||||
forward_speed: self.forward_speed,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
charge_duration: self.charge_duration,
|
|
||||||
charge_duration_attained: self.charge_duration_attained,
|
|
||||||
infinite_charge: self.infinite_charge,
|
|
||||||
swing_duration: self.swing_duration,
|
|
||||||
recover_duration: self.recover_duration,
|
|
||||||
timer: self
|
timer: self
|
||||||
.timer
|
.timer
|
||||||
.checked_add(Duration::from_secs_f32(data.dt.0))
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
stage_section: self.stage_section,
|
stage_section: self.stage_section,
|
||||||
|
exhausted: self.exhausted,
|
||||||
})
|
})
|
||||||
} else if self.stage_section == StageSection::Buildup {
|
} else if self.stage_section == StageSection::Buildup {
|
||||||
// Transitions to charge section of stage
|
// Transitions to charge section of stage
|
||||||
update.character = CharacterState::DashMelee(Data {
|
update.character = CharacterState::DashMelee(Data {
|
||||||
base_damage: self.base_damage,
|
static_data: self.static_data,
|
||||||
max_damage: self.max_damage,
|
end_charge: self.end_charge,
|
||||||
base_knockback: self.base_knockback,
|
|
||||||
max_knockback: self.max_knockback,
|
|
||||||
range: self.range,
|
|
||||||
angle: self.angle,
|
|
||||||
energy_drain: self.energy_drain,
|
|
||||||
forward_speed: self.forward_speed,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
charge_duration: self.charge_duration,
|
|
||||||
charge_duration_attained: self.charge_duration_attained,
|
|
||||||
infinite_charge: self.infinite_charge,
|
|
||||||
swing_duration: self.swing_duration,
|
|
||||||
recover_duration: self.recover_duration,
|
|
||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
stage_section: StageSection::Charge,
|
stage_section: StageSection::Charge,
|
||||||
|
exhausted: self.exhausted,
|
||||||
})
|
})
|
||||||
} else if self.stage_section == StageSection::Charge && data.physics.touch_entities.is_empty() && ((self.timer < self.charge_duration && !self.infinite_charge) || (data.inputs.secondary.is_pressed() && self.infinite_charge)) && update.energy.current() > 0
|
} else if self.stage_section == StageSection::Charge
|
||||||
|
&& ((self.timer < self.static_data.charge_duration && !self.static_data.infinite_charge)
|
||||||
|
|| (data.inputs.secondary.is_pressed() && self.static_data.infinite_charge))
|
||||||
|
&& update.energy.current() > 0
|
||||||
|
&& !self.end_charge
|
||||||
{
|
{
|
||||||
// Forward movement
|
// Forward movement
|
||||||
forward_move(data, &mut update, 0.1, self.forward_speed);
|
forward_move(data, &mut update, 0.1, self.static_data.forward_speed);
|
||||||
|
|
||||||
// Checks how much a charge has built up
|
// Hit attempt
|
||||||
let charge_attained = if self.timer > self.charge_duration_attained {
|
if !self.exhausted {
|
||||||
if self.timer > self.charge_duration_attained {
|
let charge_frac = (self.timer.as_secs_f32()
|
||||||
self.charge_duration
|
/ self.static_data.charge_duration.as_secs_f32())
|
||||||
} else {
|
.min(1.0);
|
||||||
self.timer
|
let damage = (self.static_data.max_damage as f32 - self.static_data.base_damage as f32) * charge_frac
|
||||||
}
|
+ self.static_data.base_damage as f32;
|
||||||
|
let knockback =
|
||||||
|
(self.static_data.max_knockback - self.static_data.base_knockback) * charge_frac + self.static_data.base_knockback;
|
||||||
|
data.updater.insert(data.entity, Attacking {
|
||||||
|
base_healthchange: -damage as i32,
|
||||||
|
range: self.static_data.range,
|
||||||
|
max_angle: self.static_data.angle.to_radians(),
|
||||||
|
applied: false,
|
||||||
|
hit_count: 0,
|
||||||
|
knockback,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// This logic basically just decides if a charge should end, and prevents the character state spamming attacks while checking if it has hit something
|
||||||
|
if !self.exhausted {
|
||||||
|
update.character = CharacterState::DashMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
end_charge: self.end_charge,
|
||||||
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
stage_section: StageSection::Charge,
|
||||||
|
exhausted: true,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
self.charge_duration_attained
|
if let Some(attack) = data.attacking {
|
||||||
};
|
if attack.applied && attack.hit_count > 0 {
|
||||||
|
update.character = CharacterState::DashMelee(Data {
|
||||||
// Charges
|
static_data: self.static_data,
|
||||||
update.character = CharacterState::DashMelee(Data {
|
end_charge: !self.static_data.infinite_charge,
|
||||||
base_damage: self.base_damage,
|
timer: self
|
||||||
max_damage: self.max_damage,
|
.timer
|
||||||
base_knockback: self.base_knockback,
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
max_knockback: self.max_knockback,
|
.unwrap_or_default(),
|
||||||
range: self.range,
|
stage_section: StageSection::Charge,
|
||||||
angle: self.angle,
|
exhausted: false,
|
||||||
energy_drain: self.energy_drain,
|
})
|
||||||
forward_speed: self.forward_speed,
|
} else if attack.applied {
|
||||||
buildup_duration: self.buildup_duration,
|
update.character = CharacterState::DashMelee(Data {
|
||||||
charge_duration: self.charge_duration,
|
static_data: self.static_data,
|
||||||
charge_duration_attained: charge_attained,
|
end_charge: self.end_charge,
|
||||||
infinite_charge: self.infinite_charge,
|
timer: self
|
||||||
swing_duration: self.swing_duration,
|
.timer
|
||||||
recover_duration: self.recover_duration,
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
timer: self
|
.unwrap_or_default(),
|
||||||
.timer
|
stage_section: StageSection::Charge,
|
||||||
.checked_add(Duration::from_secs_f32(data.dt.0))
|
exhausted: false,
|
||||||
.unwrap_or_default(),
|
})
|
||||||
stage_section: self.stage_section,
|
} else {
|
||||||
});
|
update.character = CharacterState::DashMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
end_charge: !self.static_data.infinite_charge,
|
||||||
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
stage_section: StageSection::Charge,
|
||||||
|
exhausted: self.exhausted,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
update.character = CharacterState::DashMelee(Data {
|
||||||
|
static_data: self.static_data,
|
||||||
|
end_charge: !self.static_data.infinite_charge,
|
||||||
|
timer: self
|
||||||
|
.timer
|
||||||
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
stage_section: StageSection::Charge,
|
||||||
|
exhausted: self.exhausted,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Consumes energy if there's enough left and charge has not stopped
|
// Consumes energy if there's enough left and charge has not stopped
|
||||||
update.energy.change_by(
|
update.energy.change_by(
|
||||||
-(self.energy_drain as f32 * data.dt.0) as i32,
|
-(self.static_data.energy_drain as f32 * data.dt.0) as i32,
|
||||||
EnergySource::Ability,
|
EnergySource::Ability,
|
||||||
);
|
);
|
||||||
} else if self.stage_section == StageSection::Charge {
|
} else if self.stage_section == StageSection::Charge {
|
||||||
// Transitions to swing section of stage
|
// Transitions to swing section of stage
|
||||||
update.character = CharacterState::DashMelee(Data {
|
update.character = CharacterState::DashMelee(Data {
|
||||||
base_damage: self.base_damage,
|
static_data: self.static_data,
|
||||||
max_damage: self.max_damage,
|
end_charge: self.end_charge,
|
||||||
base_knockback: self.base_knockback,
|
|
||||||
max_knockback: self.max_knockback,
|
|
||||||
range: self.range,
|
|
||||||
angle: self.angle,
|
|
||||||
energy_drain: self.energy_drain,
|
|
||||||
forward_speed: self.forward_speed,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
charge_duration: self.charge_duration,
|
|
||||||
charge_duration_attained: self.charge_duration_attained,
|
|
||||||
infinite_charge: self.infinite_charge,
|
|
||||||
swing_duration: self.swing_duration,
|
|
||||||
recover_duration: self.recover_duration,
|
|
||||||
timer: Duration::default(),
|
|
||||||
stage_section: StageSection::Swing,
|
|
||||||
})
|
|
||||||
} else if self.stage_section == StageSection::Swing && self.timer < self.swing_duration {
|
|
||||||
// Swings
|
|
||||||
update.character = CharacterState::DashMelee(Data {
|
|
||||||
base_damage: self.base_damage,
|
|
||||||
max_damage: self.max_damage,
|
|
||||||
base_knockback: self.base_knockback,
|
|
||||||
max_knockback: self.max_knockback,
|
|
||||||
range: self.range,
|
|
||||||
angle: self.angle,
|
|
||||||
energy_drain: self.energy_drain,
|
|
||||||
forward_speed: self.forward_speed,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
charge_duration: self.charge_duration,
|
|
||||||
charge_duration_attained: self.charge_duration_attained,
|
|
||||||
infinite_charge: self.infinite_charge,
|
|
||||||
swing_duration: self.swing_duration,
|
|
||||||
recover_duration: self.recover_duration,
|
|
||||||
timer: self
|
|
||||||
.timer
|
|
||||||
.checked_add(Duration::from_secs_f32(data.dt.0))
|
|
||||||
.unwrap_or_default(),
|
|
||||||
stage_section: self.stage_section,
|
|
||||||
})
|
|
||||||
} else if self.stage_section == StageSection::Swing {
|
|
||||||
// Hit attempt
|
|
||||||
let charge_frac =
|
|
||||||
(self.charge_duration_attained.as_secs_f32() / self.charge_duration.as_secs_f32()).min(1.0);
|
|
||||||
let damage = (self.max_damage as f32 - self.base_damage as f32) * charge_frac
|
|
||||||
+ self.base_damage as f32;
|
|
||||||
let knockback =
|
|
||||||
(self.max_knockback - self.base_knockback) * charge_frac + self.base_knockback;
|
|
||||||
data.updater.insert(data.entity, Attacking {
|
|
||||||
base_healthchange: -damage as i32,
|
|
||||||
range: self.range,
|
|
||||||
max_angle: self.angle.to_radians(),
|
|
||||||
applied: false,
|
|
||||||
hit_count: 0,
|
|
||||||
knockback,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Transitions to recover section of stage
|
|
||||||
update.character = CharacterState::DashMelee(Data {
|
|
||||||
base_damage: self.base_damage,
|
|
||||||
max_damage: self.max_damage,
|
|
||||||
base_knockback: self.base_knockback,
|
|
||||||
max_knockback: self.max_knockback,
|
|
||||||
range: self.range,
|
|
||||||
angle: self.angle,
|
|
||||||
energy_drain: self.energy_drain,
|
|
||||||
forward_speed: self.forward_speed,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
charge_duration: self.charge_duration,
|
|
||||||
charge_duration_attained: self.charge_duration_attained,
|
|
||||||
infinite_charge: self.infinite_charge,
|
|
||||||
swing_duration: self.swing_duration,
|
|
||||||
recover_duration: self.recover_duration,
|
|
||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
stage_section: StageSection::Recover,
|
stage_section: StageSection::Recover,
|
||||||
|
exhausted: self.exhausted,
|
||||||
})
|
})
|
||||||
} else if self.stage_section == StageSection::Recover && self.timer < self.recover_duration
|
} else if self.stage_section == StageSection::Recover && self.timer < self.static_data.recover_duration
|
||||||
{
|
{
|
||||||
// Recover
|
// Recover
|
||||||
update.character = CharacterState::DashMelee(Data {
|
update.character = CharacterState::DashMelee(Data {
|
||||||
base_damage: self.base_damage,
|
static_data: self.static_data,
|
||||||
max_damage: self.max_damage,
|
end_charge: self.end_charge,
|
||||||
base_knockback: self.base_knockback,
|
|
||||||
max_knockback: self.max_knockback,
|
|
||||||
range: self.range,
|
|
||||||
angle: self.angle,
|
|
||||||
energy_drain: self.energy_drain,
|
|
||||||
forward_speed: self.forward_speed,
|
|
||||||
buildup_duration: self.buildup_duration,
|
|
||||||
charge_duration: self.charge_duration,
|
|
||||||
charge_duration_attained: self.charge_duration_attained,
|
|
||||||
infinite_charge: self.infinite_charge,
|
|
||||||
swing_duration: self.swing_duration,
|
|
||||||
recover_duration: self.recover_duration,
|
|
||||||
timer: self
|
timer: self
|
||||||
.timer
|
.timer
|
||||||
.checked_add(Duration::from_secs_f32(data.dt.0))
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
stage_section: self.stage_section,
|
stage_section: self.stage_section,
|
||||||
|
exhausted: self.exhausted,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Done
|
// Done
|
||||||
|
@ -192,7 +192,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
if entity == entity_other || (ignore_group.is_some() && ignore_group == group_b) {
|
if entity == entity_other || (ignore_group.is_some() && ignore_group == group_b) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if entity_other == entity {
|
if entity_other == entity {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user