Add plant metabolism effects to chemical guidebook (#28038)

* draft one of plant metabolism guidebook

* loc fix?

* add attributes loc

* fix loc syntax

* improved appearance

* last commit was undercooked, my bad

* last commit was still undercooked, my worse

* last commit was even still undercooked, my worst

* Addressed comments?

* Fix newlines

* Hopefully this works

* Cleanup, I think

* 2xs
This commit is contained in:
Flesh
2024-05-20 01:01:44 +02:00
committed by GitHub
parent f2df51660d
commit c551cafdae
22 changed files with 154 additions and 6 deletions

View File

@@ -47,6 +47,17 @@
</CollapsibleBody>
</Collapsible>
</BoxContainer>
<BoxContainer Name="PlantMetabolismsContainer" HorizontalExpand="True">
<Collapsible>
<CollapsibleHeading Title="{Loc 'guidebook-reagent-plant-metabolisms-header'}"/>
<CollapsibleBody>
<BoxContainer Name="PlantMetabolismsDescriptionContainer"
Orientation="Vertical"
Margin="10 0 10 0"
HorizontalExpand="True"/>
</CollapsibleBody>
</Collapsible>
</BoxContainer>
<BoxContainer Margin="10 5 10 10" HorizontalExpand="True">
<!-- The troublemaker !-->
<RichTextLabel Name="ReagentDescription" HorizontalAlignment="Left"/>

View File

@@ -157,6 +157,39 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
}
#endregion
#region PlantMetabolisms
if (_chemistryGuideData.ReagentGuideRegistry.TryGetValue(reagent.ID, out var guideEntryRegistryPlant) &&
guideEntryRegistryPlant.PlantMetabolisms != null &&
guideEntryRegistryPlant.PlantMetabolisms.Count > 0)
{
PlantMetabolismsDescriptionContainer.Children.Clear();
var metabolismLabel = new RichTextLabel();
metabolismLabel.SetMarkup(Loc.GetString("guidebook-reagent-plant-metabolisms-rate"));
var descriptionLabel = new RichTextLabel
{
Margin = new Thickness(25, 0, 10, 0)
};
var descMsg = new FormattedMessage();
var descriptionsCount = guideEntryRegistryPlant.PlantMetabolisms.Count;
var i = 0;
foreach (var effectString in guideEntryRegistryPlant.PlantMetabolisms)
{
descMsg.AddMarkup(effectString);
i++;
if (i < descriptionsCount)
descMsg.PushNewline();
}
descriptionLabel.SetMessage(descMsg);
PlantMetabolismsDescriptionContainer.AddChild(metabolismLabel);
PlantMetabolismsDescriptionContainer.AddChild(descriptionLabel);
}
else
{
PlantMetabolismsContainer.Visible = false;
}
#endregion
GenerateSources(reagent);
FormattedMessage description = new();

View File

@@ -15,6 +15,18 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[DataField]
public float Prob { get; protected set; } = 1; // = (80);
/// <summary>
/// Localisation key for the name of the adjusted attribute. Used for guidebook descriptions.
/// </summary>
[DataField]
public abstract string GuidebookAttributeName { get; set; }
/// <summary>
/// Whether the attribute in question is a good thing. Used for guidebook descriptions to determine the color of the number.
/// </summary>
[DataField]
public virtual bool GuidebookIsAttributePositive { get; protected set; } = true;
/// <summary>
/// Checks if the plant holder can metabolize the reagent or not. Checks if it has an alive plant by default.
/// </summary>
@@ -40,6 +52,18 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
return !(Prob <= 0f) && IoCManager.Resolve<IRobustRandom>().Prob(Prob);
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-missing", ("chance", Probability));
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
{
string color;
if (GuidebookIsAttributePositive ^ Amount < 0.0)
{
color = "green";
}
else
{
color = "red";
}
return Loc.GetString("reagent-effect-guidebook-plant-attribute", ("attribute", Loc.GetString(GuidebookAttributeName)), ("amount", Amount.ToString("0.00")), ("colorName", color), ("chance", Probability));
}
}
}

View File

@@ -5,6 +5,9 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
public sealed partial class PlantAdjustHealth : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-health";
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -4,6 +4,9 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
public sealed partial class PlantAdjustMutationLevel : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-mutation-level";
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -6,6 +6,8 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAdjustMutationMod : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-mutation-mod";
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -7,6 +7,8 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAdjustNutrition : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-nutrition";
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager, mustHaveAlivePlant: false))

View File

@@ -6,6 +6,9 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAdjustPests : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-pests";
public override bool GuidebookIsAttributePositive { get; protected set; } = false;
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -6,6 +6,9 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAdjustToxins : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-toxins";
public override bool GuidebookIsAttributePositive { get; protected set; } = false;
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -7,6 +7,8 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAdjustWater : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-water";
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager, mustHaveAlivePlant: false))

View File

@@ -6,6 +6,9 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAdjustWeeds : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-weeds";
public override bool GuidebookIsAttributePositive { get; protected set; } = false;
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -7,6 +7,8 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
[UsedImplicitly]
public sealed partial class PlantAffectGrowth : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-growth";
public override void Effect(ReagentEffectArgs args)
{
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))

View File

@@ -28,6 +28,6 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
plantHolderComp.ForceUpdate = true;
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-missing", ("chance", Probability));
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-cryoxadone", ("chance", Probability));
}
}

View File

@@ -36,6 +36,6 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
}
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-missing", ("chance", Probability));
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-diethylamine", ("chance", Probability));
}
}

View File

@@ -19,6 +19,6 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
plantHolderComp.Seed.Viable = true;
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-missing", ("chance", Probability));
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-phalanximine", ("chance", Probability));
}
}

View File

@@ -49,6 +49,6 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
}
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-missing", ("chance", Probability));
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-robust-harvest", ("seedlesstreshold", PotencySeedlessThreshold), ("limit", PotencyLimit), ("increase", PotencyIncrease), ("chance", Probability));
}
}

View File

@@ -195,12 +195,22 @@ namespace Content.Shared.Chemistry.Reagent
public Dictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsGuideEntry>? GuideEntries;
public List<string>? PlantMetabolisms = null;
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);
if (proto.PlantMetabolisms.Count > 0)
{
PlantMetabolisms = new List<string> (proto.PlantMetabolisms
.Select(x => x.GuidebookEffectDescription(prototype, entSys))
.Where(x => x is not null)
.Select(x => x!)
.ToArray());
}
}
}

View File

@@ -15,6 +15,8 @@ guidebook-reagent-sources-ent-wrapper = [bold]{$name}[/bold] \[1\]
guidebook-reagent-sources-gas-wrapper = [bold]{$name} (gas)[/bold] \[1\]
guidebook-reagent-effects-header = Effects
guidebook-reagent-effects-metabolism-group-rate = [bold]{$group}[/bold] [color=gray]({$rate} units per second)[/color]
guidebook-reagent-plant-metabolisms-header = Plant Metabolism
guidebook-reagent-plant-metabolisms-rate = [bold]Plant Metabolism[/bold] [color=gray](1 unit every 3 seconds as base)[/color]
guidebook-reagent-physical-description = [italic]Seems to be {$description}.[/italic]
guidebook-reagent-recipes-mix-info = {$minTemp ->
[0] {$hasMax ->

View File

@@ -350,3 +350,33 @@ reagent-effect-guidebook-missing =
[1] Causes
*[other] cause
} an unknown effect as nobody has written this effect yet
reagent-effect-guidebook-plant-attribute =
{ $chance ->
[1] Adjusts
*[other] adjust
} {$attribute} by [color={$colorName}]{$amount}[/color]
reagent-effect-guidebook-plant-cryoxadone =
{ $chance ->
[1] Ages back
*[other] age back
} the plant, depending on the plant's age and time to grow
reagent-effect-guidebook-plant-phalanximine =
{ $chance ->
[1] Makes
*[other] make
} a plant not viable due to mutation viable again
reagent-effect-guidebook-plant-diethylamine =
{ $chance ->
[1] Increases
*[other] increase
} the plant's lifespan and/or base health with 10% chance for each.
reagent-effect-guidebook-plant-robust-harvest =
{ $chance ->
[1] Increases
*[other] increase
} the plant's potency by {$increase} up to a maximum of {$limit}. Causes the plant to lose its seeds once the potency reaches {$seedlesstreshold}. Trying to add potency over {$limit} may cause decrease in yield at a 10% chance.

View File

@@ -0,0 +1,9 @@
plant-attribute-growth = age
plant-attribute-water = water level
plant-attribute-weeds = weeds level
plant-attribute-toxins = toxins level
plant-attribute-nutrition = nutrition level
plant-attribute-mutation-level = mutation level
plant-attribute-pests = pests level
plant-attribute-mutation-mod = mutation modifier
plant-attribute-health = health

View File

@@ -5,3 +5,4 @@ metabolism-group-alcohol = Alcohol
metabolism-group-food = Food
metabolism-group-drink = Drink
metabolism-group-gas = Gas
metabolism-group-plant-metabolisms = Plant Metabolism

View File

@@ -27,3 +27,8 @@
- type: metabolismGroup
id: Gas
name: metabolism-group-gas
# Dummy for the guide
- type: metabolismGroup
id: PlantMetabolisms
name: metabolism-group-plant-metabolisms