mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'timo-no-ckback' into 'master'
no-ckback See merge request veloren/veloren!391
This commit is contained in:
commit
66a8ed58db
@ -1,4 +1,4 @@
|
|||||||
use crate::comp::{Agent, Controller, Pos};
|
use crate::comp::{Agent, Controller, Pos, Stats};
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
use specs::{Entities, Join, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, ReadStorage, System, WriteStorage};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -8,14 +8,15 @@ pub struct Sys;
|
|||||||
impl<'a> System<'a> for Sys {
|
impl<'a> System<'a> for Sys {
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
WriteStorage<'a, Agent>,
|
|
||||||
ReadStorage<'a, Pos>,
|
ReadStorage<'a, Pos>,
|
||||||
|
ReadStorage<'a, Stats>,
|
||||||
|
WriteStorage<'a, Agent>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, (entities, mut agents, positions, mut controllers): Self::SystemData) {
|
fn run(&mut self, (entities, positions, stats, mut agents, mut controllers): Self::SystemData) {
|
||||||
for (entity, agent, pos, controller) in
|
for (entity, pos, agent, controller) in
|
||||||
(&entities, &mut agents, &positions, &mut controllers).join()
|
(&entities, &positions, &mut agents, &mut controllers).join()
|
||||||
{
|
{
|
||||||
match agent {
|
match agent {
|
||||||
Agent::Wanderer(bearing) => {
|
Agent::Wanderer(bearing) => {
|
||||||
@ -60,52 +61,58 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
Agent::Enemy { bearing, target } => {
|
Agent::Enemy { bearing, target } => {
|
||||||
const SIGHT_DIST: f32 = 30.0;
|
const SIGHT_DIST: f32 = 30.0;
|
||||||
|
let mut choose_new = false;
|
||||||
|
|
||||||
let choose_new = match target.map(|tgt| positions.get(tgt)).flatten() {
|
if let Some((Some(target_pos), Some(target_stats))) =
|
||||||
Some(tgt_pos) => {
|
target.map(|target| (positions.get(target), stats.get(target)))
|
||||||
let dist = Vec2::<f32>::from(tgt_pos.0 - pos.0).magnitude();
|
{
|
||||||
if dist < 2.0 {
|
let dist = Vec2::<f32>::from(target_pos.0 - pos.0).magnitude();
|
||||||
controller.move_dir = Vec2::zero();
|
if target_stats.is_dead {
|
||||||
|
choose_new = true;
|
||||||
|
} else if dist < 1.5 {
|
||||||
|
// Get more distance
|
||||||
|
controller.move_dir =
|
||||||
|
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * -0.96;
|
||||||
|
} else if dist < 4.0 {
|
||||||
|
// Fight and slowly move closer
|
||||||
|
controller.move_dir =
|
||||||
|
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.1;
|
||||||
|
|
||||||
if rand::random::<f32>() < 0.05 {
|
if rand::random::<f32>() < 0.1 {
|
||||||
controller.attack = true;
|
controller.attack = true;
|
||||||
} else {
|
|
||||||
controller.attack = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
} else if dist < SIGHT_DIST {
|
|
||||||
controller.move_dir =
|
|
||||||
Vec2::<f32>::from(tgt_pos.0 - pos.0).normalized();
|
|
||||||
|
|
||||||
false
|
|
||||||
} else {
|
} else {
|
||||||
true
|
controller.attack = false;
|
||||||
}
|
}
|
||||||
|
} else if dist < SIGHT_DIST {
|
||||||
|
controller.move_dir =
|
||||||
|
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.96;
|
||||||
|
} else {
|
||||||
|
choose_new = true;
|
||||||
}
|
}
|
||||||
None => {
|
} else {
|
||||||
*bearing +=
|
*bearing +=
|
||||||
Vec2::new(rand::random::<f32>() - 0.5, rand::random::<f32>() - 0.5)
|
Vec2::new(rand::random::<f32>() - 0.5, rand::random::<f32>() - 0.5)
|
||||||
* 0.1
|
* 0.1
|
||||||
- *bearing * 0.005;
|
- *bearing * 0.005;
|
||||||
|
|
||||||
controller.move_dir = if bearing.magnitude_squared() > 0.1 {
|
controller.move_dir = if bearing.magnitude_squared() > 0.1 {
|
||||||
bearing.normalized()
|
bearing.normalized()
|
||||||
} else {
|
} else {
|
||||||
Vec2::zero()
|
Vec2::zero()
|
||||||
};
|
};
|
||||||
true
|
|
||||||
}
|
choose_new = true;
|
||||||
};
|
}
|
||||||
|
|
||||||
if choose_new && rand::random::<f32>() < 0.1 {
|
if choose_new && rand::random::<f32>() < 0.1 {
|
||||||
let entities = (&entities, &positions)
|
let entities = (&entities, &positions, &stats)
|
||||||
.join()
|
.join()
|
||||||
.filter(|(e, e_pos)| {
|
.filter(|(e, e_pos, e_stats)| {
|
||||||
Vec2::<f32>::from(e_pos.0 - pos.0).magnitude() < SIGHT_DIST
|
Vec2::<f32>::from(e_pos.0 - pos.0).magnitude() < SIGHT_DIST
|
||||||
&& *e != entity
|
&& *e != entity
|
||||||
|
&& !e_stats.is_dead
|
||||||
})
|
})
|
||||||
.map(|(e, _)| e)
|
.map(|(e, _, _)| e)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -48,14 +48,13 @@ impl<'a> System<'a> for Sys {
|
|||||||
if entity != b
|
if entity != b
|
||||||
&& !stat_b.is_dead
|
&& !stat_b.is_dead
|
||||||
&& pos.0.distance_squared(pos_b.0) < 50.0
|
&& pos.0.distance_squared(pos_b.0) < 50.0
|
||||||
&& ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0
|
&& ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 90.0
|
||||||
{
|
{
|
||||||
// Deal damage
|
// Deal damage
|
||||||
stat_b
|
stat_b
|
||||||
.health
|
.health
|
||||||
.change_by(-10, HealthSource::Attack { by: *uid }); // TODO: variable damage and weapon
|
.change_by(-10, HealthSource::Attack { by: *uid }); // TODO: variable damage and weapon
|
||||||
vel_b.0 += (pos_b.0 - pos.0).normalized() * 10.0;
|
vel_b.0.z = 4.0;
|
||||||
vel_b.0.z = 15.0;
|
|
||||||
let _ = force_updates.insert(b, ForceUpdate);
|
let _ = force_updates.insert(b, ForceUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set direction based on velocity when on the ground
|
// Set direction based on velocity when on the ground
|
||||||
if Vec2::<f32>::from(vel.0).magnitude_squared() > 0.1 {
|
if Vec2::<f32>::from(vel.0).magnitude_squared() > 0.0001 {
|
||||||
ori.0 = Lerp::lerp(
|
ori.0 = Lerp::lerp(
|
||||||
ori.0,
|
ori.0,
|
||||||
vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0),
|
vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0),
|
||||||
|
@ -767,24 +767,30 @@ impl FigureMgr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let target_skeleton = match animation_info.animation {
|
let target_skeleton = match animation_info.animation {
|
||||||
comp::Animation::Run => anim::quadruped::RunAnimation::update_skeleton(
|
comp::Animation::Run | comp::Animation::Crun => {
|
||||||
state.skeleton_mut(),
|
anim::quadruped::RunAnimation::update_skeleton(
|
||||||
(vel.0.magnitude(), time),
|
state.skeleton_mut(),
|
||||||
animation_info.time,
|
(vel.0.magnitude(), time),
|
||||||
skeleton_attr,
|
animation_info.time,
|
||||||
),
|
skeleton_attr,
|
||||||
comp::Animation::Idle => anim::quadruped::IdleAnimation::update_skeleton(
|
)
|
||||||
state.skeleton_mut(),
|
}
|
||||||
time,
|
comp::Animation::Idle | comp::Animation::Cidle => {
|
||||||
animation_info.time,
|
anim::quadruped::IdleAnimation::update_skeleton(
|
||||||
skeleton_attr,
|
state.skeleton_mut(),
|
||||||
),
|
time,
|
||||||
comp::Animation::Jump => anim::quadruped::JumpAnimation::update_skeleton(
|
animation_info.time,
|
||||||
state.skeleton_mut(),
|
skeleton_attr,
|
||||||
(vel.0.magnitude(), time),
|
)
|
||||||
animation_info.time,
|
}
|
||||||
skeleton_attr,
|
comp::Animation::Jump | comp::Animation::Cjump => {
|
||||||
),
|
anim::quadruped::JumpAnimation::update_skeleton(
|
||||||
|
state.skeleton_mut(),
|
||||||
|
(vel.0.magnitude(), time),
|
||||||
|
animation_info.time,
|
||||||
|
skeleton_attr,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO!
|
// TODO!
|
||||||
_ => state.skeleton_mut().clone(),
|
_ => state.skeleton_mut().clone(),
|
||||||
@ -807,7 +813,7 @@ impl FigureMgr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let target_skeleton = match animation_info.animation {
|
let target_skeleton = match animation_info.animation {
|
||||||
comp::Animation::Run => {
|
comp::Animation::Run | comp::Animation::Crun => {
|
||||||
anim::quadrupedmedium::RunAnimation::update_skeleton(
|
anim::quadrupedmedium::RunAnimation::update_skeleton(
|
||||||
state.skeleton_mut(),
|
state.skeleton_mut(),
|
||||||
(vel.0.magnitude(), time),
|
(vel.0.magnitude(), time),
|
||||||
@ -815,7 +821,7 @@ impl FigureMgr {
|
|||||||
skeleton_attr,
|
skeleton_attr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
comp::Animation::Idle => {
|
comp::Animation::Idle | comp::Animation::Cidle => {
|
||||||
anim::quadrupedmedium::IdleAnimation::update_skeleton(
|
anim::quadrupedmedium::IdleAnimation::update_skeleton(
|
||||||
state.skeleton_mut(),
|
state.skeleton_mut(),
|
||||||
time,
|
time,
|
||||||
@ -823,7 +829,7 @@ impl FigureMgr {
|
|||||||
skeleton_attr,
|
skeleton_attr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
comp::Animation::Jump => {
|
comp::Animation::Jump | comp::Animation::Cjump => {
|
||||||
anim::quadrupedmedium::JumpAnimation::update_skeleton(
|
anim::quadrupedmedium::JumpAnimation::update_skeleton(
|
||||||
state.skeleton_mut(),
|
state.skeleton_mut(),
|
||||||
(vel.0.magnitude(), time),
|
(vel.0.magnitude(), time),
|
||||||
|
Loading…
Reference in New Issue
Block a user