ManaMiniGame.cs 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  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. GameA = true;
  790. //if (ManaCenter.Level >= 18)
  791. //{
  792. // if (Random.Range(0f, 1f) <= 0.5f)
  793. // {
  794. // GameB = true;
  795. // }
  796. // else
  797. // {
  798. // GameA = true;
  799. // }
  800. //}
  801. //else
  802. //{
  803. // GameA = true;
  804. //}
  805. }
  806. public static void GameEnd()
  807. {
  808. PrepareLab.GetStreamScale().InOrigin = true;
  809. if (Game)
  810. {
  811. ManaCenter.MiniLock = false;
  812. ManaCenter.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
  813. }
  814. if (ManaCenter.MiniTimer <= 0)
  815. {
  816. ManaReso.Get("C_MiniGame").TweenForCG();
  817. }
  818. Score = 0;
  819. Pause = false;
  820. Game = false;
  821. Panalty = false;
  822. Prepare = false;
  823. GameTimer = GameTime;
  824. for (int i = 0; i < OpList.Count; i++)
  825. {
  826. OpList[i].GameOver();
  827. }
  828. for (int i = 0; i < IdleList.Count; i++)
  829. {
  830. IdleList[i].GameOver();
  831. }
  832. for (int i = 0; i < DropList.Count; i++)
  833. {
  834. DropList[i].Retrieve();
  835. DropList.RemoveAt(i--);
  836. }
  837. }
  838. public static void GameOver()
  839. {
  840. ManaAudio.PlayClip(Clip.MiniEndClip);
  841. Award.GetAward(Score);
  842. ManaCenter.MiniGameAmt++;
  843. FlowerLock = false;
  844. GameEnd();
  845. }
  846. public static void GameEnter()
  847. {
  848. if (ManaTutorial.TutorialA)
  849. {
  850. Award.FlowerID = 1;
  851. Award.FlowerLock = true;
  852. InitializeMode();
  853. }
  854. else
  855. {
  856. if (!FlowerLock)
  857. {
  858. InitializeMode();
  859. InitializeAward();
  860. FlowerLock = true;
  861. }
  862. }
  863. if (GameA)
  864. {
  865. GameEnterA();
  866. }
  867. if (GameB)
  868. {
  869. GameEnterB();
  870. }
  871. ScoreLab = Language.GetStr("UI", "D_ScoreLab");
  872. TimerBk.fillAmount = 0;
  873. TimerLab.text = GameTime.ToString("0");
  874. ManaReso.Get("C_MiniGame").TweenBacCG();
  875. }
  876. public static void GameEnterA()
  877. {
  878. D_Operate1.SetActive(true);
  879. D_Timer.SetParent(D_Status1);
  880. D_Grid.SetParent(D_Status1);
  881. D_Begin.SetParent(D_Operate1);
  882. PrepareLab.SetParent(ManaReso.Get("D_PrepareLayout1"));
  883. ManaReso.SetActive("D_Rip1", false);
  884. ManaReso.SetActive("D_Water1", false);
  885. ManaReso.SetActive("D_Fertilize1", false);
  886. ManaReso.SetActive("D_Begin", true);
  887. if (Award.FlowerLock)
  888. {
  889. for (int i = 1; i < 10; i++)
  890. {
  891. while (true)
  892. {
  893. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  894. if (flowerInfo.Unlock)
  895. {
  896. IdleList.Add(ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + i)));
  897. break;
  898. }
  899. }
  900. }
  901. }
  902. else
  903. {
  904. List<int> idList = new List<int>();
  905. idList = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9};
  906. int special = idList.Random(true);
  907. Flower flower = ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special));
  908. IdleList.Add(flower);
  909. for (int i = 0; i < idList.Count; i++)
  910. {
  911. while (true)
  912. {
  913. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  914. if (flowerInfo.Unlock)
  915. {
  916. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  917. IdleList.Add(flower);
  918. break;
  919. }
  920. }
  921. }
  922. }
  923. }
  924. public static void GameEnterB()
  925. {
  926. D_Operate2.SetActive(true);
  927. D_Timer.SetParent(D_Status2);
  928. D_Grid.SetParent(D_Status2);
  929. D_Begin.SetParent(D_Operate2);
  930. PrepareLab.SetParent(ManaReso.Get("D_PrepareLayout2"));
  931. ManaReso.SetActive("D_FlowerBtn1", false);
  932. ManaReso.SetActive("D_FlowerBtn2", false);
  933. ManaReso.SetActive("D_FlowerBtn3", false);
  934. ManaReso.SetActive("D_FlowerBtn4", false);
  935. ManaReso.SetActive("D_FlowerBtn5", false);
  936. ManaReso.SetActive("D_FlowerBtn6", false);
  937. ManaReso.SetActive("D_Begin", true);
  938. List<int> idList = new List<int>() {1, 2, 4, 5, 7, 8};
  939. FlowerDic = new Dictionary<int, Flower>();
  940. Flower flower;
  941. if (Award.FlowerLock)
  942. {
  943. for (int i = 0; i < idList.Count; i++)
  944. {
  945. while (true)
  946. {
  947. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  948. if (flowerInfo.Unlock)
  949. {
  950. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  951. IdleList.Add(flower);
  952. FlowerDic.Add(idList[i], flower);
  953. break;
  954. }
  955. }
  956. }
  957. }
  958. else
  959. {
  960. int special = idList.Random(true);
  961. flower = ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special));
  962. IdleList.Add(flower);
  963. FlowerDic.Add(special, flower);
  964. for (int i = 0; i < idList.Count; i++)
  965. {
  966. while (true)
  967. {
  968. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  969. if (flowerInfo.Unlock)
  970. {
  971. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  972. IdleList.Add(flower);
  973. FlowerDic.Add(idList[i], flower);
  974. break;
  975. }
  976. }
  977. }
  978. }
  979. for (int i = 0; i < IdleList.Count; i++)
  980. {
  981. IdleList[i].FlowerIcon.CreateTweenSr(1, 0, 0.25f, true, false, Curve.EaseOutQuad, false, true);
  982. }
  983. ManaReso.Get("D_Mask").TweenBacGra();
  984. }
  985. public static void GameBegin()
  986. {
  987. Game = true;
  988. MiniGameIndex++;
  989. Score = 0;
  990. OpTimer = OpTime;
  991. FadeTimer = FadeTime;
  992. GoldTimer = Random.Range(3f, 6f);
  993. GameTimer = 0;
  994. NewOpTime = OpTime;
  995. NewFadeTime = FadeTime;
  996. DiamondTimer = Random.Range(0f, GameTime - 5);
  997. if (GameA)
  998. {
  999. for (int i = 0; i < IdleList.Count; i++)
  1000. {
  1001. IdleList[i].GameBegin();
  1002. }
  1003. }
  1004. if (GameB)
  1005. {
  1006. RoundReset();
  1007. }
  1008. if (Random.Range(5, 9) <= MiniGameIndex)
  1009. {
  1010. MiniGameIndex = 0;
  1011. DropDiamond = true;
  1012. }
  1013. else
  1014. {
  1015. if (Random.Range(0, 1f) <= 0.01f)
  1016. {
  1017. DropDiamond = true;
  1018. }
  1019. else
  1020. {
  1021. DropDiamond = false;
  1022. }
  1023. }
  1024. }
  1025. public static void GamePrepare()
  1026. {
  1027. Prepare = true;
  1028. PrepareTimer = 3;
  1029. ManaReso.Get("D_Begin").SetActive(false);
  1030. if (GameA)
  1031. {
  1032. ManaReso.Get("D_Rip1").SetActive(true);
  1033. ManaReso.Get("D_Water1").SetActive(true);
  1034. ManaReso.Get("D_Fertilize1").SetActive(true);
  1035. }
  1036. if (GameB)
  1037. {
  1038. ManaReso.Get("D_Mask").TweenForGra();
  1039. ManaReso.SetActive("D_FlowerBtn1", true);
  1040. ManaReso.SetActive("D_FlowerBtn2", true);
  1041. ManaReso.SetActive("D_FlowerBtn3", true);
  1042. ManaReso.SetActive("D_FlowerBtn4", true);
  1043. ManaReso.SetActive("D_FlowerBtn5", true);
  1044. ManaReso.SetActive("D_FlowerBtn6", true);
  1045. ManaReso.SetSprite("D_FlowerIcon1", FlowerDic[1].FlowerInfo.Icon).Resize(1f, 1f);
  1046. ManaReso.SetSprite("D_FlowerIcon2", FlowerDic[2].FlowerInfo.Icon).Resize(1f, 1f);
  1047. ManaReso.SetSprite("D_FlowerIcon3", FlowerDic[4].FlowerInfo.Icon).Resize(1f, 1f);
  1048. ManaReso.SetSprite("D_FlowerIcon4", FlowerDic[5].FlowerInfo.Icon).Resize(1f, 1f);
  1049. ManaReso.SetSprite("D_FlowerIcon5", FlowerDic[7].FlowerInfo.Icon).Resize(1f, 1f);
  1050. ManaReso.SetSprite("D_FlowerIcon6", FlowerDic[8].FlowerInfo.Icon).Resize(1f, 1f);
  1051. }
  1052. PrepareLab.StreamForScale();
  1053. }
  1054. public static void RoundEnd()
  1055. {
  1056. ManaReso.Get("D_Mask").TweenForGra();
  1057. }
  1058. public static void RoundReset()
  1059. {
  1060. for (int i = 0; i < FadeList.Count; i++)
  1061. {
  1062. IdleList.Add(FadeList[i]);
  1063. }
  1064. NewFadeTime -= NewFadeTime * 0.3f;
  1065. FadeTimer = NewFadeTime;
  1066. FadeList = new List<Flower>();
  1067. IndexList = new List<int>();
  1068. List<int> randomList = new List<int>() { 1, 2, 4, 5, 7, 8 };
  1069. for (int i = 0; i < randomList.Count; i++)
  1070. {
  1071. IndexList.Add(randomList.Random(true));
  1072. i--;
  1073. }
  1074. }
  1075. public static void RoundBegin()
  1076. {
  1077. ManaReso.Get("D_Mask").TweenBacGra();
  1078. }
  1079. public void OnApplicationPause(bool pause)
  1080. {
  1081. if (!pause)
  1082. {
  1083. if (!ManaTutorial.TutorialA)
  1084. {
  1085. if (Game || Prepare)
  1086. {
  1087. ManaReso.Get<Button>("D_Quit").onClick.Invoke();
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. #region DebugList
  1094. //结束界面的图标能否重复显示
  1095. #endregion