From 74b7613cd997b6eba2ac5cec019d4378a64bcb91 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sat, 3 Aug 2019 22:08:19 +0200 Subject: [PATCH] Get rid of unwraps --- server/src/lib.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 6de1516188..47a00a6792 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -878,18 +878,19 @@ impl Server { } // Give EXP to the client - if let comp::HealthSource::Attack { by } = dying.cause { - ecs.entity_from_uid(by.into()).map(|attacker| { - let mut stats = ecs.write_storage::(); - let entity_stats = stats.get(entity).unwrap().clone(); - let attacker_stats = stats.get_mut(attacker).unwrap(); - - // TODO: Discuss whether we should give EXP by Player Killing or not. - attacker_stats.exp.change_by( - entity_stats.health.maximum() as f64 / 10.0 - * entity_stats.level.level() as f64, - ); - }); + let mut stats = ecs.write_storage::(); + if let Some(entity_stats) = stats.get(entity).cloned() { + if let comp::HealthSource::Attack { by } = dying.cause { + ecs.entity_from_uid(by.into()).map(|attacker| { + if let Some(attacker_stats) = stats.get_mut(attacker) { + // TODO: Discuss whether we should give EXP by Player Killing or not. + attacker_stats.exp.change_by( + entity_stats.health.maximum() as f64 / 10.0 + * entity_stats.level.level() as f64, + ); + } + }); + } } entity