multiple workbench results
This commit is contained in:
@@ -54,7 +54,8 @@ public sealed partial class CP14WorkbenchRequirementControl : Control
|
||||
private void UpdateName()
|
||||
{
|
||||
var result = _prototype.Index(_recipePrototype.Result);
|
||||
Name.Text = Loc.GetString(result.Name);
|
||||
var counter = _recipePrototype.ResultCount > 1 ? $" x{_recipePrototype.ResultCount}" : "";
|
||||
Name.Text = $"{Loc.GetString(result.Name)} {counter}" ;
|
||||
}
|
||||
|
||||
private void UpdateView()
|
||||
|
||||
@@ -114,7 +114,8 @@ public sealed partial class CP14WorkbenchWindow : DefaultWindow
|
||||
var result = _prototype.Index(recipe.Result);
|
||||
|
||||
ItemView.SetPrototype(recipe.Result);
|
||||
ItemName.Text = result.Name;
|
||||
var counter = recipe.ResultCount > 1 ? $" x{recipe.ResultCount}" : "";
|
||||
ItemName.Text = result.Name + counter;
|
||||
ItemDescription.Text = result.Description;
|
||||
|
||||
ItemRequirements.RemoveAllChildren();
|
||||
|
||||
@@ -77,7 +77,9 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
if (!_proto.TryIndex(args.Recipe, out var recipe))
|
||||
return;
|
||||
|
||||
var placedEntities = _lookup.GetEntitiesInRange(Transform(ent).Coordinates, ent.Comp.WorkbenchRadius, LookupFlags.Uncontained);
|
||||
var placedEntities = _lookup.GetEntitiesInRange(Transform(ent).Coordinates,
|
||||
ent.Comp.WorkbenchRadius,
|
||||
LookupFlags.Uncontained);
|
||||
|
||||
if (!CanCraftRecipe(recipe, placedEntities, args.User))
|
||||
{
|
||||
@@ -85,23 +87,31 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_proto.TryIndex(args.Recipe, out var indexedRecipe))
|
||||
return;
|
||||
|
||||
if (recipe.KnowledgeRequired is not null)
|
||||
_knowledge.UseKnowledge(args.User, recipe.KnowledgeRequired.Value);
|
||||
|
||||
var resultEntity = Spawn(indexedRecipe.Result);
|
||||
_stack.TryMergeToContacts(resultEntity);
|
||||
|
||||
_solutionContainer.TryGetSolution(resultEntity, recipe.Solution, out var resultSolution, out _);
|
||||
if (recipe.TryMergeSolutions && resultSolution is not null)
|
||||
var resultEntities = new HashSet<EntityUid>();
|
||||
for (int i = 0; i < recipe.ResultCount; i++)
|
||||
{
|
||||
resultSolution.Value.Comp.Solution.MaxVolume = 0;
|
||||
_solutionContainer.RemoveAllSolution(resultSolution.Value); //If we combine ingredient solutions, we do not use the default solution prescribed in the entity.
|
||||
var resultEntity = Spawn(recipe.Result);
|
||||
resultEntities.Add(resultEntity);
|
||||
_transform.SetCoordinates(resultEntity, Transform(ent).Coordinates);
|
||||
_stack.TryMergeToContacts(resultEntity);
|
||||
|
||||
if (recipe.TryMergeSolutions)
|
||||
{
|
||||
_solutionContainer.TryGetSolution(resultEntity, recipe.Solution, out var resultSolution, out _);
|
||||
|
||||
if (resultSolution is not null)
|
||||
{
|
||||
resultSolution.Value.Comp.Solution.MaxVolume = 0;
|
||||
_solutionContainer.RemoveAllSolution(resultSolution
|
||||
.Value); //If we combine ingredient solutions, we do not use the default solution prescribed in the entity.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var requiredIngredient in recipe.Entities)
|
||||
foreach (var requiredIngredient in recipe.Entities)
|
||||
{
|
||||
var requiredCount = requiredIngredient.Value;
|
||||
foreach (var placedEntity in placedEntities)
|
||||
@@ -114,12 +124,33 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
if (placedProto == requiredIngredient.Key && requiredCount > 0)
|
||||
{
|
||||
// Trying merge solutions
|
||||
if (recipe.TryMergeSolutions
|
||||
&& resultSolution is not null
|
||||
&& _solutionContainer.TryGetSolution(placedEntity, recipe.Solution, out var ingredientSoln, out var ingredientSolution))
|
||||
if (recipe.TryMergeSolutions)
|
||||
{
|
||||
resultSolution.Value.Comp.Solution.MaxVolume += ingredientSoln.Value.Comp.Solution.MaxVolume;
|
||||
_solutionContainer.TryAddSolution(resultSolution.Value, ingredientSolution);
|
||||
_solutionContainer.TryGetSolution(placedEntity,
|
||||
recipe.Solution,
|
||||
out var ingredientSoln,
|
||||
out var ingredientSolution);
|
||||
|
||||
if (ingredientSoln is null ||
|
||||
ingredientSolution is null)
|
||||
continue;
|
||||
|
||||
var splitted = _solutionContainer.SplitSolution(ingredientSoln.Value,
|
||||
ingredientSolution.Volume / recipe.ResultCount);
|
||||
|
||||
foreach (var resultEntity in resultEntities)
|
||||
{
|
||||
_solutionContainer.TryGetSolution(resultEntity,
|
||||
recipe.Solution,
|
||||
out var resultSolution,
|
||||
out _);
|
||||
if (resultSolution is not null)
|
||||
{
|
||||
resultSolution.Value.Comp.Solution.MaxVolume +=
|
||||
ingredientSoln.Value.Comp.Solution.MaxVolume / recipe.ResultCount;
|
||||
_solutionContainer.TryAddSolution(resultSolution.Value, splitted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requiredCount--;
|
||||
@@ -149,12 +180,14 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
requiredCount -= count;
|
||||
}
|
||||
}
|
||||
_transform.SetCoordinates(resultEntity, Transform(ent).Coordinates);
|
||||
|
||||
UpdateUIRecipes(ent, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void StartCraft(Entity<CP14WorkbenchComponent> workbench, EntityUid user, CP14WorkbenchRecipePrototype recipe)
|
||||
private void StartCraft(Entity<CP14WorkbenchComponent> workbench,
|
||||
EntityUid user,
|
||||
CP14WorkbenchRecipePrototype recipe)
|
||||
{
|
||||
var craftDoAfter = new CP14CraftDoAfterEvent
|
||||
{
|
||||
@@ -185,7 +218,7 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
|
||||
//Ingredients check
|
||||
var indexedIngredients = IndexIngredients(entities);
|
||||
foreach (var requiredIngredient in recipe.Entities)
|
||||
foreach (var requiredIngredient in recipe.Entities)
|
||||
{
|
||||
if (!indexedIngredients.TryGetValue(requiredIngredient.Key, out var availableQuantity) ||
|
||||
availableQuantity < requiredIngredient.Value)
|
||||
@@ -209,6 +242,7 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
if (count < value)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -227,6 +261,7 @@ public sealed partial class CP14WorkbenchSystem : SharedCP14WorkbenchSystem
|
||||
else
|
||||
indexedIngredients[protoId] = 1;
|
||||
}
|
||||
|
||||
return indexedIngredients;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ public sealed class CP14WorkbenchRecipePrototype : IPrototype
|
||||
[DataField(required: true)]
|
||||
public EntProtoId Result;
|
||||
|
||||
[DataField]
|
||||
public int ResultCount = 1;
|
||||
|
||||
[DataField]
|
||||
public bool TryMergeSolutions = false;
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
stacks:
|
||||
CP14CopperBar: 1
|
||||
result: CP14Crossbolt
|
||||
resultCount: 3
|
||||
knowledgeRequired: MetallForging
|
||||
|
||||
- type: CP14Recipe
|
||||
|
||||
Reference in New Issue
Block a user