Animation for reaching charge. Changed dash melee code to probe with a test melee instead of performing the actual melee strike during charge.

This commit is contained in:
Sam 2022-09-04 19:37:03 -04:00
parent 2e5dfd86de
commit 9091d46554
5 changed files with 83 additions and 158 deletions

View File

@ -1,13 +1,13 @@
DashMelee(
energy_cost: 10,
melee_constructor: (
kind: Slash(
kind: Stab(
damage: 4,
poise: 0,
knockback: 0,
energy_regen: 5,
),
scaled: Some(Slash(
scaled: Some(Stab(
damage: 12,
poise: 0,
knockback: 0,
@ -18,7 +18,7 @@ DashMelee(
),
energy_drain: 20,
forward_speed: 3,
buildup_duration: 0.5,
buildup_duration: 0.2,
charge_duration: 1.0,
swing_duration: 0.1,
recover_duration: 1.0,

View File

@ -96,7 +96,7 @@ pub use self::{
last::Last,
location::{MapMarker, MapMarkerChange, MapMarkerUpdate, Waypoint, WaypointArea},
loot_owner::LootOwner,
melee::{Melee, MeleeConstructor},
melee::{Melee, MeleeConstructor, MeleeConstructorKind},
misc::Object,
ori::Ori,
pet::Pet,

View File

@ -1,5 +1,8 @@
use crate::{
comp::{character_state::OutputEvents, CharacterState, Melee, MeleeConstructor, StateUpdate},
comp::{
character_state::OutputEvents, CharacterState, Melee, MeleeConstructor,
MeleeConstructorKind, StateUpdate,
},
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
@ -58,6 +61,15 @@ impl CharacterBehavior for Data {
handle_move(data, &mut update, 0.1);
let create_melee = |charge_frac: f32| {
let crit_data = get_crit_data(data, self.static_data.ability_info);
let buff_strength = get_buff_strength(data, self.static_data.ability_info);
self.static_data
.melee_constructor
.handle_scaling(charge_frac)
.create_melee(crit_data, buff_strength)
};
match self.stage_section {
StageSection::Buildup => {
if self.timer < self.static_data.buildup_duration {
@ -101,17 +113,16 @@ impl CharacterBehavior for Data {
// and prevents the character state spamming attacks
// while checking if it has hit something.
if !self.exhausted {
// Hit attempt
let crit_data = get_crit_data(data, self.static_data.ability_info);
let buff_strength = get_buff_strength(data, self.static_data.ability_info);
// If charge through, use actual melee strike, otherwise just use a test
// strike to "probe" to see when to end charge
let melee = if self.static_data.charge_through {
create_melee(charge_frac)
} else {
create_test_melee(self.static_data)
};
data.updater.insert(
data.entity,
self.static_data
.melee_constructor
.handle_scaling(charge_frac)
.create_melee(crit_data, buff_strength),
);
// Hit attempt
data.updater.insert(data.entity, melee);
update.character = CharacterState::DashMelee(Data {
timer: tick_attack_or_default(data, self.timer, None),
@ -159,6 +170,7 @@ impl CharacterBehavior for Data {
timer: Duration::default(),
stage_section: StageSection::Action,
exhausted: false,
charge_end_timer: self.timer,
..*self
});
}
@ -181,13 +193,15 @@ impl CharacterBehavior for Data {
timer: Duration::default(),
stage_section: StageSection::Action,
exhausted: false,
charge_end_timer: self.timer,
..*self
});
}
},
StageSection::Action => {
if self.static_data.charge_through && !self.exhausted {
if !self.exhausted {
// If can charge through and not exhausted, do one more melee attack
// If not charge through, actual melee attack happens now
// Assumes charge got to charge_end_timer for damage calculations
let charge_frac = (self.charge_end_timer.as_secs_f32()
@ -254,3 +268,20 @@ impl CharacterBehavior for Data {
update
}
}
fn create_test_melee(static_data: StaticData) -> Melee {
let melee = MeleeConstructor {
kind: MeleeConstructorKind::Slash {
damage: 0.0,
poise: 0.0,
knockback: 0.0,
energy_regen: 0.0,
},
scaled: None,
range: static_data.melee_constructor.range,
angle: static_data.melee_constructor.angle,
multi_target: false,
damage_effect: None,
};
melee.create_melee((0.0, 0.0), 0.0)
}

View File

@ -10,14 +10,15 @@ use core::f32::consts::PI;
pub struct DashAnimation;
type DashAnimationDependency = (
type DashAnimationDependency<'a> = (
(Option<Hands>, Option<Hands>),
Option<&'a str>,
f32,
Option<StageSection>,
Option<AbilityInfo>,
);
impl Animation for DashAnimation {
type Dependency<'a> = DashAnimationDependency;
type Dependency<'a> = DashAnimationDependency<'a>;
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
@ -27,7 +28,7 @@ impl Animation for DashAnimation {
#[allow(clippy::single_match)] // TODO: Pending review in #587
fn update_skeleton_inner<'a>(
skeleton: &Self::Skeleton,
(hands, _global_time, stage_section, ability_info): Self::Dependency<'a>,
(hands, ability_id, _global_time, stage_section, ability_info): Self::Dependency<'a>,
anim_time: f32,
rate: &mut f32,
s_a: &SkeletonAttr,
@ -35,153 +36,45 @@ impl Animation for DashAnimation {
*rate = 1.0;
let mut next = (*skeleton).clone();
let (movement1, movement2, movement3, move4) = match stage_section {
Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
Some(StageSection::Charge) => (1.0, anim_time, 0.0, 0.0),
Some(StageSection::Action) => (1.0, 1.0, anim_time.powf(0.01), 0.0),
Some(StageSection::Recover) => (1.1, 1.0, 1.0, anim_time.powi(4)),
_ => (0.0, 0.0, 0.0, 0.0),
};
if matches!(
stage_section,
Some(StageSection::Action | StageSection::Recover)
) {
next.main_weapon_trail = true;
next.off_weapon_trail = true;
}
let pullback = 1.0 - move4;
let move1 = movement1 * pullback;
let move2 = movement2 * pullback;
let move3 = movement3 * pullback;
next.main.position = Vec3::new(0.0, 0.0, 0.0);
next.main.orientation = Quaternion::rotation_z(0.0);
fn slow(x: f32) -> f32 {
((5.0 / (1.1 + 3.9 * ((x * 12.4).sin()).powi(2))).sqrt()) * ((x * 12.4).sin())
}
match ability_id {
Some("common.abilities.sword.reaching_charge") => {
let (move1, move2, move3, move4) = match stage_section {
Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
Some(StageSection::Charge) => (1.0, anim_time / (anim_time + 0.1), 0.0, 0.0),
Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(2), 0.0),
Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time.powi(4)),
_ => (0.0, 0.0, 0.0, 0.0),
};
fn short(x: f32) -> f32 {
((5.0 / (1.5 + 3.5 * ((x * 5.0).sin()).powi(2))).sqrt()) * ((x * 5.0).sin())
}
next.hand_l.position = Vec3::new(s_a.shl.0, s_a.shl.1, s_a.shl.2);
next.hand_l.orientation =
Quaternion::rotation_x(s_a.shl.3) * Quaternion::rotation_y(s_a.shl.4);
next.hand_r.position =
Vec3::new(-s_a.sc.0 + 6.0 + move1 * -12.0, -4.0 + move1 * 3.0, -2.0);
next.hand_r.orientation = Quaternion::rotation_x(0.9 + move1 * 0.5);
next.control.position = Vec3::new(s_a.sc.0, s_a.sc.1, s_a.sc.2);
next.control.orientation = Quaternion::rotation_x(s_a.sc.3);
fn shortalt(x: f32) -> f32 { (x * 5.0 + PI / 2.0).sin() }
next.chest.orientation.rotate_z(move1 * 0.4);
next.head.orientation.rotate_z(move1 * -0.2);
next.shorts.orientation.rotate_z(move1 * -0.3);
next.belt.orientation.rotate_z(move1 * -0.1);
next.control.orientation.rotate_z(move1 * -0.7);
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.second.position = Vec3::new(0.0, 0.0, 0.0);
next.second.orientation = Quaternion::rotation_z(0.0);
match ability_info.and_then(|a| a.tool) {
Some(ToolKind::Sword) => {
next.main.position = Vec3::new(0.0, 0.0, 0.0);
next.main.orientation = Quaternion::rotation_x(0.0);
next.head.position =
Vec3::new(0.0, 0.0 + s_a.head.0, s_a.head.1 + move2.min(1.0) * 1.0);
next.head.orientation = Quaternion::rotation_y(move2.min(1.0) * -0.3 + move3 * 0.3)
* Quaternion::rotation_z(move1 * -0.9 + move3 * 1.6);
next.chest.position = Vec3::new(
0.0,
s_a.chest.0,
s_a.chest.1 + (2.0 + shortalt(move2) * -2.5) + move3 * -3.0,
);
next.chest.orientation =
Quaternion::rotation_x(move2.min(1.0) * -0.4 + move3 * 0.4)
* Quaternion::rotation_y(move2.min(1.0) * -0.2 + move3 * 0.3)
* Quaternion::rotation_z(move1 * 1.1 + move3 * -2.2);
next.shorts.orientation = Quaternion::rotation_z(short(move2).min(1.0) * 0.25);
next.belt.orientation = Quaternion::rotation_z(short(move2).min(1.0) * 0.1);
next.control.orientation.rotate_x(move3 * -1.1);
next.chest.orientation.rotate_z(move3 * -1.1);
next.head.orientation.rotate_z(move3 * 0.4);
next.shorts.orientation.rotate_z(move3 * 0.5);
next.belt.orientation.rotate_z(move3 * 0.2);
next.control.orientation.rotate_z(move3 * 0.9);
next.control.position += Vec3::new(0.0, move3 * 6.0, 0.0);
},
_ => {},
}
next.lantern.orientation = Quaternion::rotation_x(slow(anim_time) * -0.7 + 0.4)
* Quaternion::rotation_y(slow(anim_time) * 0.4);
match hands {
(Some(Hands::Two), _) | (None, Some(Hands::Two)) => {
match ability_info.and_then(|a| a.tool) {
Some(ToolKind::Sword) => {
next.hand_l.position = Vec3::new(s_a.shl.0, s_a.shl.1, s_a.shl.2);
next.hand_l.orientation =
Quaternion::rotation_x(s_a.shl.3) * Quaternion::rotation_y(s_a.shl.4);
next.hand_r.position = Vec3::new(s_a.shr.0, s_a.shr.1, s_a.shr.2);
next.hand_r.orientation =
Quaternion::rotation_x(s_a.shr.3) * Quaternion::rotation_y(s_a.shr.4);
next.control.position = Vec3::new(
s_a.sc.0 + (move1 * -5.0 + move3 * -2.0),
s_a.sc.1 + (move2.min(1.0) * -2.0),
s_a.sc.2 + (move2.min(1.0) * 2.0),
);
next.control.orientation =
Quaternion::rotation_x(s_a.sc.3 + (move1 * -1.0 + move3 * -0.5))
* Quaternion::rotation_y(s_a.sc.4 + (move1 * 1.5 + move3 * -2.5));
},
_ => {},
}
},
(_, _) => {},
};
match hands {
(Some(Hands::One), _) => match ability_info.and_then(|a| a.tool) {
Some(ToolKind::Sword) => {
next.control_l.position = Vec3::new(-7.0, 8.0 + move3 * 5.0, 2.0 + move1 * 4.0);
next.control_l.orientation =
Quaternion::rotation_x(-0.3 + move2 * 1.0 + move3 * 1.0)
* Quaternion::rotation_y(move1 * -1.2 + move3 * -1.5)
* Quaternion::rotation_z(move2 * 1.0 + move3 * 1.5);
next.hand_l.position = Vec3::new(0.0, -0.5, 0.0);
next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0)
},
_ => {},
},
(_, _) => {},
};
match hands {
(None | Some(Hands::One), Some(Hands::One)) => {
match ability_info.and_then(|a| a.tool) {
Some(ToolKind::Sword) => {
next.control_r.position = Vec3::new(
7.0 + move1 * 5.0 + move3 * -30.0,
8.0 + move3 * -5.0,
2.0 + move1 * 1.0,
);
next.control_r.orientation =
Quaternion::rotation_x(-0.3 + move1 * -3.0 + move3 * -0.5)
* Quaternion::rotation_y(
move1 * 1.5 + (move2 * 1.0).min(0.8) + move3 * 1.5,
)
* Quaternion::rotation_z(move3 * 1.5);
next.hand_r.position = Vec3::new(0.0, -0.5, 0.0);
next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0)
},
_ => {},
}
},
(_, _) => {},
};
match hands {
(None, None) | (None, Some(Hands::One)) => {
next.hand_l.position = Vec3::new(-4.5, 8.0, 5.0);
next.hand_l.orientation = Quaternion::rotation_x(1.9) * Quaternion::rotation_y(-0.5)
},
(_, _) => {},
};
match hands {
(None, None) | (Some(Hands::One), None) => {
next.hand_r.position = Vec3::new(4.5, 8.0, 5.0);
next.hand_r.orientation = Quaternion::rotation_x(1.9) * Quaternion::rotation_y(0.5)
},
(_, _) => {},
};
if let (None, Some(Hands::Two)) = hands {
next.second = next.main;
}
next
}
}

View File

@ -1445,6 +1445,7 @@ impl FigureMgr {
&target_base,
(
hands,
ability_id,
time,
Some(s.stage_section),
Some(s.static_data.ability_info),