2019-12-26 14:43:59 +00:00
|
|
|
use crate::{
|
2020-03-21 21:16:26 +00:00
|
|
|
comp::{Energy, Loadout, Ori, Pos, Vel},
|
2020-02-03 10:54:50 +00:00
|
|
|
event::{LocalEvent, ServerEvent},
|
2020-03-14 18:50:07 +00:00
|
|
|
states::*,
|
2020-03-21 21:16:26 +00:00
|
|
|
sys::character_behavior::JoinData,
|
2019-12-26 14:43:59 +00:00
|
|
|
};
|
2020-02-03 21:02:32 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-03-07 18:15:02 +00:00
|
|
|
use specs::{Component, FlaggedStorage, HashMapStorage, VecStorage};
|
2020-03-14 21:17:27 +00:00
|
|
|
use std::collections::VecDeque;
|
2019-12-26 14:43:59 +00:00
|
|
|
|
2020-03-07 18:15:02 +00:00
|
|
|
/// Data returned from character behavior fn's to Character Behavior System.
|
2019-12-28 16:10:39 +00:00
|
|
|
pub struct StateUpdate {
|
2019-12-26 14:43:59 +00:00
|
|
|
pub character: CharacterState,
|
|
|
|
pub pos: Pos,
|
|
|
|
pub vel: Vel,
|
|
|
|
pub ori: Ori,
|
2020-02-24 18:17:16 +00:00
|
|
|
pub energy: Energy,
|
2020-03-21 21:16:26 +00:00
|
|
|
pub loadout: Loadout,
|
2020-02-03 10:54:50 +00:00
|
|
|
pub local_events: VecDeque<LocalEvent>,
|
|
|
|
pub server_events: VecDeque<ServerEvent>,
|
2019-12-26 14:43:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 21:16:26 +00:00
|
|
|
impl From<&JoinData<'_>> for StateUpdate {
|
|
|
|
fn from(data: &JoinData) -> Self {
|
|
|
|
StateUpdate {
|
|
|
|
pos: *data.pos,
|
|
|
|
vel: *data.vel,
|
|
|
|
ori: *data.ori,
|
|
|
|
energy: *data.energy,
|
|
|
|
loadout: data.loadout.clone(),
|
|
|
|
character: data.character.clone(),
|
|
|
|
local_events: VecDeque::new(),
|
|
|
|
server_events: VecDeque::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2020-01-21 22:54:32 +00:00
|
|
|
pub enum CharacterState {
|
2020-03-14 15:40:29 +00:00
|
|
|
Idle,
|
|
|
|
Climb,
|
2020-03-14 21:17:27 +00:00
|
|
|
Sit,
|
2020-03-14 15:40:29 +00:00
|
|
|
Glide,
|
2020-03-07 18:15:02 +00:00
|
|
|
/// A basic blocking state
|
2020-03-14 15:40:29 +00:00
|
|
|
BasicBlock,
|
2020-03-14 21:17:27 +00:00
|
|
|
/// Player is busy equipping or unequipping weapons
|
|
|
|
Equipping(equipping::Data),
|
|
|
|
/// Player is holding a weapon and can perform other actions
|
2020-03-15 13:34:17 +00:00
|
|
|
Wielding,
|
2020-03-14 21:17:27 +00:00
|
|
|
/// A dodge where player can roll
|
|
|
|
Roll(roll::Data),
|
2020-03-16 11:32:57 +00:00
|
|
|
/// A basic melee attack (e.g. sword)
|
|
|
|
BasicMelee(basic_melee::Data),
|
|
|
|
/// A basic ranged attack (e.g. bow)
|
|
|
|
BasicRanged(basic_ranged::Data),
|
|
|
|
/// A force will boost you into a direction for some duration
|
|
|
|
Boost(boost::Data),
|
2020-03-16 15:34:53 +00:00
|
|
|
/// Dash forward and then attack
|
|
|
|
DashMelee(dash_melee::Data),
|
2020-03-08 19:37:17 +00:00
|
|
|
/// A three-stage attack where play must click at appropriate times
|
|
|
|
/// to continue attack chain.
|
2020-03-14 21:17:27 +00:00
|
|
|
TimedCombo(timed_combo::Data),
|
2020-03-12 14:25:06 +00:00
|
|
|
/// A three-stage attack where each attack pushes player forward
|
|
|
|
/// and successive attacks increase in damage, while player holds button.
|
2020-03-14 21:17:27 +00:00
|
|
|
TripleStrike(triple_strike::Data),
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 22:54:32 +00:00
|
|
|
impl CharacterState {
|
2020-03-07 20:49:48 +00:00
|
|
|
pub fn is_wield(&self) -> bool {
|
2020-02-24 19:57:33 +00:00
|
|
|
match self {
|
2020-03-15 13:34:17 +00:00
|
|
|
CharacterState::Wielding
|
2020-03-16 11:32:57 +00:00
|
|
|
| CharacterState::BasicMelee(_)
|
2020-03-19 21:03:17 +00:00
|
|
|
| CharacterState::BasicRanged(_)
|
|
|
|
| CharacterState::DashMelee(_)
|
2020-03-20 14:05:40 +00:00
|
|
|
| CharacterState::TripleStrike(_)
|
2020-03-14 18:50:07 +00:00
|
|
|
| CharacterState::TimedCombo(_)
|
2020-03-14 21:17:27 +00:00
|
|
|
| CharacterState::BasicBlock => true,
|
2020-02-24 19:57:33 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:40:03 +00:00
|
|
|
pub fn can_swap(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
CharacterState::Wielding => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:54:32 +00:00
|
|
|
pub fn is_attack(&self) -> bool {
|
2019-12-03 06:30:08 +00:00
|
|
|
match self {
|
2020-03-16 11:32:57 +00:00
|
|
|
CharacterState::BasicMelee(_)
|
|
|
|
| CharacterState::BasicRanged(_)
|
2020-03-14 18:50:07 +00:00
|
|
|
| CharacterState::TimedCombo(_)
|
2020-03-19 21:03:17 +00:00
|
|
|
| CharacterState::DashMelee(_)
|
2020-03-20 14:05:40 +00:00
|
|
|
| CharacterState::TripleStrike(_) => true,
|
2019-12-26 14:43:59 +00:00
|
|
|
_ => false,
|
2019-12-03 06:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:54:32 +00:00
|
|
|
pub fn is_block(&self) -> bool {
|
2019-12-26 14:43:59 +00:00
|
|
|
match self {
|
2020-03-14 21:17:27 +00:00
|
|
|
CharacterState::BasicBlock => true,
|
2019-12-26 14:43:59 +00:00
|
|
|
_ => false,
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-24 16:38:59 +00:00
|
|
|
|
2020-01-21 22:54:32 +00:00
|
|
|
pub fn is_dodge(&self) -> bool {
|
2019-12-26 14:43:59 +00:00
|
|
|
match self {
|
2020-03-14 21:17:27 +00:00
|
|
|
CharacterState::Roll(_) => true,
|
2019-12-26 14:43:59 +00:00
|
|
|
_ => false,
|
2019-08-24 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-08 19:31:42 +00:00
|
|
|
|
2020-01-22 12:48:55 +00:00
|
|
|
/// Compares for shallow equality (does not check internal struct equality)
|
2020-03-22 12:46:09 +00:00
|
|
|
pub fn same_variant(&self, other: &Self) -> bool {
|
2020-01-08 19:31:42 +00:00
|
|
|
// Check if state is the same without looking at the inner data
|
2020-01-22 12:48:55 +00:00
|
|
|
std::mem::discriminant(self) == std::mem::discriminant(other)
|
2019-12-03 06:30:08 +00:00
|
|
|
}
|
2019-08-30 18:40:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 10:11:37 +00:00
|
|
|
impl Default for CharacterState {
|
2020-03-14 21:17:27 +00:00
|
|
|
fn default() -> Self { Self::Idle }
|
2019-08-23 10:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for CharacterState {
|
|
|
|
type Storage = FlaggedStorage<Self, HashMapStorage<Self>>;
|
|
|
|
}
|
2020-02-11 15:42:17 +00:00
|
|
|
|
2020-03-17 13:15:39 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2020-02-11 15:42:17 +00:00
|
|
|
pub struct Attacking {
|
2020-03-14 21:33:20 +00:00
|
|
|
pub base_damage: u32,
|
2020-03-17 13:15:39 +00:00
|
|
|
pub max_angle: f32,
|
2020-03-10 17:54:59 +00:00
|
|
|
pub applied: bool,
|
|
|
|
pub hit_count: u32,
|
2020-02-11 15:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for Attacking {
|
|
|
|
type Storage = VecStorage<Self>;
|
|
|
|
}
|