Merge branch 'slipped/wielding' into 'master'

Holding weapon while running/jumping/standing

See merge request veloren/veloren!312
This commit is contained in:
Joshua Barretto 2019-07-06 19:00:05 +00:00
commit 064832fe87
4 changed files with 39 additions and 9 deletions

View File

@ -8,13 +8,13 @@ pub struct Respawning;
pub struct MoveDir(pub Vec2<f32>);
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Attacking {
pub struct Wielding {
pub time: f32,
pub applied: bool,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Wielding {
pub struct Attacking {
pub time: f32,
pub applied: bool,
}
@ -41,7 +41,7 @@ impl Component for Respawning {
type Storage = NullStorage<Self>;
}
impl Attacking {
impl Wielding {
pub fn start() -> Self {
Self {
time: 0.0,
@ -50,7 +50,7 @@ impl Attacking {
}
}
impl Wielding {
impl Attacking {
pub fn start() -> Self {
Self {
time: 0.0,
@ -72,11 +72,11 @@ impl Component for MoveDir {
type Storage = VecStorage<Self>;
}
impl Component for Attacking {
impl Component for Wielding {
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
}
impl Component for Wielding {
impl Component for Attacking {
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
}

View File

@ -1,5 +1,5 @@
use crate::{
comp::{Attacking, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel},
comp::{Attacking, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel, Wielding},
state::{DeltaTime, Uid},
};
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
@ -15,6 +15,7 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, Ori>,
WriteStorage<'a, Vel>,
WriteStorage<'a, Attacking>,
WriteStorage<'a, Wielding>,
WriteStorage<'a, Stats>,
WriteStorage<'a, ForceUpdate>,
);
@ -29,6 +30,7 @@ impl<'a> System<'a> for Sys {
orientations,
mut velocities,
mut attackings,
mut wieldings,
mut stats,
mut force_updates,
): Self::SystemData,
@ -73,5 +75,15 @@ impl<'a> System<'a> for Sys {
.for_each(|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;
}
}
}
}
}

View File

@ -1,5 +1,6 @@
use crate::comp::{
ActionState, Attacking, Controller, Gliding, Jumping, MoveDir, Respawning, Rolling, Stats, Vel,
Wielding,
};
use specs::{Entities, Join, ReadStorage, System, WriteStorage};
@ -15,6 +16,7 @@ impl<'a> System<'a> for Sys {
WriteStorage<'a, MoveDir>,
WriteStorage<'a, Jumping>,
WriteStorage<'a, Attacking>,
WriteStorage<'a, Wielding>,
WriteStorage<'a, Rolling>,
WriteStorage<'a, Respawning>,
WriteStorage<'a, Gliding>,
@ -31,6 +33,7 @@ impl<'a> System<'a> for Sys {
mut move_dirs,
mut jumpings,
mut attackings,
mut wieldings,
mut rollings,
mut respawns,
mut glidings,
@ -76,8 +79,19 @@ impl<'a> System<'a> for Sys {
a.gliding = false;
}
// Wield
if controller.attack && !a.wielding && !a.gliding && !a.rolling {
let _ = wieldings.insert(entity, Wielding::start());
a.wielding = true;
}
// 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());
a.attacking = true;
}

View File

@ -1,5 +1,5 @@
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,
terrain::TerrainMap,
vol::{ReadVol, Vox},
@ -48,6 +48,7 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, Stats>,
ReadStorage<'a, ActionState>,
WriteStorage<'a, Jumping>,
WriteStorage<'a, Wielding>,
WriteStorage<'a, Rolling>,
WriteStorage<'a, OnGround>,
WriteStorage<'a, Pos>,
@ -65,6 +66,7 @@ impl<'a> System<'a> for Sys {
stats,
action_states,
mut jumpings,
mut wieldings,
mut rollings,
mut on_grounds,
mut positions,
@ -125,12 +127,14 @@ impl<'a> System<'a> for Sys {
// Glide
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;
vel.0.z += dt.0 * lift * Vec2::<f32>::from(vel.0 * 0.15).magnitude().min(1.0);
}
// Roll
if let Some(time) = rollings.get_mut(entity).map(|r| &mut r.time) {
let _ = wieldings.remove(entity);
*time += dt.0;
if *time > 0.55 || !a.moving {
rollings.remove(entity);