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_idvs::IDVStorage;
use std::time::Duration;
@ -7,11 +8,12 @@ pub enum Effect {
Damage(u32),
Vanish,
Stick,
Possess(u64),
Possess,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Projectile {
pub owner: Option<Uid>,
pub hit_ground: Vec<Effect>,
pub hit_wall: 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)]
pub enum HealthSource {
Attack { by: Uid }, // TODO: Implement weapon
Projectile,
Suicide,
World,
Revive,

View File

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

View File

@ -74,15 +74,20 @@ impl<'a> System<'a> for Sys {
server_emitter.emit(ServerEvent::Damage {
uid: other,
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 {
entity,
cause: HealthSource::World,
}),
projectile::Effect::Possess(client_uid) => {
server_emitter.emit(ServerEvent::Possess(client_uid.into(), other))
projectile::Effect::Possess => {
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 =
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
.push(comp::Item::Debug(comp::item::Debug::Possess));
} else {