MakeSentient uses EntityUid

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 15:44:07 +01:00
parent f9c2b832e5
commit 6803c52fe9

View File

@@ -28,40 +28,35 @@ namespace Content.Server.Mind.Commands
return; return;
} }
if (!int.TryParse(args[0], out var id)) if (!EntityUid.TryParse(args[0], out var entId))
{ {
shell.WriteLine("Invalid argument."); shell.WriteLine("Invalid argument.");
return; return;
} }
var entId = new EntityUid(id);
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.TryGetEntity(entId, out var entity) || entity.Deleted) if (!entityManager.EntityExists(entId))
{ {
shell.WriteLine("Invalid entity specified!"); shell.WriteLine("Invalid entity specified!");
return; return;
} }
MakeSentient(entity); MakeSentient(entId, entityManager);
} }
public static void MakeSentient(IEntity entity) public static void MakeSentient(EntityUid uid, IEntityManager entityManager)
{ {
if(entity.HasComponent<AiControllerComponent>()) if(entityManager.HasComponent<AiControllerComponent>(uid))
entity.RemoveComponent<AiControllerComponent>(); entityManager.RemoveComponent<AiControllerComponent>(uid);
// Delay spawning these components to avoid race conditions with the deferred removal of AiController.
Timer.Spawn(100, () => entityManager.EnsureComponent<MindComponent>(uid);
{ entityManager.EnsureComponent<SharedPlayerInputMoverComponent>(uid);
entity.EnsureComponent<MindComponent>(); entityManager.EnsureComponent<SharedPlayerMobMoverComponent>(uid);
entity.EnsureComponent<SharedPlayerInputMoverComponent>(); entityManager.EnsureComponent<SharedSpeechComponent>(uid);
entity.EnsureComponent<SharedPlayerMobMoverComponent>(); entityManager.EnsureComponent<SharedEmotingComponent>(uid);
entity.EnsureComponent<SharedSpeechComponent>(); entityManager.EnsureComponent<ExaminerComponent>(uid);
entity.EnsureComponent<SharedEmotingComponent>();
entity.EnsureComponent<ExaminerComponent>();
});
} }
} }
} }