2019-12-26 14:43:59 +00:00
|
|
|
use self::ActionState::*;
|
|
|
|
use super::states::*;
|
|
|
|
use crate::{
|
|
|
|
comp::{Body, ControllerInputs, Ori, PhysicsState, Pos, Stats, Vel},
|
|
|
|
event::{EventBus, LocalEvent, ServerEvent},
|
|
|
|
state::DeltaTime,
|
|
|
|
};
|
|
|
|
use specs::LazyUpdate;
|
|
|
|
use specs::{Component, Entity, FlaggedStorage, HashMapStorage, NullStorage};
|
|
|
|
use sphynx::Uid;
|
2019-08-23 10:11:37 +00:00
|
|
|
use std::time::Duration;
|
2019-12-20 13:30:37 +00:00
|
|
|
|
2019-12-26 18:01:19 +00:00
|
|
|
pub struct EcsCharacterState<'a> {
|
2019-12-26 14:43:59 +00:00
|
|
|
pub entity: &'a Entity,
|
|
|
|
pub uid: &'a Uid,
|
|
|
|
pub character: &'a CharacterState,
|
|
|
|
pub pos: &'a Pos,
|
|
|
|
pub vel: &'a Vel,
|
|
|
|
pub ori: &'a Ori,
|
|
|
|
pub dt: &'a DeltaTime,
|
|
|
|
pub inputs: &'a ControllerInputs,
|
|
|
|
pub stats: &'a Stats,
|
|
|
|
pub body: &'a Body,
|
|
|
|
pub physics: &'a PhysicsState,
|
|
|
|
pub updater: &'a LazyUpdate,
|
|
|
|
pub server_bus: &'a EventBus<ServerEvent>,
|
|
|
|
pub local_bus: &'a EventBus<LocalEvent>,
|
|
|
|
}
|
|
|
|
|
2019-12-26 18:01:19 +00:00
|
|
|
pub struct EcsStateUpdate {
|
2019-12-26 14:43:59 +00:00
|
|
|
pub character: CharacterState,
|
|
|
|
pub pos: Pos,
|
|
|
|
pub vel: Vel,
|
|
|
|
pub ori: Ori,
|
|
|
|
}
|
|
|
|
|
2019-12-20 13:30:37 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-12-26 14:43:59 +00:00
|
|
|
pub enum MoveState {
|
|
|
|
Stand(StandHandler),
|
|
|
|
Run(RunHandler),
|
|
|
|
Sit(SitHandler),
|
|
|
|
Jump(JumpHandler),
|
|
|
|
Fall(FallHandler),
|
|
|
|
Glide(GlideHandler),
|
|
|
|
Swim(SwimHandler),
|
|
|
|
Climb(ClimbHandler),
|
|
|
|
}
|
|
|
|
|
2019-12-22 16:08:48 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-12-26 14:43:59 +00:00
|
|
|
pub enum ActionState {
|
|
|
|
Idle,
|
|
|
|
Wield(WieldHandler),
|
|
|
|
Attack(AttackKind),
|
|
|
|
Block(BlockKind),
|
|
|
|
Dodge(DodgeKind),
|
|
|
|
// Interact,
|
|
|
|
}
|
|
|
|
|
2019-12-22 16:08:48 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-12-26 14:43:59 +00:00
|
|
|
pub enum AttackKind {
|
|
|
|
BasicAttack(BasicAttackHandler),
|
|
|
|
Charge(ChargeAttackHandler),
|
|
|
|
}
|
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-12-26 14:43:59 +00:00
|
|
|
pub enum BlockKind {
|
|
|
|
BasicBlock(BasicBlockHandler),
|
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-12-26 14:43:59 +00:00
|
|
|
pub enum DodgeKind {
|
|
|
|
Roll(RollHandler),
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ActionState {
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_equip_finished(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Wield(WieldHandler { equip_delay }) => *equip_delay == Duration::default(),
|
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn get_delay(&self) -> Duration {
|
|
|
|
match self {
|
|
|
|
Wield(WieldHandler { equip_delay }) => *equip_delay,
|
|
|
|
_ => Duration::default(),
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_attacking(&self) -> bool {
|
2019-12-03 06:30:08 +00:00
|
|
|
match self {
|
2019-12-26 14:43:59 +00:00
|
|
|
Block(_) => true,
|
|
|
|
_ => false,
|
2019-12-03 06:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_blocking(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Attack(_) => true,
|
|
|
|
_ => false,
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-24 16:38:59 +00:00
|
|
|
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_dodging(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Dodge(_) => true,
|
|
|
|
_ => false,
|
2019-08-24 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-03 06:30:08 +00:00
|
|
|
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_wielding(&self) -> bool {
|
|
|
|
if let Wield(_) = self {
|
2019-12-03 06:30:08 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_idling(&self) -> bool {
|
|
|
|
if let Idle = self {
|
2019-12-03 06:30:08 +00:00
|
|
|
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 {
|
2019-12-26 14:43:59 +00:00
|
|
|
pub move_state: MoveState,
|
|
|
|
pub action_state: ActionState,
|
2019-12-26 18:01:19 +00:00
|
|
|
pub action_disabled: bool,
|
|
|
|
pub move_disabled: bool,
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 18:40:22 +00:00
|
|
|
impl CharacterState {
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_same_move_state(&self, other: &Self) -> bool {
|
|
|
|
// Check if state is the same without looking at the inner data
|
|
|
|
std::mem::discriminant(&self.move_state) == std::mem::discriminant(&other.move_state)
|
2019-08-30 18:40:22 +00:00
|
|
|
}
|
2019-12-26 18:01:19 +00:00
|
|
|
|
2019-12-26 14:43:59 +00:00
|
|
|
pub fn is_same_action_state(&self, other: &Self) -> bool {
|
|
|
|
// Check if state is the same without looking at the inner data
|
|
|
|
std::mem::discriminant(&self.action_state) == std::mem::discriminant(&other.action_state)
|
2019-08-30 18:40:22 +00:00
|
|
|
}
|
|
|
|
pub fn is_same_state(&self, other: &Self) -> bool {
|
2019-12-26 14:43:59 +00:00
|
|
|
self.is_same_move_state(other) && self.is_same_action_state(other)
|
2019-08-30 18:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:11:37 +00:00
|
|
|
impl Default for CharacterState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2019-12-26 14:43:59 +00:00
|
|
|
move_state: MoveState::Fall(FallHandler),
|
|
|
|
action_state: ActionState::Idle,
|
2019-12-26 18:01:19 +00:00
|
|
|
action_disabled: false,
|
|
|
|
move_disabled: false,
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for CharacterState {
|
|
|
|
type Storage = FlaggedStorage<Self, HashMapStorage<Self>>;
|
|
|
|
}
|
2019-12-26 14:43:59 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct OverrideState;
|
|
|
|
impl Component for OverrideState {
|
|
|
|
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct OverrideAction;
|
|
|
|
impl Component for OverrideAction {
|
|
|
|
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
pub struct OverrideMove;
|
|
|
|
impl Component for OverrideMove {
|
|
|
|
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
|
|
|
|
}
|