2020-09-04 01:54:59 +00:00
|
|
|
use crate::{
|
2021-01-28 18:50:56 +00:00
|
|
|
combat::{
|
|
|
|
Attack, AttackEffect, CombatBuff, CombatRequirement, DamageComponent, EffectComponent,
|
|
|
|
},
|
2020-12-06 02:29:46 +00:00
|
|
|
comp::{
|
2021-01-26 00:31:06 +00:00
|
|
|
CharacterState, EnergyChange, EnergySource, MeleeAttack, PoiseChange, PoiseSource,
|
2020-12-06 02:29:46 +00:00
|
|
|
StateUpdate,
|
|
|
|
},
|
2020-12-01 00:28:00 +00:00
|
|
|
states::{
|
|
|
|
behavior::{CharacterBehavior, JoinData},
|
|
|
|
utils::*,
|
|
|
|
},
|
2021-01-25 22:46:43 +00:00
|
|
|
Damage, DamageSource, GroupTarget, Knockback, KnockbackDir,
|
2020-09-04 01:54:59 +00:00
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
2020-11-13 03:24:19 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
2020-11-11 01:49:05 +00:00
|
|
|
pub struct Stage<T> {
|
2020-09-04 01:54:59 +00:00
|
|
|
/// Specifies which stage the combo attack is in
|
|
|
|
pub stage: u32,
|
|
|
|
/// Initial damage of stage
|
|
|
|
pub base_damage: u32,
|
|
|
|
/// Damage scaling per combo
|
|
|
|
pub damage_increase: u32,
|
2020-12-05 18:23:45 +00:00
|
|
|
/// Initial poise damage of stage
|
|
|
|
pub base_poise_damage: u32,
|
2020-12-16 23:30:33 +00:00
|
|
|
/// Poise damage scaling per combo
|
|
|
|
pub poise_damage_increase: u32,
|
2020-09-04 01:54:59 +00:00
|
|
|
/// Knockback of stage
|
|
|
|
pub knockback: f32,
|
|
|
|
/// Range of attack
|
|
|
|
pub range: f32,
|
|
|
|
/// Angle of attack
|
|
|
|
pub angle: f32,
|
|
|
|
/// Initial buildup duration of stage (how long until state can deal damage)
|
2020-11-11 01:49:05 +00:00
|
|
|
pub base_buildup_duration: T,
|
2020-09-08 00:16:55 +00:00
|
|
|
/// Duration of stage spent in swing (controls animation stuff, and can also
|
|
|
|
/// be used to handle movement separately to buildup)
|
2020-11-11 01:49:05 +00:00
|
|
|
pub base_swing_duration: T,
|
2020-09-04 01:54:59 +00:00
|
|
|
/// Initial recover duration of stage (how long until character exits state)
|
2020-11-11 01:49:05 +00:00
|
|
|
pub base_recover_duration: T,
|
2020-09-09 00:28:59 +00:00
|
|
|
/// How much forward movement there is in the swing portion of the stage
|
|
|
|
pub forward_movement: f32,
|
2020-09-06 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 01:49:05 +00:00
|
|
|
impl Stage<u64> {
|
|
|
|
pub fn to_duration(self) -> Stage<Duration> {
|
|
|
|
Stage::<Duration> {
|
|
|
|
stage: self.stage,
|
|
|
|
base_damage: self.base_damage,
|
|
|
|
damage_increase: self.damage_increase,
|
2020-12-05 18:23:45 +00:00
|
|
|
base_poise_damage: self.base_poise_damage,
|
2020-12-16 23:30:33 +00:00
|
|
|
poise_damage_increase: self.poise_damage_increase,
|
2020-11-11 01:49:05 +00:00
|
|
|
knockback: self.knockback,
|
|
|
|
range: self.range,
|
|
|
|
angle: self.angle,
|
|
|
|
base_buildup_duration: Duration::from_millis(self.base_buildup_duration),
|
|
|
|
base_swing_duration: Duration::from_millis(self.base_swing_duration),
|
|
|
|
base_recover_duration: Duration::from_millis(self.base_recover_duration),
|
|
|
|
forward_movement: self.forward_movement,
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 03:24:19 +00:00
|
|
|
|
2021-01-27 03:05:13 +00:00
|
|
|
pub fn adjusted_by_stats(mut self, power: f32, poise_strength: f32, speed: f32) -> Self {
|
2020-11-13 03:24:19 +00:00
|
|
|
self.base_damage = (self.base_damage as f32 * power) as u32;
|
|
|
|
self.damage_increase = (self.damage_increase as f32 * power) as u32;
|
2021-01-27 03:05:13 +00:00
|
|
|
self.base_poise_damage = (self.base_poise_damage as f32 * poise_strength) as u32;
|
|
|
|
self.poise_damage_increase = (self.poise_damage_increase as f32 * poise_strength) as u32;
|
2020-11-13 03:24:19 +00:00
|
|
|
self.base_buildup_duration = (self.base_buildup_duration as f32 / speed) as u64;
|
|
|
|
self.base_swing_duration = (self.base_swing_duration as f32 / speed) as u64;
|
|
|
|
self.base_recover_duration = (self.base_recover_duration as f32 / speed) as u64;
|
|
|
|
self
|
|
|
|
}
|
2020-12-20 22:28:17 +00:00
|
|
|
|
|
|
|
pub fn modify_strike(mut self, knockback_mult: f32) -> Self {
|
|
|
|
self.knockback *= knockback_mult;
|
|
|
|
self
|
|
|
|
}
|
2020-11-11 01:49:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 01:54:59 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2020-09-21 22:38:01 +00:00
|
|
|
/// Separated out to condense update portions of character state
|
|
|
|
pub struct StaticData {
|
2020-09-04 01:54:59 +00:00
|
|
|
/// Indicates number of stages in combo
|
|
|
|
pub num_stages: u32,
|
2020-09-12 16:46:21 +00:00
|
|
|
/// Data for each stage
|
2020-11-11 01:49:05 +00:00
|
|
|
pub stage_data: Vec<Stage<Duration>>,
|
2020-09-04 01:54:59 +00:00
|
|
|
/// Initial energy gain per strike
|
|
|
|
pub initial_energy_gain: u32,
|
|
|
|
/// Max energy gain per strike
|
|
|
|
pub max_energy_gain: u32,
|
|
|
|
/// Energy gain increase per combo
|
|
|
|
pub energy_increase: u32,
|
2020-09-12 16:46:21 +00:00
|
|
|
/// (100% - speed_increase) is percentage speed increases from current to
|
2020-12-07 03:35:29 +00:00
|
|
|
/// max per combo increase
|
2020-09-11 19:24:55 +00:00
|
|
|
pub speed_increase: f32,
|
2020-12-07 03:35:29 +00:00
|
|
|
/// This value is the highest percentage speed can increase from the base
|
|
|
|
/// speed
|
2020-09-11 19:24:55 +00:00
|
|
|
pub max_speed_increase: f32,
|
2020-12-08 04:00:24 +00:00
|
|
|
/// Number of times damage scales with combo
|
|
|
|
pub scales_from_combo: u32,
|
2020-09-12 16:46:21 +00:00
|
|
|
/// Whether the state can be interrupted by other abilities
|
|
|
|
pub is_interruptible: bool,
|
2020-10-31 18:44:00 +00:00
|
|
|
/// What key is used to press ability
|
|
|
|
pub ability_key: AbilityKey,
|
2020-09-04 01:54:59 +00:00
|
|
|
}
|
2020-09-21 22:38:01 +00:00
|
|
|
/// A sequence of attacks that can incrementally become faster and more
|
|
|
|
/// damaging.
|
|
|
|
#[derive(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,
|
|
|
|
/// Indicates what stage the combo is in
|
|
|
|
pub stage: u32,
|
|
|
|
/// Number of consecutive strikes
|
|
|
|
pub combo: u32,
|
|
|
|
/// Timer for each stage
|
|
|
|
pub timer: Duration,
|
|
|
|
/// Checks what section a stage is in
|
|
|
|
pub stage_section: StageSection,
|
|
|
|
/// Whether the state should go onto the next stage
|
|
|
|
pub next_stage: bool,
|
|
|
|
}
|
2020-09-04 01:54:59 +00:00
|
|
|
|
|
|
|
impl CharacterBehavior for Data {
|
|
|
|
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate::from(data);
|
|
|
|
|
2020-09-09 00:28:59 +00:00
|
|
|
handle_orientation(data, &mut update, 1.0);
|
2020-09-12 16:46:21 +00:00
|
|
|
handle_move(data, &mut update, 0.3);
|
2020-11-20 17:30:48 +00:00
|
|
|
if !ability_key_is_pressed(data, self.static_data.ability_key) {
|
2020-11-20 17:54:56 +00:00
|
|
|
handle_interrupt(data, &mut update, self.static_data.is_interruptible);
|
2020-11-20 17:30:48 +00:00
|
|
|
if let CharacterState::Roll(roll) = &mut update.character {
|
|
|
|
roll.was_combo = Some((self.stage, self.combo));
|
2020-11-15 22:08:14 +00:00
|
|
|
}
|
2020-09-13 01:33:46 +00:00
|
|
|
match update.character {
|
|
|
|
CharacterState::ComboMelee(_) => {},
|
|
|
|
_ => {
|
|
|
|
return update;
|
|
|
|
},
|
2020-09-12 16:46:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 17:30:48 +00:00
|
|
|
let stage_index = (self.stage - 1) as usize;
|
|
|
|
|
2020-11-09 01:27:44 +00:00
|
|
|
let speed_modifer = 1.0
|
|
|
|
+ self.static_data.max_speed_increase
|
|
|
|
* (1.0 - self.static_data.speed_increase.powi(self.combo as i32));
|
2020-11-09 00:11:53 +00:00
|
|
|
|
2020-09-21 22:38:01 +00:00
|
|
|
match self.stage_section {
|
|
|
|
StageSection::Buildup => {
|
|
|
|
if self.timer < self.static_data.stage_data[stage_index].base_buildup_duration {
|
|
|
|
// Build up
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
timer: self
|
|
|
|
.timer
|
2020-11-09 00:11:53 +00:00
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer))
|
2020-09-21 22:38:01 +00:00
|
|
|
.unwrap_or_default(),
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Transitions to swing section of stage
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
timer: Duration::default(),
|
|
|
|
stage_section: StageSection::Swing,
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
2020-09-11 18:29:42 +00:00
|
|
|
|
2020-09-21 22:38:01 +00:00
|
|
|
// Hit attempt
|
2020-12-08 04:00:24 +00:00
|
|
|
let damage = self.static_data.stage_data[stage_index].base_damage
|
|
|
|
+ self
|
|
|
|
.static_data
|
|
|
|
.scales_from_combo
|
|
|
|
.min(self.combo / self.static_data.num_stages)
|
|
|
|
* self.static_data.stage_data[stage_index].damage_increase;
|
2020-12-16 23:30:33 +00:00
|
|
|
|
|
|
|
let poise_damage = self.static_data.stage_data[stage_index].base_poise_damage
|
|
|
|
+ self
|
|
|
|
.static_data
|
|
|
|
.scales_from_combo
|
|
|
|
.min(self.combo / self.static_data.num_stages)
|
|
|
|
* self.static_data.stage_data[stage_index].poise_damage_increase;
|
2021-01-26 02:50:16 +00:00
|
|
|
|
|
|
|
let damage = Damage {
|
|
|
|
source: DamageSource::Melee,
|
|
|
|
value: damage as f32,
|
|
|
|
};
|
|
|
|
let knockback = AttackEffect::Knockback(Knockback {
|
|
|
|
strength: self.static_data.stage_data[stage_index].knockback,
|
|
|
|
direction: KnockbackDir::Away,
|
|
|
|
});
|
2021-01-26 17:58:52 +00:00
|
|
|
let energy = self.static_data.max_energy_gain.min(
|
|
|
|
self.static_data.initial_energy_gain
|
|
|
|
+ self.combo * self.static_data.energy_increase,
|
|
|
|
);
|
|
|
|
let energy = AttackEffect::EnergyReward(energy);
|
2021-01-28 18:50:56 +00:00
|
|
|
let energy = EffectComponent::new(None, energy)
|
|
|
|
.with_requirement(CombatRequirement::AnyDamage);
|
2021-01-28 01:44:49 +00:00
|
|
|
let buff = AttackEffect::Buff(CombatBuff::default_melee());
|
2021-01-26 02:50:16 +00:00
|
|
|
let damage = DamageComponent::new(damage, Some(GroupTarget::OutOfGroup))
|
2021-01-26 17:58:52 +00:00
|
|
|
.with_effect(knockback)
|
2021-01-28 01:44:49 +00:00
|
|
|
.with_effect(buff);
|
2021-01-28 18:50:56 +00:00
|
|
|
let attack = Attack::default()
|
|
|
|
.with_damage(damage)
|
|
|
|
.with_crit(0.5, 1.3)
|
|
|
|
.with_effect(energy);
|
2021-01-26 03:53:52 +00:00
|
|
|
|
2021-01-26 00:31:06 +00:00
|
|
|
data.updater.insert(data.entity, MeleeAttack {
|
2021-01-26 02:50:16 +00:00
|
|
|
attack,
|
2020-09-21 22:38:01 +00:00
|
|
|
range: self.static_data.stage_data[stage_index].range,
|
|
|
|
max_angle: self.static_data.stage_data[stage_index].angle.to_radians(),
|
|
|
|
applied: false,
|
|
|
|
hit_count: 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StageSection::Swing => {
|
|
|
|
if self.timer < self.static_data.stage_data[stage_index].base_swing_duration {
|
|
|
|
// Forward movement
|
2020-10-25 20:22:40 +00:00
|
|
|
handle_forced_movement(
|
2020-09-21 22:38:01 +00:00
|
|
|
data,
|
|
|
|
&mut update,
|
2020-10-25 20:22:40 +00:00
|
|
|
ForcedMovement::Forward {
|
|
|
|
strength: self.static_data.stage_data[stage_index].forward_movement,
|
|
|
|
},
|
2020-09-21 22:38:01 +00:00
|
|
|
0.3,
|
|
|
|
);
|
2020-09-10 02:58:28 +00:00
|
|
|
|
2020-09-21 22:38:01 +00:00
|
|
|
// Swings
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
timer: self
|
|
|
|
.timer
|
2020-11-09 00:11:53 +00:00
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer))
|
2020-09-21 22:38:01 +00:00
|
|
|
.unwrap_or_default(),
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Transitions to recover section of stage
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
timer: Duration::default(),
|
|
|
|
stage_section: StageSection::Recover,
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StageSection::Recover => {
|
|
|
|
if self.timer < self.static_data.stage_data[stage_index].base_recover_duration {
|
|
|
|
// Recovers
|
2020-10-31 18:44:00 +00:00
|
|
|
if ability_key_is_pressed(data, self.static_data.ability_key) {
|
2020-09-21 22:38:01 +00:00
|
|
|
// Checks if state will transition to next stage after recover
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
timer: self
|
|
|
|
.timer
|
2020-11-09 00:11:53 +00:00
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer))
|
2020-09-21 22:38:01 +00:00
|
|
|
.unwrap_or_default(),
|
|
|
|
next_stage: true,
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
timer: self
|
|
|
|
.timer
|
2020-11-09 00:11:53 +00:00
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer))
|
2020-09-21 22:38:01 +00:00
|
|
|
.unwrap_or_default(),
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if self.next_stage {
|
|
|
|
// Transitions to buildup section of next stage
|
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
|
|
|
static_data: self.static_data.clone(),
|
|
|
|
stage: (self.stage % self.static_data.num_stages) + 1,
|
|
|
|
timer: Duration::default(),
|
|
|
|
stage_section: StageSection::Buildup,
|
|
|
|
next_stage: false,
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-09-21 22:38:01 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Done
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
// Make sure attack component is removed
|
2021-01-26 00:31:06 +00:00
|
|
|
data.updater.remove::<MeleeAttack>(data.entity);
|
2020-09-21 22:38:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
// If it somehow ends up in an incorrect stage section
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
// Make sure attack component is removed
|
2021-01-26 00:31:06 +00:00
|
|
|
data.updater.remove::<MeleeAttack>(data.entity);
|
2020-09-21 22:38:01 +00:00
|
|
|
},
|
2020-09-04 01:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Grant energy on successful hit
|
2021-01-26 00:31:06 +00:00
|
|
|
if let Some(attack) = data.melee_attack {
|
2020-09-04 01:54:59 +00:00
|
|
|
if attack.applied && attack.hit_count > 0 {
|
2020-09-11 19:34:00 +00:00
|
|
|
update.character = CharacterState::ComboMelee(Data {
|
2020-09-21 22:38:01 +00:00
|
|
|
static_data: self.static_data.clone(),
|
2020-09-11 19:34:00 +00:00
|
|
|
stage: self.stage,
|
|
|
|
combo: self.combo + 1,
|
|
|
|
timer: self.timer,
|
|
|
|
stage_section: self.stage_section,
|
|
|
|
next_stage: self.next_stage,
|
|
|
|
});
|
2021-01-26 00:31:06 +00:00
|
|
|
data.updater.remove::<MeleeAttack>(data.entity);
|
2020-09-04 01:54:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update
|
|
|
|
}
|
|
|
|
}
|