using System.Collections; using System.Collections.Generic; using UnityEngine; using RPGCreationKit; using UnityEngine.UI; using TMPro; using System; using RPGCreationKit.Player; using UnityEngine.EventSystems; namespace RPGCreationKit { public class AlchemyManager : MonoBehaviour { public static AlchemyManager instance; private void Awake() { if (instance == null) instance = this; else { Debug.Log("Anomaly detected with the singleton pattern of 'AlchemyManager', do you have more than one AlchemyManager?"); Destroy(this); } } [Header("Alchemy Elements")] public GameObject AlchemyUI; public GameObject TopCompassUI; public GameObject PlayerStatsUI; public ItemsInListPoolManager AlchemyPoolManager; public TextMeshProUGUI Slot1; public TextMeshProUGUI Slot2; public TextMeshProUGUI Slot3; public TextMeshProUGUI Slot4; public TextMeshProUGUI Result; public TextMeshProUGUI ResultInfo; public bool S1Filled = false; public bool S2Filled = false; public bool S3Filled = false; public bool S4Filled = false; public ConsumableItem consumableItem1; public ConsumableItem consumableItem2; public ConsumableItem consumableItem3; public ConsumableItem consumableItem4; [Header("Alchemy Recipes")] public List Recipe = new List(); // public void OpenAlchemyPanel() { // Debug.Log("Schaken - Alchemy opened"); // if (AlchemyUI.activeSelf == true) { // RckPlayer.instance.input.SwitchCurrentActionMap("Player"); // RckPlayer.instance.isCrafting = false; // AlchemyUI.SetActive(false); // } else { // Debug.Log("Schaken - Alchemy panel is closed"); // RckPlayer.instance.input.SwitchCurrentActionMap("CraftingUI"); // AlchemyUI.SetActive(true); // RckPlayer.instance.isCrafting = true; // } // } public void FindOpenSlot(ConsumableItem A, int B) { if (CheckForDupes(A, B) == false) { if (S1Filled == false) { consumableItem1 = A; Slot1.text = A.ItemName; S1Filled = true; } else if (S2Filled == false) { consumableItem2 = A; Slot2.text = A.ItemName; S2Filled = true; } else if (S3Filled == false) { consumableItem3 = A; Slot3.text = A.ItemName; S3Filled = true; } else if (S4Filled == false) { consumableItem4 = A; Slot4.text = A.ItemName; S4Filled = true; } else { AlertMessage.instance.InitAlertMessage("There is no more empty slots left.", 3f); } } else { AlertMessage.instance.InitAlertMessage("This item is already listed.", 3f); } } private bool CheckForDupes(ConsumableItem A, int B) { int i = B; Debug.Log("i = "+i); if ((A == consumableItem1)) { if (i > 1) { i -= 1; Debug.Log("i = "+i); } else { return true; } } if (A == consumableItem2) { if (i > 1) { i -= 1; Debug.Log("i = "+i); } else { return true; } } if (A == consumableItem3) { if (i > 1) { i -= 1; Debug.Log("i = "+i); } else { return true; } } if (A == consumableItem4) { if (i > 1) { i -= 1; Debug.Log("i = "+i); } else { return true; } } return false; } public void ClearSlot(int A) { if (A == 1) { consumableItem1 = null; Slot1.text = "Empty"; S1Filled = false; } else if (A == 2) { consumableItem2 = null; Slot2.text = "Empty"; S2Filled = false; } else if (A == 3) { consumableItem3 = null; Slot3.text = "Empty"; S3Filled = false; } else if (A == 4) { consumableItem4 = null; Slot4.text = "Empty"; S4Filled = false; } } public void OpenAlchemyPanel() { if (AlchemyUI.activeSelf == true) { RckPlayer.instance.input.SwitchCurrentActionMap("Player"); RckPlayer.instance.EnableDisableControls(true); RckPlayer.instance.isCrafting = false; AlchemyUI.SetActive(false); TopCompassUI.SetActive(true); PlayerStatsUI.SetActive(true); ClearAllSlots(); } else { RckPlayer.instance.input.SwitchCurrentActionMap("CraftingUI"); RckPlayer.instance.EnableDisableControls(false); RckPlayer.instance.isCrafting = true; AlchemyUI.SetActive(true); TopCompassUI.SetActive(false); PlayerStatsUI.SetActive(false); AlchemyPoolManager.PopulateConsumableItems();//PopulateAll(); //ConsumableTab() AlchemyPoolManager.ShowConsumableItems(); } } public void MixPotion() { for(int i = Recipe.Count-1; i >= 0; i--) { if (S1Filled) { if (CompareItem(Recipe[i].RecipeItem1.ItemName)) { //step 1 if (S2Filled) { if (CompareItem(Recipe[i].RecipeItem2.ItemName)) { if ((Slot3.text == "Empty") && (Slot4.text == "Empty")) { ClearAllSlots(); RewardMixedPotion(i); } else if (CompareItem(Recipe[i].RecipeItem3.ItemName)) { if (Slot4.text == "Empty") { ClearAllSlots(); RewardMixedPotion(i); } else if (CompareItem(Recipe[i].RecipeItem4.ItemName)) { ClearAllSlots(); RewardMixedPotion(i); } else { AlertMessage.instance.InitAlertMessage("No matches found.", 3f); ClearAllSlots(); } } else { AlertMessage.instance.InitAlertMessage("No matches found.", 3f); ClearAllSlots(); } } else { AlertMessage.instance.InitAlertMessage("No matches found.", 3f); ClearAllSlots(); } } else { AlertMessage.instance.InitAlertMessage("There needs to be at least 2 items to mix.", 3f); } } } else { AlertMessage.instance.InitAlertMessage("No items entered.", 3f); } } } private bool CompareItem(string A) { if (A == Slot1.text) { return true; } else if (A == Slot2.text) { return true; } else if (A == Slot3.text) { return true; } else if (A == Slot4.text) { return true; } else { return false; } } private void RewardMixedPotion(int A) { Result.text = Recipe[A].CreatedItem.ItemName; ResultInfo.text = Recipe[A].CreatedItem.tooltipValue; Inventory.PlayerInventory.AddItem(Recipe[A].CreatedItem, new Metadata(), 1); Inventory.PlayerInventory.RemoveItem(Recipe[A].RecipeItem1, 1); Inventory.PlayerInventory.RemoveItem(Recipe[A].RecipeItem2, 1); if (Recipe[A].RecipeItem3) { Inventory.PlayerInventory.RemoveItem(Recipe[A].RecipeItem3, 1); } if (Recipe[A].RecipeItem4) { Inventory.PlayerInventory.RemoveItem(Recipe[A].RecipeItem4, 1); } ClearAllSlots(); AlchemyPoolManager.ConsumablesPool.ResetPool(); AlchemyPoolManager.PopulateConsumableItems(); AlchemyPoolManager.ShowConsumableItems(); } private void ClearAllSlots() { ClearSlot(1); ClearSlot(2); ClearSlot(3); ClearSlot(4); } } }