2019-12-21 15:57:15 +00:00
|
|
|
use crate::comp::{Body, Controller, ControllerInputs, ItemKind, PhysicsState, Stats};
|
2019-08-23 10:11:37 +00:00
|
|
|
use specs::{Component, FlaggedStorage, HashMapStorage};
|
2019-12-20 13:30:37 +00:00
|
|
|
use specs::{Entities, Join, LazyUpdate, Read, ReadStorage, System};
|
|
|
|
use sphynx::{Uid, UidAllocator};
|
2019-09-04 23:03:49 +00:00
|
|
|
//use specs_idvs::IDVStorage;
|
2019-12-20 13:30:37 +00:00
|
|
|
use self::{ActionState::*, MovementState::*};
|
2019-08-23 10:11:37 +00:00
|
|
|
use std::time::Duration;
|
2019-12-20 13:30:37 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct RunData;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct StandData;
|
2019-12-22 16:08:48 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct SitData;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct JumpData;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct FallData;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct GlideData;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct SwimData;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct ClimbData;
|
2019-12-20 13:30:37 +00:00
|
|
|
|
2019-08-18 09:01:57 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-08-23 10:11:37 +00:00
|
|
|
pub enum MovementState {
|
2019-12-20 16:50:54 +00:00
|
|
|
Stand(StandData),
|
|
|
|
Run(RunData),
|
2019-12-22 16:08:48 +00:00
|
|
|
Sit(SitData),
|
|
|
|
Jump(JumpData),
|
|
|
|
Fall(FallData),
|
|
|
|
Glide(GlideData),
|
|
|
|
Swim(SwimData),
|
|
|
|
Climb(ClimbData),
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-18 09:01:57 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-08-23 10:11:37 +00:00
|
|
|
pub enum ActionState {
|
|
|
|
Idle,
|
2019-12-09 14:45:10 +00:00
|
|
|
Wield {
|
|
|
|
time_left: Duration,
|
|
|
|
},
|
|
|
|
Attack {
|
|
|
|
time_left: Duration,
|
|
|
|
applied: bool,
|
|
|
|
},
|
|
|
|
Block {
|
|
|
|
time_active: Duration,
|
|
|
|
},
|
|
|
|
Roll {
|
|
|
|
time_left: Duration,
|
|
|
|
// Whether character was wielding before they started roll
|
|
|
|
was_wielding: bool,
|
|
|
|
},
|
|
|
|
Charge {
|
|
|
|
time_left: Duration,
|
|
|
|
},
|
2019-12-20 13:30:37 +00:00
|
|
|
// Handle(CharacterAction),
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ActionState {
|
|
|
|
pub fn is_wield(&self) -> bool {
|
|
|
|
if let Self::Wield { .. } = self {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 06:30:08 +00:00
|
|
|
pub fn is_action_finished(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Self::Wield { time_left }
|
|
|
|
| Self::Attack { time_left, .. }
|
2019-12-09 14:45:10 +00:00
|
|
|
| Self::Roll { time_left, .. }
|
2019-12-03 06:30:08 +00:00
|
|
|
| Self::Charge { time_left } => *time_left == Duration::default(),
|
|
|
|
Self::Idle | Self::Block { .. } => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:11:37 +00:00
|
|
|
pub fn is_attack(&self) -> bool {
|
|
|
|
if let Self::Attack { .. } = self {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 16:38:59 +00:00
|
|
|
|
|
|
|
pub fn is_block(&self) -> bool {
|
|
|
|
if let Self::Block { .. } = self {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2019-12-03 06:30:08 +00:00
|
|
|
|
|
|
|
pub fn is_roll(&self) -> bool {
|
|
|
|
if let Self::Roll { .. } = self {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_charge(&self) -> bool {
|
|
|
|
if let Self::Charge { .. } = self {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-18 09:01:57 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-08-23 10:11:37 +00:00
|
|
|
pub struct CharacterState {
|
|
|
|
pub movement: MovementState,
|
|
|
|
pub action: ActionState,
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:40:22 +00:00
|
|
|
impl CharacterState {
|
|
|
|
pub fn is_same_movement(&self, other: &Self) -> bool {
|
|
|
|
// Check if enum item is the same without looking at the inner data
|
|
|
|
std::mem::discriminant(&self.movement) == std::mem::discriminant(&other.movement)
|
|
|
|
}
|
|
|
|
pub fn is_same_action(&self, other: &Self) -> bool {
|
|
|
|
// Check if enum item is the same without looking at the inner data
|
|
|
|
std::mem::discriminant(&self.action) == std::mem::discriminant(&other.action)
|
|
|
|
}
|
|
|
|
pub fn is_same_state(&self, other: &Self) -> bool {
|
|
|
|
self.is_same_movement(other) && self.is_same_action(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:11:37 +00:00
|
|
|
impl Default for CharacterState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2019-12-22 16:08:48 +00:00
|
|
|
movement: MovementState::Fall(FallData),
|
2019-08-23 10:11:37 +00:00
|
|
|
action: ActionState::Idle,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for CharacterState {
|
|
|
|
type Storage = FlaggedStorage<Self, HashMapStorage<Self>>;
|
|
|
|
}
|