Allow OnDeath event to handle all actors

This commit is contained in:
Joshua Barretto
2023-04-05 23:24:16 +01:00
parent ce5ef481e1
commit d7ba4ecef7
7 changed files with 158 additions and 116 deletions

View File

@ -25,6 +25,7 @@ use common::{
link::{Link, LinkHandle},
mounting::Mounting,
resources::{Secs, Time, TimeOfDay},
rtsim::{Actor, RtSimEntity},
slowjob::SlowJobPool,
uid::{Uid, UidAllocator},
LoadoutBuilder, ViewDistances,
@ -139,6 +140,8 @@ pub trait StateExt {
&mut self,
entity: EcsEntity,
) -> Result<(), specs::error::WrongGeneration>;
/// Get the given entity as an [`Actor`], if it is one.
fn entity_as_actor(&self, entity: EcsEntity) -> Option<Actor>;
}
impl StateExt for State {
@ -1103,6 +1106,26 @@ impl StateExt for State {
}
res
}
fn entity_as_actor(&self, entity: EcsEntity) -> Option<Actor> {
if let Some(rtsim_entity) = self
.ecs()
.read_storage::<RtSimEntity>()
.get(entity)
.copied()
{
Some(Actor::Npc(rtsim_entity.0))
} else if let Some(PresenceKind::Character(character)) = self
.ecs()
.read_storage::<Presence>()
.get(entity)
.map(|p| p.kind)
{
Some(Actor::Character(character))
} else {
None
}
}
}
fn send_to_group(g: &Group, ecs: &specs::World, msg: &comp::ChatMsg) {