Make bows give experience via giving projectiles an owner field

This commit is contained in:
Imbris
2019-10-11 19:30:05 -04:00
parent 2f9d8ee2e6
commit 028d010624
5 changed files with 18 additions and 16 deletions

View File

@ -1,3 +1,4 @@
use crate::state::Uid;
use specs::{Component, FlaggedStorage}; use specs::{Component, FlaggedStorage};
use specs_idvs::IDVStorage; use specs_idvs::IDVStorage;
use std::time::Duration; use std::time::Duration;
@ -7,11 +8,12 @@ pub enum Effect {
Damage(u32), Damage(u32),
Vanish, Vanish,
Stick, Stick,
Possess(u64), Possess,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Projectile { pub struct Projectile {
pub owner: Option<Uid>,
pub hit_ground: Vec<Effect>, pub hit_ground: Vec<Effect>,
pub hit_wall: Vec<Effect>, pub hit_wall: Vec<Effect>,
pub hit_entity: Vec<Effect>, pub hit_entity: Vec<Effect>,

View File

@ -5,7 +5,6 @@ use specs_idvs::IDVStorage;
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub enum HealthSource { pub enum HealthSource {
Attack { by: Uid }, // TODO: Implement weapon Attack { by: Uid }, // TODO: Implement weapon
Projectile,
Suicide, Suicide,
World, World,
Revive, Revive,

View File

@ -148,6 +148,7 @@ impl<'a> System<'a> for Sys {
body: comp::Body::Object(comp::object::Body::Arrow), body: comp::Body::Object(comp::object::Body::Arrow),
light: None, light: None,
projectile: Projectile { projectile: Projectile {
owner: uid.get(entity).copied(),
hit_ground: vec![projectile::Effect::Stick], hit_ground: vec![projectile::Effect::Stick],
hit_wall: vec![projectile::Effect::Stick], hit_wall: vec![projectile::Effect::Stick],
hit_entity: vec![ hit_entity: vec![
@ -226,18 +227,13 @@ impl<'a> System<'a> for Sys {
..Default::default() ..Default::default()
}), }),
projectile: Projectile { projectile: Projectile {
owner: uid.get(entity).copied(),
hit_ground: vec![projectile::Effect::Vanish], hit_ground: vec![projectile::Effect::Vanish],
hit_wall: vec![projectile::Effect::Vanish], hit_wall: vec![projectile::Effect::Vanish],
hit_entity: { hit_entity: vec![
let mut effects = vec![projectile::Effect::Vanish]; projectile::Effect::Vanish,
if let Some(uid) = uid.get(entity) { projectile::Effect::Possess,
// TODO: if projectiles themselves get owners we don't need to store the uid here ],
effects.push(projectile::Effect::Possess(
(*uid).into(),
));
}
effects
},
time_left: Duration::from_secs(60 * 5), time_left: Duration::from_secs(60 * 5),
}, },
}); });

View File

@ -74,15 +74,20 @@ impl<'a> System<'a> for Sys {
server_emitter.emit(ServerEvent::Damage { server_emitter.emit(ServerEvent::Damage {
uid: other, uid: other,
dmg: power, dmg: power,
cause: HealthSource::Projectile, cause: match projectile.owner {
Some(uid) => HealthSource::Attack { by: uid },
None => HealthSource::Unknown,
},
}) })
} }
projectile::Effect::Vanish => server_emitter.emit(ServerEvent::Destroy { projectile::Effect::Vanish => server_emitter.emit(ServerEvent::Destroy {
entity, entity,
cause: HealthSource::World, cause: HealthSource::World,
}), }),
projectile::Effect::Possess(client_uid) => { projectile::Effect::Possess => {
server_emitter.emit(ServerEvent::Possess(client_uid.into(), other)) if let Some(uid) = projectile.owner {
server_emitter.emit(ServerEvent::Possess(uid.into(), other))
}
} }
_ => {} _ => {}
} }

View File

@ -482,7 +482,7 @@ impl Server {
{ {
let mut inventories = let mut inventories =
state.ecs_mut().write_storage::<comp::Inventory>(); state.ecs_mut().write_storage::<comp::Inventory>();
if let Some(mut inventory) = inventories.get_mut(possesse) { if let Some(inventory) = inventories.get_mut(possesse) {
inventory inventory
.push(comp::Item::Debug(comp::item::Debug::Possess)); .push(comp::Item::Debug(comp::item::Debug::Possess));
} else { } else {