Use Segments for RandomMetadata (#11190)

* use segments for randomized names now

* separator datafields

* public api
This commit is contained in:
Nemanja
2022-09-14 03:13:22 -04:00
committed by GitHub
parent f14f3d4999
commit cff6fe267c
7 changed files with 43 additions and 38 deletions

View File

@@ -1,17 +1,20 @@
using Content.Shared.Dataset; namespace Content.Server.RandomMetadata;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.RandomMetadata;
/// <summary> /// <summary>
/// Randomizes the description and/or the name for an entity by pulling from a dataset prototype. /// Randomizes the description and/or the name for an entity by creating it from list of dataset prototypes or strings.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed class RandomMetadataComponent : Component public sealed class RandomMetadataComponent : Component
{ {
[DataField("descriptionSet", customTypeSerializer:typeof(PrototypeIdSerializer<DatasetPrototype>))] [DataField("descriptionSegments")]
public string? DescriptionSet; public List<string>? DescriptionSegments;
[DataField("nameSet", customTypeSerializer:typeof(PrototypeIdSerializer<DatasetPrototype>))] [DataField("nameSegments")]
public string? NameSet; public List<string>? NameSegments;
[DataField("nameSeparator")]
public string NameSeparator = " ";
[DataField("descriptionSeparator")]
public string DescriptionSeparator = " ";
} }

View File

@@ -1,4 +1,5 @@
using Content.Shared.Dataset; using Content.Shared.Dataset;
using JetBrains.Annotations;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -21,16 +22,33 @@ public sealed class RandomMetadataSystem : EntitySystem
{ {
var meta = MetaData(uid); var meta = MetaData(uid);
if (component.NameSet != null) if (component.NameSegments != null)
{ {
var nameProto = _prototype.Index<DatasetPrototype>(component.NameSet); meta.EntityName = GetRandomFromSegments(component.NameSegments, component.NameSeparator);
meta.EntityName = _random.Pick(nameProto.Values);
} }
if (component.DescriptionSet != null) if (component.DescriptionSegments != null)
{ {
var descProto = _prototype.Index<DatasetPrototype>(component.DescriptionSet); meta.EntityDescription = GetRandomFromSegments(component.DescriptionSegments, component.DescriptionSeparator);
meta.EntityDescription = _random.Pick(descProto.Values);
} }
} }
/// <summary>
/// Generates a random string from segments and a separator.
/// </summary>
/// <param name="segments">The segments that it will be generated from</param>
/// <param name="separator">The separator that will be inbetween each segment</param>
/// <returns>The newly generated string</returns>
[PublicAPI]
public string GetRandomFromSegments(List<string> segments, string? separator)
{
var outputSegments = new List<string>();
foreach (var segment in segments)
{
outputSegments.Add(_prototype.TryIndex<DatasetPrototype>(segment, out var proto)
? _random.Pick(proto.Values)
: segment);
}
return string.Join(separator, outputSegments);
}
} }

View File

@@ -1,6 +1,4 @@
using Content.Shared.Actions.ActionTypes; using Content.Shared.Actions.ActionTypes;
using Content.Shared.Dataset;
using Content.Shared.Disease;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -44,11 +42,5 @@ namespace Content.Server.RatKing
/// </summary> /// </summary>
[ViewVariables, DataField("molesMiasmaPerDomain")] [ViewVariables, DataField("molesMiasmaPerDomain")]
public float MolesMiasmaPerDomain = 100f; public float MolesMiasmaPerDomain = 100f;
// Both of these are used to generate the random name for rat king.
[DataField("titleNameDataset", customTypeSerializer: typeof(PrototypeIdSerializer<DatasetPrototype>))]
public string TitleNameDataset = "RegalRatNameTitle";
[DataField("kingdomNameDataset", customTypeSerializer: typeof(PrototypeIdSerializer<DatasetPrototype>))]
public string KingdomNameDataset = "RegalRatNameKingdom";
} }
}; };

View File

@@ -1,23 +1,16 @@
using Content.Server.Actions; using Content.Server.Actions;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Disease;
using Content.Server.Disease.Components;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Shared.Actions; using Content.Shared.Actions;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Dataset;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.RatKing namespace Content.Server.RatKing
{ {
public sealed class RatKingSystem : EntitySystem public sealed class RatKingSystem : EntitySystem
{ {
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly ActionsSystem _action = default!; [Dependency] private readonly ActionsSystem _action = default!;
[Dependency] private readonly AtmosphereSystem _atmos = default!; [Dependency] private readonly AtmosphereSystem _atmos = default!;
@@ -37,11 +30,6 @@ namespace Content.Server.RatKing
{ {
_action.AddAction(uid, component.ActionRaiseArmy, null); _action.AddAction(uid, component.ActionRaiseArmy, null);
_action.AddAction(uid, component.ActionDomain, null); _action.AddAction(uid, component.ActionDomain, null);
var kingdom = _proto.Index<DatasetPrototype>(component.KingdomNameDataset);
var title = _proto.Index<DatasetPrototype>(component.TitleNameDataset);
MetaData(uid).EntityName = $"{_random.Pick(kingdom.Values)} {_random.Pick(title.Values)}";
} }
/// <summary> /// <summary>

View File

@@ -113,6 +113,10 @@
- TongueTwister - TongueTwister
- type: MobPrice - type: MobPrice
price: 2500 # rat wealth price: 2500 # rat wealth
- type: RandomMetadata
nameSegments:
- RegalRatNameKingdom
- RegalRatNameTitle
- type: entity - type: entity
id: MobRatKingBuff id: MobRatKingBuff

View File

@@ -64,7 +64,7 @@
- type: Loadout - type: Loadout
prototype: ERTLeaderGear prototype: ERTLeaderGear
- type: RandomMetadata - type: RandomMetadata
nameSet: NamesFirstMilitaryLeader nameSegments: [NamesFirstMilitaryLeader]
- type: RandomHumanoidAppearance - type: RandomHumanoidAppearance
randomizeName: false randomizeName: false
@@ -197,7 +197,7 @@
- type: Loadout - type: Loadout
prototype: SyndicateOperativeGearExtremelyBasic prototype: SyndicateOperativeGearExtremelyBasic
- type: RandomMetadata - type: RandomMetadata
nameSet: names_death_commando nameSegments: [names_death_commando]
# Nuclear Operative # Nuclear Operative
- type: entity - type: entity

View File

@@ -236,7 +236,7 @@
- Cargo - Cargo
- Maintenance - Maintenance
- type: RandomMetadata - type: RandomMetadata
descriptionSet: ATVDescriptions descriptionSegments: [ATVDescriptions]
- type: MovementSpeedModifier - type: MovementSpeedModifier
acceleration: 1 acceleration: 1
friction: 1 friction: 1