mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Finish Stand handle() (untested)
This commit is contained in:
parent
e074c7ce1d
commit
e40eb2ba20
@ -1,4 +1,6 @@
|
|||||||
use crate::comp::{Body, CharacterState, Controller, ControllerInputs, PhysicsState};
|
use crate::comp::{
|
||||||
|
Body, CharacterState, Controller, ControllerInputs, ItemKind, PhysicsState, Stats,
|
||||||
|
};
|
||||||
use specs::{Component, FlaggedStorage, HashMapStorage};
|
use specs::{Component, FlaggedStorage, HashMapStorage};
|
||||||
use specs::{Entities, Join, LazyUpdate, Read, ReadStorage, System};
|
use specs::{Entities, Join, LazyUpdate, Read, ReadStorage, System};
|
||||||
use sphynx::{Uid, UidAllocator};
|
use sphynx::{Uid, UidAllocator};
|
||||||
@ -10,6 +12,7 @@ pub trait State {
|
|||||||
&self,
|
&self,
|
||||||
character: &CharacterState,
|
character: &CharacterState,
|
||||||
inputs: &ControllerInputs,
|
inputs: &ControllerInputs,
|
||||||
|
stats: &Stats,
|
||||||
body: &Body,
|
body: &Body,
|
||||||
physics: &PhysicsState,
|
physics: &PhysicsState,
|
||||||
) -> CharacterState;
|
) -> CharacterState;
|
||||||
@ -25,6 +28,7 @@ impl State for StandData {
|
|||||||
&self,
|
&self,
|
||||||
character: &CharacterState,
|
character: &CharacterState,
|
||||||
inputs: &ControllerInputs,
|
inputs: &ControllerInputs,
|
||||||
|
stats: &Stats,
|
||||||
body: &Body,
|
body: &Body,
|
||||||
physics: &PhysicsState,
|
physics: &PhysicsState,
|
||||||
) -> CharacterState {
|
) -> CharacterState {
|
||||||
@ -100,26 +104,45 @@ impl State for StandData {
|
|||||||
&& !inputs.glide.is_held_down()
|
&& !inputs.glide.is_held_down()
|
||||||
&& body.is_humanoid()
|
&& body.is_humanoid()
|
||||||
{
|
{
|
||||||
character.movement = Glide;
|
return CharacterState {
|
||||||
continue;
|
action: Idle,
|
||||||
|
movement: Glide,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
character.movement = Fall;
|
return CharacterState {
|
||||||
|
action: character.action,
|
||||||
|
movement: Fall,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tool Actions
|
// Tool Actions
|
||||||
if inputs.toggle_wield.is_just_pressed() {
|
if inputs.toggle_wield.is_just_pressed() {
|
||||||
match action_state {
|
match character.action {
|
||||||
Wield { .. } | Attack { .. } => {
|
Wield { .. } | Attack { .. } => {
|
||||||
// Prevent instantaneous reequipping by checking
|
// Prevent instantaneous reequipping by checking
|
||||||
// for done wielding
|
// for done wielding
|
||||||
if character.action.is_action_finished() {
|
if character.action.is_action_finished() {
|
||||||
character.action = Idle;
|
return CharacterState {
|
||||||
|
action: Idle,
|
||||||
|
movement: character.movement,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Idle => {
|
Idle => {
|
||||||
character.action = try_wield(stats);
|
return CharacterState {
|
||||||
continue;
|
// Try to wield if an item is equipped in main hand
|
||||||
|
action: if let Some(ItemKind::Tool { kind, .. }) =
|
||||||
|
stats.equipment.main.as_ref().map(|i| &i.kind)
|
||||||
|
{
|
||||||
|
let wield_duration = kind.wield_duration();
|
||||||
|
Wield {
|
||||||
|
time_left: wield_duration,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Idle
|
||||||
|
},
|
||||||
|
movement: character.movement,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Charge { .. } | Roll { .. } | Block { .. } => {}
|
Charge { .. } | Roll { .. } | Block { .. } => {}
|
||||||
}
|
}
|
||||||
@ -129,14 +152,27 @@ impl State for StandData {
|
|||||||
} else if inputs.secondary.is_pressed() {
|
} else if inputs.secondary.is_pressed() {
|
||||||
// TODO: SecondaryStart
|
// TODO: SecondaryStart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if inputs.move_dir.magnitude_squared() > 0.0 {
|
||||||
|
return CharacterState {
|
||||||
|
action: character.action,
|
||||||
|
movement: Run(RunData),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return CharacterState {
|
||||||
|
action: character.action,
|
||||||
|
movement: Stand(StandData),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return character;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||||||
pub enum MovementState {
|
pub enum MovementState {
|
||||||
Stand(Stand),
|
Stand(StandData),
|
||||||
Sit,
|
Sit,
|
||||||
Run(Run),
|
Run(RunData),
|
||||||
Jump,
|
Jump,
|
||||||
Fall,
|
Fall,
|
||||||
Glide,
|
Glide,
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
use super::movement::ROLL_DURATION;
|
use super::movement::ROLL_DURATION;
|
||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
self, item, projectile, ActionState, ActionState::*, Body, CharacterState, ControlEvent,
|
self, item, projectile, ActionState,
|
||||||
Controller, ControllerInputs, HealthChange, HealthSource, ItemKind, Mounting,
|
ActionState::*,
|
||||||
MovementState, MovementState::*, PhysicsState, Projectile, Stats, Vel,
|
Body, CharacterState,
|
||||||
|
CharacterState::{RunData, StandData},
|
||||||
|
ControlEvent, Controller, ControllerInputs, HealthChange, HealthSource, ItemKind, Mounting,
|
||||||
|
MovementState,
|
||||||
|
MovementState::*,
|
||||||
|
PhysicsState, Projectile, Stats, Vel,
|
||||||
},
|
},
|
||||||
event::{Emitter, EventBus, LocalEvent, ServerEvent},
|
event::{Emitter, EventBus, LocalEvent, ServerEvent},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
@ -88,9 +93,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
let get_state_from_move_dir = |move_dir: &Vec2<f32>| -> MovementState {
|
let get_state_from_move_dir = |move_dir: &Vec2<f32>| -> MovementState {
|
||||||
if move_dir.magnitude_squared() > 0.0 {
|
if move_dir.magnitude_squared() > 0.0 {
|
||||||
Run(_)
|
Run(RunData)
|
||||||
} else {
|
} else {
|
||||||
Stand(_)
|
Stand(StandData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -204,7 +209,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
character.movement = Fall;
|
character.movement = Fall;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
character.movement = Stand(comp::character_state::Stand);
|
character.movement = Stand(StandData);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +359,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
// character.movement will be Stand after updating when
|
// character.movement will be Stand after updating when
|
||||||
// no movement has occurred
|
// no movement has occurred
|
||||||
if character.movement == Stand(_) {
|
if character.movement == Stand(StandData) {
|
||||||
character.movement = Sit;
|
character.movement = Sit;
|
||||||
}
|
}
|
||||||
if inputs.jump.is_pressed() && !inputs.jump.is_held_down() {
|
if inputs.jump.is_pressed() && !inputs.jump.is_held_down() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user