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
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-05 20:44:38 +03:00
|
|
|
using Content.Shared._CP14.Skill;
|
2024-08-06 21:25:59 +10:00
|
|
|
using Content.Shared._CP14.Workbench;
|
2025-07-05 20:44:38 +03:00
|
|
|
using Content.Shared.Placeable;
|
2024-08-06 21:25:59 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Workbench;
|
|
|
|
|
|
|
|
|
|
public sealed partial class CP14WorkbenchSystem
|
|
|
|
|
{
|
2025-07-05 20:44:38 +03:00
|
|
|
[Dependency] private readonly CP14SharedSkillSystem _skill = default!;
|
|
|
|
|
|
2024-08-06 21:25:59 +10:00
|
|
|
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-07-05 20:44:38 +03:00
|
|
|
private void UpdateUIRecipes(Entity<CP14WorkbenchComponent> entity)
|
2024-08-06 21:25:59 +10:00
|
|
|
{
|
2025-07-11 15:55:41 +03:00
|
|
|
var getResource = new CP14WorkbenchGetResourcesEvent();
|
|
|
|
|
RaiseLocalEvent(entity, getResource);
|
2025-07-05 20:44:38 +03:00
|
|
|
|
2025-07-11 15:55:41 +03:00
|
|
|
var resources = getResource.Resources;
|
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;
|
|
|
|
|
|
|
|
|
|
foreach (var requirement in indexedRecipe.Requirements)
|
|
|
|
|
{
|
2025-07-11 15:55:41 +03:00
|
|
|
if (!requirement.CheckRequirement(EntityManager, _proto, resources))
|
2025-03-27 17:20:20 +03:00
|
|
|
{
|
|
|
|
|
canCraft = false;
|
2025-07-05 20:44:38 +03:00
|
|
|
break;
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|