/// <summary>
    /// Pushes crafting material of given type onto
    /// crafting menu's "On Deck" list
    /// </summary>
    /// <param name="materialToPush">type of material to push</param>
    /// <param name="amount">IGNORED - needed to listen for remove materials event</param>
    void PushMaterial(CraftingMaterials materialToPush, int amount)
    {
        // if materials currently on deck isn't above max
        if (materialsOnDeck.Count < maxMaterialsOnDeck)
        {
            // push crafting material onto deck
            materialsOnDeck.Add(materialToPush);
            CraftingMaterialOnDeck newOnDeck = Instantiate(onDeckMaterialTemplate, parentContainer).GetComponent <CraftingMaterialOnDeck>();

            // modify visual elements of new on deck crafting material
            newOnDeck.Icon         = craftingMaterialsIcons[(int)materialToPush];
            newOnDeck.MaterialType = materialToPush;

            // if user pushed last material onto deck
            if (materialsOnDeck.Count == maxMaterialsOnDeck)
            {
                // determine whether player can craft an item and return
                myWeaponCrafter.DetermineItemFromMaterials(materialsOnDeck.ToArray());
                return;
            }

            // didn't return, play standard push sound effect
            AudioManager.Play(pushSound, true);
        }
        // otherwise (materials on deck plus new exceeds max)
        else
        {
            // discard material, returning it to player's inventory
            addMaterialsEvent.Invoke(materialToPush, 1);

            // play appropriate sound effect
            AudioManager.Play(cantPushSound, true);
        }
    }
 /// <summary>
 /// Adds all possible permutations of a given
 /// crafting material combination into registry.
 /// NOTE: Code taken from:
 /// https://www.geeksforgeeks.org/c-program-to-print-all-permutations-of-a-given-string-2/
 /// </summary>
 /// <param name="combination">combination of materials to permute</param>
 /// <param name="startingIndex">index of first element in combination</param>
 /// <param name="endingIndex">index of last element in combination</param>
 static void Permute(CraftingMaterials[] combination, WeaponType craftableItem, int startingIndex, int endingIndex)
 {
     // if starting index matches end (fully permuted)
     if (startingIndex == endingIndex)
     {
         // add deep copy of combination to registry
         CraftingMaterials[] newCombo = new CraftingMaterials[combination.Length];
         for (int i = 0; i < combination.Length; i++)
         {
             newCombo[i] = combination[i];
         }
         materialsToWeapons.Add(newCombo, craftableItem);
     }
     // otherwise (still needs to be permuted)
     else
     {
         // swap elements in current combination and continue permuting
         for (int i = startingIndex; i <= endingIndex; i++)
         {
             combination = SwapElements(combination, startingIndex, i);
             Permute(combination, craftableItem, startingIndex + 1, endingIndex);
             combination = SwapElements(combination, startingIndex, i);
         }
     }
 }
    /// <summary>
    /// Swaps two elements in combination, returning new combination.
    /// Code based on:
    /// https://www.geeksforgeeks.org/c-program-to-print-all-permutations-of-a-given-string-2/
    /// </summary>
    /// <param name="combination">combination to swap elements within</param>
    /// <param name="a">element to swap with b</param>
    /// <param name="b">element to swap with a</param>
    /// <returns>combination with swapped elements</returns>
    static CraftingMaterials[] SwapElements(CraftingMaterials[] combination, int a, int b)
    {
        CraftingMaterials temp = combination[a];

        combination[a] = combination[b];
        combination[b] = temp;
        return(combination);
    }
Example #4
0
    /// <summary>
    /// Updates material holders on UI to reflect player's
    /// current inventory, adding or removing holders if necessary
    /// </summary>
    /// <param name="materialToUpdate">type of material to be updated</param>
    /// <param name="newAmount">new amount corresponding to material to update</param>
    void UpdateMaterial(CraftingMaterials materialToUpdate, int newAmount)
    {
        // if new amount does not remove material from inventory
        if (newAmount > 0)
        {
            // attempt to update material's amount (assumes material already exists in player's inventory)
            try
            {
                materialHolders[materialToUpdate].Amount = newAmount;
            }
            // add new material holder to list (accessing material on UI by type returned nothing)
            catch
            {
                // add new material to inventory
                materialHolders.Add(materialToUpdate,
                                    Instantiate(defaultMaterialHolder, parentContainer).GetComponent <CraftingMaterialHolder>());

                // set icon, color, amount, and name of material
                materialHolders[materialToUpdate].Icon         = craftingMaterialsIcons[(int)materialToUpdate];
                materialHolders[materialToUpdate].Amount       = newAmount;
                materialHolders[materialToUpdate].MaterialType = materialToUpdate;
            }
        }
        // otherwise (new amount is 0 or less)
        else
        {
            // attempt to remove material type from inventory
            try
            {
                Destroy(materialHolders[materialToUpdate].gameObject);
                materialHolders.Remove(materialToUpdate);
            }
            // print warning if material to add does not exist in player's inventory
            catch
            {
                Debug.LogWarning("WARNING: Attempting to remove crafting material in UI that does not exist.");
            }
        }
    }
Example #5
0
 /// <summary>
 /// Removes materials of given type from player's inventory
 /// </summary>
 /// <param name="materialToRemove">type of material to remove</param>
 /// <param name="amount">amount to remove</param>
 void RemoveMaterials(CraftingMaterials materialToRemove, int amount)
 {
     materialsCarried[(int)materialToRemove] = Mathf.Max(0, materialsCarried[(int)materialToRemove] - amount);
     updateUIEvent.Invoke(materialToRemove, materialsCarried[(int)materialToRemove]);
 }
Example #6
0
 /// <summary>
 /// Adds materials of given type to player's inventory
 /// </summary>
 /// <param name="materialToAdd">type of material to add</param>
 /// <param name="amount">amount to add</param>
 void AddMaterials(CraftingMaterials materialToAdd, int amount)
 {
     materialsCarried[(int)materialToAdd] = Mathf.Min(materialCap, materialsCarried[(int)materialToAdd] + amount);
     updateUIEvent.Invoke(materialToAdd, materialsCarried[(int)materialToAdd]);
 }
Example #7
0
    /// <summary>
    /// Flashes vignette on bottom screen when player collects a crafting material.
    /// Note: Method ignores parameters -- needed only to listen for Add Material event.
    /// </summary>
    /// <param name="material">material to add - ignored</param>
    /// <param name="amount">amount by which to add - ignored</param>
    void HandleCraftingMaterialCollect(CraftingMaterials material, int amount)
    {
        IEnumerator flashCollect = FlashMaterialVignette(matCollectFlashTime);

        StartCoroutine(flashCollect);
    }
 /// <summary>
 /// Removes popped crafting material from interal list
 /// </summary>
 /// <param name="materialPopped">material to remove</param>
 void PopMaterial(CraftingMaterials materialPopped)
 {
     // remove material and empty craftable item slot
     materialsOnDeck.Remove(materialPopped);
     myWeaponCrafter.EmptyCraftableItemSlot();
 }