* pricing check 1 * Update CP14Economy.cs * seed and dye * mini tweak * seed and test mithril * hammer and pickaxe * blade * expensive check * fix test * Update CP14Workbench.cs * misc * misc 2 * Update CP14Workbench.cs * Update CP14Workbench.cs * misc 3 * misc 4 * misc 5 * meat * food * dough * Clothing * misc * food 2 * food 3 * Wallpaper * Wallpape 2 * Floor * Floor 2 * carpet * plushie * Plushie 2 * meat 66 * food 4 * misc 9 * misc 10 * Bucket * meat 8 * meat 10 * rope * TagResource deleted * meat 11 * meat 12 * meat 13 * meat 14 * meat 15 * fix * meat 16 --------- Co-authored-by: Nimfar11 <nimfiar@gmail.com> Co-authored-by: Nim <128169402+Nimfar11@users.noreply.github.com>
116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Chemistry.Reagent;
|
|
using Content.Shared.FixedPoint;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Shared._CP14.Workbench.Requirements;
|
|
|
|
public sealed partial class SolutionResource : CP14WorkbenchCraftRequirement
|
|
{
|
|
[DataField(required: true)]
|
|
public ProtoId<ReagentPrototype> Reagent = default!;
|
|
|
|
/// <summary>
|
|
/// How much impurity from other reagents is allowed?
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public float Purity = 1f;
|
|
|
|
[DataField(required: true)]
|
|
public FixedPoint2 Amount = 1f;
|
|
|
|
[DataField]
|
|
public EntProtoId DummyEntityIcon = "CP14LiquidDropDummy";
|
|
|
|
public override bool CheckRequirement(IEntityManager entManager,
|
|
IPrototypeManager protoManager,
|
|
HashSet<EntityUid> placedEntities)
|
|
{
|
|
var solutionSys = entManager.System<SharedSolutionContainerSystem>();
|
|
foreach (var ent in placedEntities)
|
|
{
|
|
if (!solutionSys.TryGetDrawableSolution(ent, out var soln, out var solution))
|
|
continue;
|
|
|
|
var volume = solution.Volume;
|
|
foreach (var (id, quantity) in solution.Contents)
|
|
{
|
|
if (id.Prototype != Reagent)
|
|
continue;
|
|
|
|
if (quantity < Amount)
|
|
continue;
|
|
|
|
//Purity check
|
|
if (quantity / volume < Purity)
|
|
continue;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override void PostCraft(IEntityManager entManager, IPrototypeManager protoManager, HashSet<EntityUid> placedEntities)
|
|
{
|
|
var solutionSys = entManager.System<SharedSolutionContainerSystem>();
|
|
foreach (var ent in placedEntities)
|
|
{
|
|
if (!solutionSys.TryGetDrawableSolution(ent, out var soln, out var solution))
|
|
continue;
|
|
|
|
var volume = solution.Volume;
|
|
if (volume < Amount)
|
|
continue;
|
|
|
|
foreach (var (id, quantity) in solution.Contents)
|
|
{
|
|
if (id.Prototype != Reagent)
|
|
continue;
|
|
|
|
//Purity check
|
|
if (quantity / volume < Purity)
|
|
continue;
|
|
|
|
solutionSys.Draw(ent, soln.Value, Amount);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override double GetPrice(IEntityManager entManager, IPrototypeManager protoManager)
|
|
{
|
|
if (!protoManager.TryIndex(Reagent, out var indexedReagent))
|
|
return 0;
|
|
|
|
return indexedReagent.PricePerUnit * (double)Amount;
|
|
}
|
|
|
|
public override string GetRequirementTitle(IPrototypeManager protoManager)
|
|
{
|
|
if (!protoManager.TryIndex(Reagent, out var indexedReagent))
|
|
return string.Empty;
|
|
|
|
return Loc.GetString("cp14-workbench-reagent-req",
|
|
("reagent", indexedReagent.LocalizedName),
|
|
("count", Amount),
|
|
("purity", Purity * 100));
|
|
}
|
|
|
|
public override EntityPrototype? GetRequirementEntityView(IPrototypeManager protoManager)
|
|
{
|
|
if (!protoManager.TryIndex(DummyEntityIcon, out var indexedEnt))
|
|
return null;
|
|
return indexedEnt;
|
|
}
|
|
|
|
public override Color GetRequirementColor(IPrototypeManager protoManager)
|
|
{
|
|
if (!protoManager.TryIndex(Reagent, out var indexedReagent))
|
|
return Color.White;
|
|
|
|
return indexedReagent.SubstanceColor;
|
|
}
|
|
}
|