Merge branch 'timo-attack-delay' into 'master'

Timo attack delay

See merge request veloren/veloren!463
This commit is contained in:
Timo Koesters 2019-08-27 12:01:45 +00:00
commit 838eab8637
5 changed files with 76 additions and 35 deletions

View File

@ -80,8 +80,7 @@ pub enum ConsumptionEffect {
pub enum Item {
Tool {
kind: Tool,
damage: i32,
strength: i32,
power: u32,
},
Armor {
kind: Armor,
@ -122,8 +121,7 @@ impl Default for Item {
fn default() -> Self {
Item::Tool {
kind: Tool::Hammer,
damage: 0,
strength: 0,
power: 0,
}
}
}

View File

@ -2,7 +2,7 @@
pub mod item;
// Reexports
pub use self::item::Item;
pub use self::item::{Item, Tool};
use specs::{Component, HashMapStorage, NullStorage};
use specs_idvs::IDVStorage;
@ -56,15 +56,35 @@ impl Inventory {
impl Default for Inventory {
fn default() -> Inventory {
let mut this = Inventory {
let mut inventory = Inventory {
slots: vec![None; 24],
};
for _ in 0..18 {
this.insert(Item::default());
inventory.insert(Item::Tool {
kind: Tool::Daggers,
power: 10,
});
inventory.insert(Item::Tool {
kind: Tool::Sword,
power: 10,
});
inventory.insert(Item::Tool {
kind: Tool::Axe,
power: 10,
});
inventory.insert(Item::Tool {
kind: Tool::Hammer,
power: 10,
});
inventory.insert(Item::Tool {
kind: Tool::Bow,
power: 10,
});
for _ in 0..10 {
inventory.insert(Item::default());
}
this
inventory
}
}

View File

@ -8,6 +8,12 @@ use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
use std::time::Duration;
use vek::*;
pub const WIELD_DURATION: Duration = Duration::from_millis(300);
pub const ATTACK_DURATION: Duration = Duration::from_millis(500);
// Delay before hit
const PREPARE_DURATION: Duration = Duration::from_millis(100);
const BASE_DMG: i32 = 10;
const BLOCK_EFFICIENCY: f32 = 0.9;
@ -49,14 +55,32 @@ impl<'a> System<'a> for Sys {
): Self::SystemData,
) {
// Attacks
for (entity, uid, pos, ori, controller) in
for (entity, uid, pos, ori, _) in
(&entities, &uids, &positions, &orientations, &controllers).join()
{
// Go through all other entities
if let Some(Attack { time_left, applied }) =
&mut character_states.get(entity).map(|c| c.action)
let (deal_damage, should_end) = if let Some(Attack { time_left, applied }) =
&mut character_states.get_mut(entity).map(|c| &mut c.action)
{
if !*applied {
*time_left = time_left
.checked_sub(Duration::from_secs_f32(dt.0))
.unwrap_or_default();
if !*applied && ATTACK_DURATION - *time_left > PREPARE_DURATION {
*applied = true;
(true, false)
} else if *time_left == Duration::default() {
(false, true)
} else {
(false, false)
}
} else {
(false, false)
};
if deal_damage {
if let Some(Attack { time_left, applied }) =
&character_states.get(entity).map(|c| c.action)
{
// Go through all other entities
for (b, pos_b, ori_b, character_b, mut vel_b, stat_b) in (
&entities,
&positions,
@ -98,24 +122,13 @@ impl<'a> System<'a> for Sys {
}
}
}
}
if let Some(Attack { time_left, applied }) =
&mut character_states.get_mut(entity).map(|c| &mut c.action)
{
// Only attack once
*applied = true;
if *time_left == Duration::default() {
if let Some(character) = &mut character_states.get_mut(entity) {
character.action = Wield {
time_left: Duration::default(),
};
}
} else {
*time_left = time_left
.checked_sub(Duration::from_secs_f32(dt.0))
.unwrap_or_default();
}
if should_end {
if let Some(character) = &mut character_states.get_mut(entity) {
character.action = Wield {
time_left: Duration::default(),
};
}
}

View File

@ -1,3 +1,7 @@
use super::{
combat::{ATTACK_DURATION, WIELD_DURATION},
movement::ROLL_DURATION,
};
use crate::{
comp::{
ActionState::*, Body, CharacterState, Controller, MovementState::*, PhysicsState, Stats,
@ -97,7 +101,7 @@ impl<'a> System<'a> for Sys {
&& (character.movement == Stand || character.movement == Run)
{
character.action = Wield {
time_left: Duration::from_millis(300),
time_left: WIELD_DURATION,
};
}
@ -111,7 +115,7 @@ impl<'a> System<'a> for Sys {
if let Wield { time_left } = character.action {
if time_left == Duration::default() {
character.action = Attack {
time_left: Duration::from_millis(300),
time_left: ATTACK_DURATION,
applied: false,
};
}
@ -137,7 +141,7 @@ impl<'a> System<'a> for Sys {
&& physics.on_ground
{
character.movement = Roll {
time_left: Duration::from_millis(600),
time_left: ROLL_DURATION,
};
}

View File

@ -11,6 +11,8 @@ use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage}
use std::time::Duration;
use vek::*;
pub const ROLL_DURATION: Duration = Duration::from_millis(600);
const HUMANOID_ACCEL: f32 = 70.0;
const HUMANOID_SPEED: f32 = 120.0;
const WIELD_ACCEL: f32 = 70.0;
@ -147,7 +149,11 @@ impl<'a> System<'a> for Sys {
character.movement = Stand;
}
if !physics.on_ground && (character.movement == Stand || character.movement == Run) {
if !physics.on_ground
&& (character.movement == Stand
|| character.movement.is_roll()
|| character.movement == Run)
{
character.movement = Jump;
}
}