Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / UI / Upgrades / Attack / AttackUpgradesInfo.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class AttackUpgradesInfo : MonoBehaviour
  6. {
  7. public Toggle attackToggle1, attackToggle2, attackToggle3, attackToggle4;
  8. public GameObject requirementsText, alreadyUpgraded;
  9. public Text levelText, goldText, normalAtkText, strongAtkText;
  10. private PlayerGold playerGold;
  11. private PlayerLevel playerLevel;
  12. private DoAttackUpgrades doAttackUpgrades;
  13. [HideInInspector] public HashTable attackdata;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. InitUpgradesHashtable();
  18. playerGold = FindObjectOfType<PlayerGold>();
  19. playerLevel = FindObjectOfType<PlayerLevel>();
  20. doAttackUpgrades = FindObjectOfType<DoAttackUpgrades>();
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. attackToggle1.onValueChanged.AddListener(delegate { ShowAttack1Requirements(); });
  26. attackToggle2.onValueChanged.AddListener(delegate { ShowAttack2Requirements(); });
  27. attackToggle3.onValueChanged.AddListener(delegate { ShowAttack3Requirements(); });
  28. attackToggle4.onValueChanged.AddListener(delegate { ShowAttack4Requirements(); });
  29. }
  30. //Inserting Upgrade Requirements on the Hashtable
  31. public void InitUpgradesHashtable()
  32. {
  33. attackdata = new HashTable(2);
  34. attackdata.Insert("Level1", 2);
  35. attackdata.Insert("Gold1", 20);
  36. attackdata.Insert("NormalAttack1", 10);
  37. attackdata.Insert("StrongAttack1", 5);
  38. attackdata.Insert("Level2", 3);
  39. attackdata.Insert("Gold2", 40);
  40. attackdata.Insert("NormalAttack2", 15);
  41. attackdata.Insert("StrongAttack2", 10);
  42. attackdata.Insert("Level3", 4);
  43. attackdata.Insert("Gold3", 60);
  44. attackdata.Insert("NormalAttack3", 20);
  45. attackdata.Insert("StrongAttack3", 15);
  46. attackdata.Insert("Level4", 5);
  47. attackdata.Insert("Gold4", 80);
  48. attackdata.Insert("NormalAttack4", 25);
  49. attackdata.Insert("StrongAttack4", 20);
  50. }
  51. private void ShowAttack1Requirements()
  52. {
  53. if (doAttackUpgrades.upgrade1 == false)
  54. {
  55. requirementsText.gameObject.SetActive(true);
  56. alreadyUpgraded.gameObject.SetActive(false);
  57. //write info about the upgtrade
  58. levelText.text = "Level: " + (int)attackdata.GetValue("Level1");
  59. goldText.text = "Gold: " + (int)attackdata.GetValue("Gold1");
  60. normalAtkText.text = "Normal Attack: +" + (int)attackdata.GetValue("NormalAttack1");
  61. strongAtkText.text = "Strong Attack: +" + (int)attackdata.GetValue("StrongAttack1");
  62. if (playerGold.gold < (int)attackdata.GetValue("Gold1"))
  63. goldText.color = Color.red;
  64. else goldText.color = Color.black;
  65. if (playerLevel.Level < (int)attackdata.GetValue("Level1"))
  66. levelText.color = Color.red;
  67. else levelText.color = Color.black;
  68. }
  69. else
  70. {
  71. requirementsText.gameObject.SetActive(false);
  72. alreadyUpgraded.gameObject.SetActive(true);
  73. }
  74. }
  75. private void ShowAttack2Requirements()
  76. {
  77. if (doAttackUpgrades.upgrade2 == false)
  78. {
  79. requirementsText.gameObject.SetActive(true);
  80. alreadyUpgraded.gameObject.SetActive(false);
  81. //write info about the upgtrade
  82. levelText.text = "Level: " + (int)attackdata.GetValue("Level2");
  83. goldText.text = "Gold: " + (int)attackdata.GetValue("Gold2");
  84. normalAtkText.text = "Normal Attack: +" + (int)attackdata.GetValue("NormalAttack2");
  85. strongAtkText.text = "Strong Attack: +" + (int)attackdata.GetValue("StrongAttack2");
  86. if (playerGold.gold < (int)attackdata.GetValue("Gold2"))
  87. goldText.color = Color.red;
  88. else goldText.color = Color.black;
  89. if (playerLevel.Level < (int)attackdata.GetValue("Level2"))
  90. levelText.color = Color.red;
  91. else levelText.color = Color.black;
  92. }
  93. else
  94. {
  95. requirementsText.gameObject.SetActive(false);
  96. alreadyUpgraded.gameObject.SetActive(true);
  97. }
  98. }
  99. private void ShowAttack3Requirements()
  100. {
  101. if (doAttackUpgrades.upgrade3 == false)
  102. {
  103. requirementsText.gameObject.SetActive(true);
  104. alreadyUpgraded.gameObject.SetActive(false);
  105. //write info about the upgtrade
  106. levelText.text = "Level: " + (int)attackdata.GetValue("Level3");
  107. goldText.text = "Gold: " + (int)attackdata.GetValue("Gold3");
  108. normalAtkText.text = "Normal Attack: +" + (int)attackdata.GetValue("NormalAttack3");
  109. strongAtkText.text = "Strong Attack: +" + (int)attackdata.GetValue("StrongAttack3");
  110. if (playerGold.gold < (int)attackdata.GetValue("Gold3"))
  111. goldText.color = Color.red;
  112. else goldText.color = Color.black;
  113. if (playerLevel.Level < (int)attackdata.GetValue("Level3"))
  114. levelText.color = Color.red;
  115. else levelText.color = Color.black;
  116. }
  117. else
  118. {
  119. requirementsText.gameObject.SetActive(false);
  120. alreadyUpgraded.gameObject.SetActive(true);
  121. }
  122. }
  123. private void ShowAttack4Requirements()
  124. {
  125. if (doAttackUpgrades.upgrade4 == false)
  126. {
  127. requirementsText.gameObject.SetActive(true);
  128. alreadyUpgraded.gameObject.SetActive(false);
  129. //write info about the upgtrade
  130. levelText.text = "Level: " + (int)attackdata.GetValue("Level4");
  131. goldText.text = "Gold: " + (int)attackdata.GetValue("Gold4");
  132. normalAtkText.text = "Normal Attack: +" + (int)attackdata.GetValue("NormalAttack4");
  133. strongAtkText.text = "Strong Attack: +" + (int)attackdata.GetValue("StrongAttack4");
  134. if (playerGold.gold < (int)attackdata.GetValue("Gold4"))
  135. goldText.color = Color.red;
  136. else goldText.color = Color.black;
  137. if (playerLevel.Level < (int)attackdata.GetValue("Level4"))
  138. levelText.color = Color.red;
  139. else levelText.color = Color.black;
  140. }
  141. else
  142. {
  143. requirementsText.gameObject.SetActive(false);
  144. alreadyUpgraded.gameObject.SetActive(true);
  145. }
  146. }
  147. }