From 028d010624f7eea42da4defd54b573d96303765e Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 11 Oct 2019 19:30:05 -0400 Subject: [PATCH] Make bows give experience via giving projectiles an owner field --- common/src/comp/projectile.rs | 4 +++- common/src/comp/stats.rs | 1 - common/src/sys/controller.rs | 16 ++++++---------- common/src/sys/projectile.rs | 11 ++++++++--- server/src/lib.rs | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/common/src/comp/projectile.rs b/common/src/comp/projectile.rs index ac1f70cb36..63b4aa59d9 100644 --- a/common/src/comp/projectile.rs +++ b/common/src/comp/projectile.rs @@ -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, pub hit_ground: Vec, pub hit_wall: Vec, pub hit_entity: Vec, diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index c5c7e29f1d..3aa080e249 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -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, diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index af46d8e52e..d6ff8f7815 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -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), }, }); diff --git a/common/src/sys/projectile.rs b/common/src/sys/projectile.rs index d1fecc4767..25cc6a388a 100644 --- a/common/src/sys/projectile.rs +++ b/common/src/sys/projectile.rs @@ -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)) + } } _ => {} } diff --git a/server/src/lib.rs b/server/src/lib.rs index 5d4ef90708..5415b504b5 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -482,7 +482,7 @@ impl Server { { let mut inventories = state.ecs_mut().write_storage::(); - 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 {