Внешний вид мага (#444)

* add: Magic mirror

* add: Wizard appearance
This commit is contained in:
Spatison
2024-07-16 18:31:28 +03:00
committed by GitHub
parent 192d2d5de7
commit f59765c072
17 changed files with 1155 additions and 54 deletions

View File

@@ -357,4 +357,4 @@ public sealed class MagicMirrorSystem : EntitySystem
{
ent.Comp.Target = null;
}
}
}

View File

@@ -0,0 +1,137 @@
using Content.Server.Humanoid;
using Content.Server.IdentityManagement;
using Content.Shared._White.Wizard.Mirror;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Interaction;
using Content.Shared.Physics;
using Content.Shared.Preferences;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
namespace Content.Server._White.Wizard.Mirror;
public sealed class WizardMirrorSystem : EntitySystem
{
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly IdentitySystem _identity = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WizardMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);
Subs.BuiEvents<WizardMirrorComponent>(WizardMirrorUiKey.Key,
subs =>
{
subs.Event<BoundUIClosedEvent>(OnUIClosed);
subs.Event<WizardMirrorSave>(OnSave);
});
SubscribeLocalEvent<WizardMirrorComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<WizardMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
SubscribeLocalEvent<WizardMirrorComponent, BoundUserInterfaceCheckRangeEvent>(OnRangeCheck);
}
private void OnOpenUIAttempt(EntityUid uid, WizardMirrorComponent mirror, ActivatableUIOpenAttemptEvent args)
{
if (!HasComp<HumanoidAppearanceComponent>(args.User))
args.Cancel();
}
private static void OnUIClosed(Entity<WizardMirrorComponent> ent, ref BoundUIClosedEvent args)
{
ent.Comp.Target = null;
}
private void OnSave(EntityUid uid, WizardMirrorComponent component, WizardMirrorSave args)
{
if (!TryComp(component.Target, out HumanoidAppearanceComponent? humanoid) || !string.IsNullOrEmpty(humanoid.Initial))
return;
_humanoid.LoadProfile(component.Target.Value, args.Profile, humanoid);
_metaData.SetEntityName(component.Target.Value, args.Profile.Name);
_identity.QueueIdentityUpdate(component.Target.Value);
}
private void OnInteractHand(EntityUid uid, WizardMirrorComponent component, ref InteractHandEvent args)
{
UpdateInterface(uid, args.User, component);
}
private void OnMagicMirrorInteract(EntityUid uid, WizardMirrorComponent component, ref AfterInteractEvent args)
{
if (!args.CanReach || args.Target == null)
return;
if (!TryComp<ActorComponent>(args.User, out var actor))
return;
if (!_uiSystem.TryOpen(uid, WizardMirrorUiKey.Key, actor.PlayerSession))
return;
UpdateInterface(uid, args.Target.Value, component);
}
private void OnRangeCheck(EntityUid uid, WizardMirrorComponent component, ref BoundUserInterfaceCheckRangeEvent args)
{
component.Target ??= args.Player.AttachedEntity;
if (!component.Target.HasValue || !_interaction.InRangeUnobstructed(uid, component.Target!.Value, range: 2f, CollisionGroup.None))
args.Result = BoundUserInterfaceRangeResult.Fail;
}
private void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, WizardMirrorComponent component)
{
if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid) ||
!TryComp<MetaDataComponent>(targetUid, out var meta))
return;
var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
? new List<Marking>(hairMarkings)[0]
: null;
var facialHair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.FacialHair, out var facialHairMarkings)
? new List<Marking>(facialHairMarkings)[0]
: null;
var profile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species)
.WithAge(humanoid.Age)
.WithGender(humanoid.Gender)
.WithName(meta.EntityName)
.WithSex(humanoid.Sex)
.WithVoice(humanoid.Voice)
.WithBodyType(humanoid.BodyType);
profile = profile.WithCharacterAppearance(
profile.WithCharacterAppearance(
profile.Appearance.WithSkinColor(humanoid.SkinColor))
.Appearance.WithEyeColor(humanoid.EyeColor));
if (hair != null)
{
profile = profile.WithCharacterAppearance(
profile.WithCharacterAppearance(
profile.Appearance.WithHairStyleName(hair.MarkingId))
.Appearance.WithHairColor(hair.MarkingColors[0]));
}
if (facialHair != null)
{
profile = profile.WithCharacterAppearance(
profile.WithCharacterAppearance(
profile.Appearance.WithFacialHairStyleName(facialHair.MarkingId))
.Appearance.WithFacialHairColor(facialHair.MarkingColors[0]));
}
var state = new WizardMirrorUiState(profile);
component.Target = targetUid;
_uiSystem.TrySetUiState(mirrorUid, WizardMirrorUiKey.Key, state);
}
}

View File

@@ -6,4 +6,22 @@ public sealed partial class WizardComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public bool EndRoundOnDeath;
[DataField]
public int MinAge = 90;
[DataField]
public int MaxAge = 170;
[DataField]
public string Hair = "WizardHair";
[DataField]
public string FacialHair = "WizardFacialHair";
[DataField]
public string Color = "WizardHairColor";
[DataField]
public string Name = "WizardNames";
}

View File

@@ -25,6 +25,7 @@ using Content.Server.Objectives;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Content.Shared._White.Antag;
using Content.Shared.Dataset;
using Content.Shared.Mind;
using Content.Shared.NPC.Components;
using Content.Shared.Objectives.Components;
@@ -55,6 +56,7 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly ObjectivesSystem _objectives = default!;
private ISawmill _sawmill = default!;
/// <inheritdoc/>
@@ -137,10 +139,6 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
if (!TryComp<WizardSpawnerComponent>(spawner, out var wizardSpawner))
return;
HumanoidCharacterProfile? profile = null;
if (TryComp(args.Spawned, out ActorComponent? actor))
profile = _prefs.GetPreferences(actor.PlayerSession.UserId).SelectedCharacter as HumanoidCharacterProfile;
if (!EntityQuery<WizardRuleComponent>().Any())
return;
@@ -150,7 +148,7 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
return;
}
SetupWizardEntity(uid, gear, profile, false);
SetupWizardEntity(uid, gear, false);
}
private void OnMindAdded(EntityUid uid, WizardComponent component, MindAddedMessage args)
@@ -279,25 +277,40 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
return true;
}
private void SetupWizardEntity(
private HumanoidCharacterProfile SetupWizardEntity(
EntityUid mob,
StartingGearPrototype gear,
HumanoidCharacterProfile? profile,
bool endRoundOnDeath)
{
EnsureComp<WizardComponent>(mob).EndRoundOnDeath = endRoundOnDeath;
EnsureComp<WizardComponent>(mob, out var component);
component.EndRoundOnDeath = endRoundOnDeath;
EnsureComp<GlobalAntagonistComponent>(mob).AntagonistPrototype = "globalAntagonistWizard";
profile ??= HumanoidCharacterProfile.RandomWithSpecies();
var random = IoCManager.Resolve<IRobustRandom>();
var profile = HumanoidCharacterProfile.RandomWithSpecies().WithAge(random.Next(component.MinAge, component.MaxAge));
var color = Color.FromHex(GetRandom(component.Color, "#B5B8B1"));
var hair = GetRandom(component.Hair, "HumanHairAfricanPigtails");
var facialHair = GetRandom(component.FacialHair, "HumanFacialHairAbe");
profile = profile.WithCharacterAppearance(
profile.WithCharacterAppearance(
profile.WithCharacterAppearance(
profile.WithCharacterAppearance(
profile.Appearance.WithHairStyleName(hair))
.Appearance.WithFacialHairStyleName(facialHair))
.Appearance.WithHairColor(color))
.Appearance.WithFacialHairColor(color));
_humanoid.LoadProfile(mob, profile);
_metaData.SetEntityName(mob, profile.Name);
_metaData.SetEntityName(mob, GetRandom(component.Name, ""));
_stationSpawning.EquipStartingGear(mob, gear);
_npcFaction.RemoveFaction(mob, "NanoTrasen", false);
_npcFaction.AddFaction(mob, "Wizard");
return profile;
}
private EntityCoordinates WizardSpawnPoint(WizardRuleComponent component)
@@ -342,13 +355,7 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
//If a session is available, spawn mob and transfer mind into it
if (session != null)
{
var profile =
_prefs.GetPreferences(session.UserId).SelectedCharacter as HumanoidCharacterProfile;
profile ??= HumanoidCharacterProfile.RandomWithSpecies();
var name = profile.Name;
if (!_prototypeManager.TryIndex(profile.Species, out SpeciesPrototype? species))
if (!_prototypeManager.TryIndex(SharedHumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species))
{
species = _prototypeManager.Index<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies);
}
@@ -360,7 +367,7 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
return;
}
SetupWizardEntity(mob, gear, profile, true);
var name = SetupWizardEntity(mob, gear, true).Name;
var newMind = _mind.CreateMind(session.UserId, name);
_mind.SetUserId(newMind, session.UserId);
@@ -442,10 +449,6 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
return false;
}
HumanoidCharacterProfile? profile = null;
if (TryComp(wizard, out ActorComponent? actor))
profile = _prefs.GetPreferences(actor.PlayerSession.UserId).SelectedCharacter as HumanoidCharacterProfile;
if (giveObjectives)
{
AddRole(mindId, mind, rule);
@@ -457,7 +460,7 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
return false;
}
SetupWizardEntity(wizard, gear, profile, false);
SetupWizardEntity(wizard, gear, false);
var spawnpoint = WizardSpawnPoint(rule);
var transform = EnsureComp<TransformComponent>(wizard);
@@ -465,4 +468,11 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
return true;
}
private string GetRandom(string list, string ifNull)
{
return _prototypeManager.TryIndex<DatasetPrototype>(list, out var prototype)
? _random.Pick(prototype.Values)
: ifNull;
}
}