Exemplo n.º 1
0
        public Crusher()
        {
            timer = new BaseLibrary.Timer(60, Callback);

            Handler = new ItemHandler(5)
            {
                Modes =
                {
                    [1] = SlotMode.Input,
                    [2] = SlotMode.Input,
                    [3] = SlotMode.Output,
                    [4] = SlotMode.Output
                }
            };

            Handler.IsItemValid += (slot, item) =>
            {
                switch (slot)
                {
                case 0:
                    return(item.modItem is BaseContainmentUnit);

                case 1:
                case 2:
                    return(Recipes.ContainsKey(item.type));

                default:
                    return(false);
                }
            };

            EnergyHandler = new EnergyHandler(10000, 1000);
        }
Exemplo n.º 2
0
 private void AddRecipe(Recipe recipe)
 {
     if (!Recipes.ContainsKey(recipe.SpellId))
     {
         Recipes.Add(recipe.SpellId, recipe);
         recipe.InitIngredients();
         recipe.InitTools();
     }
 }
Exemplo n.º 3
0
 public void AddRecipe(Recipe recipe)
 {
     if (Recipes.ContainsKey(recipe.ID))
     {
         return;
     }
     Recipes.Add(recipe.ID, recipe);
     recipe.InitIngredients();
     recipe.InitTools();
 }
Exemplo n.º 4
0
        public Recipe(int id, CraftSystem system, CraftItem item)
        {
            ID          = id;
            CraftSystem = system;
            CraftItem   = item;

            if (Recipes.ContainsKey(id))
            {
                throw new Exception("Attempting to create recipe with preexisting ID.");
            }

            Recipes.Add(id, this);
            LargestRecipeID = Math.Max(id, LargestRecipeID);
        }
Exemplo n.º 5
0
        private void Callback()
        {
            if (EnergyHandler.Energy < EnergyPerItem)
            {
                return;
            }

            int slot = Handler.GetFirstInput();

            if (slot != -1)
            {
                Item item = Handler.GetItemInSlot(slot);
                if (Recipes.ContainsKey(item.type) && Handler.OutputSlots.Any((x, i) => x.IsAir || x.type == Recipes[item.type] && x.stack < x.maxStack))
                {
                    for (int i = 0; i < Handler.Slots; i++)
                    {
                        if (Handler.Modes[i] != SlotMode.Output)
                        {
                            continue;
                        }

                        if (Handler.Items[i].type == Recipes[item.type] && Handler.Items[i].stack < Handler.Items[i].maxStack)
                        {
                            Handler.Items[i].stack++;
                            break;
                        }

                        if (Handler.Items[i].IsAir)
                        {
                            Handler.Items[i].SetDefaults(Recipes[item.type]);
                            Handler.Items[i].stack = 1;
                            break;
                        }
                    }

                    Handler.Shrink(slot, 1);
                    EnergyHandler.ExtractEnergy(EnergyPerItem);
                }
            }
        }
Exemplo n.º 6
0
        public Part GetRecipe(string code)
        {
            var key = Lookup.ContainsKey(code) ? Lookup[code] : code;

            return(Recipes.ContainsKey(key) ? Recipes[key] : null);
        }