Merge branch 'healing' into 'master'

#753 Do not make pets think they are attacked when healed

See merge request veloren/veloren!1374
This commit is contained in:
Justin Shipsey 2020-09-09 23:43:19 +00:00
commit 9cab5de99d
4 changed files with 43 additions and 14 deletions

View File

@ -25,6 +25,7 @@ pub enum HealthSource {
Command,
LevelUp,
Item,
Healing { by: Option<Uid> },
Unknown,
}

View File

@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys {
damage.modify_damage(block, loadout);
}
if damage.healthchange != 0.0 {
if damage.healthchange < 0.0 {
server_emitter.emit(ServerEvent::Damage {
uid: *uid_b,
change: HealthChange {
@ -137,7 +137,16 @@ impl<'a> System<'a> for Sys {
cause: HealthSource::Attack { by: *uid },
},
});
} else if damage.healthchange > 0.0 {
server_emitter.emit(ServerEvent::Damage {
uid: *uid_b,
change: HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Healing { by: Some(*uid) },
},
});
}
if attack.knockback != 0.0 {
local_emitter.emit(LocalEvent::ApplyForce {
entity: b,

View File

@ -82,15 +82,27 @@ impl<'a> System<'a> for Sys {
}
if other != owner_uid {
server_emitter.emit(ServerEvent::Damage {
uid: other,
change: HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Projectile {
owner: Some(owner_uid),
if damage.healthchange < 0.0 {
server_emitter.emit(ServerEvent::Damage {
uid: other,
change: HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Projectile {
owner: Some(owner_uid),
},
},
},
});
});
} else if damage.healthchange > 0.0 {
server_emitter.emit(ServerEvent::Damage {
uid: other,
change: HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Healing {
by: Some(owner_uid),
},
},
});
}
}
},
projectile::Effect::Knockback(knockback) => {

View File

@ -135,6 +135,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
| HealthSource::Command
| HealthSource::LevelUp
| HealthSource::Item
| HealthSource::Healing { by: _ }
| HealthSource::Unknown => KillSource::Other,
};
state.notify_registered_clients(
@ -450,7 +451,6 @@ pub fn handle_explosion(
power,
reagent,
});
let owner_entity = owner.and_then(|uid| {
ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(uid.into())
@ -493,10 +493,17 @@ pub fn handle_explosion(
damage.modify_damage(block, loadout);
}
stats_b.health.change_by(HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Explosion { owner },
});
if damage.healthchange < 0.0 {
stats_b.health.change_by(HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Explosion { owner },
});
} else if damage.healthchange > 0.0 {
stats_b.health.change_by(HealthChange {
amount: damage.healthchange as i32,
cause: HealthSource::Healing { by: owner },
});
}
}
}