ManaGarden.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using Random = UnityEngine.Random;
  11. public struct KV<T1,T2>
  12. {
  13. public T1 Key;
  14. public T2 Value;
  15. public KV(T1 key, T2 value)
  16. {
  17. Key = key;
  18. Value = value;
  19. }
  20. }
  21. public class ManaGarden : Regist
  22. {
  23. #region 变量
  24. public static int MyFlower
  25. {
  26. get { return MyFlower_; }
  27. set
  28. {
  29. MyFlower_ = value;
  30. ManaAchieve.UpdateStatus(AchieveType.FlowerAmt, MyFlower_);
  31. ManaReso.SetText("F_FlowerLab", string.Format("{0}", MyFlower));
  32. ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower));
  33. }
  34. }
  35. public static int MyFlowerSpec
  36. {
  37. get { return MyFlowerSpec_; }
  38. set
  39. {
  40. MyFlowerSpec_ = value;
  41. MyFlower = MyFlowerSpec_ + MyFlowerRegu_;
  42. }
  43. }
  44. public static int MyFlowerRegu
  45. {
  46. get { return MyFlowerRegu_; }
  47. set
  48. {
  49. MyFlowerRegu_ = value;
  50. MyFlower = MyFlowerSpec_ + MyFlowerRegu_;
  51. }
  52. }
  53. public static int TotalFlowerSpec
  54. {
  55. get { return TotalFlowerSpec_; }
  56. set
  57. {
  58. TotalFlowerSpec_ = value;
  59. TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_;
  60. }
  61. }
  62. public static int TotalFlowerRegu
  63. {
  64. get { return TotalFlowerRegu_; }
  65. set
  66. {
  67. TotalFlowerRegu_ = value;
  68. TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_;
  69. }
  70. }
  71. private static int MyFlower_;
  72. private static int MyFlowerSpec_;
  73. private static int MyFlowerRegu_;
  74. private static int TotalFlowerSpec_;
  75. private static int TotalFlowerRegu_;
  76. public static int TotalFlower;
  77. public static bool AwardValid = true;
  78. public static float AnimTimer;
  79. public static float AwardTimer;
  80. public static FlowerInfo SeleInfo;
  81. public static List<Slot> SlotList = new List<Slot>();
  82. public static List<Slot> PlantList = new List<Slot>();
  83. public static List<ObjType> ElfList = new List<ObjType>();
  84. public static Dictionary<int, FlowerInfo> FlowerInfoDic = new Dictionary<int, FlowerInfo>();
  85. #endregion
  86. public override void Instantiate()
  87. {
  88. ManaReso.Get("Garden", Folder.Scene, true, transform, true).AddScript<Garden>();
  89. #region 生成FlowerItem
  90. List<XmlAttributeCollection> attributeList = Data.GetFlowerConfig();
  91. for (int i = 0; i < attributeList.Count; i++)
  92. {
  93. FlowerInfo flowerInfo = new FlowerInfo(attributeList[i]);
  94. if (flowerInfo.Special)
  95. {
  96. TotalFlowerSpec++;
  97. }
  98. else
  99. {
  100. TotalFlowerRegu++;
  101. }
  102. FlowerInfoDic.Add(flowerInfo.ID_, flowerInfo);
  103. }
  104. #endregion
  105. }
  106. public override void RegistValueA()
  107. {
  108. AnimTimer = Random.Range(0f, 30f);
  109. AwardTimer = Random.Range(20f, 60f);
  110. SlotList = new List<Slot>()
  111. {
  112. ManaReso.Get("SlotA1").AddScript<Slot>(),
  113. ManaReso.Get("SlotA2").AddScript<Slot>(),
  114. ManaReso.Get("SlotA3").AddScript<Slot>(),
  115. ManaReso.Get("SlotA4").AddScript<Slot>(),
  116. ManaReso.Get("SlotA5").AddScript<Slot>(),
  117. ManaReso.Get("SlotA6").AddScript<Slot>(),
  118. ManaReso.Get("SlotA7").AddScript<Slot>(),
  119. ManaReso.Get("SlotA8").AddScript<Slot>(),
  120. ManaReso.Get("SlotA9").AddScript<Slot>(),
  121. ManaReso.Get("SlotB1").AddScript<Slot>(),
  122. ManaReso.Get("SlotB2").AddScript<Slot>(),
  123. ManaReso.Get("SlotB3").AddScript<Slot>(),
  124. ManaReso.Get("SlotB4").AddScript<Slot>(),
  125. ManaReso.Get("SlotB5").AddScript<Slot>(),
  126. ManaReso.Get("SlotB6").AddScript<Slot>(),
  127. ManaReso.Get("SlotB7").AddScript<Slot>(),
  128. ManaReso.Get("SlotB8").AddScript<Slot>(),
  129. ManaReso.Get("SlotB9").AddScript<Slot>(),
  130. };
  131. #region 读花朵存档
  132. List<int> flowerList = Data.GetFlowerList();
  133. for (int i = 0; i < flowerList.Count; i++)
  134. {
  135. FlowerInfoDic[flowerList[i]].Unlock = true;
  136. }
  137. List<KV<int, string>> plantList = Data.GetPlantList();
  138. for (int i = 0; i < plantList.Count; i++)
  139. {
  140. PlantFlower(plantList[i].Key, plantList[i].Value);
  141. }
  142. #endregion
  143. }
  144. public void FixedUpdate()
  145. {
  146. if (ManaTutorial.TutorialA)
  147. {
  148. return;
  149. }
  150. ElfThread();
  151. AwardThread();
  152. }
  153. public void ElfThread()
  154. {
  155. AnimTimer -= Time.fixedDeltaTime;
  156. if (AnimTimer < 0)
  157. {
  158. AnimTimer = Random.Range(0f, 30f);
  159. if (ElfList.Count > 0 && PlantList.Count > 0)
  160. {
  161. PlantList.Random().Flower.PlayAnim(ElfList.Random());
  162. }
  163. }
  164. }
  165. public void AwardThread()
  166. {
  167. if (AwardValid)
  168. {
  169. AwardTimer -= Time.fixedDeltaTime;
  170. if (AwardTimer <= 0)
  171. {
  172. AwardTimer = Random.Range(20, 60);
  173. List<Flower> spareList = new List<Flower>();
  174. for (int i = 0; i < PlantList.Count; i++)
  175. {
  176. if (PlantList[i].Flower.Award == false)
  177. {
  178. spareList.Add(PlantList[i].Flower);
  179. }
  180. }
  181. if (spareList.Count > 0)
  182. {
  183. spareList.Random().Award = true;
  184. }
  185. }
  186. }
  187. }
  188. public static void UnlockSlot()
  189. {
  190. for (int i = 0; i < SlotList.Count; i++)
  191. {
  192. if (SlotList[i].Valid == false)
  193. {
  194. ManaData.Slot++;
  195. SlotList[i].Valid = true;
  196. SlotList[i].Available = true;
  197. return;
  198. }
  199. }
  200. ManaDebug.Log("所有土地已解锁");
  201. }
  202. public static void ShowFlowerCard(FlowerInfo flowerInfo)
  203. {
  204. SeleInfo = flowerInfo;
  205. ManaReso.Get("H_FlowerCard").TweenForCG();
  206. ManaLan.Add(ManaReso.Get<Text>("H_Lab"), new LanStr("FlowerName", flowerInfo.ID));
  207. Image image = ManaReso.Get<Image>("H_Icon2");
  208. image.sprite = flowerInfo.Icon;
  209. Vector2 newSize = flowerInfo.Icon.rect.size;
  210. newSize.x *= 0.65f;
  211. newSize.y *= 0.65f;
  212. image.rectTransform.sizeDelta = newSize;
  213. }
  214. public static void RetriveFlower()
  215. {
  216. SeleInfo.Slot.Retrieve();
  217. }
  218. public static void RetriveFlowerAll()
  219. {
  220. for (int i = 0; i < PlantList.Count; i++)
  221. {
  222. PlantList[i--].Retrieve();
  223. }
  224. }
  225. public static void PlantFlower(FlowerInfo flowerInfo)
  226. {
  227. if (flowerInfo.Plant)
  228. {
  229. ShowFlowerCard(flowerInfo);
  230. }
  231. else
  232. {
  233. Slot slot = null;
  234. for (int i = 0; i < SlotList.Count; i++)
  235. {
  236. if (SlotList[i].Available)
  237. {
  238. slot = SlotList[i];
  239. break;
  240. }
  241. }
  242. if (slot == null)
  243. {
  244. ManaDebug.Log("已经没有空地了");
  245. }
  246. else
  247. {
  248. slot.Plant(flowerInfo, true);
  249. }
  250. }
  251. }
  252. public static void PlantFlower(int id, string slotName)
  253. {
  254. Slot slot = ManaReso.Get<Slot>(slotName);
  255. FlowerInfo flowerInfo = FlowerInfoDic[id];
  256. slot.Plant(flowerInfo, false);
  257. }
  258. }