Chem guidebook (#17123)
* im good at atomizing. welcome to half-finished chem guides. * wagh * e * save work * aa * woweee UI * finishing the last of it * don't actually update the engine :( --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Localizations;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reagent
|
||||
@@ -23,6 +26,10 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[DataField("conditions")]
|
||||
public ReagentEffectCondition[]? Conditions;
|
||||
|
||||
public virtual string ReagentEffectFormat => "guidebook-reagent-effect-description";
|
||||
|
||||
protected abstract string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys); // => Loc.GetString("reagent-effect-guidebook-missing", ("chance", Probability));
|
||||
|
||||
/// <summary>
|
||||
/// What's the chance, from 0 to 1, that this effect will occur?
|
||||
/// </summary>
|
||||
@@ -42,6 +49,23 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
public virtual bool ShouldLog { get; } = false;
|
||||
|
||||
public abstract void Effect(ReagentEffectArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// Produces a localized, bbcode'd guidebook description for this effect.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string? GuidebookEffectDescription(IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
var effect = ReagentEffectGuidebookText(prototype, entSys);
|
||||
if (effect is null)
|
||||
return null;
|
||||
|
||||
return Loc.GetString(ReagentEffectFormat, ("effect", effect), ("chance", Probability),
|
||||
("conditionCount", Conditions?.Length ?? 0),
|
||||
("conditions",
|
||||
ContentLocalizationManager.FormatList(Conditions?.Select(x => x.GuidebookExplanation(prototype)).ToList() ??
|
||||
new List<string>())));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReagentEffectExt
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reagent
|
||||
{
|
||||
@@ -10,5 +11,12 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[JsonPropertyName("id")] private protected string _id => this.GetType().Name;
|
||||
|
||||
public abstract bool Condition(ReagentEffectArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// Effect explanations are of the form "[chance to] [action] when [condition] and [condition]"
|
||||
/// </summary>
|
||||
/// <param name="prototype"></param>
|
||||
/// <returns></returns>
|
||||
public abstract string GuidebookExplanation(IPrototypeManager prototype);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Prototypes;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
@@ -9,6 +10,7 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
@@ -157,6 +159,23 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public struct ReagentGuideEntry
|
||||
{
|
||||
public string ReagentPrototype;
|
||||
|
||||
public Dictionary<string, ReagentEffectsGuideEntry>? GuideEntries;
|
||||
|
||||
public ReagentGuideEntry(ReagentPrototype proto, IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
ReagentPrototype = proto.ID;
|
||||
GuideEntries = proto.Metabolisms?
|
||||
.Select(x => (x.Key, x.Value.MakeGuideEntry(prototype, entSys)))
|
||||
.ToDictionary(x => x.Key, x => x.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DataDefinition]
|
||||
public sealed class ReagentEffectsEntry
|
||||
{
|
||||
@@ -173,6 +192,30 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[JsonPropertyName("effects")]
|
||||
[DataField("effects", required: true)]
|
||||
public ReagentEffect[] Effects = default!;
|
||||
|
||||
public ReagentEffectsGuideEntry MakeGuideEntry(IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
return new ReagentEffectsGuideEntry(MetabolismRate,
|
||||
Effects
|
||||
.Select(x => x.GuidebookEffectDescription(prototype, entSys)) // hate.
|
||||
.Where(x => x is not null)
|
||||
.Select(x => x!)
|
||||
.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public struct ReagentEffectsGuideEntry
|
||||
{
|
||||
public FixedPoint2 MetabolismRate;
|
||||
|
||||
public string[] EffectDescriptions;
|
||||
|
||||
public ReagentEffectsGuideEntry(FixedPoint2 metabolismRate, string[] effectDescriptions)
|
||||
{
|
||||
MetabolismRate = metabolismRate;
|
||||
EffectDescriptions = effectDescriptions;
|
||||
}
|
||||
}
|
||||
|
||||
[DataDefinition]
|
||||
|
||||
Reference in New Issue
Block a user