125 lines
3.8 KiB
C#
125 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class MarisaPotionMaker : MicroGameHandler
|
|
{
|
|
#region Statication
|
|
|
|
public static MarisaPotionMaker instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public Chemical[] allChemicals;
|
|
|
|
[Serializable]
|
|
public class ChemicalSpawnPoint //this sucks but whatever!
|
|
{
|
|
public Transform location;
|
|
public bool inUse;
|
|
}
|
|
public ChemicalSpawnPoint[] chemicalSpawnPoints;
|
|
public List<Chemical> chemicalInstances = new();
|
|
public MicrogamePotion[] allPotions;
|
|
public MicrogamePotion currentPotion;
|
|
public List<MicrogamePotion> requestedPotions = new();
|
|
public List<MicrogamePotion> completedPotions = new();
|
|
public List<MicrogamePotion> failedPotions = new(); //bad to have 3 lists but whatever.
|
|
public int currentPotionIndex;
|
|
[SerializeField] private TextMeshProUGUI potionRecipeTitle;
|
|
[SerializeField] private TextMeshProUGUI potionRecipeText;
|
|
|
|
public void StartPotion(MicrogamePotion potionRequested)
|
|
{
|
|
currentPotion = potionRequested;
|
|
foreach (Chemical requestedChemical in potionRequested.chemicals)
|
|
{
|
|
int index = Random.Range(0, chemicalSpawnPoints.Length);
|
|
CreateChemical(requestedChemical,chemicalSpawnPoints[index].location);
|
|
chemicalSpawnPoints[index].inUse = true;
|
|
}
|
|
foreach (ChemicalSpawnPoint spawnpoint in chemicalSpawnPoints)
|
|
{
|
|
if (spawnpoint.inUse)
|
|
{
|
|
continue;
|
|
}
|
|
CreateChemical(allChemicals[Random.Range(0, allChemicals.Length)], spawnpoint.location);
|
|
}
|
|
}
|
|
|
|
public void CreateChemical(Chemical chemicalRequested, Transform location)
|
|
{
|
|
Chemical newChemical = Instantiate(chemicalRequested, location.position, Quaternion.identity);
|
|
newChemical.transform.SetParent(transform);
|
|
chemicalInstances.Add(newChemical);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
UpdateUI();
|
|
}
|
|
|
|
public void UpdateUI()
|
|
{
|
|
//supposed to check off every chemical once added but i'll input that later
|
|
//for now i have to initialize the ui
|
|
potionRecipeTitle.text = currentPotion.potionName;
|
|
string recipe = "";
|
|
for (int i = 0; i < currentPotion.chemicals.Length; i++)
|
|
{
|
|
recipe += $"{i+1}. {currentPotion.chemicals[i].chemicalName}\n";
|
|
}
|
|
potionRecipeText.text = recipe;
|
|
}
|
|
public void AddChemical(Chemical chemical)
|
|
{
|
|
if (currentPotion.chemicals[currentPotionIndex].chemicalName == chemical.chemicalName ) //string comparisons are bad but i don't give a fuck
|
|
{
|
|
currentPotionIndex++;
|
|
if (currentPotion.chemicals.Length <= currentPotionIndex)
|
|
{
|
|
CompletePotion(currentPotion, true);
|
|
currentPotionIndex = 0;
|
|
StartPotion(allPotions[Random.Range(0, allPotions.Length)]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CompletePotion(currentPotion, false);
|
|
}
|
|
}
|
|
|
|
public void CompletePotion(MicrogamePotion potion, bool success)
|
|
{
|
|
requestedPotions.Remove(potion); //doesn't work if there's multiple of the same potion....
|
|
foreach (Chemical chemicalInstance in chemicalInstances.ToArray())
|
|
{
|
|
if (chemicalInstance)
|
|
{
|
|
Destroy(chemicalInstance);
|
|
}
|
|
chemicalInstances.Remove(chemicalInstance);
|
|
}
|
|
if (success)
|
|
{
|
|
completedPotions.Add(potion);
|
|
}
|
|
else
|
|
{
|
|
failedPotions.Add(potion);
|
|
}
|
|
}
|
|
}
|