Add RtsimEntity mapping if it is included as a component on a newly

created npc.

Also, improve wording of a comment.
This commit is contained in:
Imbris 2023-06-03 16:51:50 -04:00
parent 01df87bdb4
commit 42ba445ea2
2 changed files with 13 additions and 5 deletions

View File

@ -34,9 +34,9 @@ impl Component for Presence {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PresenceKind { pub enum PresenceKind {
Spectator, Spectator,
// Note: we don't know if this character ID is valid and associated with the respective player // Note: we don't know if this character ID is valid and associated with the player until the
// until it the character has loaded successfully. The ID should only be trusted and included // character has loaded successfully. The ID should only be trusted and included in the
// in the mapping when the variant changed to `Character`. // mapping when the variant is changed to `Character`.
LoadingCharacter(CharacterId), LoadingCharacter(CharacterId),
Character(CharacterId), Character(CharacterId),
Possessor, Possessor,

View File

@ -18,7 +18,7 @@ use common::{
outcome::Outcome, outcome::Outcome,
resources::{Secs, Time}, resources::{Secs, Time},
rtsim::RtSimVehicle, rtsim::RtSimVehicle,
uid::Uid, uid::{IdMaps, Uid},
util::Dir, util::Dir,
vol::IntoFullVolIterator, vol::IntoFullVolIterator,
ViewDistances, ViewDistances,
@ -140,7 +140,7 @@ pub fn handle_create_npc(server: &mut Server, pos: Pos, mut npc: NpcBuilder) ->
entity entity
}; };
// TODO: rtsim entity added here // Rtsim entity added to IdMaps below.
let entity = if let Some(rtsim_entity) = npc.rtsim_entity { let entity = if let Some(rtsim_entity) = npc.rtsim_entity {
entity.with(rtsim_entity).with(RepositionOnChunkLoad { entity.with(rtsim_entity).with(RepositionOnChunkLoad {
needs_ground: false, needs_ground: false,
@ -157,6 +157,14 @@ pub fn handle_create_npc(server: &mut Server, pos: Pos, mut npc: NpcBuilder) ->
let new_entity = entity.build(); let new_entity = entity.build();
if let Some(rtsim_entity) = npc.rtsim_entity {
server
.state()
.ecs()
.write_resource::<IdMaps>()
.add_rtsim(rtsim_entity, new_entity);
}
// Add to group system if a pet // Add to group system if a pet
if let comp::Alignment::Owned(owner_uid) = npc.alignment { if let comp::Alignment::Owned(owner_uid) = npc.alignment {
let state = server.state(); let state = server.state();