2024-08-29 20:23:33 +05:00
|
|
|
/*
|
|
|
|
|
* This file is sublicensed under MIT License
|
|
|
|
|
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-06 21:25:59 +10:00
|
|
|
using Content.Shared._CP14.Workbench;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Workbench;
|
|
|
|
|
|
|
|
|
|
public sealed partial class CP14WorkbenchSystem
|
|
|
|
|
{
|
|
|
|
|
private void OnCraft(Entity<CP14WorkbenchComponent> entity, ref CP14WorkbenchUiCraftMessage args)
|
|
|
|
|
{
|
|
|
|
|
if (!entity.Comp.Recipes.Contains(args.Recipe))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!_proto.TryIndex(args.Recipe, out var prototype))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StartCraft(entity, args.Actor, prototype);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 00:08:13 +03:00
|
|
|
private void UpdateUIRecipes(Entity<CP14WorkbenchComponent> entity, EntityUid user)
|
2024-08-06 21:25:59 +10:00
|
|
|
{
|
2024-09-28 01:29:02 +03:00
|
|
|
var placedEntities = _lookup.GetEntitiesInRange(Transform(entity).Coordinates, entity.Comp.WorkbenchRadius);
|
2024-08-06 21:25:59 +10:00
|
|
|
|
|
|
|
|
var recipes = new List<CP14WorkbenchUiRecipesEntry>();
|
|
|
|
|
foreach (var recipeId in entity.Comp.Recipes)
|
|
|
|
|
{
|
2025-01-15 00:34:08 +03:00
|
|
|
if (!_proto.TryIndex(recipeId, out var indexedRecipe))
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-03-27 17:20:20 +03:00
|
|
|
var canCraft = true;
|
|
|
|
|
var hidden = false;
|
|
|
|
|
|
|
|
|
|
foreach (var requirement in indexedRecipe.Requirements)
|
|
|
|
|
{
|
|
|
|
|
if (!requirement.CheckRequirement(EntityManager, _proto, placedEntities, user, indexedRecipe))
|
|
|
|
|
{
|
|
|
|
|
canCraft = false;
|
|
|
|
|
hidden = requirement.HideRecipe;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hidden)
|
|
|
|
|
continue;
|
2025-01-17 00:08:13 +03:00
|
|
|
|
2025-03-27 17:20:20 +03:00
|
|
|
var entry = new CP14WorkbenchUiRecipesEntry(recipeId, canCraft);
|
2024-08-06 21:25:59 +10:00
|
|
|
|
|
|
|
|
recipes.Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_userInterface.SetUiState(entity.Owner, CP14WorkbenchUiKey.Key, new CP14WorkbenchUiRecipesState(recipes));
|
|
|
|
|
}
|
|
|
|
|
}
|