public KeyValuePair <int, int> TryToCraft(Dictionary <int, int> items)
    {
        KeyValuePair <int, int> nothing = new KeyValuePair <int, int>(-1, -1);

        if (items.Keys.Count < ItemsRequired.Count)
        {
            return(nothing);
        }
        foreach (KeyValuePair <int, int> item in items)
        {
            bool found = false;
            foreach (KeyValuePair <int, int> itemsR in ItemsRequired)
            {
                if (itemsR.Key == item.Key && item.Value >= itemsR.Value)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                return(nothing);
            }
        }

        return(Crafted.First());
    }
Ejemplo n.º 2
0
        public bool IsViable()
        {
            var map = new Dictionary <string, int>();

            foreach (Block curBlock in inputs)
            {
                if (curBlock != null)
                {
                    int count;
                    if (map.TryGetValue(curBlock.BlockType, out count))
                    {
                        map[curBlock.BlockType] += 1;
                    }
                    else
                    {
                        map.Add(curBlock.BlockType, 1);
                    }
                }
            }

            bool result = true;

            foreach (var pair in map)
            {
                if (pair.Value > Inventory.GetCount(pair.Key))
                {
                    result = false;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private void Crafting()
        {
            var inventory = GameController.Instance.Player.Inventory;

            if (!this.Recipe.CanCreate(inventory))
            {
                return;
            }

            var productItem = this.Recipe.ProductItemSpec;

            Craft.Crafting(inventory, this.Recipe);
            UniRxEvent.GlobalBroker.Publish(Crafted.Get(productItem.Hash));
        }
Ejemplo n.º 4
0
 public Recipe(Crafted newResult, Block[,] newInputs)
 {
     inputs = newInputs;
     result = newResult;
     result.SetRecipe(this);
 }