ManaMiniGame.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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. score = (int)Mathf.Clamp(score, 1, Mathf.Infinity);
  32. if (score < Standard[1])
  33. {
  34. rate = 0;
  35. }
  36. else if (score < Standard[2])
  37. {
  38. rate = 1;
  39. }
  40. else
  41. {
  42. rate = 2;
  43. }
  44. #endregion
  45. #region Reset
  46. bool flowerFlag = false;
  47. bool diamondFlag = false;
  48. #endregion
  49. StringBuilder sb = new StringBuilder();
  50. #region Coin
  51. int coin = (int)Auxiliary.FmlParse(CoinFml, "s", score.ToString(), "l", Mathf.Clamp(ManaCenter.Level, 1, 9999).ToString());
  52. coin = (int)(coin * (1 + ManaCenter.SkillPlus) + BonusCoin);
  53. coin = (int) Mathf.Clamp(coin, 1, Mathf.Infinity);
  54. ManaCenter.Coin += coin;
  55. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", coin);
  56. #endregion
  57. #region Diamond
  58. int diamond = 0;
  59. float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaCenter.Level, 1, 1000).ToString());
  60. if (Random.Range(0, 1f) <= diamondRate)
  61. {
  62. diamondFlag = true;
  63. diamond = (int)(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond);
  64. ManaCenter.Diamond += diamond;
  65. ManaReso.SetActive("Da_Diamond", true);
  66. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", diamond);
  67. }
  68. else
  69. {
  70. if (BonusDiamond > 0)
  71. {
  72. diamondFlag = true;
  73. diamond = BonusDiamond;
  74. ManaCenter.Diamond += diamond;
  75. ManaReso.SetActive("Da_Diamond", true);
  76. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", diamond);
  77. }
  78. }
  79. #endregion
  80. #region Flower
  81. if (ManaTutorial.TutorialA)
  82. {
  83. flowerFlag = true;
  84. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[1];
  85. ManaReso.SetActive("Da_FlowerIcon", true);
  86. ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
  87. ManaReso.Get<Image>("Da_FlowerIcon").Resize(0.2f, 0.2f);
  88. ManaReso.SetText("Da_FlowerLab", flowerInfo.Name);
  89. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  90. }
  91. else
  92. {
  93. if (!FlowerLock)
  94. {
  95. flowerFlag = true;
  96. if (Random.Range(0, 1f) <= Odds[rate])
  97. {
  98. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerID];
  99. flowerInfo.Unlock = true;
  100. ManaReso.SetActive("Da_Flower", true);
  101. ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
  102. ManaReso.Get<Image>("Da_FlowerIcon").Resize(0.2f, 0.2f);
  103. ManaReso.SetText("Da_FlowerLab", flowerInfo.Name);
  104. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  105. }
  106. else
  107. {
  108. ManaReso.SetActive("Da_Flower", false);
  109. ManaReso.SetText("Da_FlowerLab", Language.GetStr("UI", "Da_HigherScore"));
  110. }
  111. }
  112. }
  113. #endregion
  114. Info = sb.ToString();
  115. BonusCoin = 0;
  116. BonusDiamond = 0;
  117. #endregion
  118. #region 构造动画
  119. #region Reset
  120. ManaReso.Get("Da_Info").TweenForCG();
  121. ManaReso.SetText("Da_Tit", Language.GetStr("UI", "Da_Tit1"));
  122. ManaReso.SetText("Da_CoinLab", "0");
  123. ManaReso.SetText("Da_DiamondLab", "0");
  124. ManaReso.SetActive("Da_Lab", false);
  125. ManaReso.SetActive("Da_Quit", false);
  126. ManaReso.SetActive("Da_Cancel", false);
  127. ManaReso.SetActive("Da_CoinLab", false);
  128. ManaReso.SetActive("Da_ScoreTit", false);
  129. ManaReso.SetActive("Da_ScoreLab", false);
  130. ManaReso.SetActive("Da_GetAward", false);
  131. ManaReso.SetActive("Da_DiamondLab", false);
  132. ManaReso.SetActive("Da_VGroup", true);
  133. ManaReso.SetActive("Da_HGroup", false);
  134. ManaReso.SetActive("Da_FlowerGroup", false);
  135. ManaReso.SetActive("Da_DiamondGroup", false);
  136. if (flowerFlag)
  137. {
  138. ManaReso.SetActive("Da_FlowerGroup", true);
  139. }
  140. if (diamondFlag)
  141. {
  142. ManaReso.SetActive("Da_DiamondGroup", true);
  143. }
  144. Auxiliary.Instance.DelayCall
  145. (
  146. () =>
  147. {
  148. ManaReso.Get<VerticalLayoutGroup>("Da_VGroup").enabled = false;
  149. ManaReso.SetActive("Da_CoinGroup", false);
  150. ManaReso.SetActive("Da_FlowerGroup", false);
  151. ManaReso.SetActive("Da_DiamondGroup", false);
  152. },
  153. 1
  154. );
  155. float timeCoin = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(coin / 15f));
  156. float timeScore = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(score / 50f));
  157. float timeDiamond = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(diamond / 15f));
  158. float time = Mathf.Max(timeCoin, timeDiamond);
  159. ManaReso.Get("Da_CoinLab").CreateTweenNumber(0, coin, time, false, true, Curve.EaseOutQuad);
  160. ManaReso.Get("Da_ScoreLab").CreateTweenNumber(0, score, timeScore, false, true, Curve.EaseOutQuad);
  161. ManaReso.Get("Da_DiamondLab").CreateTweenNumber(0, diamond, time, false, true, Curve.EaseOutQuad);
  162. #endregion
  163. #region 花
  164. TweenRoot tween;
  165. if (flowerFlag)
  166. {
  167. tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
  168. tween.AddEventOnetime
  169. (
  170. EventType.ForwardFinish,
  171. () =>
  172. {
  173. ManaReso.Get("Da_FlowerGroup").TweenReForScale();
  174. }
  175. );
  176. }
  177. #endregion
  178. #region 按钮
  179. if (flowerFlag)
  180. {
  181. tween = ManaReso.Get("Da_FlowerGroup").GetTweenScale();
  182. tween.AddEventOnetime
  183. (
  184. EventType.ForwardFinish,
  185. () =>
  186. {
  187. ManaReso.Get("Da_GetAward").TweenReForCG();
  188. }
  189. );
  190. }
  191. else
  192. {
  193. tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
  194. tween.AddEventOnetime
  195. (
  196. EventType.ForwardFinish,
  197. () =>
  198. {
  199. ManaReso.Get("Da_GetAward").TweenReForCG();
  200. }
  201. );
  202. }
  203. if (ManaTutorial.TutorialA)
  204. {
  205. tween = ManaReso.Get("Da_GetAward").GetTweenCG();
  206. tween.AddEventOnetime
  207. (
  208. EventType.ForwardFinish,
  209. () =>
  210. {
  211. Tutorial.HightScreen(ManaReso.Get("Da_Arrow0"), ManaReso.Get("Da_Arrow1"), ManaReso.Get("Da_GetAward"));
  212. }
  213. );
  214. }
  215. ManaReso.AddButtonEventOnetime
  216. (
  217. "Da_GetAward",
  218. () =>
  219. {
  220. ManaReso.Get("Da_VGroup").GetComponent<VerticalLayoutGroup>().enabled = true;
  221. }
  222. );
  223. #endregion
  224. #region 得分
  225. if (rate == 0)
  226. {
  227. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  228. }
  229. else if (rate == 1)
  230. {
  231. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  232. }
  233. else if (rate == 2)
  234. {
  235. tween = ManaReso.Get("Da_Star3").GetTweenScale();
  236. }
  237. tween.AddEventOnetime
  238. (
  239. EventType.ForwardFinish,
  240. () =>
  241. {
  242. ManaReso.Get("Da_ScoreTit").TweenReForFont();
  243. }
  244. );
  245. tween = ManaReso.Get("Da_ScoreTit").GetTweenFont();
  246. tween.InOrigin = true;
  247. tween.AddEventOnetime
  248. (
  249. EventType.ForwardFinish,
  250. () =>
  251. {
  252. ManaReso.Get("Da_ScoreLab").TweenReForNumber();
  253. }
  254. );
  255. #endregion
  256. #region 五角星
  257. tween = ManaReso.Get("Da_Star3").GetTweenScale();
  258. tween.InOrigin = true;
  259. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  260. tween.InOrigin = true;
  261. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  262. tween.InOrigin = true;
  263. tween = ManaReso.Get("Da_Info").GetTweenCG();
  264. tween.AddEventOnetime
  265. (
  266. EventType.ForwardFinish,
  267. () =>
  268. {
  269. ManaReso.Get("Da_Star1").TweenReForScale();
  270. ManaReso.SetActive("Da_HGroup", true);
  271. }
  272. );
  273. if (rate == 0)
  274. {
  275. ManaReso.SetActive("Da_Star2", false);
  276. ManaReso.SetActive("Da_Star3", false);
  277. }
  278. else if (rate == 1)
  279. {
  280. ManaReso.SetActive("Da_Star2", true);
  281. ManaReso.SetActive("Da_Star3", false);
  282. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  283. tween.AddEventOnetime
  284. (
  285. EventType.ForwardFinish,
  286. () =>
  287. {
  288. ManaReso.Get("Da_Star2").TweenReForScale();
  289. }
  290. );
  291. }
  292. else if (rate == 2)
  293. {
  294. ManaReso.SetActive("Da_Star2", true);
  295. ManaReso.SetActive("Da_Star3", true);
  296. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  297. tween.AddEventOnetime
  298. (
  299. EventType.ForwardFinish,
  300. () =>
  301. {
  302. ManaReso.Get("Da_Star2").TweenReForScale();
  303. }
  304. );
  305. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  306. tween.AddEventOnetime
  307. (
  308. EventType.ForwardFinish,
  309. () =>
  310. {
  311. ManaReso.Get("Da_Star3").TweenReForScale();
  312. }
  313. );
  314. }
  315. #endregion
  316. #region 金币钻石
  317. tween = ManaReso.Get("Da_ScoreLab").GetTweenNumber();
  318. tween.AddEventOnetime
  319. (
  320. EventType.ForwardFinish,
  321. () =>
  322. {
  323. ManaReso.Get("Da_CoinGroup").TweenReForScale();
  324. if (diamondFlag)
  325. {
  326. ManaReso.Get("Da_DiamondGroup").TweenReForScale();
  327. }
  328. }
  329. );
  330. tween = ManaReso.Get("Da_CoinGroup").GetTweenScale();
  331. tween.AddEventOnetime
  332. (
  333. EventType.ForwardFinish,
  334. () =>
  335. {
  336. ManaReso.Get("Da_CoinLab").TweenReForNumber();
  337. }
  338. );
  339. if (diamondFlag)
  340. {
  341. tween = ManaReso.Get("Da_DiamondGroup").GetTweenScale();
  342. tween.AddEventOnetime
  343. (
  344. EventType.ForwardFinish,
  345. () =>
  346. {
  347. ManaReso.Get("Da_DiamondLab").TweenReForNumber();
  348. }
  349. );
  350. }
  351. #endregion
  352. #endregion
  353. }
  354. public Award(XmlAttributeCollection attribute)
  355. {
  356. Flower.CoinFml = attribute[8].Value;
  357. DropGold.CoinFml = attribute[7].Value;
  358. Star.CD = float.Parse(attribute[9].Value);
  359. Star.Time = float.Parse(attribute[11].Value);
  360. string[] strings = attribute[10].Value.Split(',');
  361. ManaGarden.MinStarTime = float.Parse(strings[0]);
  362. ManaGarden.MaxStarTime = float.Parse(strings[1]);
  363. ManaGarden.StarTimer = Mathf.Lerp(ManaGarden.MinStarTime, ManaGarden.MaxStarTime, Random.Range(0f, 1f));
  364. CoinFml = attribute[1].Value;
  365. FlowerFml = attribute[4].Value;
  366. DiamondFml = attribute[3].Value;
  367. strings = attribute[2].Value.Split(',');
  368. DiamondMin = int.Parse(strings[0]);
  369. DiamondMax = int.Parse(strings[1]);
  370. strings = attribute[5].Value.Split(',');
  371. Odds = new List<float>()
  372. {
  373. float.Parse(strings[0]),
  374. float.Parse(strings[1]),
  375. float.Parse(strings[2]),
  376. };
  377. strings = attribute[6].Value.Split(',');
  378. Standard = new List<float>()
  379. {
  380. float.Parse(strings[0]),
  381. float.Parse(strings[1]),
  382. float.Parse(strings[2]),
  383. };
  384. }
  385. }
  386. public class ManaMiniGame : Regist
  387. {
  388. #region 变量
  389. public static int Score
  390. {
  391. get { return Score_; }
  392. set
  393. {
  394. Score_ = value;
  395. ManaReso.SetText("D_ScoreLab", ScoreLab + Score_);
  396. }
  397. }
  398. public static bool Game
  399. {
  400. get { return Game_; }
  401. set
  402. {
  403. Game_ = value;
  404. if (Game_)
  405. {
  406. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  407. }
  408. else
  409. {
  410. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0"));
  411. }
  412. }
  413. }
  414. public static bool Pause
  415. {
  416. get { return Pause_; }
  417. set
  418. {
  419. Pause_ = value;
  420. if (Game)
  421. {
  422. if (Pause_)
  423. {
  424. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2"));
  425. }
  426. else
  427. {
  428. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  429. }
  430. }
  431. else if (Prepare)
  432. {
  433. if (Pause_)
  434. {
  435. PrepareLab.GetStreamScale().Pause();
  436. }
  437. else
  438. {
  439. PrepareLab.GetStreamScale().Resume();
  440. }
  441. }
  442. }
  443. }
  444. public static bool Panalty
  445. {
  446. get { return Panalty_; }
  447. set
  448. {
  449. Panalty_ = value;
  450. if (Game)
  451. {
  452. if (Panalty_)
  453. {
  454. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3"));
  455. }
  456. else
  457. {
  458. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  459. }
  460. }
  461. }
  462. }
  463. public static float GameTimer
  464. {
  465. get { return GameTimer_; }
  466. set
  467. {
  468. GameTimer_ = value;
  469. TimerLab.text = (GameTime-GameTimer_).ToString("0.0");
  470. TimerBk.fillAmount = GameTimer_/GameTime;
  471. TimerBk.material.SetFloat("_Fill", TimerBk.fillAmount);
  472. }
  473. }
  474. private static int Score_;
  475. private static bool Game_;
  476. private static bool Pause_;
  477. private static bool Panalty_;
  478. private static float GameTimer_;
  479. public static Text TimerLab;
  480. public static Text PrepareLab;
  481. public static Image TimerBk;
  482. public static Award Award;
  483. public static Transform D_Grid;
  484. public static Transform D_Timer;
  485. public static Transform D_Begin;
  486. public static Transform D_Status1;
  487. public static Transform D_Status2;
  488. public static Transform D_Operate1;
  489. public static Transform D_Operate2;
  490. public static List<int> IndexList = new List<int>();
  491. public static List<Drop> DropList = new List<Drop>();
  492. public static List<Flower> OpList = new List<Flower>();
  493. public static List<Flower> IdleList = new List<Flower>();
  494. public static List<Flower> FadeList = new List<Flower>();
  495. public static Dictionary<int, Flower> FlowerDic = new Dictionary<int, Flower>();
  496. public static int MiniGameIndex;
  497. public static string ScoreLab;
  498. public static bool GameA;
  499. public static bool GameB;
  500. public static bool Prepare;
  501. public static bool FlowerLock;
  502. public static bool TutorialLock = true;
  503. public static bool DropDiamond;
  504. public static float OpTimer;
  505. public static float FadeTimer;
  506. public static float GoldTimer;
  507. public static float PanaltyTimer;
  508. public static float PrepareTimer;
  509. public static float DiamondTimer;
  510. public static float OpTime = 1.5f;
  511. public static float FadeTime = 2f;
  512. public static float GameTime = 45f;
  513. public static float PanaltyTime = 1f;
  514. public static float NewOpTime;
  515. public static float NewFadeTime;
  516. #endregion
  517. private void FixedUpdate()
  518. {
  519. if (Pause)
  520. {
  521. return;
  522. }
  523. if (Game)
  524. {
  525. GameThreadA();
  526. GameThreadB();
  527. }
  528. if (Prepare)
  529. {
  530. PrepareThread();
  531. }
  532. }
  533. private void GameThreadA()
  534. {
  535. if (GameB)
  536. {
  537. return;
  538. }
  539. GameTimer += Time.fixedDeltaTime;
  540. if (GameTimer >= GameTime)
  541. {
  542. GameOver();
  543. return;
  544. }
  545. if (Panalty)
  546. {
  547. PanaltyTimer -= Time.fixedDeltaTime;
  548. if (PanaltyTimer <= 0)
  549. {
  550. Panalty = false;
  551. }
  552. }
  553. if (IdleList.Count > 0)
  554. {
  555. OpTimer -= Time.fixedDeltaTime;
  556. if (OpTimer <= 0)
  557. {
  558. NewOpTime -= NewOpTime * 0.03f;
  559. OpTimer = NewOpTime;
  560. CreateOperate();
  561. }
  562. }
  563. BonusThread();
  564. }
  565. private void GameThreadB()
  566. {
  567. if (GameA)
  568. {
  569. return;
  570. }
  571. GameTimer += Time.fixedDeltaTime;
  572. if (GameTimer >= GameTime)
  573. {
  574. GameOver();
  575. return;
  576. }
  577. if (Panalty)
  578. {
  579. PanaltyTimer -= Time.fixedDeltaTime;
  580. if (PanaltyTimer <= 0)
  581. {
  582. Panalty = false;
  583. }
  584. }
  585. if (FadeList.Count < 6)
  586. {
  587. FadeTimer -= Time.fixedDeltaTime;
  588. if (FadeTimer <= 0)
  589. {
  590. FadeTimer = NewFadeTime;
  591. Fade();
  592. }
  593. }
  594. BonusThread();
  595. }
  596. private void BonusThread()
  597. {
  598. GoldTimer -= Time.fixedDeltaTime;
  599. if (GoldTimer < 0)
  600. {
  601. GoldTimer = Random.Range(3f, 6f);
  602. DropList.Add(ManaReso.GetDrop(ObjType.DropGold));
  603. }
  604. if (DropDiamond)
  605. {
  606. DiamondTimer -= Time.fixedDeltaTime;
  607. if (DiamondTimer < 0)
  608. {
  609. DropDiamond = false;
  610. DropList.Add(ManaReso.GetDrop(ObjType.DropDiamond));
  611. }
  612. }
  613. }
  614. private void PrepareThread()
  615. {
  616. PrepareTimer -= Time.fixedDeltaTime;
  617. if (PrepareTimer <= 0)
  618. {
  619. Prepare = false;
  620. GameBegin();
  621. }
  622. }
  623. public override void RegistValueA()
  624. {
  625. Award = new Award(ManaData.GetAwardConfig());
  626. MiniGameIndex = ManaData.GetPlayerInt("MiniGameIndex");
  627. }
  628. public override void RegistReference()
  629. {
  630. D_Grid = ManaReso.Get("D_Grid");
  631. D_Begin = ManaReso.Get("D_Begin");
  632. D_Timer = ManaReso.Get("D_Timer");
  633. D_Status1 = ManaReso.Get("D_Status1");
  634. D_Status2 = ManaReso.Get("D_Status2");
  635. D_Operate1 = ManaReso.Get("D_Operate1");
  636. D_Operate2 = ManaReso.Get("D_Operate2");
  637. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  638. PrepareLab = ManaReso.Get<Text>("D_PrepareLab");
  639. TimerBk = ManaReso.Get<Image>("D_TimerIcon");
  640. }
  641. public static void Fade()
  642. {
  643. for (int i = 0; i < IndexList.Count; i++)
  644. {
  645. Flower flower = FlowerDic[IndexList[i]];
  646. if (FadeList.UniqueAdd(flower))
  647. {
  648. IdleList.Remove(flower);
  649. flower.PlayParticle();
  650. flower.FlowerIcon.TweenForSr();
  651. if (FadeList.Count == 6)
  652. {
  653. RoundBegin();
  654. }
  655. break;
  656. }
  657. }
  658. }
  659. public static void Operate(int index)
  660. {
  661. if (Panalty || !FadeList.Valid())
  662. {
  663. return;
  664. }
  665. if (IndexList.Count == 0)
  666. {
  667. return;
  668. }
  669. if (index == IndexList[0])
  670. {
  671. IndexList.RemoveAt(0);
  672. Flower flower = FlowerDic[index];
  673. ManaReso.GetHudText("+45", Color.white, 90, flower.ChildDic["ScorePosTra"], ManaReso.Get("D_MiniGame"), true);
  674. Score += 45;
  675. flower.PlayParticle();
  676. TweenRoot tween = flower.FlowerIcon.TweenBacSr();
  677. ManaAudio.PlayClip(Clip.BtnClip);
  678. if (IndexList.Count == 0)
  679. {
  680. tween.AddEventOnetime
  681. (
  682. EventType.BackwardFinish,
  683. () =>
  684. {
  685. RoundEnd();
  686. RoundReset();
  687. RoundBegin();
  688. }
  689. );
  690. }
  691. }
  692. else
  693. {
  694. Panalty = true;
  695. PanaltyTimer = PanaltyTime;
  696. ManaAudio.PlayClip(Clip.ErrorClip);
  697. }
  698. }
  699. public static void Operate(OpType opType)
  700. {
  701. if (Panalty || !OpList.Valid())
  702. {
  703. return;
  704. }
  705. if (OpList[0].Operate(opType))
  706. {
  707. IdleList.Add(OpList[0]);
  708. OpList.Remove(OpList[0]);
  709. if (OpList.Count >= 2)
  710. {
  711. OpList[0].SetFirstOp();
  712. OpList[1].SetSecondOp();
  713. }
  714. else if (OpList.Count >= 1)
  715. {
  716. OpList[0].SetFirstOp();
  717. }
  718. }
  719. else
  720. {
  721. Panalty = true;
  722. PanaltyTimer = PanaltyTime;
  723. }
  724. }
  725. public static void CreateOperate()
  726. {
  727. ManaAudio.PlayClip(Clip.BubbleClip);
  728. if (ManaTutorial.TutorialA && TutorialLock)
  729. {
  730. Pause = true;
  731. TutorialLock = false;
  732. Flower flower = IdleList[4];
  733. flower.CreateOp(OpList.Count, OpType.Water);
  734. OpList.Add(flower);
  735. IdleList.Remove(flower);
  736. Tutorial.HightScreen(ManaReso.Get("D_WaterArrow0"), ManaReso.Get("D_WaterArrow1"), ManaReso.Get("D_Water1"));
  737. Tutorial.SetArea(OpList[0].OperateIcon.transform, 0.1f, 0.125f);
  738. ManaReso.AddButtonEventOnetime
  739. (
  740. "D_Water2",
  741. () =>
  742. {
  743. Pause = false;
  744. Tutorial.HightDisable();
  745. }
  746. );
  747. }
  748. else
  749. {
  750. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  751. flower.CreateOp(OpList.Count);
  752. OpList.Add(flower);
  753. IdleList.Remove(flower);
  754. }
  755. }
  756. public static void InitializeAward()
  757. {
  758. float flowerRate = (float)Auxiliary.FmlParse(Award.FlowerFml, "l", ManaCenter.Level.ToString(), "f", ManaGarden.MyFlower.ToString());
  759. if (Random.Range(0, 1f) <= flowerRate)
  760. {
  761. if (ManaGarden.MyFlower < ManaGarden.TotalFlower)
  762. {
  763. foreach (var kv in ManaGarden.FlowerInfoDic)
  764. {
  765. if (kv.Value.Unlock == false)
  766. {
  767. Award.FlowerID = kv.Value.ID_;
  768. Award.FlowerLock = false;
  769. break;
  770. }
  771. }
  772. }
  773. else
  774. {
  775. Award.FlowerLock = true;
  776. }
  777. }
  778. else
  779. {
  780. Award.FlowerLock = true;
  781. }
  782. }
  783. public static void InitializeMode()
  784. {
  785. GameA = false;
  786. GameB = false;
  787. D_Operate1.SetActive(false);
  788. D_Operate2.SetActive(false);
  789. if (ManaCenter.Level >= 18)
  790. {
  791. if (Random.Range(0f, 1f) <= 0.5f)
  792. {
  793. GameB = true;
  794. }
  795. else
  796. {
  797. GameA = true;
  798. }
  799. }
  800. else
  801. {
  802. GameA = true;
  803. }
  804. }
  805. public static void GameEnd()
  806. {
  807. PrepareLab.GetStreamScale().InOrigin = true;
  808. if (Game)
  809. {
  810. ManaCenter.MiniLock = false;
  811. ManaCenter.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
  812. }
  813. if (ManaCenter.MiniTimer <= 0)
  814. {
  815. ManaReso.Get("C_MiniGame").TweenForCG();
  816. }
  817. Score = 0;
  818. Pause = false;
  819. Game = false;
  820. Panalty = false;
  821. Prepare = false;
  822. GameTimer = GameTime;
  823. for (int i = 0; i < OpList.Count; i++)
  824. {
  825. OpList[i].GameOver();
  826. }
  827. for (int i = 0; i < IdleList.Count; i++)
  828. {
  829. IdleList[i].GameOver();
  830. }
  831. for (int i = 0; i < DropList.Count; i++)
  832. {
  833. DropList[i].Retrieve();
  834. DropList.RemoveAt(i--);
  835. }
  836. }
  837. public static void GameOver()
  838. {
  839. ManaAudio.PlayClip(Clip.MiniEndClip);
  840. Award.GetAward(Score);
  841. ManaCenter.MiniGameAmt++;
  842. FlowerLock = false;
  843. GameEnd();
  844. }
  845. public static void GameEnter()
  846. {
  847. if (ManaTutorial.TutorialA)
  848. {
  849. Award.FlowerID = 1;
  850. Award.FlowerLock = true;
  851. InitializeMode();
  852. }
  853. else
  854. {
  855. if (!FlowerLock)
  856. {
  857. InitializeMode();
  858. InitializeAward();
  859. FlowerLock = true;
  860. }
  861. }
  862. if (GameA)
  863. {
  864. GameEnterA();
  865. }
  866. if (GameB)
  867. {
  868. GameEnterB();
  869. }
  870. ScoreLab = Language.GetStr("UI", "D_ScoreLab");
  871. TimerBk.fillAmount = 0;
  872. TimerLab.text = GameTime.ToString("0");
  873. ManaReso.Get("C_MiniGame").TweenBacCG();
  874. }
  875. public static void GameEnterA()
  876. {
  877. D_Operate1.SetActive(true);
  878. D_Timer.SetParent(D_Status1);
  879. D_Grid.SetParent(D_Status1);
  880. D_Begin.SetParent(D_Operate1);
  881. PrepareLab.SetParent(ManaReso.Get("D_PrepareLayout1"));
  882. ManaReso.SetActive("D_Rip1", false);
  883. ManaReso.SetActive("D_Water1", false);
  884. ManaReso.SetActive("D_Fertilize1", false);
  885. ManaReso.SetActive("D_Begin", true);
  886. if (Award.FlowerLock)
  887. {
  888. for (int i = 1; i < 10; i++)
  889. {
  890. while (true)
  891. {
  892. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  893. if (flowerInfo.Unlock)
  894. {
  895. IdleList.Add(ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + i)));
  896. break;
  897. }
  898. }
  899. }
  900. }
  901. else
  902. {
  903. List<int> idList = new List<int>();
  904. idList = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9};
  905. int special = idList.Random(true);
  906. Flower flower = ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special));
  907. IdleList.Add(flower);
  908. for (int i = 0; i < idList.Count; i++)
  909. {
  910. while (true)
  911. {
  912. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  913. if (flowerInfo.Unlock)
  914. {
  915. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  916. IdleList.Add(flower);
  917. break;
  918. }
  919. }
  920. }
  921. }
  922. }
  923. public static void GameEnterB()
  924. {
  925. D_Operate2.SetActive(true);
  926. D_Timer.SetParent(D_Status2);
  927. D_Grid.SetParent(D_Status2);
  928. D_Begin.SetParent(D_Operate2);
  929. PrepareLab.SetParent(ManaReso.Get("D_PrepareLayout2"));
  930. ManaReso.SetActive("D_FlowerBtn1", false);
  931. ManaReso.SetActive("D_FlowerBtn2", false);
  932. ManaReso.SetActive("D_FlowerBtn3", false);
  933. ManaReso.SetActive("D_FlowerBtn4", false);
  934. ManaReso.SetActive("D_FlowerBtn5", false);
  935. ManaReso.SetActive("D_FlowerBtn6", false);
  936. ManaReso.SetActive("D_Begin", true);
  937. List<int> idList = new List<int>() {1, 2, 4, 5, 7, 8};
  938. FlowerDic = new Dictionary<int, Flower>();
  939. Flower flower;
  940. if (Award.FlowerLock)
  941. {
  942. for (int i = 0; i < idList.Count; i++)
  943. {
  944. while (true)
  945. {
  946. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  947. if (flowerInfo.Unlock)
  948. {
  949. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  950. IdleList.Add(flower);
  951. FlowerDic.Add(idList[i], flower);
  952. break;
  953. }
  954. }
  955. }
  956. }
  957. else
  958. {
  959. int special = idList.Random(true);
  960. flower = ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special));
  961. IdleList.Add(flower);
  962. FlowerDic.Add(special, flower);
  963. for (int i = 0; i < idList.Count; i++)
  964. {
  965. while (true)
  966. {
  967. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  968. if (flowerInfo.Unlock)
  969. {
  970. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  971. IdleList.Add(flower);
  972. FlowerDic.Add(idList[i], flower);
  973. break;
  974. }
  975. }
  976. }
  977. }
  978. for (int i = 0; i < IdleList.Count; i++)
  979. {
  980. IdleList[i].FlowerIcon.CreateTweenSr(1, 0, 0.25f, true, false, Curve.EaseOutQuad, false, true);
  981. }
  982. ManaReso.Get("D_Mask").TweenBacGra();
  983. }
  984. public static void GameBegin()
  985. {
  986. Game = true;
  987. MiniGameIndex++;
  988. Score = 0;
  989. OpTimer = OpTime;
  990. FadeTimer = FadeTime;
  991. GoldTimer = Random.Range(3f, 6f);
  992. GameTimer = 0;
  993. NewOpTime = OpTime;
  994. NewFadeTime = FadeTime;
  995. DiamondTimer = Random.Range(0f, GameTime - 5);
  996. if (GameA)
  997. {
  998. for (int i = 0; i < IdleList.Count; i++)
  999. {
  1000. IdleList[i].GameBegin();
  1001. }
  1002. }
  1003. if (GameB)
  1004. {
  1005. RoundReset();
  1006. }
  1007. if (Random.Range(5, 9) <= MiniGameIndex)
  1008. {
  1009. MiniGameIndex = 0;
  1010. DropDiamond = true;
  1011. }
  1012. else
  1013. {
  1014. if (Random.Range(0, 1f) <= 0.01f)
  1015. {
  1016. DropDiamond = true;
  1017. }
  1018. else
  1019. {
  1020. DropDiamond = false;
  1021. }
  1022. }
  1023. }
  1024. public static void GamePrepare()
  1025. {
  1026. Prepare = true;
  1027. PrepareTimer = 3;
  1028. ManaReso.Get("D_Begin").SetActive(false);
  1029. if (GameA)
  1030. {
  1031. ManaReso.Get("D_Rip1").SetActive(true);
  1032. ManaReso.Get("D_Water1").SetActive(true);
  1033. ManaReso.Get("D_Fertilize1").SetActive(true);
  1034. }
  1035. if (GameB)
  1036. {
  1037. ManaReso.Get("D_Mask").TweenForGra();
  1038. ManaReso.SetActive("D_FlowerBtn1", true);
  1039. ManaReso.SetActive("D_FlowerBtn2", true);
  1040. ManaReso.SetActive("D_FlowerBtn3", true);
  1041. ManaReso.SetActive("D_FlowerBtn4", true);
  1042. ManaReso.SetActive("D_FlowerBtn5", true);
  1043. ManaReso.SetActive("D_FlowerBtn6", true);
  1044. ManaReso.SetSprite("D_FlowerIcon1", FlowerDic[1].FlowerInfo.Icon).Resize(1f, 1f);
  1045. ManaReso.SetSprite("D_FlowerIcon2", FlowerDic[2].FlowerInfo.Icon).Resize(1f, 1f);
  1046. ManaReso.SetSprite("D_FlowerIcon3", FlowerDic[4].FlowerInfo.Icon).Resize(1f, 1f);
  1047. ManaReso.SetSprite("D_FlowerIcon4", FlowerDic[5].FlowerInfo.Icon).Resize(1f, 1f);
  1048. ManaReso.SetSprite("D_FlowerIcon5", FlowerDic[7].FlowerInfo.Icon).Resize(1f, 1f);
  1049. ManaReso.SetSprite("D_FlowerIcon6", FlowerDic[8].FlowerInfo.Icon).Resize(1f, 1f);
  1050. }
  1051. PrepareLab.StreamForScale();
  1052. }
  1053. public static void RoundEnd()
  1054. {
  1055. ManaReso.Get("D_Mask").TweenForGra();
  1056. }
  1057. public static void RoundReset()
  1058. {
  1059. for (int i = 0; i < FadeList.Count; i++)
  1060. {
  1061. IdleList.Add(FadeList[i]);
  1062. }
  1063. NewFadeTime -= NewFadeTime * 0.3f;
  1064. FadeTimer = NewFadeTime;
  1065. FadeList = new List<Flower>();
  1066. IndexList = new List<int>();
  1067. List<int> randomList = new List<int>() { 1, 2, 4, 5, 7, 8 };
  1068. for (int i = 0; i < randomList.Count; i++)
  1069. {
  1070. IndexList.Add(randomList.Random(true));
  1071. i--;
  1072. }
  1073. }
  1074. public static void RoundBegin()
  1075. {
  1076. ManaReso.Get("D_Mask").TweenBacGra();
  1077. }
  1078. public void OnApplicationPause(bool pause)
  1079. {
  1080. if (!pause)
  1081. {
  1082. if (!ManaTutorial.TutorialA)
  1083. {
  1084. if (Game || Prepare)
  1085. {
  1086. ManaReso.Get<Button>("D_Quit").onClick.Invoke();
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. #region DebugList
  1093. //结束界面的图标能否重复显示
  1094. #endregion