Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public GuideReagentEmbed(ReagentPrototype reagent) : this()
GenerateControl(reagent);
}

public GuideReagentEmbed(ReactionPrototype reagent) : this()
{
GenerateControl(reagent);
}

public bool CheckMatchesSearch(string query)
{
return this.ChildrenContainText(query);
Expand Down Expand Up @@ -245,6 +250,144 @@ private void GenerateControl(ReagentPrototype reagent)
ReagentDescription.SetMessage(description);
}

private void GenerateControl(ReactionPrototype reagent)
{
RepresentedPrototype = reagent;

NameBackground.PanelOverride = new StyleBoxFlat
{
BackgroundColor = Color.Black
};

if (reagent.Effects.Length < 1)
return;
IEnumerable<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity> spawnEvents = reagent.Effects.OfType<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity>();
if (spawnEvents.Count() == 0)
return;

var spawnId = spawnEvents.First().Entity;
ReagentName.SetMarkup(Loc.GetString("guidebook-reagent-name",
("color", Color.White), ("name", _prototype.Index<EntityPrototype>(spawnId).Name)));

_sawmill.Info($"{reagent.ID}");
#region Recipe
var reactions = _prototype.EnumeratePrototypes<ReactionPrototype>()
.Where(p => !p.Source && p.Effects.Length >= 1)
.OrderBy(p => p.Priority)
.ThenBy(p => p.Products.Count)
.ToList();

if (reactions.Any())
{
foreach (var reactionPrototype in reactions)
{
IEnumerable<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity> stuff = reactionPrototype.Effects.OfType<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity>();
if (stuff.Count() >= 1 && stuff.First().Entity == spawnId)
{
RecipesDescriptionContainer.AddChild(new GuideReagentReaction(reactionPrototype, _prototype, _systemManager, spawnId));
}
}
}
else
{
RecipesContainer.Visible = false;
}
#endregion

#region Effects
if (_chemistryGuideData.ReagentGuideRegistry.TryGetValue(reagent.ID, out var guideEntryRegistry) &&
guideEntryRegistry.GuideEntries != null &&
guideEntryRegistry.GuideEntries.Values.Any(pair => pair.EffectDescriptions.Any() || pair.Metabolites?.Any() == true))
{
EffectsDescriptionContainer.Children.Clear();
foreach (var (stage, effect) in guideEntryRegistry.GuideEntries)
{
var hasMetabolites = effect.Metabolites?.Any() == true;
if (!effect.EffectDescriptions.Any() && !hasMetabolites)
continue;

var groupLabel = new RichTextLabel();
groupLabel.SetMarkup(Loc.GetString("guidebook-reagent-effects-metabolism-stage-rate",
("stage", _prototype.Index<MetabolismStagePrototype>(stage).LocalizedName), ("rate", effect.MetabolismRate)));
var descriptionLabel = new RichTextLabel
{
Margin = new Thickness(25, 0, 10, 0)
};

var descMsg = new FormattedMessage();
var descriptionsCount = effect.EffectDescriptions.Length;
var i = 0;
foreach (var effectString in effect.EffectDescriptions)
{
descMsg.AddMarkupOrThrow(effectString);
i++;
if (i < descriptionsCount || hasMetabolites)
descMsg.PushNewline();
}
if (hasMetabolites)
{
var metabolites = new List<string>();
foreach (var (metabolite, ratio) in effect.Metabolites!)
{
metabolites.Add(Loc.GetString("guidebook-reagent-effects-metabolite-item", ("rate", (double)ratio), ("reagent", _prototype.Index(metabolite).LocalizedName)));
}
metabolites.Sort();

descMsg.AddMarkupOrThrow(Loc.GetString("guidebook-reagent-effects-metabolites", ("items", ContentLocalizationManager.FormatList(metabolites))));
}
descriptionLabel.SetMessage(descMsg);

EffectsDescriptionContainer.AddChild(groupLabel);
EffectsDescriptionContainer.AddChild(descriptionLabel);
}
}
else
{
EffectsContainer.Visible = false;
}
#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.AddMarkupOrThrow(effectString);
i++;
if (i < descriptionsCount)
descMsg.PushNewline();
}
descriptionLabel.SetMessage(descMsg);

PlantMetabolismsDescriptionContainer.AddChild(metabolismLabel);
PlantMetabolismsDescriptionContainer.AddChild(descriptionLabel);
}
else
{
PlantMetabolismsContainer.Visible = false;
}
#endregion
SourcesContainer.Visible = false;

FormattedMessage description = new();
description.AddText(_prototype.Index<EntityPrototype>(spawnId).Description);


ReagentDescription.SetMessage(description);
}

private void GenerateSources(ReagentPrototype reagent)
{
var sources = _chemistryGuideData.GetReagentSources(reagent.ID);
Expand Down
65 changes: 55 additions & 10 deletions Content.Client/Guidebook/Controls/GuideReagentGroupEmbed.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Content.Shared.Chemistry.Reaction;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -32,12 +33,28 @@ public GuideReagentGroupEmbed()

public GuideReagentGroupEmbed(string group) : this()
{
var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
.Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
foreach (var reagent in prototypes)
if (group == "Precipitate")
{
var prototypes = _prototype.EnumeratePrototypes<ReactionPrototype>()
.Where(p => !p.Source && p.Effects.Length >= 1)
.OrderBy(p => p.Priority)
.ThenBy(p => p.Products.Count)
.ToList();
foreach (var reagent in prototypes)
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
}
}
else
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
.Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
foreach (var reagent in prototypes)
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
}
}
}

Expand All @@ -50,12 +67,40 @@ public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out
return false;
}

var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
.Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
foreach (var reagent in prototypes)
if (group == "Precipitate")
{
Dictionary<string, GuideReagentEmbed> precipitateDict = new Dictionary<string, GuideReagentEmbed>();
var prototypes = _prototype.EnumeratePrototypes<ReactionPrototype>()
.Where(p => !p.Source && p.Effects.Length >= 1)
.OrderBy(p => p.Priority)
.ThenBy(p => p.Products.Count)
.ToList();
foreach (var reagent in prototypes)
{
if (reagent.Effects.Length < 1)
continue;
IEnumerable<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity> spawnEvents = reagent.Effects.OfType<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity>();
if (spawnEvents.Count() == 0)
continue;
var spawnId = _prototype.Index<EntityPrototype>(spawnEvents.First().Entity).Name;
if (precipitateDict.ContainsKey(spawnId))
continue;
precipitateDict.Add(spawnId, new GuideReagentEmbed(reagent));
}
foreach (var key in precipitateDict.Keys.OrderBy(k => k))
{
GroupContainer.AddChild(precipitateDict[key]);
}
}
else
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
.Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
foreach (var reagent in prototypes)
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
}
}

control = this;
Expand Down
41 changes: 30 additions & 11 deletions Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ public GuideReagentReaction(IPrototypeManager protoMan)
_protoMan = protoMan;
}

public GuideReagentReaction(ReactionPrototype prototype, IPrototypeManager protoMan, IEntitySystemManager sysMan) : this(protoMan)
public GuideReagentReaction(ReactionPrototype prototype, IPrototypeManager protoMan, IEntitySystemManager sysMan, string prod = "") : this(protoMan)
{
Container container = ReactantsContainer;
SetReagents(prototype.Reactants, ref container, protoMan);
Container productContainer = ProductsContainer;
var products = new Dictionary<string, FixedPoint2>(prototype.Products);
if (prod != "")
{
products.Add(prod, 1);
}
foreach (var (reagent, reactantProto) in prototype.Reactants)
{
if (reactantProto.Catalyst)
Expand Down Expand Up @@ -156,16 +160,31 @@ private void SetReagents(Dictionary<string, FixedPoint2> reagents, ref Container
{
foreach (var (product, amount) in reagents.OrderByDescending(p => p.Value))
{
var productProto = protoMan.Index<ReagentPrototype>(product);
var msg = new FormattedMessage();
msg.AddMarkupOrThrow(Loc.GetString("guidebook-reagent-recipes-reagent-display",
("reagent", productProto.LocalizedName), ("ratio", amount)));

var label = new GuidebookRichPrototypeLink();
if (addLinks)
label.LinkedPrototype = productProto;
label.SetMessage(msg);
container.AddChild(label);
if (!protoMan.HasIndex<ReagentPrototype>(product))
{
var productProto = protoMan.Index<EntityPrototype>(product);
var msg = new FormattedMessage();
msg.AddMarkupOrThrow(Loc.GetString("guidebook-reagent-recipes-reagent-display",
("reagent", productProto.Name), ("ratio", amount)));
var label = new GuidebookRichPrototypeLink();
if (addLinks)
label.LinkedPrototype = productProto;
label.SetMessage(msg);
container.AddChild(label);
}
else
{
var productProto = protoMan.Index<ReagentPrototype>(product);
var msg = new FormattedMessage();
msg.AddMarkupOrThrow(Loc.GetString("guidebook-reagent-recipes-reagent-display",
("reagent", productProto.LocalizedName), ("ratio", amount)));

var label = new GuidebookRichPrototypeLink();
if (addLinks)
label.LinkedPrototype = productProto;
label.SetMessage(msg);
container.AddChild(label);
}
}
container.Visible = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/GameTicking/GameTicker.Spawning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void SpawnPlayer(ICommonSession player,
{
var character = GetPlayerProfile(player);
if (character == null)
return;
character = new HumanoidCharacterProfile();

var jobBans = _banManager.GetJobBans(player.UserId);
if (jobBans == null || jobId != null && jobBans.Contains(jobId)) //TODO: use IsRoleBanned directly?
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/guidebook/guides.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ guide-entry-radio = Radio and Speech
guide-entry-references = Tables & References
guide-entry-chemicals = Chemicals
guide-entry-drinks = Drinks
guide-entry-entities = Entity Recipes
guide-entry-foodrecipes = Food Recipes

guide-entry-elements = Elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
abstract: true
parent: BaseItem
id: BaseSoap
name: soap
components:
- type: Tag
tags:
Expand Down Expand Up @@ -72,6 +71,7 @@
- type: entity
parent: BaseSoap
id: Soap
name: soap
description: A cheap bar of soap. Doesn't smell.
components:
- type: Sprite
Expand All @@ -84,6 +84,7 @@
- type: entity
parent: BaseSoap
id: SoapNT
name: nanotrasen soap
description: A Nanotrasen brand bar of soap. Smells of plasma.
components:
- type: Sprite
Expand All @@ -107,6 +108,7 @@
- type: entity
parent: BaseSoap
id: SoapDeluxe
name: deluxe soap
description: A deluxe Waffle Co. brand bar of soap. Smells of strawberries.
components:
- type: Sprite
Expand All @@ -123,6 +125,7 @@
- type: entity
parent: [BaseSoap, BaseSyndicateContraband]
id: SoapSyndie
name: syndie soap
description: An untrustworthy bar of soap. Smells of fear.
components:
- type: Sprite
Expand Down Expand Up @@ -205,6 +208,7 @@
- type: entity
parent: BaseSoap
id: SoapHomemade
name: homemade soap
description: A homemade bar of soap. Smells of... well....
components:
- type: Sprite
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Guidebook/chemicals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
id: Others
name: guide-entry-others
text: "/ServerInfo/Guidebook/ChemicalTabs/Other.xml"
filterEnabled: True
filterEnabled: True
7 changes: 7 additions & 0 deletions Resources/Prototypes/Guidebook/references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
children:
- Chemicals
- Drinks
- EntityRecipes
- FoodRecipes
- Writing
- Lawsets
Expand All @@ -16,6 +17,12 @@
text: "/ServerInfo/Guidebook/ReferenceTables/Drinks.xml"
filterEnabled: True

- type: guideEntry
id: EntityRecipes
name: guide-entry-entities
text: "/ServerInfo/Guidebook/ReferenceTables/Entities.xml"
filterEnabled: True

- type: guideEntry
id: FoodRecipes
name: guide-entry-foodrecipes
Expand Down
Loading
Loading