internal bool Produce(LatheRecipePrototype recipe)
        {
            if (Producing || !CanProduce(recipe) || !Owner.TryGetComponent(out MaterialStorageComponent storage))
            {
                return(false);
            }

            _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue()));

            Producing        = true;
            _producingRecipe = recipe;

            foreach (var(material, amount) in recipe.RequiredMaterials)
            {
                // This should always return true, otherwise CanProduce f****d up.
                storage.RemoveMaterial(material, amount);
            }

            _userInterface.SendMessage(new LatheProducingRecipeMessage(recipe.ID));

            Timer.Spawn(recipe.CompleteTime, () =>
            {
                Producing        = false;
                _producingRecipe = null;
                Owner.EntityManager.TrySpawnEntityAt(recipe.Result, Owner.Transform.GridPosition, out var entity);
                _userInterface.SendMessage(new LatheStoppedProducingRecipeMessage());
            });

            return(true);
        }
 public override void AddRecipe(LatheRecipePrototype recipe)
 {
     if (Static)
     {
         return;
     }
     Dirty();
 }
 public override bool RemoveRecipe(LatheRecipePrototype recipe)
 {
     if (Static || !base.RemoveRecipe(recipe))
     {
         return(false);
     }
     Dirty();
     return(true);
 }
        /// <summary>
        ///     Unlocks a recipe but only if it's one of the allowed recipes on this protolathe.
        /// </summary>
        /// <param name="recipe">The recipe</param>
        /// <returns>Whether it could add it or not.</returns>
        public bool UnlockRecipe(LatheRecipePrototype recipe)
        {
            if (!ProtolatheRecipes.Contains(recipe))
            {
                return(false);
            }

            AddRecipe(recipe);

            return(true);
        }
Пример #5
0
 public void SetInfo(LatheRecipePrototype recipe)
 {
     _icon.Texture = recipe.Icon.Frame0();
     if (recipe.Name != null)
     {
         _nameLabel.Text = recipe.Name;
     }
     if (recipe.Description != null)
     {
         _description.Text = recipe.Description;
     }
 }
Пример #6
0
        public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
        {
            if (!Owner.TryGetComponent(out SharedMaterialStorageComponent? storage) ||
                !Owner.TryGetComponent(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 void Queue(LatheRecipePrototype recipe, int quantity = 1)
 {
     SendMessage(new SharedLatheComponent.LatheQueueRecipeMessage(recipe.ID, quantity));
 }