Initial bow & arrow implementation

This commit is contained in:
timokoesters 2019-09-16 17:58:40 +02:00
parent d598f2879c
commit d46f1e1859
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
8 changed files with 38 additions and 9 deletions

BIN
assets/voxygen/voxel/weapon/bow/simple-arrow.vox (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/voxygen/voxel/weapon/bow/simple-bow.vox (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -2,6 +2,7 @@ use rand::{seq::SliceRandom, thread_rng};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Body {
Arrow,
Bomb,
Scarecrow,
Cauldron,
@ -60,6 +61,7 @@ impl Body {
}
const ALL_OBJECTS: [Body; 47] = [
Body::Arrow,
Body::Bomb,
Body::Scarecrow,
Body::Cauldron,

View File

@ -74,6 +74,10 @@ impl Default for Inventory {
};
inventory.push(Item::Debug(Debug::Boost));
inventory.push(Item::Tool {
kind: Tool::Bow,
power: 10,
});
inventory.push(Item::Tool {
kind: Tool::Daggers,
power: 10,
@ -90,9 +94,6 @@ impl Default for Inventory {
kind: Tool::Hammer,
power: 10,
});
for _ in 0..10 {
inventory.push(Item::default());
}
inventory
}

View File

@ -30,7 +30,7 @@ pub enum ServerEvent {
cause: comp::HealthSource,
},
Respawn(EcsEntity),
Shoot(EcsEntity),
Shoot(EcsEntity, Vec3<f32>),
Mount(EcsEntity, EcsEntity),
Unmount(EcsEntity),
}

View File

@ -127,6 +127,25 @@ impl<'a> System<'a> for Sys {
}
match stats.equipment.main {
Some(Item::Tool {
kind: item::Tool::Bow,
..
}) => {
if controller.primary
&& (character.movement == Stand
|| character.movement == Run
|| character.movement == Jump)
{
if let Wield { time_left } = character.action {
if time_left == Duration::default() {
// Immediately end the wield
character.action = Idle;
server_emitter
.emit(ServerEvent::Shoot(entity, controller.look_dir));
}
}
}
}
Some(Item::Tool { .. }) => {
// Attack
if controller.primary

View File

@ -288,7 +288,7 @@ impl Server {
}
}
ServerEvent::Shoot(entity) => {
ServerEvent::Shoot(entity, dir) => {
let pos = state
.ecs()
.read_storage::<comp::Pos>()
@ -298,8 +298,8 @@ impl Server {
Self::create_projectile(
state,
comp::Pos(pos),
comp::Vel(Vec3::new(0.0, 100.0, 3.0)),
comp::Body::Object(comp::object::Body::Bomb),
comp::Vel(dir * 100.0),
comp::Body::Object(comp::object::Body::Arrow),
)
.build();
}

View File

@ -357,8 +357,8 @@ pub fn mesh_main(item: Option<&Item>) -> Mesh<FigurePipeline> {
Tool::Hammer => ("weapon.hammer.rusty_2h", Vec3::new(-2.5, -5.5, -4.0)),
Tool::Daggers => ("weapon.hammer.rusty_2h", Vec3::new(-2.5, -5.5, -4.0)),
Tool::SwordShield => ("weapon.axe.rusty_2h", Vec3::new(-2.5, -6.5, -2.0)),
Tool::Bow => ("weapon.hammer.rusty_2h", Vec3::new(-2.5, -5.5, -4.0)),
Tool::Staff => ("weapon.axe.rusty_2h", Vec3::new(-2.5, -5.5, -4.0)),
Tool::Bow => ("weapon.bow.simple-bow", Vec3::new(-2.5, -5.5, -4.0)),
Tool::Staff => ("weapon.axe.rusty_2h", Vec3::new(-2.5, -6.5, -2.0)),
},
Item::Debug(_) => ("weapon.debug_wand", Vec3::new(-1.5, -9.5, -4.0)),
_ => return Mesh::new(),
@ -581,6 +581,7 @@ pub fn mesh_object(obj: object::Body) -> Mesh<FigurePipeline> {
use object::Body;
let (name, offset) = match obj {
Body::Arrow => ("weapon.bow.simple-arrow", Vec3::new(-5.5, -5.5, 0.0)),
Body::Bomb => ("object.bomb", Vec3::new(-5.5, -5.5, 0.0)),
Body::Scarecrow => ("object.scarecrow", Vec3::new(-9.5, -4.0, 0.0)),
Body::Cauldron => ("object.cauldron", Vec3::new(-10.0, -10.0, 0.0)),