Еще одни фиксы апстрима (#671)

* wizard appearance system refactor

* new helper method for drop anything from inventory

* fix wizard and nukie inventory saving

* remove wieldable from laser rifle

* replace comment with todo
This commit is contained in:
ThereDrD
2024-08-28 09:54:39 +03:00
committed by GitHub
parent 77574a28e7
commit 2fa46e0b3e
8 changed files with 101 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.Humanoid;
using Content.Shared._White.Wizard.Appearance;
using Content.Shared.Dataset;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -22,8 +23,41 @@ public sealed class WizardAppearanceSystem : EntitySystem
private void OnInit(EntityUid wizard, WizardAppearanceComponent appearance, ComponentInit _)
{
var random = IoCManager.Resolve<IRobustRandom>();
var profile = HumanoidCharacterProfile.RandomWithSpecies().WithAge(random.Next(appearance.MinAge, appearance.MaxAge));
Wizardify(wizard, appearance);
}
public void Wizardify(EntityUid wizard, WizardAppearanceComponent appearance)
{
var profile = GetWizardProfile(appearance);
_humanoid.LoadProfile(wizard, profile);
_metaData.SetEntityName(wizard, GetRandom(appearance.Name, string.Empty));
}
public string GetWizardName(WizardAppearanceComponent appearance)
{
return GetRandom(appearance.Name, string.Empty);
}
public EntityUid GetWizardEntity(WizardAppearanceComponent appearance)
{
var profile = GetWizardProfile(appearance);
if (!_prototypeManager.TryIndex(profile.Species, out SpeciesPrototype? species))
return EntityUid.Invalid;
var entity = Spawn(species.Prototype);
_humanoid.LoadProfile(entity, profile);
_metaData.SetEntityName(entity, GetWizardName(appearance));
return entity;
}
public HumanoidCharacterProfile GetWizardProfile(WizardAppearanceComponent appearance)
{
var profile = HumanoidCharacterProfile.RandomWithSpecies().WithAge(_random.Next(appearance.MinAge, appearance.MaxAge));
var color = Color.FromHex(GetRandom(appearance.Color, "#B5B8B1"));
var hair = GetRandom(appearance.Hair, "HumanHairAfricanPigtails");
@@ -37,9 +71,7 @@ public sealed class WizardAppearanceSystem : EntitySystem
.Appearance.WithHairColor(color))
.Appearance.WithFacialHairColor(color));
_humanoid.LoadProfile(wizard, profile);
_metaData.SetEntityName(wizard, GetRandom(appearance.Name, string.Empty));
return profile;
}
private string GetRandom(string list, string ifNull)

View File

@@ -4,9 +4,10 @@ using Content.Server.Mind;
using Content.Server.RoundEnd;
using Content.Shared.Mobs;
using System.Linq;
using Content.Server._White.Wizard.Appearance;
using Content.Server.Objectives;
using Content.Server.StationEvents.Components;
using Content.Shared._White.Mood;
using Content.Shared._White.Wizard.Appearance;
using Content.Shared.Mind;
using Content.Shared.Objectives.Components;
@@ -20,12 +21,16 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly ObjectivesSystem _objectives = default!;
[Dependency] private readonly WizardAppearanceSystem _wizardAppearance = default!;
private const string WizardObjective = "WizardSurviveObjective";
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WizardRuleComponent, AntagSelectEntityEvent>(OnAntagSelectEntity);
SubscribeLocalEvent<WizardRuleComponent, AfterAntagEntitySelectedEvent>(AfterEntitySelected);
SubscribeLocalEvent<WizardComponent, MobStateChangedEvent>(OnMobStateChanged);
@@ -46,7 +51,7 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
private void GiveObjectives(EntityUid mindId, MindComponent mind, WizardRuleComponent wizardRule)
{
_mind.TryAddObjective(mindId, mind, "WizardSurviveObjective");
_mind.TryAddObjective(mindId, mind, WizardObjective);
var difficulty = 0f;
for (var pick = 0; pick < 6 && 8 > difficulty; pick++)
@@ -66,6 +71,24 @@ public sealed class WizardRuleSystem : GameRuleSystem<WizardRuleComponent>
MakeWizard(args.EntityUid, ent);
}
private void OnAntagSelectEntity(Entity<WizardRuleComponent> ent, ref AntagSelectEntityEvent args)
{
if (args.Handled)
return;
if (!args.Entity.HasValue)
return;
var wizardAppearanceComponent = EnsureComp<WizardAppearanceComponent>(args.Entity.Value);
// TODO: Пофиксить, что игрун сохраняет свой прототип вместе с расой и остаются абилки расы
var entity = _wizardAppearance.GetWizardEntity(wizardAppearanceComponent);
if (entity != EntityUid.Invalid)
args.Entity = entity;
}
private void MakeWizard(EntityUid wizard, WizardRuleComponent component, bool giveObjectives = true)
{
if (!_mind.TryGetMind(wizard, out var mindId, out var mind))