Пример #1
0
    void RecipeDone()
    {
        foreach (ItemOutput output in CurrentRecipe.Recipe.Outputs)
        {
            ItemSpawner.Instance.SpawnItems(output.ContainedItem, SpawnPoint.transform.position, (uint)output.Amount);
        }
        Queue.Remove(CurrentRecipe);
        CurrentRecipe = null;
        Color newcolor = Color.white;

        newcolor.a         = 0f;
        RecipeSprite.color = newcolor;

        if (Queue.Count > 0)
        {
            StartRecipe();
        }
        else
        {
            if (OnRecipeOver != null)
            {
                OnRecipeOver();
            }
        }
    }
Пример #2
0
    public void AddRecipe()
    {
        PlayerInventory inventory = GameManager.Instance.Player.GetComponent <PlayerInventory>();

        if (ChosenRecipe == null)
        {
            // print("no recipes");

            return;
        }
        for (int i = 0; i < ChosenRecipe.Amount; i++)
        {
            Queue.Add(ChosenRecipe);
            foreach (CraftingIngredient ingredient in ChosenRecipe.Recipe.Ingredients)
            {
                inventory.RemoveItem(ingredient.ContainedItem, (uint)ingredient.Amount);
            }
        }
        ChosenItems.Clear();
        if (Queue.Count > 0)
        {
            StartRecipe();
        }
        ChosenRecipe = null;
    }
 void SelectRecipe(RecipeContainer pRecipe)
 {
     CurrentRecipe        = pRecipe;
     CurrentRecipe.Amount = 1;
     CurrentStation.RecipeManualSelect(CurrentRecipe);
     DrawRecipe();
 }
Пример #4
0
 public void RecipeManualSelect(RecipeContainer pRecipe)
 {
     ChosenRecipe = pRecipe;
     if (OnOutputChanged != null)
     {
         OnOutputChanged(this);
     }
 }
Пример #5
0
 public bool CheckIfKnows(RecipeContainer pRecipe)
 {
     if (KnownRecipes.Contains(pRecipe))
     {
         return(true);
     }
     return(false);
 }
Пример #6
0
 void DrawAmount(RecipeContainer pOutput)
 {
     if (pOutput != null)
     {
         AmountText.text = "x" + pOutput.Amount.ToString();
     }
     else
     {
         AmountText.text = string.Empty;
     }
 }
Пример #7
0
    public static RecipeContainer Load()
    {
        XmlSerializer   serializer      = new XmlSerializer(typeof(RecipeContainer));
        StreamReader    reader          = new StreamReader("Assets/Scripts/Recipes.xml");
        RecipeContainer recipeContainer = (RecipeContainer)serializer.Deserialize(reader);

        reader.Close();


        return(recipeContainer);
    }
Пример #8
0
    public void ReAddRecipeItems(RecipeContainer pRecipe)
    {
        PlayerInventory inventory = GameManager.Instance.Player.GetComponent <PlayerInventory>();

        for (int i = 0; i < pRecipe.Amount; i++)
        {
            foreach (CraftingIngredient ingredient in pRecipe.Recipe.Ingredients)
            {
                inventory.Add(ingredient.ContainedItem, (uint)ingredient.Amount, true);
            }
        }
    }
Пример #9
0
    void Awake()
    {
        m_recipes = new Dictionary <ItemType, ItemType[]>();
        m_recipes.Add(ItemType.HAMMER, new ItemType[] { ItemType.ROCK, ItemType.STICK, ItemType.WIRE });
        m_recipes.Add(ItemType.RAM, new ItemType[] { ItemType.CART, ItemType.LOG, ItemType.WIRE });
        m_recipes.Add(ItemType.DYNAMITE, new ItemType[] { ItemType.TUBE, ItemType.FUSE, ItemType.GUN_POWDER, ItemType.MATCH });

        Transform inventoryScreen = this.gameObject.transform.GetChild(0);
        int       lastChild       = inventoryScreen.childCount - 1;

        m_recipeContainer = inventoryScreen.GetChild(lastChild).gameObject.GetComponent <RecipeContainer>();
        m_player          = GameObject.FindGameObjectWithTag("Player").gameObject;
    }
Пример #10
0
    void StartRecipe()
    {
        CurrentRecipe       = Queue[0];
        RecipeSprite.sprite = CurrentRecipe.Recipe.Outputs[0].ContainedItem.Icon;
        Color newcolor = Color.white;

        newcolor.a         = 0.1f;
        RecipeSprite.color = newcolor;
        CurrentProgress    = 0;
        TargetProgress     = CurrentRecipe.Recipe.CraftingTime;
        if (OnRecipeChanged != null)
        {
            OnRecipeChanged();
        }
    }
 public bool CanCraft(RecipeContainer pRecipe)
 {
     if (Inventory == null)
     {
         return(false);
     }
     foreach (CraftingIngredient ingredient in pRecipe.Recipe.Ingredients)
     {
         if (Inventory.GetItemAmount(ingredient.ContainedItem) < ingredient.Amount)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #12
0
    public bool TeachRecipe(RecipeContainer pRecipe)
    {
        if (pRecipe == null)
        {
            return(false);
        }
        if (!KnownRecipes.Contains(pRecipe))
        {
            KnownRecipes.Add(pRecipe);
            string itemName = pRecipe.Recipe.Outputs[0].ContainedItem.Name;
            PixelCrushers.DialogueSystem.DialogueManager.ShowAlert("Learned new recipe: " + itemName);
            PixelCrushers.DialogueSystem.DialogueLua.SetVariable("CraftingManager Recipe" + KnownRecipes.Count, itemName);
            PixelCrushers.DialogueSystem.DialogueLua.SetVariable("CraftingManager RecipeAmount", KnownRecipes.Count);

            return(true);
        }
        return(false);
    }
Пример #13
0
    void SetRecipe()
    {
        if (RecipesInInput.Count < 1)
        {
            ChosenRecipe = null;
        }

        else if (RecipesInInput[RecipeIndex] != null)
        {
            ChosenRecipe = RecipesInInput[RecipeIndex];
        }
        else
        {
            ChosenRecipe = null;
        }
        if (OnOutputChanged != null)
        {
            OnOutputChanged(this);
        }
    }
Пример #14
0
    public void Reset()
    {
        CurrentRecipe = null;
        Color newcolor = Color.white;

        newcolor.a         = 0f;
        RecipeSprite.color = newcolor;
        ChosenRecipe       = null;

        foreach (RecipeContainer recipe in Queue)
        {
            ReAddRecipeItems(recipe);
        }
        Queue.Clear();

        if (OnRecipeOver != null)
        {
            OnRecipeOver();
        }
    }
Пример #15
0
    void DrawOutput(RecipeContainer pOutput)
    {
        if (OutputUI.Button != null)
        {
            OutputUI.Button.interactable = false;
        }

        if (pOutput != null)
        {
            int amount = pOutput.Recipe.Outputs[0].Amount * pOutput.Amount;


            OutputUI.ItemIcon.color  = Color.white;
            OutputUI.ItemIcon.sprite = pOutput.Recipe.Outputs[0].ContainedItem.Icon;

            OutputUI.ItemAmount.text = "x" + amount;
            if (OutputUI.ItemNameText != null)
            {
                OutputUI.ItemNameText.text = pOutput.Recipe.Outputs[0].ContainedItem.Name;
            }
        }
        else
        {
            if (OutputUI.ItemNameText != null)
            {
                OutputUI.ItemNameText.text = "No Recipe Selected";
            }
            OutputUI.ItemIcon.color  = new Color(0, 0, 0, 0);
            OutputUI.ItemAmount.text = "";
        }

        if (pOutput == null)
        {
            ConfirmBtn.interactable = false;
        }
        else
        {
            ConfirmBtn.interactable = true;
        }
    }
Пример #16
0
    /// <summary>
    /// actualiza para mostrar los botones disponibles. MODE: Constant Assist
    /// </summary>
    public void UpdateValue(int[] inventoryId, int[] inventoryValues, RecipeContainer recipeContainer, int mode)
    {
        _actualMode = mode;
        clearCanvas();
        switch (GetComponent <Dropdown>().value)
        {
        case 0:
            foreach (GameObject go in Material)
            {
                go.GetComponent <ButtonInventoryCanvas>().CheckAvailability(inventoryId, inventoryValues, recipeContainer, mode);
                go.SetActive(true);
            }
            break;

        case 1:
            foreach (GameObject go in Structures)
            {
                go.GetComponent <ButtonInventoryCanvas>().CheckAvailability(inventoryId, inventoryValues, recipeContainer, mode);
                go.SetActive(true);
            }
            break;

        case 2:
            foreach (GameObject go in Tools)
            {
                go.GetComponent <ButtonInventoryCanvas>().CheckAvailability(inventoryId, inventoryValues, recipeContainer, mode);
                go.SetActive(true);
            }
            break;

        case 3:
            foreach (GameObject go in Food)
            {
                go.GetComponent <ButtonInventoryCanvas>().CheckAvailability(inventoryId, inventoryValues, recipeContainer, mode);
                go.SetActive(true);
            }
            break;
        }
    }
Пример #17
0
 void SelectRecipe(RecipeContainer pRecipe)
 {
     CurrentRecipe = pRecipe.Recipe;
     DrawRecipe();
 }
Пример #18
0
    /// <summary>
    /// mira la disponibilidad de este boton según los objetos del inventario y el modo de abertura. MODE Const Assist
    /// </summary>
    /// <param name="inventoryId"></param>
    /// <param name="inventoryValues"></param>
    /// <param name="recipeContainer"></param>
    /// <param name="mode"></param>
    public void CheckAvailability(int[] inventoryId, int[] inventoryValues, RecipeContainer recipeContainer, int mode)
    {
        _actualMode = mode;
        rc          = recipeContainer;

        if (_myRecipe == null)
        {
            foreach (Recipe recipe in rc.Recipes)
            {
                if (recipe.Id == _id)
                {
                    _myRecipe = recipe;
                    break;
                }
            }
        }

        if (_myRecipe != null)
        {
            bool haveAll = true;
            foreach (ResourceXML resource in _myRecipe.Resources)
            {
                bool isInInventory = false;
                for (int i = 0; i < inventoryId.Length; i++)
                {
                    if (inventoryId[i] == resource.Id && inventoryValues[i] >= resource.Number)
                    {
                        isInInventory = true;
                    }
                }

                if (!isInInventory)
                {
                    haveAll = false;
                }
            }

            if (haveAll)
            {
                GetComponent <Button>().interactable = true;
            }
            else
            {
                GetComponent <Button>().interactable = false;
            }
        }
        else
        {
            GetComponent <Button>().interactable = false;
        }

        //Comprobacion de que se pueda activar el boton en el actual mode

        if (GetComponent <Button>().interactable)
        {
            foreach (int m in _myOpenModes)
            {
                //Debug.Log("openmode: " + m + "---actual: " + _actualMode);
                if (m == _actualMode)
                {
                    return;
                }
            }
            GetComponent <Button>().interactable = false;
        }
    }
    private void OnEnable()
    {
        _dropdown = GameObject.FindGameObjectWithTag("DropdownInventoryCanvas");

        _recipeContainer = RecipeContainer.Load();
    }