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.

109 lines
2.3 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. }
  31. //Button calls
  32. public void OpenRecipe()
  33. {
  34. RecipeCanvas.SetActive(true);
  35. }
  36. public void CloseRecipe()
  37. {
  38. RecipeCanvas.SetActive(false);
  39. }
  40. //Veggie interactions
  41. public void pickupItem(Vegetable newVeggie)
  42. {
  43. localPlayer.heldVeggie = newVeggie;
  44. Inventory.gameObject.SetActive(true);
  45. Inventory.sprite = newVeggie.Image;
  46. }
  47. public void dropItem()
  48. {
  49. localPlayer.heldVeggie = null;
  50. Inventory.gameObject.SetActive(false);
  51. }
  52. public void friendlyPickup(string VeggieName, int change)
  53. {
  54. StartCoroutine(ItemLookup(VeggieName, change));
  55. }
  56. IEnumerator ItemLookup(string VeggieName, int change)
  57. {
  58. for (int i = 0; i < Veggies.Length; i++)
  59. {
  60. if(Veggies[i].Name == VeggieName)
  61. {
  62. heldQtys[i] += change;
  63. }
  64. }
  65. yield return new WaitForEndOfFrame();
  66. }
  67. public bool CheckVictory()
  68. {
  69. bool winning = true;
  70. for (int i = 0; i < Veggies.Length; i++)
  71. {
  72. if (Qtys[i] != heldQtys[i])
  73. {
  74. winning = false;
  75. }
  76. }
  77. return winning;
  78. }
  79. }
  80. [Serializable]
  81. public class Vegetable
  82. {
  83. public string Name;
  84. public Sprite Image;
  85. }
  86. [Serializable]
  87. public class Frame
  88. {
  89. public Image VegetableSpot;
  90. public TextMeshProUGUI Qty;
  91. }