mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
feat(bow): sticky arrows
This commit is contained in:
parent
575f7da64d
commit
fc97c27b65
@ -5,6 +5,7 @@ use specs_idvs::IDVStorage;
|
|||||||
pub enum Effect {
|
pub enum Effect {
|
||||||
Damage(u32),
|
Damage(u32),
|
||||||
Vanish,
|
Vanish,
|
||||||
|
Stick,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
@ -36,7 +36,11 @@ pub enum ServerEvent {
|
|||||||
cause: comp::HealthSource,
|
cause: comp::HealthSource,
|
||||||
},
|
},
|
||||||
Respawn(EcsEntity),
|
Respawn(EcsEntity),
|
||||||
Shoot(EcsEntity, Vec3<f32>),
|
Shoot {
|
||||||
|
entity: EcsEntity,
|
||||||
|
dir: Vec3<f32>,
|
||||||
|
projectile: comp::Projectile,
|
||||||
|
},
|
||||||
Mount(EcsEntity, EcsEntity),
|
Mount(EcsEntity, EcsEntity),
|
||||||
Unmount(EcsEntity),
|
Unmount(EcsEntity),
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
item, ActionState::*, Body, CharacterState, ControlEvent, Controller, Item,
|
item, projectile, ActionState::*, Body, CharacterState, ControlEvent, Controller, Item,
|
||||||
MovementState::*, PhysicsState, Stats, Vel,
|
MovementState::*, PhysicsState, Projectile, Stats, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
};
|
};
|
||||||
@ -140,8 +140,17 @@ impl<'a> System<'a> for Sys {
|
|||||||
if time_left == Duration::default() {
|
if time_left == Duration::default() {
|
||||||
// Immediately end the wield
|
// Immediately end the wield
|
||||||
character.action = Idle;
|
character.action = Idle;
|
||||||
server_emitter
|
server_emitter.emit(ServerEvent::Shoot {
|
||||||
.emit(ServerEvent::Shoot(entity, controller.look_dir));
|
entity,
|
||||||
|
dir: controller.look_dir,
|
||||||
|
projectile: Projectile {
|
||||||
|
hit_ground: vec![projectile::Effect::Stick],
|
||||||
|
hit_entity: vec![
|
||||||
|
projectile::Effect::Damage(10),
|
||||||
|
projectile::Effect::Vanish,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
type SystemData = (
|
type SystemData = (
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
ReadStorage<'a, Vel>,
|
|
||||||
ReadStorage<'a, PhysicsState>,
|
ReadStorage<'a, PhysicsState>,
|
||||||
|
WriteStorage<'a, Vel>,
|
||||||
WriteStorage<'a, Ori>,
|
WriteStorage<'a, Ori>,
|
||||||
WriteStorage<'a, Projectile>,
|
WriteStorage<'a, Projectile>,
|
||||||
);
|
);
|
||||||
@ -21,8 +21,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
(
|
(
|
||||||
entities,
|
entities,
|
||||||
server_bus,
|
server_bus,
|
||||||
velocities,
|
|
||||||
physics_states,
|
physics_states,
|
||||||
|
mut velocities,
|
||||||
mut orientations,
|
mut orientations,
|
||||||
mut projectiles,
|
mut projectiles,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
@ -30,25 +30,25 @@ impl<'a> System<'a> for Sys {
|
|||||||
let mut server_emitter = server_bus.emitter();
|
let mut server_emitter = server_bus.emitter();
|
||||||
|
|
||||||
// Attacks
|
// Attacks
|
||||||
for (entity, vel, physics, ori, projectile) in (
|
for (entity, physics, ori, projectile) in (
|
||||||
&entities,
|
&entities,
|
||||||
&velocities,
|
|
||||||
&physics_states,
|
&physics_states,
|
||||||
&mut orientations,
|
&mut orientations,
|
||||||
&mut projectiles,
|
&mut projectiles,
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
ori.0 = vel.0.normalized();
|
if let Some(vel) = velocities.get(entity) {
|
||||||
|
ori.0 = vel.0.normalized();
|
||||||
|
}
|
||||||
|
|
||||||
// Hit ground
|
// Hit ground
|
||||||
if physics.on_ground {
|
if physics.on_ground {
|
||||||
for effect in projectile.hit_ground.drain(..) {
|
for effect in projectile.hit_ground.drain(..) {
|
||||||
match effect {
|
match effect {
|
||||||
projectile::Effect::Vanish => server_emitter.emit(ServerEvent::Destroy {
|
projectile::Effect::Stick => {
|
||||||
entity,
|
velocities.remove(entity);
|
||||||
cause: HealthSource::World,
|
}
|
||||||
}),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,6 +68,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
entity,
|
entity,
|
||||||
cause: HealthSource::World,
|
cause: HealthSource::World,
|
||||||
}),
|
}),
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,11 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerEvent::Shoot(entity, dir /*, projectile*/) => {
|
ServerEvent::Shoot {
|
||||||
|
entity,
|
||||||
|
dir,
|
||||||
|
projectile,
|
||||||
|
} => {
|
||||||
let pos = state
|
let pos = state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Pos>()
|
.read_storage::<comp::Pos>()
|
||||||
@ -302,13 +306,7 @@ impl Server {
|
|||||||
comp::Pos(pos),
|
comp::Pos(pos),
|
||||||
comp::Vel(dir * 100.0),
|
comp::Vel(dir * 100.0),
|
||||||
comp::Body::Object(comp::object::Body::Arrow),
|
comp::Body::Object(comp::object::Body::Arrow),
|
||||||
comp::Projectile {
|
projectile,
|
||||||
hit_ground: vec![comp::projectile::Effect::Vanish],
|
|
||||||
hit_entity: vec![
|
|
||||||
comp::projectile::Effect::Damage(10),
|
|
||||||
comp::projectile::Effect::Vanish,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user