mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'slipped/wielding' into 'master'
Holding weapon while running/jumping/standing See merge request veloren/veloren!312
This commit is contained in:
commit
064832fe87
@ -8,13 +8,13 @@ pub struct Respawning;
|
|||||||
pub struct MoveDir(pub Vec2<f32>);
|
pub struct MoveDir(pub Vec2<f32>);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Attacking {
|
pub struct Wielding {
|
||||||
pub time: f32,
|
pub time: f32,
|
||||||
pub applied: bool,
|
pub applied: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Wielding {
|
pub struct Attacking {
|
||||||
pub time: f32,
|
pub time: f32,
|
||||||
pub applied: bool,
|
pub applied: bool,
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ impl Component for Respawning {
|
|||||||
type Storage = NullStorage<Self>;
|
type Storage = NullStorage<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Attacking {
|
impl Wielding {
|
||||||
pub fn start() -> Self {
|
pub fn start() -> Self {
|
||||||
Self {
|
Self {
|
||||||
time: 0.0,
|
time: 0.0,
|
||||||
@ -50,7 +50,7 @@ impl Attacking {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wielding {
|
impl Attacking {
|
||||||
pub fn start() -> Self {
|
pub fn start() -> Self {
|
||||||
Self {
|
Self {
|
||||||
time: 0.0,
|
time: 0.0,
|
||||||
@ -72,11 +72,11 @@ impl Component for MoveDir {
|
|||||||
type Storage = VecStorage<Self>;
|
type Storage = VecStorage<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for Attacking {
|
impl Component for Wielding {
|
||||||
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for Wielding {
|
impl Component for Attacking {
|
||||||
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{Attacking, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel},
|
comp::{Attacking, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel, Wielding},
|
||||||
state::{DeltaTime, Uid},
|
state::{DeltaTime, Uid},
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
||||||
@ -15,6 +15,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadStorage<'a, Ori>,
|
ReadStorage<'a, Ori>,
|
||||||
WriteStorage<'a, Vel>,
|
WriteStorage<'a, Vel>,
|
||||||
WriteStorage<'a, Attacking>,
|
WriteStorage<'a, Attacking>,
|
||||||
|
WriteStorage<'a, Wielding>,
|
||||||
WriteStorage<'a, Stats>,
|
WriteStorage<'a, Stats>,
|
||||||
WriteStorage<'a, ForceUpdate>,
|
WriteStorage<'a, ForceUpdate>,
|
||||||
);
|
);
|
||||||
@ -29,6 +30,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
orientations,
|
orientations,
|
||||||
mut velocities,
|
mut velocities,
|
||||||
mut attackings,
|
mut attackings,
|
||||||
|
mut wieldings,
|
||||||
mut stats,
|
mut stats,
|
||||||
mut force_updates,
|
mut force_updates,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
@ -73,5 +75,15 @@ impl<'a> System<'a> for Sys {
|
|||||||
.for_each(|e| {
|
.for_each(|e| {
|
||||||
attackings.remove(e);
|
attackings.remove(e);
|
||||||
});
|
});
|
||||||
|
{
|
||||||
|
// Wields
|
||||||
|
for wielding in (&mut wieldings).join() {
|
||||||
|
if !wielding.applied && wielding.time > 0.3 {
|
||||||
|
wielding.applied = true;
|
||||||
|
} else {
|
||||||
|
wielding.time += dt.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::comp::{
|
use crate::comp::{
|
||||||
ActionState, Attacking, Controller, Gliding, Jumping, MoveDir, Respawning, Rolling, Stats, Vel,
|
ActionState, Attacking, Controller, Gliding, Jumping, MoveDir, Respawning, Rolling, Stats, Vel,
|
||||||
|
Wielding,
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, ReadStorage, System, WriteStorage};
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
WriteStorage<'a, MoveDir>,
|
WriteStorage<'a, MoveDir>,
|
||||||
WriteStorage<'a, Jumping>,
|
WriteStorage<'a, Jumping>,
|
||||||
WriteStorage<'a, Attacking>,
|
WriteStorage<'a, Attacking>,
|
||||||
|
WriteStorage<'a, Wielding>,
|
||||||
WriteStorage<'a, Rolling>,
|
WriteStorage<'a, Rolling>,
|
||||||
WriteStorage<'a, Respawning>,
|
WriteStorage<'a, Respawning>,
|
||||||
WriteStorage<'a, Gliding>,
|
WriteStorage<'a, Gliding>,
|
||||||
@ -31,6 +33,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut move_dirs,
|
mut move_dirs,
|
||||||
mut jumpings,
|
mut jumpings,
|
||||||
mut attackings,
|
mut attackings,
|
||||||
|
mut wieldings,
|
||||||
mut rollings,
|
mut rollings,
|
||||||
mut respawns,
|
mut respawns,
|
||||||
mut glidings,
|
mut glidings,
|
||||||
@ -76,8 +79,19 @@ impl<'a> System<'a> for Sys {
|
|||||||
a.gliding = false;
|
a.gliding = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wield
|
||||||
|
if controller.attack && !a.wielding && !a.gliding && !a.rolling {
|
||||||
|
let _ = wieldings.insert(entity, Wielding::start());
|
||||||
|
a.wielding = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Attack
|
// Attack
|
||||||
if controller.attack && !a.attacking && !a.gliding && !a.rolling {
|
if controller.attack
|
||||||
|
&& !a.attacking
|
||||||
|
&& wieldings.get(entity).map(|w| w.applied).unwrap_or(false)
|
||||||
|
&& !a.gliding
|
||||||
|
&& !a.rolling
|
||||||
|
{
|
||||||
let _ = attackings.insert(entity, Attacking::start());
|
let _ = attackings.insert(entity, Attacking::start());
|
||||||
a.attacking = true;
|
a.attacking = true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{ActionState, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Stats, Vel},
|
comp::{ActionState, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Stats, Vel, Wielding},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
terrain::TerrainMap,
|
terrain::TerrainMap,
|
||||||
vol::{ReadVol, Vox},
|
vol::{ReadVol, Vox},
|
||||||
@ -48,6 +48,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadStorage<'a, Stats>,
|
ReadStorage<'a, Stats>,
|
||||||
ReadStorage<'a, ActionState>,
|
ReadStorage<'a, ActionState>,
|
||||||
WriteStorage<'a, Jumping>,
|
WriteStorage<'a, Jumping>,
|
||||||
|
WriteStorage<'a, Wielding>,
|
||||||
WriteStorage<'a, Rolling>,
|
WriteStorage<'a, Rolling>,
|
||||||
WriteStorage<'a, OnGround>,
|
WriteStorage<'a, OnGround>,
|
||||||
WriteStorage<'a, Pos>,
|
WriteStorage<'a, Pos>,
|
||||||
@ -65,6 +66,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
stats,
|
stats,
|
||||||
action_states,
|
action_states,
|
||||||
mut jumpings,
|
mut jumpings,
|
||||||
|
mut wieldings,
|
||||||
mut rollings,
|
mut rollings,
|
||||||
mut on_grounds,
|
mut on_grounds,
|
||||||
mut positions,
|
mut positions,
|
||||||
@ -125,12 +127,14 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
// Glide
|
// Glide
|
||||||
if a.gliding && vel.0.magnitude_squared() < GLIDE_SPEED.powf(2.0) && vel.0.z < 0.0 {
|
if a.gliding && vel.0.magnitude_squared() < GLIDE_SPEED.powf(2.0) && vel.0.z < 0.0 {
|
||||||
|
let _ = wieldings.remove(entity);
|
||||||
let lift = GLIDE_ANTIGRAV + vel.0.z.powf(2.0) * 0.2;
|
let lift = GLIDE_ANTIGRAV + vel.0.z.powf(2.0) * 0.2;
|
||||||
vel.0.z += dt.0 * lift * Vec2::<f32>::from(vel.0 * 0.15).magnitude().min(1.0);
|
vel.0.z += dt.0 * lift * Vec2::<f32>::from(vel.0 * 0.15).magnitude().min(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roll
|
// Roll
|
||||||
if let Some(time) = rollings.get_mut(entity).map(|r| &mut r.time) {
|
if let Some(time) = rollings.get_mut(entity).map(|r| &mut r.time) {
|
||||||
|
let _ = wieldings.remove(entity);
|
||||||
*time += dt.0;
|
*time += dt.0;
|
||||||
if *time > 0.55 || !a.moving {
|
if *time > 0.55 || !a.moving {
|
||||||
rollings.remove(entity);
|
rollings.remove(entity);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user