Remove unwrap

Former-commit-id: 68d26e366450010d1455c7662dc283cc0e0d9380
This commit is contained in:
timokoesters 2019-05-27 22:41:19 +02:00
parent 171ca86340
commit 07b9bfe3b7

View File

@ -218,19 +218,21 @@ impl Server {
.map(|(entity, dying)| {
// Chat message
if let Some(player) = ecs.read_storage::<comp::Player>().get(entity) {
// While waiting for if-let-chains to be implemented...
let msg = if let comp::HealthSource::Attack { by } = dying.cause {
if let Some(attacker) = ecs
.read_storage::<comp::Player>()
.get(ecs.entity_from_uid(by.into()).unwrap())
{
format!("{} was killed by {}", &player.alias, &attacker.alias)
} else {
format!("{} died", &player.alias)
}
ecs.entity_from_uid(by.into()).and_then(|attacker| {
ecs.read_storage::<comp::Player>()
.get(attacker)
.map(|attacker_alias| {
format!(
"{} was killed by {}",
&player.alias, &attacker_alias.alias
)
})
})
} else {
format!("{} died", &player.alias)
};
None
}
.unwrap_or(format!("{} died", &player.alias));
clients.notify_registered(ServerMsg::Chat(msg));
}