Ejemplo n.º 1
0
        public bool Matches(CraftingContainer container)
        {
            bool CheckMatch(int x, int y, bool flipX)
            {
                for (int i = 0; i < container.ContainerSize.X; i++)
                {
                    for (int j = 0; j < container.ContainerSize.Y; j++)
                    {
                        int k = i - x;
                        int l = j - y;

                        char ingredientKey = ' ';

                        if (k >= 0 && l >= 0 && k < Width && l < Height)
                        {
                            if (flipX)
                            {
                                ingredientKey = RecipeLayouts[l][Width - k - 1];
                            }
                            else
                            {
                                ingredientKey = RecipeLayouts[l][k];
                            }
                        }

                        if (ingredientKey == ' ' && container.GetItemStackByLocation(i, (int)container.ContainerSize.Y - j - 1) == null)
                        {
                            continue;
                        }

                        if (ingredientKey == ' ' ||
                            container.GetItemStackByLocation(i, (int)container.ContainerSize.Y - j - 1) == null ||
                            container.GetItemStackByLocation(i, (int)container.ContainerSize.Y - j - 1).ItemKey != ItemsKey[ingredientKey])
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }

            for (int i = 0; i <= container.ContainerSize.X - Width; i++)
            {
                for (int y = 0; y <= container.ContainerSize.Y - Height; y++)
                {
                    if (CheckMatch(i, y, true))
                    {
                        return(true);
                    }

                    if (CheckMatch(i, y, false))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Typically called by the owner of the CraftingContainer
        /// </summary>
        public void Bind(List <Recipe> recipes, CraftingContainer crafter, Inventory inventory)
        {
            _crafter = crafter;
            _crafter.OnCraftingQueued     += OnCraftingQueued;
            _crafter.OnCraftingCompleteUI += OnCraftingComplete;
            _crafter.OnCraftingBegin      += StartProgressBar;

            _recipes = recipes;

            _inventory = inventory;
            _inventory.OnInventoryChanged += SetCanAffordOnButtons;

            BindToUI();
        }
Ejemplo n.º 3
0
        // Crafting items here are temporary. They will eventually work entirely through Placeables
        private void InstantiateCraftingContainer()
        {
            // standard unity instantiation
            var crafterGo = new GameObject();

            crafterGo.name = "crafting_container";
            crafterGo.transform.SetParent(_layers[LayerType.Core].transform);
            var crafter = crafterGo.GetOrAddComponent <CraftingContainer>();

            // until single instances are figured out
            crafter.WorldClock = _worldClock;

            // bind to container
            crafter.Info = _productLookup.GetContainers().FirstOrDefault();
            _crafter     = crafter;
        }
Ejemplo n.º 4
0
        public static CraftingRecipe GetMatchingRecipe(CraftingContainer container)
        {
            CraftingRecipe recipe = null;

            for (int i = 0; i < recipes.Count; i++)
            {
                CraftingRecipe rec = recipes[i];

                if (rec.Matches(container))
                {
                    recipe = rec;
                    break;
                }
            }

            return(recipe);
        }
Ejemplo n.º 5
0
        // Factory binds to Inventory and initializes its container. Will begin crafting if InitialRecipe not null
        public void Initialize(Inventory inventory, ProductLookup productLookup)
        {
            _inventory     = inventory;
            _productLookup = productLookup;
            if (_container == null)
            {
                _container      = gameObject.GetOrAddComponent <CraftingContainer>();
                _container.Info = ProductLookup.Instance.GetContainer(_containerType);
                _container.OnCraftingComplete += StoreProductAndRestartCrafting;
            }

            LoadRecipes();
            if (!string.IsNullOrEmpty(InitialRecipe))
            {
                var recipe = _recipes.FirstOrDefault(i => i.ResultProductName == InitialRecipe);
                if (recipe == null)
                {
                    throw new UnityException(string.Format("ProductFactory initialized with recipe it doesnt have: {0}", InitialRecipe));
                }
                StartCrafting(recipe);
            }
        }