ManaMiniGame.cs 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Xml;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Random = UnityEngine.Random;
  10. public class Award
  11. {
  12. #region 变量
  13. public static int BonusCoin;
  14. public static int BonusDiamond;
  15. public static string Info;
  16. public static int FlowerID;
  17. public static bool FlowerLock;
  18. public int DiamondMin;
  19. public int DiamondMax;
  20. public string CoinFml;
  21. public string FlowerFml;
  22. public string DiamondFml;
  23. public List<float> Odds = new List<float>();
  24. public List<float> Standard = new List<float>();
  25. #endregion
  26. public void GetAward(int score)
  27. {
  28. #region 获得奖励
  29. #region Rate
  30. int rate;
  31. if (score < Standard[1])
  32. {
  33. rate = 0;
  34. }
  35. else if (score < Standard[2])
  36. {
  37. rate = 1;
  38. }
  39. else
  40. {
  41. rate = 2;
  42. }
  43. #endregion
  44. #region Reset
  45. bool flowerFlag = false;
  46. bool diamondFlag = false;
  47. #endregion
  48. StringBuilder sb = new StringBuilder();
  49. #region Coin
  50. int coin = (int)Auxiliary.FmlParse(CoinFml, "s", score.ToString(), "l", Mathf.Clamp(ManaCenter.Level, 1, 9999).ToString());
  51. coin = (int)(coin * (1 + ManaCenter.SkillPlus) + BonusCoin);
  52. ManaCenter.Coin += coin;
  53. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", coin);
  54. #endregion
  55. #region Diamond
  56. int diamond = 0;
  57. float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaCenter.Level, 1, 1000).ToString());
  58. if (Random.Range(0, 1f) <= diamondRate)
  59. {
  60. diamondFlag = true;
  61. diamond = (int)(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond);
  62. ManaCenter.Diamond += diamond;
  63. ManaReso.SetActive("Da_Diamond", true);
  64. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", diamond);
  65. }
  66. else
  67. {
  68. if (BonusDiamond > 0)
  69. {
  70. diamondFlag = true;
  71. diamond = BonusDiamond;
  72. ManaCenter.Diamond += diamond;
  73. ManaReso.SetActive("Da_Diamond", true);
  74. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", diamond);
  75. }
  76. }
  77. #endregion
  78. #region Flower
  79. if (ManaTutorial.TutorialA)
  80. {
  81. flowerFlag = true;
  82. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[1];
  83. ManaReso.SetActive("Da_FlowerIcon", true);
  84. ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
  85. ManaReso.Get<Image>("Da_FlowerIcon").Resize(0.2f, 0.2f);
  86. ManaReso.SetText("Da_FlowerLab", flowerInfo.Name);
  87. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  88. }
  89. else
  90. {
  91. if (!FlowerLock)
  92. {
  93. flowerFlag = true;
  94. if (Random.Range(0, 1f) <= Odds[rate])
  95. {
  96. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerID];
  97. flowerInfo.Unlock = true;
  98. ManaReso.SetActive("Da_Flower", true);
  99. ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
  100. ManaReso.Get<Image>("Da_FlowerIcon").Resize(0.2f, 0.2f);
  101. ManaReso.SetText("Da_FlowerLab", flowerInfo.Name);
  102. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  103. }
  104. else
  105. {
  106. ManaReso.SetActive("Da_Flower", false);
  107. ManaReso.SetText("Da_FlowerLab", Language.GetStr("UI", "Da_HigherScore"));
  108. }
  109. }
  110. }
  111. #endregion
  112. Info = sb.ToString();
  113. BonusCoin = 0;
  114. BonusDiamond = 0;
  115. #endregion
  116. #region 构造动画
  117. #region Reset
  118. ManaReso.Get("Da_Info").TweenForCG();
  119. ManaReso.SetText("Da_Tit", Language.GetStr("UI", "Da_Tit1"));
  120. ManaReso.SetText("Da_CoinLab", "0");
  121. ManaReso.SetText("Da_DiamondLab", "0");
  122. ManaReso.SetActive("Da_Lab", false);
  123. ManaReso.SetActive("Da_Quit", false);
  124. ManaReso.SetActive("Da_Cancel", false);
  125. ManaReso.SetActive("Da_CoinLab", false);
  126. ManaReso.SetActive("Da_ScoreTit", false);
  127. ManaReso.SetActive("Da_ScoreLab", false);
  128. ManaReso.SetActive("Da_GetAward", false);
  129. ManaReso.SetActive("Da_DiamondLab", false);
  130. ManaReso.SetActive("Da_VGroup", true);
  131. ManaReso.SetActive("Da_HGroup", false);
  132. ManaReso.SetActive("Da_FlowerGroup", false);
  133. ManaReso.SetActive("Da_DiamondGroup", false);
  134. if (flowerFlag)
  135. {
  136. ManaReso.SetActive("Da_FlowerGroup", true);
  137. }
  138. if (diamondFlag)
  139. {
  140. ManaReso.SetActive("Da_DiamondGroup", true);
  141. }
  142. Auxiliary.Instance.DelayCall
  143. (
  144. () =>
  145. {
  146. ManaReso.Get<VerticalLayoutGroup>("Da_VGroup").enabled = false;
  147. ManaReso.SetActive("Da_CoinGroup", false);
  148. ManaReso.SetActive("Da_FlowerGroup", false);
  149. ManaReso.SetActive("Da_DiamondGroup", false);
  150. },
  151. 1
  152. );
  153. float timeCoin = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(coin / 15f));
  154. float timeScore = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(score / 50f));
  155. float timeDiamond = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(diamond / 15f));
  156. float time = Mathf.Max(timeCoin, timeDiamond);
  157. ManaReso.Get("Da_CoinLab").CreateTweenNumber(0, coin, time, false, true, Curve.EaseOutQuad);
  158. ManaReso.Get("Da_ScoreLab").CreateTweenNumber(0, score, timeScore, false, true, Curve.EaseOutQuad);
  159. ManaReso.Get("Da_DiamondLab").CreateTweenNumber(0, diamond, time, false, true, Curve.EaseOutQuad);
  160. #endregion
  161. #region 花
  162. TweenRoot tween;
  163. if (flowerFlag)
  164. {
  165. tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
  166. tween.AddEventOnetime
  167. (
  168. EventType.ForwardFinish,
  169. () =>
  170. {
  171. ManaReso.Get("Da_FlowerGroup").TweenReForScale();
  172. }
  173. );
  174. }
  175. #endregion
  176. #region 按钮
  177. if (flowerFlag)
  178. {
  179. tween = ManaReso.Get("Da_FlowerGroup").GetTweenScale();
  180. tween.AddEventOnetime
  181. (
  182. EventType.ForwardFinish,
  183. () =>
  184. {
  185. ManaReso.Get("Da_GetAward").TweenReForCG();
  186. }
  187. );
  188. }
  189. else
  190. {
  191. tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
  192. tween.AddEventOnetime
  193. (
  194. EventType.ForwardFinish,
  195. () =>
  196. {
  197. ManaReso.Get("Da_GetAward").TweenReForCG();
  198. }
  199. );
  200. }
  201. if (ManaTutorial.TutorialA)
  202. {
  203. tween = ManaReso.Get("Da_GetAward").GetTweenCG();
  204. tween.AddEventOnetime
  205. (
  206. EventType.ForwardFinish,
  207. () =>
  208. {
  209. Tutorial.HightScreen(ManaReso.Get("Da_Arrow0"), ManaReso.Get("Da_Arrow1"), ManaReso.Get("Da_GetAward"));
  210. }
  211. );
  212. }
  213. ManaReso.AddButtonEventOnetime
  214. (
  215. "Da_GetAward",
  216. () =>
  217. {
  218. ManaReso.Get("Da_VGroup").GetComponent<VerticalLayoutGroup>().enabled = true;
  219. }
  220. );
  221. #endregion
  222. #region 得分
  223. if (rate == 0)
  224. {
  225. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  226. }
  227. else if (rate == 1)
  228. {
  229. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  230. }
  231. else if (rate == 2)
  232. {
  233. tween = ManaReso.Get("Da_Star3").GetTweenScale();
  234. }
  235. tween.AddEventOnetime
  236. (
  237. EventType.ForwardFinish,
  238. () =>
  239. {
  240. ManaReso.Get("Da_ScoreTit").TweenReForFont();
  241. }
  242. );
  243. tween = ManaReso.Get("Da_ScoreTit").GetTweenFont();
  244. tween.InOrigin = true;
  245. tween.AddEventOnetime
  246. (
  247. EventType.ForwardFinish,
  248. () =>
  249. {
  250. ManaReso.Get("Da_ScoreLab").TweenReForNumber();
  251. }
  252. );
  253. #endregion
  254. #region 五角星
  255. tween = ManaReso.Get("Da_Star3").GetTweenScale();
  256. tween.InOrigin = true;
  257. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  258. tween.InOrigin = true;
  259. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  260. tween.InOrigin = true;
  261. tween = ManaReso.Get("Da_Info").GetTweenCG();
  262. tween.AddEventOnetime
  263. (
  264. EventType.ForwardFinish,
  265. () =>
  266. {
  267. ManaReso.Get("Da_Star1").TweenReForScale();
  268. ManaReso.SetActive("Da_HGroup", true);
  269. }
  270. );
  271. if (rate == 0)
  272. {
  273. ManaReso.SetActive("Da_Star2", false);
  274. ManaReso.SetActive("Da_Star3", false);
  275. }
  276. else if (rate == 1)
  277. {
  278. ManaReso.SetActive("Da_Star2", true);
  279. ManaReso.SetActive("Da_Star3", false);
  280. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  281. tween.AddEventOnetime
  282. (
  283. EventType.ForwardFinish,
  284. () =>
  285. {
  286. ManaReso.Get("Da_Star2").TweenReForScale();
  287. }
  288. );
  289. }
  290. else if (rate == 2)
  291. {
  292. ManaReso.SetActive("Da_Star2", true);
  293. ManaReso.SetActive("Da_Star3", true);
  294. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  295. tween.AddEventOnetime
  296. (
  297. EventType.ForwardFinish,
  298. () =>
  299. {
  300. ManaReso.Get("Da_Star2").TweenReForScale();
  301. }
  302. );
  303. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  304. tween.AddEventOnetime
  305. (
  306. EventType.ForwardFinish,
  307. () =>
  308. {
  309. ManaReso.Get("Da_Star3").TweenReForScale();
  310. }
  311. );
  312. }
  313. #endregion
  314. #region 金币钻石
  315. tween = ManaReso.Get("Da_ScoreLab").GetTweenNumber();
  316. tween.AddEventOnetime
  317. (
  318. EventType.ForwardFinish,
  319. () =>
  320. {
  321. ManaReso.Get("Da_CoinGroup").TweenReForScale();
  322. if (diamondFlag)
  323. {
  324. ManaReso.Get("Da_DiamondGroup").TweenReForScale();
  325. }
  326. }
  327. );
  328. tween = ManaReso.Get("Da_CoinGroup").GetTweenScale();
  329. tween.AddEventOnetime
  330. (
  331. EventType.ForwardFinish,
  332. () =>
  333. {
  334. ManaReso.Get("Da_CoinLab").TweenReForNumber();
  335. }
  336. );
  337. if (diamondFlag)
  338. {
  339. tween = ManaReso.Get("Da_DiamondGroup").GetTweenScale();
  340. tween.AddEventOnetime
  341. (
  342. EventType.ForwardFinish,
  343. () =>
  344. {
  345. ManaReso.Get("Da_DiamondLab").TweenReForNumber();
  346. }
  347. );
  348. }
  349. #endregion
  350. #endregion
  351. }
  352. public Award(XmlAttributeCollection attribute)
  353. {
  354. Flower.CoinFml = attribute[8].Value;
  355. DropGold.CoinFml = attribute[7].Value;
  356. Star.CD = float.Parse(attribute[9].Value);
  357. Star.Time = float.Parse(attribute[11].Value);
  358. ManaGarden.StarTime = float.Parse(attribute[10].Value);
  359. CoinFml = attribute[1].Value;
  360. FlowerFml = attribute[4].Value;
  361. DiamondFml = attribute[3].Value;
  362. string[] strings = attribute[2].Value.Split(',');
  363. DiamondMin = int.Parse(strings[0]);
  364. DiamondMax = int.Parse(strings[1]);
  365. strings = attribute[5].Value.Split(',');
  366. Odds = new List<float>()
  367. {
  368. float.Parse(strings[0]),
  369. float.Parse(strings[1]),
  370. float.Parse(strings[2]),
  371. };
  372. strings = attribute[6].Value.Split(',');
  373. Standard = new List<float>()
  374. {
  375. float.Parse(strings[0]),
  376. float.Parse(strings[1]),
  377. float.Parse(strings[2]),
  378. };
  379. }
  380. }
  381. public class ManaMiniGame : Regist
  382. {
  383. #region 变量
  384. public static int Score
  385. {
  386. get { return Score_; }
  387. set
  388. {
  389. Score_ = value;
  390. ManaReso.SetText("D_ScoreLab", ScoreLab + Score_);
  391. }
  392. }
  393. public static bool Game
  394. {
  395. get { return Game_; }
  396. set
  397. {
  398. Game_ = value;
  399. if (Game_)
  400. {
  401. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  402. }
  403. else
  404. {
  405. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0"));
  406. }
  407. }
  408. }
  409. public static bool Pause
  410. {
  411. get { return Pause_; }
  412. set
  413. {
  414. Pause_ = value;
  415. if (Game)
  416. {
  417. if (Pause_)
  418. {
  419. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2"));
  420. }
  421. else
  422. {
  423. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  424. }
  425. }
  426. else if (Prepare)
  427. {
  428. if (Pause_)
  429. {
  430. PrepareLab.GetStreamScale().Pause();
  431. }
  432. else
  433. {
  434. PrepareLab.GetStreamScale().Resume();
  435. }
  436. }
  437. }
  438. }
  439. public static bool Panalty
  440. {
  441. get { return Panalty_; }
  442. set
  443. {
  444. Panalty_ = value;
  445. if (Game)
  446. {
  447. if (Panalty_)
  448. {
  449. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3"));
  450. }
  451. else
  452. {
  453. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  454. }
  455. }
  456. }
  457. }
  458. public static float GameTimer
  459. {
  460. get { return GameTimer_; }
  461. set
  462. {
  463. GameTimer_ = value;
  464. TimerLab.text = (GameTime-GameTimer_).ToString("0.0");
  465. TimerBk.fillAmount = GameTimer_/GameTime;
  466. TimerBk.material.SetFloat("_Fill", TimerBk.fillAmount);
  467. }
  468. }
  469. private static int Score_;
  470. private static bool Game_;
  471. private static bool Pause_;
  472. private static bool Panalty_;
  473. private static float GameTimer_;
  474. public static Text TimerLab;
  475. public static Text PrepareLab;
  476. public static Image TimerBk;
  477. public static Award Award;
  478. public static List<Drop> DropList = new List<Drop>();
  479. public static List<Flower> OpList = new List<Flower>();
  480. public static List<Flower> IdleList = new List<Flower>();
  481. public static int MiniGameIndex;
  482. public static string ScoreLab;
  483. public static bool Prepare;
  484. public static bool FlowerLock;
  485. public static bool TutorialLock = true;
  486. public static bool DropDiamond;
  487. public static float OpTimer;
  488. public static float GoldTimer;
  489. public static float PanaltyTimer;
  490. public static float PrepareTimer;
  491. public static float DiamondTimer;
  492. public static float OpTime = 1.5f;
  493. public static float GameTime = 45;
  494. public static float PanaltyTime = 1;
  495. public static float NewOpTime;
  496. #endregion
  497. private void FixedUpdate()
  498. {
  499. if (Pause)
  500. {
  501. return;
  502. }
  503. if (Game)
  504. {
  505. GameThread();
  506. }
  507. if (Prepare)
  508. {
  509. PrepareThread();
  510. }
  511. }
  512. private void GameThread()
  513. {
  514. GameTimer += Time.fixedDeltaTime;
  515. if (GameTimer >= GameTime)
  516. {
  517. GameOver();
  518. return;
  519. }
  520. if (Panalty)
  521. {
  522. PanaltyTimer -= Time.fixedDeltaTime;
  523. if (PanaltyTimer <= 0)
  524. {
  525. Panalty = false;
  526. }
  527. }
  528. if (IdleList.Count > 0)
  529. {
  530. OpTimer -= Time.fixedDeltaTime;
  531. if (OpTimer <= 0)
  532. {
  533. NewOpTime -= NewOpTime * 0.03f;
  534. OpTimer = NewOpTime;
  535. CreateOperate();
  536. }
  537. }
  538. BonusThread();
  539. }
  540. private void BonusThread()
  541. {
  542. GoldTimer -= Time.fixedDeltaTime;
  543. if (GoldTimer < 0)
  544. {
  545. GoldTimer = Random.Range(3f, 6f);
  546. DropList.Add(ManaReso.GetDrop(ObjType.DropGold));
  547. }
  548. if (DropDiamond)
  549. {
  550. DiamondTimer -= Time.fixedDeltaTime;
  551. if (DiamondTimer < 0)
  552. {
  553. DropDiamond = false;
  554. DropList.Add(ManaReso.GetDrop(ObjType.DropDiamond));
  555. }
  556. }
  557. }
  558. private void PrepareThread()
  559. {
  560. PrepareTimer -= Time.fixedDeltaTime;
  561. if (PrepareTimer <= 0)
  562. {
  563. Prepare = false;
  564. GameBegin();
  565. }
  566. }
  567. public override void RegistValueA()
  568. {
  569. Award = new Award(ManaData.GetAwardConfig());
  570. MiniGameIndex = ManaData.GetPlayerInt("MiniGameIndex");
  571. }
  572. public override void RegistReference()
  573. {
  574. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  575. PrepareLab = ManaReso.Get<Text>("D_PrepareLab");
  576. TimerBk = ManaReso.Get<Image>("D_TimerIcon");
  577. }
  578. public static void Operate(OpType opType)
  579. {
  580. if (Panalty || !OpList.Valid())
  581. {
  582. return;
  583. }
  584. if (OpList[0].Operate(opType))
  585. {
  586. IdleList.Add(OpList[0]);
  587. OpList.Remove(OpList[0]);
  588. if (OpList.Count >= 2)
  589. {
  590. OpList[0].SetFirstOp();
  591. OpList[1].SetSecondOp();
  592. }
  593. else if (OpList.Count >= 1)
  594. {
  595. OpList[0].SetFirstOp();
  596. }
  597. }
  598. else
  599. {
  600. Panalty = true;
  601. PanaltyTimer = PanaltyTime;
  602. }
  603. }
  604. public static void CreateOperate()
  605. {
  606. ManaAudio.PlayClip(Clip.BubbleClip);
  607. if (ManaTutorial.TutorialA && TutorialLock)
  608. {
  609. Pause = true;
  610. TutorialLock = false;
  611. Flower flower = IdleList[4];
  612. flower.CreateOp(OpList.Count, OpType.Water);
  613. OpList.Add(flower);
  614. IdleList.Remove(flower);
  615. Tutorial.HightScreen(ManaReso.Get("D_WaterArrow0"), ManaReso.Get("D_WaterArrow1"), ManaReso.Get("D_Water1"));
  616. Tutorial.SetArea(OpList[0].OperateIcon.transform, 0.1f, 0.125f);
  617. ManaReso.AddButtonEventOnetime
  618. (
  619. "D_Water2",
  620. () =>
  621. {
  622. Pause = false;
  623. Tutorial.HightDisable();
  624. }
  625. );
  626. }
  627. else
  628. {
  629. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  630. flower.CreateOp(OpList.Count);
  631. OpList.Add(flower);
  632. IdleList.Remove(flower);
  633. }
  634. }
  635. public static void InitializeFlower()
  636. {
  637. float flowerRate = (float)Auxiliary.FmlParse(Award.FlowerFml, "l", ManaCenter.Level.ToString(), "f", ManaGarden.MyFlower.ToString());
  638. if (Random.Range(0, 1f) <= flowerRate)
  639. {
  640. if (ManaGarden.MyFlower < ManaGarden.TotalFlower)
  641. {
  642. foreach (var kv in ManaGarden.FlowerInfoDic)
  643. {
  644. if (kv.Value.Unlock == false)
  645. {
  646. Award.FlowerID = kv.Value.ID_;
  647. Award.FlowerLock = false;
  648. break;
  649. }
  650. }
  651. }
  652. else
  653. {
  654. Award.FlowerLock = true;
  655. }
  656. }
  657. else
  658. {
  659. Award.FlowerLock = true;
  660. }
  661. }
  662. public static void GameEnd()
  663. {
  664. PrepareLab.GetStreamScale().InOrigin = true;
  665. if (Game)
  666. {
  667. ManaCenter.MiniLock = false;
  668. ManaCenter.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
  669. }
  670. if (ManaCenter.MiniTimer <= 0)
  671. {
  672. ManaReso.Get("C_MiniGame").TweenForCG();
  673. }
  674. Score = 0;
  675. Pause = false;
  676. Game = false;
  677. Panalty = false;
  678. Prepare = false;
  679. GameTimer = GameTime;
  680. for (int i = 0; i < OpList.Count; i++)
  681. {
  682. OpList[i].GameOver();
  683. }
  684. for (int i = 0; i < IdleList.Count; i++)
  685. {
  686. IdleList[i].GameOver();
  687. }
  688. for (int i = 0; i < DropList.Count; i++)
  689. {
  690. DropList[i].Retrieve();
  691. DropList.RemoveAt(i--);
  692. }
  693. }
  694. public static void GameOver()
  695. {
  696. ManaAudio.PlayClip(Clip.MiniEndClip);
  697. Award.GetAward(Score);
  698. ManaCenter.MiniGameAmt++;
  699. FlowerLock = false;
  700. GameEnd();
  701. }
  702. public static void GameEnter()
  703. {
  704. if (ManaTutorial.TutorialA)
  705. {
  706. Award.FlowerID = 1;
  707. Award.FlowerLock = true;
  708. }
  709. else
  710. {
  711. if (!FlowerLock)
  712. {
  713. InitializeFlower();
  714. FlowerLock = true;
  715. }
  716. }
  717. if (Award.FlowerLock)
  718. {
  719. for (int i = 1; i < 10; i++)
  720. {
  721. while (true)
  722. {
  723. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  724. if (flowerInfo.Unlock)
  725. {
  726. IdleList.Add(ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + i)));
  727. break;
  728. }
  729. }
  730. }
  731. }
  732. else
  733. {
  734. List<int> idList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  735. int special = idList.Random(true);
  736. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special)));
  737. for (int i = 0; i < idList.Count; i++)
  738. {
  739. while (true)
  740. {
  741. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  742. if (flowerInfo.Unlock)
  743. {
  744. IdleList.Add(ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i])));
  745. break;
  746. }
  747. }
  748. }
  749. }
  750. ScoreLab = Language.GetStr("UI", "D_ScoreLab");
  751. TimerBk.fillAmount = 0;
  752. TimerLab.text = GameTime.ToString("0");
  753. ManaReso.Get("C_MiniGame").TweenBacCG();
  754. ManaReso.SetActive("D_Rip1", false);
  755. ManaReso.SetActive("D_Begin", true);
  756. ManaReso.SetActive("D_Water1", false);
  757. ManaReso.SetActive("D_Fertilize1", false);
  758. }
  759. public static void GameBegin()
  760. {
  761. Game = true;
  762. MiniGameIndex++;
  763. Score = 0;
  764. OpTimer = OpTime;
  765. GoldTimer = Random.Range(3f, 6f);
  766. GameTimer = 0;
  767. NewOpTime = OpTime;
  768. DiamondTimer = Random.Range(0f, GameTime - 5);
  769. for (int i = 0; i < IdleList.Count; i++)
  770. {
  771. IdleList[i].GameBegin();
  772. }
  773. if (Random.Range(5, 9) <= MiniGameIndex)
  774. {
  775. MiniGameIndex = 0;
  776. DropDiamond = true;
  777. }
  778. else
  779. {
  780. if (Random.Range(0, 1f) <= 0.01f)
  781. {
  782. DropDiamond = true;
  783. }
  784. else
  785. {
  786. DropDiamond = false;
  787. }
  788. }
  789. }
  790. public static void GamePrepare()
  791. {
  792. Prepare = true;
  793. PrepareTimer = 3;
  794. ManaReso.Get("D_Rip1").SetActive(true);
  795. ManaReso.Get("D_Water1").SetActive(true);
  796. ManaReso.Get("D_Fertilize1").SetActive(true);
  797. ManaReso.Get("D_Begin").SetActive(false);
  798. PrepareLab.StreamForScale();
  799. }
  800. public void OnApplicationPause(bool pause)
  801. {
  802. if (!pause)
  803. {
  804. if (!ManaTutorial.TutorialA)
  805. {
  806. if (Game || Prepare)
  807. {
  808. ManaReso.Get<Button>("D_Quit").onClick.Invoke();
  809. }
  810. }
  811. }
  812. }
  813. }
  814. #region DebugList
  815. //结束界面的图标能否重复显示
  816. #endregion