2020-03-14 18:50:07 +00:00
|
|
|
use crate::{
|
2020-03-24 19:31:54 +00:00
|
|
|
comp::{
|
2020-05-04 11:12:32 +00:00
|
|
|
ability::Stage, item::Item, Body, CharacterState, EnergySource, Gravity, LightEmitter,
|
|
|
|
Projectile, StateUpdate,
|
2020-03-24 19:31:54 +00:00
|
|
|
},
|
2020-04-01 15:39:18 +00:00
|
|
|
states::{triple_strike::*, *},
|
2020-03-17 14:01:41 +00:00
|
|
|
sys::character_behavior::JoinData,
|
2020-03-14 18:50:07 +00:00
|
|
|
};
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-03-22 04:49:32 +00:00
|
|
|
use specs::{Component, FlaggedStorage};
|
2020-07-06 05:56:02 +00:00
|
|
|
use specs_idvs::IdvStorage;
|
2020-03-14 15:40:29 +00:00
|
|
|
use std::time::Duration;
|
2020-01-01 17:16:29 +00:00
|
|
|
|
2020-04-04 07:48:17 +00:00
|
|
|
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum CharacterAbilityType {
|
|
|
|
BasicMelee,
|
|
|
|
BasicRanged,
|
|
|
|
Boost,
|
|
|
|
DashMelee,
|
|
|
|
BasicBlock,
|
2020-05-04 11:12:32 +00:00
|
|
|
TripleStrike(Stage),
|
2020-07-03 15:40:12 +00:00
|
|
|
LeapMelee,
|
2020-04-04 07:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&CharacterState> for CharacterAbilityType {
|
|
|
|
fn from(state: &CharacterState) -> Self {
|
|
|
|
match state {
|
|
|
|
CharacterState::BasicMelee(_) => Self::BasicMelee,
|
|
|
|
CharacterState::BasicRanged(_) => Self::BasicRanged,
|
|
|
|
CharacterState::Boost(_) => Self::Boost,
|
|
|
|
CharacterState::DashMelee(_) => Self::DashMelee,
|
|
|
|
CharacterState::BasicBlock => Self::BasicBlock,
|
2020-07-03 15:40:12 +00:00
|
|
|
CharacterState::LeapMelee(_) => Self::LeapMelee,
|
2020-05-04 11:12:32 +00:00
|
|
|
CharacterState::TripleStrike(data) => Self::TripleStrike(data.stage),
|
2020-04-04 07:48:17 +00:00
|
|
|
_ => Self::BasicMelee,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
2020-03-14 15:40:29 +00:00
|
|
|
pub enum CharacterAbility {
|
2020-03-16 11:32:57 +00:00
|
|
|
BasicMelee {
|
2020-03-24 21:03:11 +00:00
|
|
|
energy_cost: u32,
|
2020-03-14 15:40:29 +00:00
|
|
|
buildup_duration: Duration,
|
|
|
|
recover_duration: Duration,
|
2020-03-24 21:03:11 +00:00
|
|
|
base_healthchange: i32,
|
2020-03-22 15:25:47 +00:00
|
|
|
range: f32,
|
|
|
|
max_angle: f32,
|
2020-03-12 14:36:02 +00:00
|
|
|
},
|
2020-03-16 11:32:57 +00:00
|
|
|
BasicRanged {
|
2020-03-24 19:09:23 +00:00
|
|
|
energy_cost: u32,
|
2020-03-26 21:52:44 +00:00
|
|
|
holdable: bool,
|
2020-03-24 13:42:31 +00:00
|
|
|
prepare_duration: Duration,
|
2020-03-22 19:39:50 +00:00
|
|
|
recover_duration: Duration,
|
|
|
|
projectile: Projectile,
|
|
|
|
projectile_body: Body,
|
2020-03-24 19:31:54 +00:00
|
|
|
projectile_light: Option<LightEmitter>,
|
|
|
|
projectile_gravity: Option<Gravity>,
|
2020-03-22 19:39:50 +00:00
|
|
|
},
|
2020-03-16 11:32:57 +00:00
|
|
|
Boost {
|
|
|
|
duration: Duration,
|
|
|
|
only_up: bool,
|
|
|
|
},
|
2020-03-16 15:34:53 +00:00
|
|
|
DashMelee {
|
2020-07-03 15:40:12 +00:00
|
|
|
energy_cost: u32,
|
2020-03-16 15:34:53 +00:00
|
|
|
buildup_duration: Duration,
|
|
|
|
recover_duration: Duration,
|
|
|
|
base_damage: u32,
|
|
|
|
},
|
2020-03-07 18:15:02 +00:00
|
|
|
BasicBlock,
|
|
|
|
Roll,
|
2020-03-19 22:40:03 +00:00
|
|
|
TripleStrike {
|
|
|
|
base_damage: u32,
|
2020-03-27 17:40:15 +00:00
|
|
|
needs_timing: bool,
|
2020-03-19 22:40:03 +00:00
|
|
|
},
|
2020-07-03 15:40:12 +00:00
|
|
|
LeapMelee {
|
|
|
|
energy_cost: u32,
|
|
|
|
movement_duration: Duration,
|
|
|
|
buildup_duration: Duration,
|
|
|
|
recover_duration: Duration,
|
|
|
|
base_damage: u32,
|
|
|
|
},
|
2020-01-01 17:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 14:01:41 +00:00
|
|
|
impl CharacterAbility {
|
2020-03-21 22:55:20 +00:00
|
|
|
/// Attempts to fulfill requirements, mutating `update` (taking energy) if
|
|
|
|
/// applicable.
|
|
|
|
pub fn requirements_paid(&self, data: &JoinData, update: &mut StateUpdate) -> bool {
|
2020-03-17 14:01:41 +00:00
|
|
|
match self {
|
2020-03-29 20:40:03 +00:00
|
|
|
CharacterAbility::TripleStrike { .. } => {
|
2020-03-26 22:28:58 +00:00
|
|
|
data.physics.on_ground
|
|
|
|
&& data.body.is_humanoid()
|
|
|
|
&& data.inputs.look_dir.xy().magnitude_squared() > 0.01
|
|
|
|
},
|
2020-03-17 14:01:41 +00:00
|
|
|
CharacterAbility::Roll => {
|
|
|
|
data.physics.on_ground
|
|
|
|
&& data.body.is_humanoid()
|
2020-03-26 19:02:01 +00:00
|
|
|
&& data.vel.0.xy().magnitude_squared() > 0.5
|
2020-03-17 14:01:41 +00:00
|
|
|
&& update
|
|
|
|
.energy
|
2020-03-26 21:52:44 +00:00
|
|
|
.try_change_by(-220, EnergySource::Ability)
|
2020-03-22 19:39:50 +00:00
|
|
|
.is_ok()
|
|
|
|
},
|
2020-07-03 15:40:12 +00:00
|
|
|
CharacterAbility::DashMelee { energy_cost, .. } => update
|
2020-03-26 13:46:08 +00:00
|
|
|
.energy
|
2020-07-03 15:40:12 +00:00
|
|
|
.try_change_by(-(*energy_cost as i32), EnergySource::Ability)
|
2020-03-26 13:46:08 +00:00
|
|
|
.is_ok(),
|
|
|
|
CharacterAbility::BasicMelee { energy_cost, .. } => update
|
|
|
|
.energy
|
|
|
|
.try_change_by(-(*energy_cost as i32), EnergySource::Ability)
|
|
|
|
.is_ok(),
|
|
|
|
CharacterAbility::BasicRanged { energy_cost, .. } => update
|
|
|
|
.energy
|
|
|
|
.try_change_by(-(*energy_cost as i32), EnergySource::Ability)
|
|
|
|
.is_ok(),
|
2020-07-03 15:40:12 +00:00
|
|
|
CharacterAbility::LeapMelee { energy_cost, .. } => update
|
|
|
|
.energy
|
|
|
|
.try_change_by(-(*energy_cost as i32), EnergySource::Ability)
|
|
|
|
.is_ok(),
|
2020-03-17 14:01:41 +00:00
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
2020-03-14 21:33:20 +00:00
|
|
|
pub struct ItemConfig {
|
|
|
|
pub item: Item,
|
2020-03-24 12:59:53 +00:00
|
|
|
pub ability1: Option<CharacterAbility>,
|
|
|
|
pub ability2: Option<CharacterAbility>,
|
|
|
|
pub ability3: Option<CharacterAbility>,
|
2020-03-14 21:33:20 +00:00
|
|
|
pub block_ability: Option<CharacterAbility>,
|
|
|
|
pub dodge_ability: Option<CharacterAbility>,
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Clone, PartialEq, Default, Debug, Serialize, Deserialize)]
|
2020-03-14 21:33:20 +00:00
|
|
|
pub struct Loadout {
|
|
|
|
pub active_item: Option<ItemConfig>,
|
|
|
|
pub second_item: Option<ItemConfig>,
|
2020-02-26 17:04:43 +00:00
|
|
|
|
|
|
|
pub shoulder: Option<Item>,
|
|
|
|
pub chest: Option<Item>,
|
|
|
|
pub belt: Option<Item>,
|
|
|
|
pub hand: Option<Item>,
|
|
|
|
pub pants: Option<Item>,
|
|
|
|
pub foot: Option<Item>,
|
2020-04-06 16:11:05 +00:00
|
|
|
pub back: Option<Item>,
|
2020-04-06 20:03:46 +00:00
|
|
|
pub ring: Option<Item>,
|
|
|
|
pub neck: Option<Item>,
|
|
|
|
pub lantern: Option<Item>,
|
|
|
|
pub head: Option<Item>,
|
|
|
|
pub tabard: Option<Item>,
|
2020-01-01 17:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
impl From<&CharacterAbility> for CharacterState {
|
|
|
|
fn from(ability: &CharacterAbility) -> Self {
|
2020-03-14 15:40:29 +00:00
|
|
|
match ability {
|
2020-03-16 11:32:57 +00:00
|
|
|
CharacterAbility::BasicMelee {
|
2020-03-14 15:40:29 +00:00
|
|
|
buildup_duration,
|
|
|
|
recover_duration,
|
2020-03-24 21:03:11 +00:00
|
|
|
base_healthchange,
|
2020-03-22 15:25:47 +00:00
|
|
|
range,
|
|
|
|
max_angle,
|
2020-03-24 21:03:11 +00:00
|
|
|
energy_cost: _,
|
2020-03-16 11:32:57 +00:00
|
|
|
} => CharacterState::BasicMelee(basic_melee::Data {
|
2020-03-14 15:40:29 +00:00
|
|
|
exhausted: false,
|
2020-03-16 11:32:57 +00:00
|
|
|
buildup_duration: *buildup_duration,
|
|
|
|
recover_duration: *recover_duration,
|
2020-03-24 21:03:11 +00:00
|
|
|
base_healthchange: *base_healthchange,
|
2020-03-22 15:25:47 +00:00
|
|
|
range: *range,
|
|
|
|
max_angle: *max_angle,
|
2020-03-16 11:32:57 +00:00
|
|
|
}),
|
|
|
|
CharacterAbility::BasicRanged {
|
2020-03-26 21:52:44 +00:00
|
|
|
holdable,
|
2020-03-24 13:42:31 +00:00
|
|
|
prepare_duration,
|
2020-03-14 15:40:29 +00:00
|
|
|
recover_duration,
|
2020-03-16 11:32:57 +00:00
|
|
|
projectile,
|
|
|
|
projectile_body,
|
2020-03-24 19:31:54 +00:00
|
|
|
projectile_light,
|
|
|
|
projectile_gravity,
|
2020-03-24 19:09:23 +00:00
|
|
|
energy_cost: _,
|
2020-03-16 11:32:57 +00:00
|
|
|
} => CharacterState::BasicRanged(basic_ranged::Data {
|
|
|
|
exhausted: false,
|
|
|
|
prepare_timer: Duration::default(),
|
2020-03-26 21:52:44 +00:00
|
|
|
holdable: *holdable,
|
2020-03-24 13:42:31 +00:00
|
|
|
prepare_duration: *prepare_duration,
|
2020-03-16 11:32:57 +00:00
|
|
|
recover_duration: *recover_duration,
|
|
|
|
projectile: projectile.clone(),
|
|
|
|
projectile_body: *projectile_body,
|
2020-03-24 19:31:54 +00:00
|
|
|
projectile_light: *projectile_light,
|
|
|
|
projectile_gravity: *projectile_gravity,
|
2020-03-14 18:50:07 +00:00
|
|
|
}),
|
2020-03-16 11:32:57 +00:00
|
|
|
CharacterAbility::Boost { duration, only_up } => CharacterState::Boost(boost::Data {
|
|
|
|
duration: *duration,
|
|
|
|
only_up: *only_up,
|
|
|
|
}),
|
2020-03-16 15:34:53 +00:00
|
|
|
CharacterAbility::DashMelee {
|
2020-07-03 15:40:12 +00:00
|
|
|
energy_cost: _,
|
2020-03-16 15:34:53 +00:00
|
|
|
buildup_duration,
|
|
|
|
recover_duration,
|
|
|
|
base_damage,
|
|
|
|
} => CharacterState::DashMelee(dash_melee::Data {
|
2020-03-19 17:33:10 +00:00
|
|
|
initialize: true,
|
2020-03-16 15:34:53 +00:00
|
|
|
exhausted: false,
|
|
|
|
buildup_duration: *buildup_duration,
|
|
|
|
recover_duration: *recover_duration,
|
|
|
|
base_damage: *base_damage,
|
|
|
|
}),
|
2020-03-16 11:32:57 +00:00
|
|
|
CharacterAbility::BasicBlock => CharacterState::BasicBlock,
|
|
|
|
CharacterAbility::Roll => CharacterState::Roll(roll::Data {
|
2020-04-01 13:24:02 +00:00
|
|
|
remaining_duration: Duration::from_millis(700),
|
2020-03-26 13:46:08 +00:00
|
|
|
was_wielded: false, // false by default. utils might set it to true
|
2020-03-14 21:17:27 +00:00
|
|
|
}),
|
2020-03-27 17:40:15 +00:00
|
|
|
CharacterAbility::TripleStrike {
|
|
|
|
base_damage,
|
|
|
|
needs_timing,
|
|
|
|
} => CharacterState::TripleStrike(triple_strike::Data {
|
|
|
|
base_damage: *base_damage,
|
|
|
|
stage: triple_strike::Stage::First,
|
|
|
|
stage_exhausted: false,
|
|
|
|
stage_time_active: Duration::default(),
|
|
|
|
initialized: false,
|
2020-06-08 18:37:41 +00:00
|
|
|
transition_style: if *needs_timing {
|
|
|
|
TransitionStyle::Timed(TimingState::NotPressed)
|
|
|
|
} else {
|
|
|
|
TransitionStyle::Hold(HoldingState::Holding)
|
2020-04-01 15:39:18 +00:00
|
|
|
},
|
2020-03-27 17:40:15 +00:00
|
|
|
}),
|
2020-07-03 15:40:12 +00:00
|
|
|
CharacterAbility::LeapMelee {
|
|
|
|
energy_cost: _,
|
|
|
|
movement_duration,
|
|
|
|
buildup_duration,
|
|
|
|
recover_duration,
|
|
|
|
base_damage,
|
|
|
|
} => CharacterState::LeapMelee(leap_melee::Data {
|
|
|
|
initialize: true,
|
|
|
|
exhausted: false,
|
|
|
|
movement_duration: *movement_duration,
|
|
|
|
buildup_duration: *buildup_duration,
|
|
|
|
recover_duration: *recover_duration,
|
|
|
|
base_damage: *base_damage,
|
|
|
|
}),
|
2020-02-03 10:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-14 21:33:20 +00:00
|
|
|
impl Component for Loadout {
|
2020-07-06 05:56:02 +00:00
|
|
|
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
|
2020-01-01 17:16:29 +00:00
|
|
|
}
|