ManaMiniGame.cs 38 KB

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