2023-09-17 18:51:42 +06:00
|
|
|
using Content.Server.Access.Systems;
|
|
|
|
|
using Content.Server.Humanoid;
|
|
|
|
|
using Content.Server.IdentityManagement;
|
|
|
|
|
using Content.Server.PDA;
|
2023-10-17 00:52:02 +09:00
|
|
|
using Content.Server.Roles;
|
2024-02-08 18:44:19 +09:00
|
|
|
using Content.Server.StationRecords.Systems;
|
2023-09-17 18:51:42 +06:00
|
|
|
using Content.Shared.Access.Components;
|
2024-01-29 01:02:37 +07:00
|
|
|
using Content.Shared.Humanoid;
|
2023-09-17 18:51:42 +06:00
|
|
|
using Content.Shared.Inventory;
|
2023-10-19 02:32:18 +09:00
|
|
|
using Content.Shared.Mind.Components;
|
|
|
|
|
using Content.Shared.NukeOps;
|
2023-09-17 18:51:42 +06:00
|
|
|
using Content.Shared.PDA;
|
|
|
|
|
using Content.Shared.Preferences;
|
2024-02-08 18:44:19 +09:00
|
|
|
using Content.Shared.StationRecords;
|
2023-09-17 18:51:42 +06:00
|
|
|
|
2024-01-28 18:18:54 +07:00
|
|
|
namespace Content.Server._White.Other.RandomHumanSystem;
|
2023-09-17 18:51:42 +06:00
|
|
|
|
|
|
|
|
public sealed class RandomHumanSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
|
|
|
|
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
|
|
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
|
|
|
|
[Dependency] private readonly IdCardSystem _card = default!;
|
|
|
|
|
[Dependency] private readonly PdaSystem _pda = default!;
|
|
|
|
|
[Dependency] private readonly IdentitySystem _identity = default!;
|
2024-02-08 18:44:19 +09:00
|
|
|
[Dependency] private readonly StationRecordsSystem _records = default!;
|
2023-09-17 18:51:42 +06:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<RandomHumanComponent, ComponentInit>(OnInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInit(EntityUid uid, RandomHumanComponent component, ComponentInit args)
|
|
|
|
|
{
|
2024-01-29 01:02:37 +07:00
|
|
|
if (!TryComp(uid, out HumanoidAppearanceComponent? humanoidAppearanceComponent))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 18:51:42 +06:00
|
|
|
var newProfile = HumanoidCharacterProfile.RandomWithSpecies();
|
|
|
|
|
|
2024-01-29 01:02:37 +07:00
|
|
|
_humanoid.LoadProfile(uid, newProfile, humanoidAppearanceComponent);
|
2023-09-17 18:51:42 +06:00
|
|
|
|
2023-10-19 02:32:18 +09:00
|
|
|
if (HasComp<NukeOperativeComponent>(uid))
|
2023-10-17 00:52:02 +09:00
|
|
|
return;
|
|
|
|
|
|
2023-09-17 18:51:42 +06:00
|
|
|
_metaData.SetEntityName(uid, newProfile.Name);
|
|
|
|
|
|
|
|
|
|
if (!_inventorySystem.TryGetSlotEntity(uid, "id", out var idUid))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-29 01:02:37 +07:00
|
|
|
if (!EntityManager.TryGetComponent(idUid, out PdaComponent? pdaComponent) ||
|
|
|
|
|
!TryComp<IdCardComponent>(pdaComponent.ContainedId, out var card))
|
2023-09-17 18:51:42 +06:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var cardId = pdaComponent.ContainedId.Value;
|
|
|
|
|
|
|
|
|
|
_card.TryChangeFullName(cardId, newProfile.Name, card);
|
2024-08-06 16:58:30 +03:00
|
|
|
_pda.SetOwnerName(idUid.Value, pdaComponent, newProfile.Name);
|
2023-09-17 18:51:42 +06:00
|
|
|
|
2024-02-08 18:44:19 +09:00
|
|
|
if (EntityManager.TryGetComponent(cardId, out StationRecordKeyStorageComponent? keyStorage)
|
|
|
|
|
&& keyStorage.Key is { } key)
|
|
|
|
|
{
|
|
|
|
|
if (_records.TryGetRecord<GeneralStationRecord>(key, out var generalRecord))
|
|
|
|
|
{
|
|
|
|
|
generalRecord.Name = newProfile.Name;
|
|
|
|
|
generalRecord.Age = newProfile.Age;
|
|
|
|
|
generalRecord.Gender = newProfile.Gender;
|
|
|
|
|
generalRecord.Species = newProfile.Species;
|
|
|
|
|
generalRecord.Profile = newProfile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_records.Synchronize(key);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 18:51:42 +06:00
|
|
|
_identity.QueueIdentityUpdate(uid);
|
|
|
|
|
}
|
|
|
|
|
}
|