You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using System;
  7. public class Recipe : MonoBehaviour {
  8. Player localPlayer;
  9. int PlayerCount;
  10. public Vegetable[] Veggies;
  11. public Frame[] Frames;
  12. public int[] Qtys;
  13. public int[] heldQtys;
  14. public GameObject RecipeCanvas;
  15. public Image Inventory;
  16. // Use this for initialization
  17. void Start () {
  18. for (int i = 0; i < PlayerCount; i++)
  19. {
  20. int rand = UnityEngine.Random.Range(0, Qtys.Length - 1);
  21. Qtys[rand] += 1;
  22. }
  23. for (int i = 0; i < 4; i++) //Set the recipe UI
  24. {
  25. Frames[i].VegetableSpot.sprite = Veggies[i].Image;
  26. Frames[i].Qty.text = Qtys[i] + "";
  27. }
  28. localPlayer = Multiplayer.PlayersManager.Instance.LocalPlayer.GetComponent<Player>();
  29. PlayerCount = Multiplayer.PlayersManager.Instance.RemotePlayers.Count + 1;
  30. localPlayer.GetComponent<LocalPlayer>().recipe = this;
  31. }
  32. //Button calls
  33. public void OpenRecipe()
  34. {
  35. RecipeCanvas.SetActive(true);
  36. }
  37. public void CloseRecipe()
  38. {
  39. RecipeCanvas.SetActive(false);
  40. }
  41. //Veggie interactions
  42. public void pickupItem(Vegetable newVeggie)
  43. {
  44. localPlayer.heldVeggie = newVeggie;
  45. Inventory.gameObject.SetActive(true);
  46. Inventory.sprite = newVeggie.Image;
  47. }
  48. public void dropItem()
  49. {
  50. localPlayer.heldVeggie = null;
  51. Inventory.gameObject.SetActive(false);
  52. }
  53. public void friendlyPickup(string VeggieName, int change)
  54. {
  55. StartCoroutine(ItemLookup(VeggieName, change));
  56. }
  57. IEnumerator ItemLookup(string VeggieName, int change)
  58. {
  59. for (int i = 0; i < Veggies.Length; i++)
  60. {
  61. if(Veggies[i].Name == VeggieName)
  62. {
  63. heldQtys[i] += change;
  64. }
  65. }
  66. yield return new WaitForEndOfFrame();
  67. }
  68. public bool CheckVictory()
  69. {
  70. bool winning = true;
  71. for (int i = 0; i < Veggies.Length; i++)
  72. {
  73. if (Qtys[i] != heldQtys[i])
  74. {
  75. winning = false;
  76. }
  77. }
  78. return winning;
  79. }
  80. }
  81. [Serializable]
  82. public class Vegetable
  83. {
  84. public string Name;
  85. public Sprite Image;
  86. }
  87. [Serializable]
  88. public class Frame
  89. {
  90. public Image VegetableSpot;
  91. public TextMeshProUGUI Qty;
  92. }