fix: block

This commit is contained in:
timokoesters 2020-02-24 15:35:07 +01:00
parent 1f4065ae32
commit 2fa902270e
9 changed files with 42 additions and 60 deletions

View File

@ -10,9 +10,7 @@ pub enum AbilityActionKind {
// UpdatePool?
}
impl Default for AbilityActionKind {
fn default() -> Self {
Self::Primary
}
fn default() -> Self { Self::Primary }
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct AbilityAction(pub AbilityActionKind);
@ -33,7 +31,7 @@ impl Default for AbilityPool {
fn default() -> Self {
Self {
primary: Some(comp::CharacterState::BasicAttack(None)),
secondary: None,
secondary: Some(comp::CharacterState::BasicBlock(None)),
block: None,
dodge: Some(comp::CharacterState::Roll(None)),
}

View File

@ -43,7 +43,7 @@ pub enum CharacterState {
Wielded(Option<wielded::State>),
Glide(Option<glide::State>),
BasicAttack(Option<basic_attack::State>),
//BasicBlock(Option<basic_block::State>),
BasicBlock(Option<basic_block::State>),
//Charge(Option<charge_attack::State>),
Roll(Option<roll::State>),
}
@ -58,7 +58,7 @@ impl CharacterState {
pub fn is_block(&self) -> bool {
match self {
//CharacterState::BasicBlock(_) => true,
CharacterState::BasicBlock(_) => true,
_ => false,
}
}
@ -102,12 +102,12 @@ impl CharacterState {
CharacterState::BasicAttack(opt_state) => opt_state
.unwrap_or_else(|| basic_attack::State::new(ecs_data))
.handle(ecs_data),
/*CharacterState::Charge(opt_state) => opt_state
.unwrap_or_else(|| charge_attack::State::new(ecs_data))
.handle(ecs_data),
CharacterState::BasicBlock(opt_state) => opt_state
.unwrap_or_else(|| basic_block::State::new(ecs_data))
.handle(ecs_data),*/
.handle(ecs_data),
/*CharacterState::Charge(opt_state) => opt_state
.unwrap_or_else(|| charge_attack::State::new(ecs_data))
.handle(ecs_data),*/
CharacterState::Roll(opt_state) => opt_state
.unwrap_or_else(|| roll::State::new(ecs_data))
.handle(ecs_data),

View File

@ -1,24 +1,19 @@
use super::utils::*;
use crate::comp::{EcsStateData, StateUpdate};
use crate::states::StateHandler;
use std::time::Duration;
use crate::{
comp::{EcsStateData, StateUpdate},
states::StateHandler,
};
use std::{collections::VecDeque, time::Duration};
use vek::Vec2;
const BLOCK_ACCEL: f32 = 30.0;
const BLOCK_SPEED: f32 = 75.0;
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct State {
/// How long the blocking state has been active
pub active_duration: Duration,
}
pub struct State {}
impl StateHandler for State {
fn new(_ecs_data: &EcsStateData) -> Self {
Self {
active_duration: Duration::default(),
}
}
fn new(_ecs_data: &EcsStateData) -> Self { Self {} }
fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate {
let mut update = StateUpdate {
@ -26,23 +21,10 @@ impl StateHandler for State {
vel: *ecs_data.vel,
ori: *ecs_data.ori,
character: *ecs_data.character,
local_events: VecDeque::new(),
server_events: VecDeque::new(),
};
// TODO: Apply simple move speed debuff instead
// Update movement
update.vel.0 += Vec2::broadcast(ecs_data.dt.0)
* ecs_data.inputs.move_dir
* match ecs_data.physics.on_ground {
true if update.vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL,
_ => 0.0,
};
if !ecs_data.inputs.secondary.is_pressed() {
update.character.action_state = attempt_wield(ecs_data.stats);
return update;
}
update
}
}

View File

@ -1,5 +1,6 @@
// Module declarations
pub mod basic_attack;
pub mod basic_block;
pub mod climb;
pub mod glide;
pub mod idle;

View File

@ -105,6 +105,16 @@ pub fn handle_primary(ecs_data: &EcsStateData, update: &mut StateUpdate) {
}
}
pub fn handle_secondary(ecs_data: &EcsStateData, update: &mut StateUpdate) {
if let Some(state) = ecs_data.ability_pool.secondary {
if let CharacterState::Wielded(_) = update.character {
if ecs_data.inputs.secondary.is_pressed() {
update.character = state;
}
}
}
}
pub fn handle_dodge(ecs_data: &EcsStateData, update: &mut StateUpdate) {
if let Some(state) = ecs_data.ability_pool.dodge {
if let CharacterState::Idle(_) | CharacterState::Wielded(_) = update.character {

View File

@ -1,8 +1,9 @@
use super::utils::*;
use crate::comp::{EcsStateData, ItemKind::Tool, StateUpdate, ToolData};
use crate::states::StateHandler;
use std::collections::VecDeque;
use std::time::Duration;
use crate::{
comp::{EcsStateData, ItemKind::Tool, StateUpdate, ToolData},
states::StateHandler,
};
use std::{collections::VecDeque, time::Duration};
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct State {
@ -41,6 +42,7 @@ impl StateHandler for State {
handle_glide(&ecs_data, &mut update);
handle_unwield(&ecs_data, &mut update);
handle_primary(&ecs_data, &mut update);
handle_secondary(&ecs_data, &mut update);
handle_dodge(&ecs_data, &mut update);
update

View File

@ -170,9 +170,9 @@ impl<Skel: Skeleton> FigureModelCache<Skel> {
if camera_mode != CameraMode::FirstPerson
|| character_state
.map(|cs| match cs {
//CharacterState::BasicAttack(_) // TODO: enable
//| CharacterState::BasicBlock(_)
CharacterState::Wielding(_)
CharacterState::BasicAttack(_)
| CharacterState::BasicBlock(_)
| CharacterState::Wielding(_)
| CharacterState::Wielded(_) => true,
_ => false,
})

View File

@ -457,15 +457,16 @@ impl FigureMgr {
skeleton_attr,
)
},
/*CharacterState::Block(_) => {
CharacterState::BasicBlock(_) => {
anim::character::BlockIdleAnimation::update_skeleton(
&target_base,
&CharacterSkeleton::new(),
(active_tool_kind, time),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
}
},
/*
CharacterState::Charge(_) => {
anim::character::ChargeAnimation::update_skeleton(
&target_base,

View File

@ -220,20 +220,8 @@ impl PlayState for SessionState {
if let Some(select_pos) = select_pos {
client.remove_block(select_pos);
}
} else if client
.state()
.read_storage::<comp::CharacterState>()
.get(client.entity())
.map(|cs| match cs {
/*ActionState::Attack(_) // TODO: uncomment
| ActionState::Block(_)
| ActionState::Wield(_) => true,*/
_ => false,
})
.unwrap_or(false)
{
self.inputs.secondary.set_state(state);
} else {
self.inputs.secondary.set_state(state);
if let Some(select_pos) = select_pos {
client.collect_block(select_pos);
}