using System; using System.Collections.Generic; using Content.Shared.Research.Prototypes; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; namespace Content.Shared.Lathe { [NetworkedComponent()] [Virtual] public class SharedLatheComponent : Component { [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] protected readonly IPrototypeManager PrototypeManager = default!; public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1) { if (!_entMan.TryGetComponent(Owner, out SharedMaterialStorageComponent? storage) || !_entMan.TryGetComponent(Owner, out SharedLatheDatabaseComponent? database)) return false; if (!database.Contains(recipe)) return false; foreach (var (material, amount) in recipe.RequiredMaterials) { if (storage[material] <= (amount * quantity)) return false; } return true; } public bool CanProduce(string id, int quantity = 1) { return PrototypeManager.TryIndex(id, out LatheRecipePrototype? recipe) && CanProduce(recipe, quantity); } /// /// Sent to the server to sync material storage and the recipe queue. /// [Serializable, NetSerializable] public sealed class LatheSyncRequestMessage : BoundUserInterfaceMessage { public LatheSyncRequestMessage() { } } /// /// Sent to the server to sync the lathe's technology database with the research server. /// [Serializable, NetSerializable] public sealed class LatheServerSyncMessage : BoundUserInterfaceMessage { public LatheServerSyncMessage() { } } /// /// Sent to the server to open the ResearchClient UI. /// [Serializable, NetSerializable] public sealed class LatheServerSelectionMessage : BoundUserInterfaceMessage { public LatheServerSelectionMessage() { } } /// /// Sent to the client when the lathe is producing a recipe. /// [Serializable, NetSerializable] public sealed class LatheProducingRecipeMessage : BoundUserInterfaceMessage { public readonly string ID; public LatheProducingRecipeMessage(string id) { ID = id; } } /// /// Sent to the client when the lathe stopped/finished producing a recipe. /// [Serializable, NetSerializable] public sealed class LatheStoppedProducingRecipeMessage : BoundUserInterfaceMessage { public LatheStoppedProducingRecipeMessage() { } } /// /// Sent to the client to let it know about the recipe queue. /// [Serializable, NetSerializable] public sealed class LatheFullQueueMessage : BoundUserInterfaceMessage { public readonly Queue Recipes; public LatheFullQueueMessage(Queue recipes) { Recipes = recipes; } } /// /// Sent to the server when a client queues a new recipe. /// [Serializable, NetSerializable] public sealed class LatheQueueRecipeMessage : BoundUserInterfaceMessage { public readonly string ID; public readonly int Quantity; public LatheQueueRecipeMessage(string id, int quantity) { ID = id; Quantity = quantity; } } [NetSerializable, Serializable] public enum LatheUiKey { Key, } } }