veloren/common/src/comp/ability.rs

162 lines
5.2 KiB
Rust
Raw Normal View History

use crate::{
2020-03-20 14:45:36 +00:00
comp::{Body, CharacterState, EnergySource, Item, Projectile, StateUpdate},
states::*,
2020-03-17 14:01:41 +00:00
sys::character_behavior::JoinData,
};
2020-03-07 18:15:02 +00:00
use specs::{Component, DenseVecStorage, FlaggedStorage, HashMapStorage};
2020-03-14 15:40:29 +00:00
use std::time::Duration;
2020-01-01 17:16:29 +00:00
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
2020-03-14 15:40:29 +00:00
pub enum CharacterAbility {
BasicMelee {
2020-03-14 15:40:29 +00:00
buildup_duration: Duration,
recover_duration: Duration,
base_damage: u32,
2020-03-12 14:36:02 +00:00
},
BasicRanged {
recover_duration: Duration,
projectile: Projectile,
projectile_body: Body,
},
Boost {
duration: Duration,
only_up: bool,
},
2020-03-16 15:34:53 +00:00
DashMelee {
buildup_duration: Duration,
recover_duration: Duration,
base_damage: u32,
},
2020-03-07 18:15:02 +00:00
BasicBlock,
Roll,
2020-03-12 14:36:02 +00:00
TimedCombo {
buildup_duration: Duration,
recover_duration: Duration,
base_damage: u32,
2020-03-12 14:36:02 +00:00
},
2020-03-19 22:40:03 +00:00
TripleStrike {
base_damage: u32,
},
2020-01-01 17:16:29 +00:00
}
2020-03-17 14:01:41 +00:00
impl CharacterAbility {
pub fn test_requirements(&self, data: &JoinData, update: &mut StateUpdate) -> bool {
match self {
CharacterAbility::Roll => {
data.physics.on_ground
&& !data.physics.in_fluid
&& data.body.is_humanoid()
&& update
.energy
.try_change_by(-200, EnergySource::Ability)
.is_ok()
},
CharacterAbility::DashMelee { .. } => {
2020-03-19 17:33:10 +00:00
!data.physics.in_fluid
2020-03-17 14:01:41 +00:00
&& update
.energy
.try_change_by(-300, EnergySource::Ability)
.is_ok()
},
_ => true,
}
}
}
2020-03-14 15:40:29 +00:00
impl Component for CharacterAbility {
2020-03-07 18:15:02 +00:00
type Storage = DenseVecStorage<Self>;
2020-01-01 17:16:29 +00:00
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct ItemConfig {
pub item: Item,
pub primary_ability: Option<CharacterAbility>,
pub secondary_ability: Option<CharacterAbility>,
pub block_ability: Option<CharacterAbility>,
pub dodge_ability: Option<CharacterAbility>,
}
#[derive(Clone, PartialEq, Default, Debug, Serialize, Deserialize)]
pub struct Loadout {
pub active_item: Option<ItemConfig>,
pub second_item: Option<ItemConfig>,
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-01-01 17:16:29 +00:00
}
impl From<&CharacterAbility> for CharacterState {
fn from(ability: &CharacterAbility) -> Self {
2020-03-14 15:40:29 +00:00
match ability {
CharacterAbility::BasicMelee {
2020-03-14 15:40:29 +00:00
buildup_duration,
recover_duration,
base_damage,
} => CharacterState::BasicMelee(basic_melee::Data {
2020-03-14 15:40:29 +00:00
exhausted: false,
buildup_duration: *buildup_duration,
recover_duration: *recover_duration,
base_damage: *base_damage,
}),
CharacterAbility::BasicRanged {
2020-03-14 15:40:29 +00:00
recover_duration,
projectile,
projectile_body,
} => CharacterState::BasicRanged(basic_ranged::Data {
exhausted: false,
prepare_timer: Duration::default(),
recover_duration: *recover_duration,
projectile: projectile.clone(),
projectile_body: *projectile_body,
}),
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 {
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,
}),
CharacterAbility::BasicBlock => CharacterState::BasicBlock,
CharacterAbility::Roll => CharacterState::Roll(roll::Data {
remaining_duration: Duration::from_millis(600),
2020-03-14 21:17:27 +00:00
}),
CharacterAbility::TimedCombo {
buildup_duration,
recover_duration,
base_damage,
2020-03-14 21:17:27 +00:00
} => CharacterState::TimedCombo(timed_combo::Data {
buildup_duration: *buildup_duration,
recover_duration: *recover_duration,
stage: 0,
2020-03-14 15:40:29 +00:00
stage_exhausted: false,
stage_time_active: Duration::default(),
base_damage: *base_damage,
}),
2020-03-19 22:40:03 +00:00
CharacterAbility::TripleStrike { base_damage } => {
CharacterState::TripleStrike(triple_strike::Data {
base_damage: *base_damage,
stage: 0,
stage_exhausted: false,
stage_time_active: Duration::default(),
})
},
2020-02-03 10:54:50 +00:00
}
}
}
impl Component for Loadout {
2020-01-07 15:49:08 +00:00
type Storage = FlaggedStorage<Self, HashMapStorage<Self>>;
2020-01-01 17:16:29 +00:00
}