ManaMiniGame.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Xml;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using Random = UnityEngine.Random;
  9. public class Award
  10. {
  11. #region 变量
  12. public int DiamondMin;
  13. public int DiamondMax;
  14. public string CoinFml;
  15. public string FlowerFml;
  16. public string DiamondFml;
  17. public List<float> Odds;
  18. public List<float> Standard;
  19. #endregion
  20. public Award(XmlAttributeCollection attribute)
  21. {
  22. CoinFml = attribute[1].Value;
  23. FlowerFml = attribute[4].Value;
  24. DiamondFml = attribute[3].Value;
  25. string[] strings = attribute[2].Value.Split(',');
  26. DiamondMin = int.Parse(strings[0]);
  27. DiamondMax = int.Parse(strings[1]);
  28. strings = attribute[5].Value.Split(',');
  29. Odds = new List<float>()
  30. {
  31. float.Parse(strings[0]),
  32. float.Parse(strings[1]),
  33. float.Parse(strings[2]),
  34. };
  35. strings = attribute[6].Value.Split(',');
  36. Standard = new List<float>()
  37. {
  38. float.Parse(strings[0]),
  39. float.Parse(strings[1]),
  40. float.Parse(strings[2]),
  41. };
  42. }
  43. public void GetAward(int score)
  44. {
  45. ManaReso.SetActive("Da_Flower", false);
  46. ManaReso.SetActive("Da_Diamond", false);
  47. int coin = (int) Auxiliary.FmlParse(CoinFml, "s", score.ToString());
  48. coin = (int) (coin * ManaData.SkillPlus);
  49. ManaData.Coin += coin;
  50. ManaReso.SetText("Da_CoinLab", coin.ToString());
  51. float diamondRate = (float) Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaData.Level, 1, 1000).ToString());
  52. if (Random.Range(0, 1f) <= diamondRate)
  53. {
  54. ManaReso.SetActive("Da_Diamond", true);
  55. int diamond = (int) Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f));
  56. ManaReso.SetText("Da_DiamondLab", diamond.ToString());
  57. ManaData.Diamond += diamond;
  58. }
  59. int grade;
  60. if (score < Standard[0])
  61. {
  62. grade = 0;
  63. }
  64. else if (score < Standard[1])
  65. {
  66. grade = 1;
  67. }
  68. else if (score < Standard[2])
  69. {
  70. grade = 2;
  71. }
  72. else
  73. {
  74. throw new Exception();
  75. }
  76. float flowerRate = (float) Auxiliary.FmlParse(DiamondFml, "l", ManaData.Level.ToString(), "f", ManaGarden.MyFlower.ToString());
  77. if (Random.Range(0, 1f) <= flowerRate)
  78. {
  79. if (Random.Range(0, 1f) <= Odds[grade])
  80. {
  81. ManaReso.SetActive("Da_Flower", true);
  82. FlowerInfo flowerInfo;
  83. while (true)
  84. {
  85. flowerInfo = ManaGarden.FlowerInfoList[Random.Range(0, ManaGarden.TotalFlower - 1)];
  86. if (flowerInfo.Unlock)
  87. {
  88. break;
  89. }
  90. }
  91. ManaReso.SetText("Da_FlowerLab", Language.GetStr("FlowerName", "Flower" + flowerInfo.Id));
  92. }
  93. }
  94. }
  95. }
  96. public class ManaMiniGame : Regist
  97. {
  98. #region 变量
  99. public static int Score
  100. {
  101. get { return _Score; }
  102. set
  103. {
  104. _Score = value;
  105. ManaReso.SetText("D_ScoreLab", _Score.ToString());
  106. }
  107. }
  108. public static bool Game
  109. {
  110. get { return _Game; }
  111. set
  112. {
  113. _Game = value;
  114. if (_Game)
  115. {
  116. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  117. }
  118. else
  119. {
  120. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0"));
  121. }
  122. }
  123. }
  124. public static bool Pause
  125. {
  126. get { return _Pause; }
  127. set
  128. {
  129. _Pause = value;
  130. if (Game)
  131. {
  132. if (_Pause)
  133. {
  134. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2"));
  135. }
  136. else
  137. {
  138. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  139. }
  140. }
  141. }
  142. }
  143. public static bool Panalty
  144. {
  145. get { return _Panalty; }
  146. set
  147. {
  148. _Panalty = value;
  149. if (_Panalty)
  150. {
  151. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3"));
  152. }
  153. else
  154. {
  155. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  156. }
  157. }
  158. }
  159. public static float GameTimer
  160. {
  161. get { return _GameTimer; }
  162. set
  163. {
  164. _GameTimer = value;
  165. TimerBk.fillAmount = _GameTimer / GameTimer;
  166. TimerLab.text = _GameTimer.ToString("0.0");
  167. }
  168. }
  169. public static float PrepareTimer
  170. {
  171. get { return _PrepareTimer; }
  172. set
  173. {
  174. _PrepareTimer = value;
  175. BtnLab.text = PrepareStr + " " + Mathf.CeilToInt(_PrepareTimer);
  176. }
  177. }
  178. private static int _Score;
  179. private static bool _Game;
  180. private static bool _Pause;
  181. private static bool _Panalty;
  182. private static float _GameTimer;
  183. private static float _PrepareTimer;
  184. public static string PrepareStr;
  185. public static Text BtnLab;
  186. public static Text TimerLab;
  187. public static Image TimerBk;
  188. public static Award Award;
  189. public static List<Flower> OpList;
  190. public static List<Flower> IdleList;
  191. private static float OpTime;
  192. private static float OpTimer;
  193. private static float GameTime;
  194. private static float PanaltyTime;
  195. private static float PanaltyTimer;
  196. #endregion
  197. private void FixedUpdate()
  198. {
  199. if (PrepareTimer > 0)
  200. {
  201. PrepareTimer -= Time.fixedDeltaTime;
  202. if (PrepareTimer <= 0)
  203. {
  204. GameBegin();
  205. }
  206. }
  207. if (!Game || Pause)
  208. {
  209. return;
  210. }
  211. GameTimer -= Time.fixedDeltaTime;
  212. if (GameTimer <= 0)
  213. {
  214. GameOver();
  215. return;
  216. }
  217. if (Panalty)
  218. {
  219. PanaltyTimer -= Time.fixedDeltaTime;
  220. if (PanaltyTimer <= 0)
  221. {
  222. Panalty = false;
  223. }
  224. }
  225. if (IdleList.Count > 0)
  226. {
  227. OpTimer -= Time.fixedDeltaTime;
  228. if (OpTimer <= 0)
  229. {
  230. OpTime -= OpTime * 0.03f;
  231. OpTimer = OpTime;
  232. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  233. flower.CreateOp(OpList.Count);
  234. OpList.Add(flower);
  235. IdleList.Remove(flower);
  236. }
  237. }
  238. }
  239. public override void RegistValueA()
  240. {
  241. PrepareStr = Language.GetStr("UI", "D_BeginLab1");
  242. OpTime = 1.5f;
  243. GameTime = 45;
  244. PanaltyTime = 1;
  245. OpTimer = OpTime;
  246. GameTimer = GameTime;
  247. Award = new Award(Data.GetAwardConfig());
  248. }
  249. public override void RegistReference()
  250. {
  251. TimerBk = ManaReso.Get<Image>("D_TimerIcon");
  252. BtnLab = ManaReso.Get<Text>("D_BeginLab");
  253. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  254. }
  255. #region MiniGame
  256. public static void Rip()
  257. {
  258. if (Panalty)
  259. {
  260. return;
  261. }
  262. if (OpList.Count == 0)
  263. {
  264. return;
  265. }
  266. if (OpList[0].Operate(OpType.Rip))
  267. {
  268. IdleList.Add(OpList[0]);
  269. OpList.Remove(OpList[0]);
  270. ResetOperate();
  271. }
  272. else
  273. {
  274. Panalty = true;
  275. PanaltyTimer = PanaltyTime;
  276. }
  277. }
  278. public static void Water()
  279. {
  280. if (Panalty)
  281. {
  282. return;
  283. }
  284. if (OpList.Count == 0)
  285. {
  286. return;
  287. }
  288. if (OpList[0].Operate(OpType.Water))
  289. {
  290. IdleList.Add(OpList[0]);
  291. OpList.Remove(OpList[0]);
  292. ResetOperate();
  293. }
  294. else
  295. {
  296. Panalty = true;
  297. PanaltyTimer = PanaltyTime;
  298. }
  299. }
  300. public static void Fertilize()
  301. {
  302. if (Panalty)
  303. {
  304. return;
  305. }
  306. if (OpList.Count == 0)
  307. {
  308. return;
  309. }
  310. if (OpList[0].Operate(OpType.Fertilize))
  311. {
  312. IdleList.Add(OpList[0]);
  313. OpList.Remove(OpList[0]);
  314. ResetOperate();
  315. }
  316. else
  317. {
  318. Panalty = true;
  319. PanaltyTimer = PanaltyTime;
  320. }
  321. }
  322. public static void GameOver()
  323. {
  324. Award.GetAward(Score);
  325. ManaReso.SetActive("Da_Info", true);
  326. ManaReso.SetActive("Da_Quit", false);
  327. ManaReso.SetActive("Da_Cancel", false);
  328. ManaReso.SetActive("Da_GetAward", true);
  329. GameAbort();
  330. }
  331. public static void GameBegin()
  332. {
  333. ManaReso.Get("D_Rip1").SetActive(true);
  334. ManaReso.Get("D_Water1").SetActive(true);
  335. ManaReso.Get("D_Fertilize1").SetActive(true);
  336. ManaReso.Get("D_Begin").SetActive(false);
  337. Score = 0;
  338. Game = true;
  339. Pause = false;
  340. Panalty = false;
  341. OpTimer = OpTime;
  342. GameTimer = GameTime;
  343. PanaltyTimer = 0;
  344. for (int i = 0; i < IdleList.Count; i++)
  345. {
  346. IdleList[i].GameBegin();
  347. }
  348. }
  349. public static void GameAbort()
  350. {
  351. ManaReso.SetActive("D_Rip1", false);
  352. ManaReso.SetActive("D_Water1", false);
  353. ManaReso.SetActive("D_Fertilize1", false);
  354. ManaReso.SetActive("D_Begin", true);
  355. ManaReso.SetText("Da_Tit", string.Format(Language.GetStr("UI", "Da_Tit1")));
  356. ManaReso.SetText("Da_Lab", string.Format("{0}{1}", Language.GetStr("UI", "Da_Lab1"), Score));
  357. Score = 0;
  358. Game = false;
  359. Pause = false;
  360. Panalty = false;
  361. OpTimer = OpTime;
  362. GameTimer = GameTime;
  363. PanaltyTimer = 0;
  364. for (int i = 0; i < IdleList.Count; i++)
  365. {
  366. IdleList[i].GameOver();
  367. }
  368. for (int i = 0; i < OpList.Count; i++)
  369. {
  370. OpList[i].GameOver();
  371. }
  372. }
  373. public static void GamePrepare()
  374. {
  375. OpList = new List<Flower>();
  376. IdleList = new List<Flower>();
  377. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[0], ManaReso.Get("SlotMini1")));
  378. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[1], ManaReso.Get("SlotMini2")));
  379. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[2], ManaReso.Get("SlotMini3")));
  380. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[3], ManaReso.Get("SlotMini4")));
  381. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[4], ManaReso.Get("SlotMini5")));
  382. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[5], ManaReso.Get("SlotMini6")));
  383. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[6], ManaReso.Get("SlotMini7")));
  384. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[7], ManaReso.Get("SlotMini8")));
  385. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[8], ManaReso.Get("SlotMini9")));
  386. }
  387. public static void ResetOperate()
  388. {
  389. if (OpList.Count >= 2)
  390. {
  391. OpList[0].SetFirstOp();
  392. OpList[1].SetSecondOp();
  393. }
  394. else if (OpList.Count >= 1)
  395. {
  396. OpList[0].SetFirstOp();
  397. }
  398. }
  399. #endregion
  400. }