MiniGameManager.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  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 Config
  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 static string FlowerIDRateFml;
  31. public static string FlowerAmtRateFml;
  32. public List<float> Odds = new List<float>();
  33. public List<float> Standard = new List<float>();
  34. #endregion
  35. #endregion
  36. public void GetAward(int score)
  37. {
  38. #region 获得奖励
  39. #region Rate
  40. Score = (int)Mathf.Clamp(score, 1, Mathf.Infinity);
  41. if (Score < Standard[1])
  42. {
  43. Rate = 0;
  44. }
  45. else if (Score < Standard[2])
  46. {
  47. Rate = 1;
  48. }
  49. else
  50. {
  51. Rate = 2;
  52. }
  53. #endregion
  54. #region Reset
  55. FlowerFlag = false;
  56. DiamondFlag = false;
  57. #endregion
  58. StringBuilder sb = new StringBuilder();
  59. #region Coin
  60. Coin = (int)Auxiliary.FmlParse(CoinFml, "s", Score.ToString(), "l", Mathf.Clamp(Manager.Level, 1, 9999).ToString());
  61. Coin = (int)(Coin * (1 + Manager.SkillPlus) + BonusCoin);
  62. Coin = (int) Mathf.Clamp(Coin, 1, Mathf.Infinity);
  63. ResourceManager.Get<Text>(ObjectLabel.Da_CoinLab).text = Coin.ToString();
  64. ResourceManager.Get<Text>(ObjectLabel.Da_CoinLab).Resize(true, false);
  65. ResourceManager.Get<ContentSizeFitter>(ObjectLabel.Da_CoinGroup).enabled = true;
  66. ResourceManager.SetActive(ObjectLabel.Da_CoinLab, true);
  67. Manager.AddCoin(Coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.MiniGame);
  68. sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.CoinSprite, Coin);
  69. #endregion
  70. #region Diamond
  71. float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(Manager.Level, 1, 1000).ToString());
  72. if (Random.Range(0, 1f) <= diamondRate)
  73. {
  74. DiamondFlag = true;
  75. Diamond = (int)(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond);
  76. ResourceManager.Get<Text>(ObjectLabel.Da_DiamondLab).text = Diamond.ToString();
  77. ResourceManager.Get<Text>(ObjectLabel.Da_DiamondLab).Resize(true, false);
  78. ResourceManager.Get<ContentSizeFitter>(ObjectLabel.Da_DiamondGroup).enabled = true;
  79. ResourceManager.SetActive(ObjectLabel.Da_DiamondLab, true);
  80. Manager.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.MiniGame);
  81. ResourceManager.SetActive(ObjectLabel.Da_Diamond, true);
  82. sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.DiamondSprite, Diamond);
  83. }
  84. else
  85. {
  86. if (BonusDiamond > 0)
  87. {
  88. DiamondFlag = true;
  89. Diamond = BonusDiamond;
  90. ResourceManager.Get<Text>(ObjectLabel.Da_DiamondLab).text = Diamond.ToString();
  91. ResourceManager.Get<Text>(ObjectLabel.Da_DiamondLab).Resize(true, false);
  92. ResourceManager.Get<ContentSizeFitter>(ObjectLabel.Da_DiamondGroup).enabled = true;
  93. ResourceManager.SetActive(ObjectLabel.Da_DiamondLab, true);
  94. Manager.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.MiniGame);
  95. ResourceManager.SetActive(ObjectLabel.Da_Diamond, true);
  96. sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.DiamondSprite, Diamond);
  97. }
  98. else
  99. {
  100. Diamond = 0;
  101. }
  102. }
  103. #endregion
  104. #region Flower
  105. if (TutorialManager.NewplayerTutorial)
  106. {
  107. FlowerFlag = true;
  108. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[1];
  109. ResourceManager.SetActive(ObjectLabel.Da_FlowerIcon, true);
  110. ResourceManager.Get<Image>(ObjectLabel.Da_FlowerIcon).sprite = flowerInfo.Icon;
  111. ResourceManager.Get<Image>(ObjectLabel.Da_FlowerIcon).Resize(true, 0.25f, 0.25f);
  112. ResourceManager.SetText(ObjectLabel.Da_FlowerLab, flowerInfo.Name);
  113. sb.AppendFormat("{0}{1}{2}", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.FlowerSprite, flowerInfo.Name);
  114. }
  115. else
  116. {
  117. if (!FlowerLock)
  118. {
  119. FlowerFlag = true;
  120. if (Random.Range(0, 1f) <= Odds[Rate])
  121. {
  122. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[FlowerID];
  123. flowerInfo.Add();
  124. ResourceManager.SetActive(ObjectLabel.Da_Flower, true);
  125. ResourceManager.Get<Image>(ObjectLabel.Da_FlowerIcon).sprite = flowerInfo.Icon;
  126. ResourceManager.Get<Image>(ObjectLabel.Da_FlowerIcon).Resize(true, 0.25f, 0.25f);
  127. ResourceManager.SetText(ObjectLabel.Da_FlowerLab, flowerInfo.Name);
  128. sb.AppendFormat("{0}{1}{2}", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.FlowerSprite, flowerInfo.Name);
  129. }
  130. else
  131. {
  132. ResourceManager.SetActive(ObjectLabel.Da_Flower, false);
  133. ResourceManager.SetText(ObjectLabel.Da_FlowerLab, Language.GetStr(LanguageLabel.UI__Da_HigherScore));
  134. }
  135. }
  136. }
  137. #endregion
  138. Info = sb.ToString();
  139. BonusCoin = 0;
  140. BonusDiamond = 0;
  141. #endregion
  142. ResourceManager.SetActive(ObjectLabel.Da_Info, true);
  143. Auxiliary.Instance.DelayCall
  144. (
  145. () =>
  146. {
  147. ResourceManager.Get<Text>(ObjectLabel.Da_CoinLab).SetLayoutDirty();
  148. ResourceManager.Get<Text>(ObjectLabel.Da_DiamondLab).SetLayoutDirty();
  149. ResourceManager.Get<ContentSizeFitter>(ObjectLabel.Da_CoinGroup).enabled = false;
  150. ResourceManager.Get<ContentSizeFitter>(ObjectLabel.Da_DiamondGroup).enabled = false;
  151. InitializeAnim();
  152. },
  153. 2
  154. );
  155. }
  156. public void InitializeAnim()
  157. {
  158. #region 构造动画
  159. #region Reset
  160. ResourceManager.Get(ObjectLabel.Da_Info).TweenForCG();
  161. ResourceManager.SetText(ObjectLabel.Da_Tit, Language.GetStr(LanguageLabel.UI__Da_Tit1));
  162. ResourceManager.SetText(ObjectLabel.Da_CoinLab, "0");
  163. ResourceManager.SetText(ObjectLabel.Da_DiamondLab, "0");
  164. ResourceManager.SetActive(ObjectLabel.Da_Lab, false);
  165. ResourceManager.SetActive(ObjectLabel.Da_Quit, false);
  166. ResourceManager.SetActive(ObjectLabel.Da_Cancel, false);
  167. ResourceManager.SetActive(ObjectLabel.Da_CoinLab, false);
  168. ResourceManager.SetActive(ObjectLabel.Da_ScoreTit, false);
  169. ResourceManager.SetActive(ObjectLabel.Da_ScoreLab, false);
  170. ResourceManager.SetActive(ObjectLabel.Da_GetAward, false);
  171. ResourceManager.SetActive(ObjectLabel.Da_DiamondLab, false);
  172. ResourceManager.SetActive(ObjectLabel.Da_VGroup, true);
  173. ResourceManager.SetActive(ObjectLabel.Da_HGroup1, false);
  174. ResourceManager.SetActive(ObjectLabel.Da_FlowerGroup, false);
  175. ResourceManager.SetActive(ObjectLabel.Da_DiamondGroup, false);
  176. if (FlowerFlag)
  177. {
  178. ResourceManager.SetActive(ObjectLabel.Da_FlowerGroup, true);
  179. }
  180. if (DiamondFlag)
  181. {
  182. ResourceManager.SetActive(ObjectLabel.Da_DiamondGroup, true);
  183. }
  184. Auxiliary.Instance.DelayCall
  185. (
  186. () =>
  187. {
  188. ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.Da_VGroup).enabled = false;
  189. ResourceManager.SetActive(ObjectLabel.Da_CoinGroup, false);
  190. ResourceManager.SetActive(ObjectLabel.Da_FlowerGroup, false);
  191. ResourceManager.SetActive(ObjectLabel.Da_DiamondGroup, false);
  192. },
  193. 1
  194. );
  195. float timeCoin = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Coin / 15f));
  196. float timeScore = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Score / 50f));
  197. float timeDiamond = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Diamond / 15f));
  198. float time = Mathf.Max(timeCoin, timeDiamond);
  199. ResourceManager.Get(ObjectLabel.Da_CoinLab).CreateTweenNumber(0, Coin, time, false, true, Curve.EaseOutQuad);
  200. ResourceManager.Get(ObjectLabel.Da_ScoreLab).CreateTweenNumber(0, Score, timeScore, false, true, Curve.EaseOutQuad);
  201. ResourceManager.Get(ObjectLabel.Da_DiamondLab).CreateTweenNumber(0, Diamond, time, false, true, Curve.EaseOutQuad);
  202. #endregion
  203. #region 花
  204. TweenRoot tween;
  205. if (FlowerFlag)
  206. {
  207. tween = ResourceManager.Get(ObjectLabel.Da_CoinLab).GetTweenNumber();
  208. tween.AddEventOnetime
  209. (
  210. EventType.ForwardFinish,
  211. () =>
  212. {
  213. ResourceManager.Get(ObjectLabel.Da_FlowerGroup).TweenReForScale();
  214. }
  215. );
  216. }
  217. #endregion
  218. #region 按钮
  219. if (FlowerFlag)
  220. {
  221. tween = ResourceManager.Get(ObjectLabel.Da_FlowerGroup).GetTweenScale();
  222. tween.AddEventOnetime
  223. (
  224. EventType.ForwardFinish,
  225. () =>
  226. {
  227. ResourceManager.Get(ObjectLabel.Da_GetAward).TweenReForCG();
  228. }
  229. );
  230. }
  231. else
  232. {
  233. tween = ResourceManager.Get(ObjectLabel.Da_CoinLab).GetTweenNumber();
  234. tween.AddEventOnetime
  235. (
  236. EventType.ForwardFinish,
  237. () =>
  238. {
  239. ResourceManager.Get(ObjectLabel.Da_GetAward).TweenReForCG();
  240. }
  241. );
  242. }
  243. if (TutorialManager.NewplayerTutorial)
  244. {
  245. tween = ResourceManager.Get(ObjectLabel.Da_GetAward).GetTweenCG();
  246. tween.AddEventOnetime
  247. (
  248. EventType.ForwardFinish,
  249. () =>
  250. {
  251. Tutorial.HightScreen(ResourceManager.Get(ObjectLabel.Da_Arrow0), ResourceManager.Get(ObjectLabel.Da_Arrow1), ResourceManager.Get(ObjectLabel.Da_GetAward));
  252. }
  253. );
  254. }
  255. ResourceManager.AddButtonEventOnetime
  256. (
  257. ObjectLabel.Da_GetAward,
  258. () =>
  259. {
  260. ResourceManager.Get(ObjectLabel.Da_VGroup).GetComponent<VerticalLayoutGroup>().enabled = true;
  261. }
  262. );
  263. #endregion
  264. #region 得分
  265. if (Rate == 0)
  266. {
  267. tween = ResourceManager.Get(ObjectLabel.Da_Star1).GetTweenScale();
  268. }
  269. else if (Rate == 1)
  270. {
  271. tween = ResourceManager.Get(ObjectLabel.Da_Star2).GetTweenScale();
  272. }
  273. else if (Rate == 2)
  274. {
  275. tween = ResourceManager.Get(ObjectLabel.Da_Star3).GetTweenScale();
  276. }
  277. tween.AddEventOnetime
  278. (
  279. EventType.ForwardFinish,
  280. () =>
  281. {
  282. ResourceManager.Get(ObjectLabel.Da_ScoreTit).TweenReForFont();
  283. }
  284. );
  285. tween = ResourceManager.Get(ObjectLabel.Da_ScoreTit).GetTweenFont();
  286. tween.InOrigin = true;
  287. tween.AddEventOnetime
  288. (
  289. EventType.ForwardFinish,
  290. () =>
  291. {
  292. ResourceManager.Get(ObjectLabel.Da_ScoreLab).TweenReForNumber();
  293. }
  294. );
  295. #endregion
  296. #region 五角星
  297. tween = ResourceManager.Get(ObjectLabel.Da_Star3).GetTweenScale();
  298. tween.InOrigin = true;
  299. tween = ResourceManager.Get(ObjectLabel.Da_Star2).GetTweenScale();
  300. tween.InOrigin = true;
  301. tween = ResourceManager.Get(ObjectLabel.Da_Star1).GetTweenScale();
  302. tween.InOrigin = true;
  303. tween = ResourceManager.Get(ObjectLabel.Da_Info).GetTweenCG();
  304. tween.AddEventOnetime
  305. (
  306. EventType.ForwardFinish,
  307. () =>
  308. {
  309. ResourceManager.Get(ObjectLabel.Da_Star1).TweenReForScale();
  310. ResourceManager.SetActive(ObjectLabel.Da_HGroup1, true);
  311. }
  312. );
  313. if (Rate == 0)
  314. {
  315. ResourceManager.SetActive(ObjectLabel.Da_Star2, false);
  316. ResourceManager.SetActive(ObjectLabel.Da_Star3, false);
  317. }
  318. else if (Rate == 1)
  319. {
  320. ResourceManager.SetActive(ObjectLabel.Da_Star2, true);
  321. ResourceManager.SetActive(ObjectLabel.Da_Star3, false);
  322. tween = ResourceManager.Get(ObjectLabel.Da_Star1).GetTweenScale();
  323. tween.AddEventOnetime
  324. (
  325. EventType.ForwardFinish,
  326. () =>
  327. {
  328. ResourceManager.Get(ObjectLabel.Da_Star2).TweenReForScale();
  329. }
  330. );
  331. }
  332. else if (Rate == 2)
  333. {
  334. ResourceManager.SetActive(ObjectLabel.Da_Star2, true);
  335. ResourceManager.SetActive(ObjectLabel.Da_Star3, true);
  336. tween = ResourceManager.Get(ObjectLabel.Da_Star1).GetTweenScale();
  337. tween.AddEventOnetime
  338. (
  339. EventType.ForwardFinish,
  340. () =>
  341. {
  342. ResourceManager.Get(ObjectLabel.Da_Star2).TweenReForScale();
  343. }
  344. );
  345. tween = ResourceManager.Get(ObjectLabel.Da_Star2).GetTweenScale();
  346. tween.AddEventOnetime
  347. (
  348. EventType.ForwardFinish,
  349. () =>
  350. {
  351. ResourceManager.Get(ObjectLabel.Da_Star3).TweenReForScale();
  352. }
  353. );
  354. }
  355. #endregion
  356. #region 金币钻石
  357. tween = ResourceManager.Get(ObjectLabel.Da_ScoreLab).GetTweenNumber();
  358. tween.AddEventOnetime
  359. (
  360. EventType.ForwardFinish,
  361. () =>
  362. {
  363. ResourceManager.Get(ObjectLabel.Da_CoinGroup).TweenReForScale();
  364. if (DiamondFlag)
  365. {
  366. ResourceManager.Get(ObjectLabel.Da_DiamondGroup).TweenReForScale();
  367. }
  368. }
  369. );
  370. tween = ResourceManager.Get(ObjectLabel.Da_CoinGroup).GetTweenScale();
  371. tween.AddEventOnetime
  372. (
  373. EventType.ForwardFinish,
  374. () =>
  375. {
  376. ResourceManager.Get(ObjectLabel.Da_CoinLab).TweenReForNumber();
  377. }
  378. );
  379. if (DiamondFlag)
  380. {
  381. tween = ResourceManager.Get(ObjectLabel.Da_DiamondGroup).GetTweenScale();
  382. tween.AddEventOnetime
  383. (
  384. EventType.ForwardFinish,
  385. () =>
  386. {
  387. ResourceManager.Get(ObjectLabel.Da_DiamondLab).TweenReForNumber();
  388. }
  389. );
  390. }
  391. #endregion
  392. #endregion
  393. }
  394. public Award(XmlAttributeCollection attribute)
  395. {
  396. Flower.FlowerCoinFml = attribute[8].Value;
  397. DropGold.CoinFml = attribute[7].Value;
  398. Star.CD = float.Parse(attribute[9].Value);
  399. Star.Time = float.Parse(attribute[11].Value);
  400. string[] strings = attribute[10].Value.Split(',');
  401. GardenManager.MinStarTime = float.Parse(strings[0]);
  402. GardenManager.MaxStarTime = float.Parse(strings[1]);
  403. GardenManager.StarTimer = Mathf.Lerp(GardenManager.MinStarTime, GardenManager.MaxStarTime, Random.Range(0f, 1f));
  404. CoinFml = attribute[1].Value;
  405. FlowerFml = attribute[4].Value;
  406. DiamondFml = attribute[3].Value;
  407. FlowerIDRateFml = attribute[12].Value;
  408. FlowerAmtRateFml = attribute[13].Value;
  409. strings = attribute[2].Value.Split(',');
  410. DiamondMin = int.Parse(strings[0]);
  411. DiamondMax = int.Parse(strings[1]);
  412. strings = attribute[5].Value.Split(',');
  413. Odds = new List<float>()
  414. {
  415. float.Parse(strings[0]),
  416. float.Parse(strings[1]),
  417. float.Parse(strings[2]),
  418. };
  419. strings = attribute[6].Value.Split(',');
  420. Standard = new List<float>()
  421. {
  422. float.Parse(strings[0]),
  423. float.Parse(strings[1]),
  424. float.Parse(strings[2]),
  425. };
  426. }
  427. public static int SelectAwardFlowerID(List<int> flowerIDs)
  428. {
  429. for (int i = 0; i < flowerIDs.Count; i++)
  430. {
  431. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[flowerIDs[i]];
  432. float flowerIDRate = (float)Auxiliary.FmlParse(FlowerIDRateFml, "i", flowerIDs[i].ToString());
  433. if (Random.Range(0f, 1f) <= flowerIDRate)
  434. {
  435. float flowerAmtRate = (float) Auxiliary.FmlParse(FlowerAmtRateFml, "a", flowerInfo.amount.ToString());
  436. if (Random.Range(0f, 1f) <= flowerAmtRate)
  437. {
  438. return flowerIDs[i];
  439. }
  440. }
  441. }
  442. return flowerIDs.Random(1)[0];
  443. }
  444. }
  445. public class MiniGameManager : Regist
  446. {
  447. #region Config
  448. public static int Score
  449. {
  450. get { return Score_; }
  451. set
  452. {
  453. Score_ = value;
  454. ResourceManager.SetText(ObjectLabel.D_ScoreLab, ScoreLab + Score_);
  455. }
  456. }
  457. public static bool Game
  458. {
  459. get { return Game_; }
  460. set
  461. {
  462. Game_ = value;
  463. if (Game_)
  464. {
  465. ResourceManager.SetText(ObjectLabel.D_StatusLab, Language.GetStr(LanguageLabel.UI__D_StatusLab1));
  466. }
  467. else
  468. {
  469. ResourceManager.SetText(ObjectLabel.D_StatusLab, Language.GetStr(LanguageLabel.UI__D_StatusLab0));
  470. }
  471. }
  472. }
  473. public static bool Pause
  474. {
  475. get { return Pause_; }
  476. set
  477. {
  478. Pause_ = value;
  479. if (Game)
  480. {
  481. if (Pause_)
  482. {
  483. ResourceManager.SetText(ObjectLabel.D_StatusLab, Language.GetStr(LanguageLabel.UI__D_StatusLab2));
  484. }
  485. else
  486. {
  487. ResourceManager.SetText(ObjectLabel.D_StatusLab, Language.GetStr(LanguageLabel.UI__D_StatusLab1));
  488. }
  489. }
  490. else if (Prepare)
  491. {
  492. if (Pause_)
  493. {
  494. PrepareLab.GetStreamScale().Pause();
  495. }
  496. else
  497. {
  498. PrepareLab.GetStreamScale().Resume();
  499. }
  500. }
  501. }
  502. }
  503. public static bool Panalty
  504. {
  505. get { return Panalty_; }
  506. set
  507. {
  508. Panalty_ = value;
  509. if (Game)
  510. {
  511. if (Panalty_)
  512. {
  513. ResourceManager.SetText(ObjectLabel.D_StatusLab, Language.GetStr(LanguageLabel.UI__D_StatusLab3));
  514. }
  515. else
  516. {
  517. ResourceManager.SetText(ObjectLabel.D_StatusLab, Language.GetStr(LanguageLabel.UI__D_StatusLab1));
  518. }
  519. }
  520. }
  521. }
  522. public static float GameTimer
  523. {
  524. get { return GameTimer_; }
  525. set
  526. {
  527. GameTimer_ = value;
  528. TimerLab.text = (GameTime-GameTimer_).ToString("0.0");
  529. TimerBk.fillAmount = GameTimer_/GameTime;
  530. TimerBk.material.SetFloat("_Fill", TimerBk.fillAmount);
  531. }
  532. }
  533. private static int Score_;
  534. private static bool Game_;
  535. private static bool Pause_;
  536. private static bool Panalty_;
  537. private static float GameTimer_;
  538. public static Text TimerLab;
  539. public static Text PrepareLab;
  540. public static Image TimerBk;
  541. public static Award Award;
  542. public static Transform Grid;
  543. public static Transform Timer;
  544. public static Transform Begin;
  545. public static Transform PunchGameStatus;
  546. public static Transform MemoryGameStatus;
  547. public static Transform FindGameStatus;
  548. public static Transform PunchGameOperate;
  549. public static Transform MemoryGameOperate;
  550. public static Transform FindGameOperate;
  551. public static Transform FindGameCorrectBtn;
  552. public static int MaxFadeAmt = 6;
  553. public static List<int> IndexList = new List<int>();
  554. public static List<int> FindGameFlowerIDs = new List<int>();
  555. public static List<Drop> DropList = new List<Drop>();
  556. public static List<Flower> OperateList = new List<Flower>();
  557. public static List<Flower> IdleList = new List<Flower>();
  558. public static List<Flower> FadeList = new List<Flower>();
  559. public static Dictionary<int, Flower> FlowerDic = new Dictionary<int, Flower>();
  560. public static int MiniGameIndex;
  561. public static string ScoreLab;
  562. public static bool PunchGame;
  563. public static bool MemoryGame;
  564. public static bool FindGame;
  565. public static bool Prepare;
  566. public static bool FlowerLock;
  567. public static bool TutorialLock = true;
  568. public static bool DropDiamond;
  569. public static float OpTimer;
  570. public static float FadeTimer;
  571. public static float GoldTimer;
  572. public static float PanaltyTimer;
  573. public static float PrepareTimer;
  574. public static float DiamondTimer;
  575. public static float MinMinigameCD = 180;
  576. public static float MaxMinigameCD = 300;
  577. public static float OpTime = 1.5f;
  578. public static float FadeTime = 2f;
  579. public static float GameTime = 45f;
  580. public static float PanaltyTime = 1f;
  581. private static float PrepareTime = 3;
  582. public static float NewOpTime;
  583. public static float NewFadeTime;
  584. #endregion
  585. private void Update()
  586. {
  587. if (Pause)
  588. {
  589. return;
  590. }
  591. if (Game)
  592. {
  593. PunchGameThread();
  594. MemoryGameThread();
  595. FindGameThread();
  596. }
  597. if (Prepare)
  598. {
  599. PrepareThread();
  600. }
  601. }
  602. private float OperateDecreaseRate = 0.03f;
  603. private void PunchGameThread()
  604. {
  605. if (!PunchGame)
  606. {
  607. return;
  608. }
  609. GameTimer += Time.deltaTime;
  610. if (GameTimer >= GameTime)
  611. {
  612. GameOver();
  613. return;
  614. }
  615. if (Panalty)
  616. {
  617. PanaltyTimer -= Time.deltaTime;
  618. if (PanaltyTimer <= 0)
  619. {
  620. Panalty = false;
  621. }
  622. }
  623. if (IdleList.Count > 0)
  624. {
  625. OpTimer -= Time.deltaTime;
  626. if (OpTimer <= 0)
  627. {
  628. NewOpTime -= NewOpTime * OperateDecreaseRate;
  629. OpTimer = NewOpTime;
  630. CreateOperate();
  631. }
  632. }
  633. BonusThread();
  634. }
  635. private void MemoryGameThread()
  636. {
  637. if (!MemoryGame)
  638. {
  639. return;
  640. }
  641. GameTimer += Time.deltaTime;
  642. if (GameTimer >= GameTime)
  643. {
  644. GameOver();
  645. return;
  646. }
  647. if (Panalty)
  648. {
  649. PanaltyTimer -= Time.deltaTime;
  650. if (PanaltyTimer <= 0)
  651. {
  652. Panalty = false;
  653. }
  654. }
  655. if (FadeList.Count < MaxFadeAmt)
  656. {
  657. FadeTimer -= Time.deltaTime;
  658. if (FadeTimer <= 0)
  659. {
  660. FadeTimer = NewFadeTime;
  661. Fade();
  662. }
  663. }
  664. BonusThread();
  665. }
  666. private void FindGameThread()
  667. {
  668. if (!FindGame)
  669. {
  670. return;
  671. }
  672. GameTimer += Time.deltaTime;
  673. if (GameTimer >= GameTime)
  674. {
  675. GameOver();
  676. return;
  677. }
  678. if (Panalty)
  679. {
  680. PanaltyTimer -= Time.deltaTime;
  681. if (PanaltyTimer <= 0)
  682. {
  683. Panalty = false;
  684. }
  685. }
  686. BonusThread();
  687. }
  688. private static int DropGoldMinTime = 3;
  689. private static int DropGoldMaxTime = 6;
  690. private void BonusThread()
  691. {
  692. GoldTimer -= Time.deltaTime;
  693. if (GoldTimer < 0)
  694. {
  695. GoldTimer = Random.Range(DropGoldMinTime, DropGoldMaxTime);
  696. DropList.Add(ResourceManager.GetDrop(ObjType.DropGold));
  697. }
  698. if (DropDiamond)
  699. {
  700. DiamondTimer -= Time.deltaTime;
  701. if (DiamondTimer < 0)
  702. {
  703. DropDiamond = false;
  704. DropList.Add(ResourceManager.GetDrop(ObjType.DropDiamond));
  705. }
  706. }
  707. }
  708. private void PrepareThread()
  709. {
  710. PrepareTimer -= Time.deltaTime;
  711. if (PrepareTimer <= 0)
  712. {
  713. Prepare = false;
  714. GameBegin();
  715. }
  716. }
  717. public override void FirstInit()
  718. {
  719. Award = new Award(ConfigManager.GetAwardConfig());
  720. MiniGameIndex = ConfigManager.GetPlayerInt("MiniGameIndex");
  721. }
  722. public override void RegistReference()
  723. {
  724. Grid = ResourceManager.Get(ObjectLabel.D_Grid);
  725. Begin = ResourceManager.Get(ObjectLabel.D_Begin);
  726. Timer = ResourceManager.Get(ObjectLabel.D_Timer);
  727. PunchGameStatus = ResourceManager.Get(ObjectLabel.D_Status1);
  728. MemoryGameStatus = ResourceManager.Get(ObjectLabel.D_Status2);
  729. FindGameStatus = ResourceManager.Get(ObjectLabel.D_Status3);
  730. PunchGameOperate = ResourceManager.Get(ObjectLabel.D_Operate1);
  731. MemoryGameOperate = ResourceManager.Get(ObjectLabel.D_Operate2);
  732. FindGameOperate = ResourceManager.Get(ObjectLabel.D_Operate3);
  733. TimerLab = ResourceManager.Get<Text>(ObjectLabel.D_TimerLab);
  734. PrepareLab = ResourceManager.Get<Text>(ObjectLabel.D_PrepareLab);
  735. TimerBk = ResourceManager.Get<Image>(ObjectLabel.D_TimerIcon);
  736. }
  737. private static int FindScore = 40;
  738. public static void OperateFindGame(int id, int btnIndex)
  739. {
  740. if (!Game)
  741. {
  742. return;
  743. }
  744. if (Panalty)
  745. {
  746. return;
  747. }
  748. if (FindGameFlowerIDs[0] == id)
  749. {
  750. Flower flower = IdleList.Find(tempFlower => { return tempFlower.ID == id; });
  751. ResourceManager.GetHudText($"+{FindScore}", Color.white, 90, flower.ChildDic["ScorePosTra"], ResourceManager.Get(ObjectLabel.D_HudParent), true);
  752. Score += FindScore;
  753. flower.PlayFlashLight();
  754. AudioManager.PlayClip(Clip.BtnClip);
  755. FindGameRoundEnd();
  756. }
  757. else
  758. {
  759. Panalty = true;
  760. PanaltyTimer = PanaltyTime;
  761. ResourceManager.Get("D_FlowerIcon" + btnIndex).TweenForGra();
  762. ResourceManager.Get("D_FlowerBtn" + btnIndex).Shake(0.5f, 3, new Vector3(20f, 0, 0), Curve.EaseOutQuad);
  763. AudioManager.PlayClip(Clip.ErrorClip);
  764. }
  765. }
  766. private static int MemoryScore = 20;
  767. private static bool PlayingNewflowerEffect;
  768. public static void OperateMemoryGame(int index, int slotIndex)
  769. {
  770. if (Panalty || !FadeList.Valid())
  771. {
  772. return;
  773. }
  774. if (IndexList.Count == 0)
  775. {
  776. return;
  777. }
  778. if (slotIndex == IndexList[0])
  779. {
  780. int uiIndex = MemoryGameIndexMap(IndexList[0]);
  781. ResourceManager.Get<Image>("D_FlowerBtn" + uiIndex).material = Lib.GrayMat;
  782. ResourceManager.Get<Button>("D_FlowerBtn" + uiIndex).interactable = false;
  783. ResourceManager.Get<Image>("D_FlowerIcon" + uiIndex).material = Lib.GrayMat;
  784. ResourceManager.SetActive("D_FlowerTick" + uiIndex, true);
  785. IndexList.RemoveAt(0);
  786. Flower flower = FlowerDic[slotIndex];
  787. ResourceManager.GetHudText($"+{MemoryScore}", Color.white, 90, flower.ChildDic["ScorePosTra"], ResourceManager.Get(ObjectLabel.D_HudParent), true);
  788. Score += MemoryScore;
  789. flower.PlayFlashLight();
  790. if (!Award.FlowerLock && Award.FlowerID == flower.ID && !PlayingNewflowerEffect)
  791. {
  792. flower.PlayNewFlowerEffec();
  793. PlayingNewflowerEffect = true;
  794. }
  795. AudioManager.PlayClip(Clip.BtnClip);
  796. TweenRoot tween = flower.FlowerIcon.TweenBacSr();
  797. if (IndexList.Count == 0)
  798. {
  799. tween.AddEventOnetime
  800. (
  801. EventType.BackwardFinish,
  802. () =>
  803. {
  804. MemoryGameRoundEnd();
  805. MemoryGameRoundReset();
  806. MemoryGameRoundBegin();
  807. }
  808. );
  809. }
  810. }
  811. else
  812. {
  813. Panalty = true;
  814. PanaltyTimer = PanaltyTime;
  815. ResourceManager.Get("D_FlowerIcon" + index).TweenForGra();
  816. ResourceManager.Get("D_FlowerBtn" + index).Shake(0.5f, 3, new Vector3(20f, 0, 0), Curve.EaseOutQuad);
  817. AudioManager.PlayClip(Clip.ErrorClip);
  818. }
  819. }
  820. public static void OperatePunchGame(OpType opType)
  821. {
  822. if (Panalty || !OperateList.Valid())
  823. {
  824. return;
  825. }
  826. if (OperateList[0].Operate(opType))
  827. {
  828. IdleList.Add(OperateList[0]);
  829. OperateList.Remove(OperateList[0]);
  830. if (OperateList.Count >= 2)
  831. {
  832. OperateList[0].SetFirstOp();
  833. OperateList[1].SetSecondOp();
  834. }
  835. else if (OperateList.Count >= 1)
  836. {
  837. OperateList[0].SetFirstOp();
  838. }
  839. }
  840. else
  841. {
  842. Panalty = true;
  843. PanaltyTimer = PanaltyTime;
  844. }
  845. }
  846. public static void ResetOprerate()
  847. {
  848. ResourceManager.Get<Image>(ObjectLabel.D_FlowerBtn1).material = null;
  849. ResourceManager.Get<Image>(ObjectLabel.D_FlowerBtn2).material = null;
  850. ResourceManager.Get<Image>(ObjectLabel.D_FlowerBtn3).material = null;
  851. ResourceManager.Get<Image>(ObjectLabel.D_FlowerBtn4).material = null;
  852. ResourceManager.Get<Image>(ObjectLabel.D_FlowerBtn5).material = null;
  853. ResourceManager.Get<Image>(ObjectLabel.D_FlowerBtn6).material = null;
  854. ResourceManager.Get<Button>(ObjectLabel.D_FlowerBtn1).interactable = true;
  855. ResourceManager.Get<Button>(ObjectLabel.D_FlowerBtn2).interactable = true;
  856. ResourceManager.Get<Button>(ObjectLabel.D_FlowerBtn3).interactable = true;
  857. ResourceManager.Get<Button>(ObjectLabel.D_FlowerBtn4).interactable = true;
  858. ResourceManager.Get<Button>(ObjectLabel.D_FlowerBtn5).interactable = true;
  859. ResourceManager.Get<Button>(ObjectLabel.D_FlowerBtn6).interactable = true;
  860. ResourceManager.Get<Image>(ObjectLabel.D_FlowerIcon1).material = null;
  861. ResourceManager.Get<Image>(ObjectLabel.D_FlowerIcon2).material = null;
  862. ResourceManager.Get<Image>(ObjectLabel.D_FlowerIcon3).material = null;
  863. ResourceManager.Get<Image>(ObjectLabel.D_FlowerIcon4).material = null;
  864. ResourceManager.Get<Image>(ObjectLabel.D_FlowerIcon5).material = null;
  865. ResourceManager.Get<Image>(ObjectLabel.D_FlowerIcon6).material = null;
  866. ResourceManager.SetActive(ObjectLabel.D_FlowerTick1, false);
  867. ResourceManager.SetActive(ObjectLabel.D_FlowerTick2, false);
  868. ResourceManager.SetActive(ObjectLabel.D_FlowerTick3, false);
  869. ResourceManager.SetActive(ObjectLabel.D_FlowerTick4, false);
  870. ResourceManager.SetActive(ObjectLabel.D_FlowerTick5, false);
  871. ResourceManager.SetActive(ObjectLabel.D_FlowerTick6, false);
  872. }
  873. public static void CreateOperate()
  874. {
  875. AudioManager.PlayClip(Clip.BubbleClip);
  876. if (TutorialManager.NewplayerTutorial && TutorialLock)
  877. {
  878. Pause = true;
  879. TutorialLock = false;
  880. Flower flower = IdleList[4];
  881. flower.CreateOp(OperateList.Count, OpType.Water);
  882. OperateList.Add(flower);
  883. IdleList.Remove(flower);
  884. Tutorial.HightScreen(ResourceManager.Get(ObjectLabel.D_WaterArrow0), ResourceManager.Get(ObjectLabel.D_WaterArrow1), ResourceManager.Get(ObjectLabel.D_Water1));
  885. Tutorial.SetArea(OperateList[0].OperateIcon.transform, 0.1f, 0.125f);
  886. ResourceManager.AddButtonEventOnetime
  887. (
  888. ObjectLabel.D_Water2,
  889. () =>
  890. {
  891. Pause = false;
  892. Tutorial.HightDisable();
  893. }
  894. );
  895. }
  896. else
  897. {
  898. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  899. flower.CreateOp(OperateList.Count);
  900. OperateList.Add(flower);
  901. IdleList.Remove(flower);
  902. }
  903. }
  904. public static void Fade()
  905. {
  906. for (int i = 0; i < IndexList.Count; i++)
  907. {
  908. Flower flower = FlowerDic[IndexList[i]];
  909. if (FadeList.UniqueAdd(flower))
  910. {
  911. IdleList.Remove(flower);
  912. flower.PlayFlashLight();
  913. flower.StopNewFlowerEffec();
  914. PlayingNewflowerEffect = false;
  915. flower.FlowerIcon.TweenForSr();
  916. if (FadeList.Count == MaxFadeAmt)
  917. {
  918. MemoryGameRoundBegin();
  919. }
  920. break;
  921. }
  922. }
  923. }
  924. public static void InitializeMode()
  925. {
  926. PunchGame = false;
  927. MemoryGame = false;
  928. FindGame = false;
  929. PunchGameOperate.SetActive(false);
  930. MemoryGameOperate.SetActive(false);
  931. FindGameOperate.SetActive(false);
  932. bool memoryGameAvailable = Manager.Level >= TutorialManager.MemoryMinigameTutorialLevel;
  933. bool findGameAvailable = GardenManager.MyFlower >= TutorialManager.MinFlowerForFindGame && Manager.Level >= TutorialManager.FindMinigameTutorialLevel;
  934. float punchGameThreshold;
  935. float memoryGameThreshold;
  936. float findGameThreshold;
  937. if (memoryGameAvailable && findGameAvailable)
  938. {
  939. punchGameThreshold = 0.33f;
  940. memoryGameThreshold = 0.66f;
  941. findGameThreshold = 1f;
  942. }
  943. else if (memoryGameAvailable)
  944. {
  945. punchGameThreshold = 0.5f;
  946. memoryGameThreshold = 1;
  947. findGameThreshold = 0;
  948. }
  949. else if (findGameAvailable)
  950. {
  951. punchGameThreshold = 0.5f;
  952. memoryGameThreshold = 0;
  953. findGameThreshold = 1;
  954. }
  955. else
  956. {
  957. punchGameThreshold = 1;
  958. memoryGameThreshold = 0;
  959. findGameThreshold = 0;
  960. }
  961. float posibility = Random.Range(0f, 1f);
  962. if (posibility <= punchGameThreshold)
  963. {
  964. PunchGame = true;
  965. }
  966. else if (posibility <= memoryGameThreshold)
  967. {
  968. MemoryGame = true;
  969. }
  970. else if (posibility <= findGameThreshold)
  971. {
  972. FindGame = true;
  973. }
  974. if (TutorialManager.MemoryMinigameTutorial)
  975. {
  976. PunchGame = false;
  977. MemoryGame = true;
  978. FindGame = false;
  979. }
  980. if (TutorialManager.FindMinigameTutorial)
  981. {
  982. PunchGame = false;
  983. MemoryGame = false;
  984. FindGame = true;
  985. }
  986. }
  987. public static void SetNewFlowerStatus()
  988. {
  989. bool newFlowerFlag = ConfigManager.GetPlayerBool(PlayerConfigLabel.NewFlowerFlag);
  990. if (newFlowerFlag)
  991. {
  992. List<int> unlockedFlowerIDList = GardenManager.UnlockedFlowerIDList;
  993. if (GardenManager.FirstUnlockFlowerID != -1)
  994. unlockedFlowerIDList.Add(GardenManager.FirstUnlockFlowerID);
  995. Award.FlowerID = Award.SelectAwardFlowerID(unlockedFlowerIDList);
  996. Award.FlowerLock = false;
  997. }
  998. else
  999. {
  1000. Award.FlowerLock = true;
  1001. }
  1002. }
  1003. public static void ResetNewFlowerStatus()
  1004. {
  1005. float flowerRate = (float) Auxiliary.FmlParse(Award.FlowerFml, "l", Manager.Level.ToString(), "f", GardenManager.MyFlower.ToString());
  1006. if (Random.Range(0, 1f) <= flowerRate)
  1007. {
  1008. ConfigManager.SavePlayerBool(PlayerConfigLabel.NewFlowerFlag, true);
  1009. }
  1010. else
  1011. {
  1012. ConfigManager.SavePlayerBool(PlayerConfigLabel.NewFlowerFlag, false);
  1013. }
  1014. }
  1015. public static void GameEnd()
  1016. {
  1017. PrepareLab.GetStreamScale().InOrigin = true;
  1018. if (Game)
  1019. {
  1020. Manager.MiniLock = false;
  1021. Manager.MiniTimer = Mathf.Lerp(MinMinigameCD, MaxMinigameCD, Random.Range(0, 1f));
  1022. ResetNewFlowerStatus();
  1023. }
  1024. ResourceManager.Get(ObjectLabel.C_MiniGame).TweenForCG();
  1025. if (Manager.MiniTimer > 0)
  1026. {
  1027. ResourceManager.Get(ObjectLabel.C_MiniGame).TweenForRect();
  1028. }
  1029. Score = 0;
  1030. Pause = false;
  1031. Game = false;
  1032. Panalty = false;
  1033. Prepare = false;
  1034. GameTimer = GameTime;
  1035. for (int i = 0; i < OperateList.Count; i++)
  1036. {
  1037. OperateList[i].GameOver();
  1038. }
  1039. for (int i = 0; i < IdleList.Count; i++)
  1040. {
  1041. IdleList[i].GameOver();
  1042. }
  1043. for (int i = 0; i < DropList.Count; i++)
  1044. {
  1045. DropList[i].Retrieve();
  1046. DropList.RemoveAt(i--);
  1047. }
  1048. }
  1049. public static void GameOver()
  1050. {
  1051. AudioManager.PlayClip(Clip.MiniEndClip);
  1052. Award.GetAward(Score);
  1053. Manager.MiniGameAmt++;
  1054. FlowerLock = false;
  1055. GameEnd();
  1056. }
  1057. public static void GameEnter()
  1058. {
  1059. if (TutorialManager.NewplayerTutorial)
  1060. {
  1061. Award.FlowerID = 1;
  1062. Award.FlowerLock = true;
  1063. InitializeMode();
  1064. }
  1065. else
  1066. {
  1067. if (!FlowerLock)
  1068. {
  1069. InitializeMode();
  1070. FlowerLock = true;
  1071. }
  1072. }
  1073. SetNewFlowerStatus();
  1074. if (TutorialManager.MemoryMinigameTutorial)
  1075. {
  1076. InitializeMode();
  1077. }
  1078. if (PunchGame)
  1079. {
  1080. EnterPunchGame();
  1081. }
  1082. if (MemoryGame)
  1083. {
  1084. EnterMemoryGame();
  1085. }
  1086. if (FindGame)
  1087. {
  1088. EnterFindGame();
  1089. }
  1090. ScoreLab = Language.GetStr(LanguageLabel.UI__D_ScoreLab);
  1091. TimerBk.fillAmount = 0;
  1092. TimerLab.text = GameTime.ToString("0");
  1093. ResourceManager.Get(ObjectLabel.C_MiniGame).TweenBacCG();
  1094. }
  1095. public static void EnterPunchGame()
  1096. {
  1097. PunchGameOperate.SetActive(true);
  1098. Timer.SetParent(PunchGameStatus);
  1099. Grid.SetParent(PunchGameStatus);
  1100. Begin.SetParent(PunchGameOperate);
  1101. PrepareLab.SetParent(ResourceManager.Get(ObjectLabel.D_PrepareLayout1));
  1102. ResourceManager.SetActive(ObjectLabel.D_Rip1, false);
  1103. ResourceManager.SetActive(ObjectLabel.D_Water1, false);
  1104. ResourceManager.SetActive(ObjectLabel.D_Fertilize1, false);
  1105. ResourceManager.SetActive(ObjectLabel.D_Begin, true);
  1106. ResourceManager.SetActive(ObjectLabel.D_DescA, true);
  1107. if (Award.FlowerLock)
  1108. {
  1109. for (int i = 1; i < 10; i++)
  1110. {
  1111. while (true)
  1112. {
  1113. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic.Random();
  1114. if (flowerInfo.Unlock)
  1115. {
  1116. IdleList.Add(ResourceManager.GetFlower(flowerInfo, ResourceManager.Get("SlotMini" + i)));
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. }
  1122. else
  1123. {
  1124. List<int> idList = new List<int>();
  1125. idList = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9};
  1126. int special = idList.Random(1, true, true)[0];
  1127. Flower flower = ResourceManager.GetFlower(GardenManager.FlowerInfoDic[Award.FlowerID], ResourceManager.Get("SlotMini" + special));
  1128. flower.PlayNewFlowerEffec();
  1129. IdleList.Add(flower);
  1130. for (int i = 0; i < idList.Count; i++)
  1131. {
  1132. while (true)
  1133. {
  1134. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic.Random();
  1135. if (flowerInfo.Unlock)
  1136. {
  1137. flower = ResourceManager.GetFlower(flowerInfo, ResourceManager.Get("SlotMini" + idList[i]));
  1138. IdleList.Add(flower);
  1139. break;
  1140. }
  1141. }
  1142. }
  1143. }
  1144. }
  1145. public static void EnterMemoryGame()
  1146. {
  1147. MemoryGameOperate.SetActive(true);
  1148. Timer.SetParent(MemoryGameStatus);
  1149. Grid.SetParent(MemoryGameStatus);
  1150. Begin.SetParent(MemoryGameOperate);
  1151. PrepareLab.SetParent(ResourceManager.Get(ObjectLabel.D_PrepareLayout2));
  1152. ResetOprerate();
  1153. ResourceManager.Get(ObjectLabel.D_Mask).TweenBacGra();
  1154. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn1, false);
  1155. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn2, false);
  1156. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn3, false);
  1157. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn4, false);
  1158. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn5, false);
  1159. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn6, false);
  1160. ResourceManager.SetActive(ObjectLabel.D_Begin, true);
  1161. ResourceManager.SetActive(ObjectLabel.D_DescB, true);
  1162. List<int> idList = new List<int>() {1, 2, 4, 5, 7, 8};
  1163. FlowerDic = new Dictionary<int, Flower>();
  1164. Flower flower;
  1165. if (Award.FlowerLock)
  1166. {
  1167. for (int i = 0; i < idList.Count; i++)
  1168. {
  1169. while (true)
  1170. {
  1171. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic.Random();
  1172. if (flowerInfo.Unlock)
  1173. {
  1174. flower = ResourceManager.GetFlower(flowerInfo, ResourceManager.Get("SlotMini" + idList[i]));
  1175. IdleList.Add(flower);
  1176. FlowerDic.Add(idList[i], flower);
  1177. break;
  1178. }
  1179. }
  1180. }
  1181. }
  1182. else
  1183. {
  1184. int special = idList.Random(1, true, true)[0];
  1185. flower = ResourceManager.GetFlower(GardenManager.FlowerInfoDic[Award.FlowerID], ResourceManager.Get("SlotMini" + special));
  1186. flower.PlayNewFlowerEffec();
  1187. IdleList.Add(flower);
  1188. FlowerDic.Add(special, flower);
  1189. for (int i = 0; i < idList.Count; i++)
  1190. {
  1191. while (true)
  1192. {
  1193. FlowerInfo flowerInfo = GardenManager.FlowerInfoDic.Random();
  1194. if (flowerInfo.Unlock)
  1195. {
  1196. flower = ResourceManager.GetFlower(flowerInfo, ResourceManager.Get("SlotMini" + idList[i]));
  1197. IdleList.Add(flower);
  1198. FlowerDic.Add(idList[i], flower);
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. }
  1204. for (int i = 0; i < IdleList.Count; i++)
  1205. {
  1206. IdleList[i].FlowerIcon.CreateTweenSr(1, 0, 0.25f, true, false, Curve.EaseOutQuad, false, true);
  1207. }
  1208. }
  1209. public static void EnterFindGame()
  1210. {
  1211. FindGameOperate.SetActive(true);
  1212. ResourceManager.SetActive(ObjectLabel.D_Begin, true);
  1213. ResourceManager.SetActive(ObjectLabel.D_DescC, true);
  1214. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn7, false);
  1215. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn8, false);
  1216. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn9, false);
  1217. Begin.SetParent(FindGameOperate);
  1218. Timer.SetParent(FindGameStatus);
  1219. Grid.SetParent(FindGameStatus);
  1220. PrepareLab.SetParent(ResourceManager.Get(ObjectLabel.D_PrepareLayout3));
  1221. FindGameRoundReset(true);
  1222. }
  1223. private static int DropDiamondMinIndex = 5;
  1224. private static int DropDiamondMaxIndex = 9;
  1225. private static float DropDiamondRate = 0.01f;
  1226. private static float DropDiamondOffsetTime = 5;
  1227. public static void GameBegin()
  1228. {
  1229. ConfigManager.SavePlayerBool("NewFlowerFlag", false);
  1230. Game = true;
  1231. MiniGameIndex++;
  1232. Score = 0;
  1233. OpTimer = OpTime;
  1234. FadeTimer = FadeTime;
  1235. GoldTimer = Random.Range(DropGoldMinTime, DropGoldMaxTime);
  1236. GameTimer = 0;
  1237. NewOpTime = OpTime;
  1238. NewFadeTime = FadeTime;
  1239. DiamondTimer = Random.Range(0f, GameTime - DropDiamondOffsetTime);
  1240. StaticsManager.GetInstance().UseItem(StaticsManager.ItemID.开始小游戏, StaticsManager.ItemType.小游戏, "1", StaticsManager.ConsumeModule.None);
  1241. if (PunchGame)
  1242. {
  1243. for (int i = 0; i < IdleList.Count; i++)
  1244. {
  1245. IdleList[i].GameBegin();
  1246. }
  1247. }
  1248. if (MemoryGame)
  1249. {
  1250. MemoryGameRoundReset();
  1251. }
  1252. if (FindGame)
  1253. {
  1254. FindGameRoundBegin(true);
  1255. }
  1256. if (Random.Range(DropDiamondMinIndex, DropDiamondMaxIndex) <= MiniGameIndex)
  1257. {
  1258. MiniGameIndex = 0;
  1259. DropDiamond = true;
  1260. }
  1261. else
  1262. {
  1263. if (Random.Range(0, 1f) <= DropDiamondRate)
  1264. {
  1265. DropDiamond = true;
  1266. }
  1267. else
  1268. {
  1269. DropDiamond = false;
  1270. }
  1271. }
  1272. }
  1273. public static void GamePrepare()
  1274. {
  1275. Prepare = true;
  1276. PrepareTimer = PrepareTime;
  1277. ResourceManager.Get(ObjectLabel.D_Begin).SetActive(false);
  1278. ResourceManager.Get(ObjectLabel.D_DescA).SetActive(false);
  1279. ResourceManager.Get(ObjectLabel.D_DescB).SetActive(false);
  1280. ResourceManager.Get(ObjectLabel.D_DescC).SetActive(false);
  1281. if (PunchGame)
  1282. {
  1283. ResourceManager.Get(ObjectLabel.D_Rip1).SetActive(true);
  1284. ResourceManager.Get(ObjectLabel.D_Water1).SetActive(true);
  1285. ResourceManager.Get(ObjectLabel.D_Fertilize1).SetActive(true);
  1286. }
  1287. if (MemoryGame)
  1288. {
  1289. ResourceManager.Get(ObjectLabel.D_Mask).TweenForGra();
  1290. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn1, true);
  1291. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn2, true);
  1292. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn3, true);
  1293. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn4, true);
  1294. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn5, true);
  1295. ResourceManager.SetActive(ObjectLabel.D_FlowerBtn6, true);
  1296. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon1, FlowerDic[1].FlowerInfo.Icon).Resize(true, 1.0625f, 1.0625f);
  1297. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon2, FlowerDic[2].FlowerInfo.Icon).Resize(true, 1.0625f, 1.0625f);
  1298. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon3, FlowerDic[4].FlowerInfo.Icon).Resize(true, 1.0625f, 1.0625f);
  1299. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon4, FlowerDic[5].FlowerInfo.Icon).Resize(true, 1.0625f, 1.0625f);
  1300. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon5, FlowerDic[7].FlowerInfo.Icon).Resize(true, 1.0625f, 1.0625f);
  1301. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon6, FlowerDic[8].FlowerInfo.Icon).Resize(true, 1.0625f, 1.0625f);
  1302. }
  1303. PrepareLab.StreamForScale();
  1304. }
  1305. public static void MemoryGameRoundEnd()
  1306. {
  1307. ResourceManager.Get(ObjectLabel.D_Mask).TweenForGra();
  1308. }
  1309. private static float MemoryGameDecreaseRate = 0.3f;
  1310. public static void MemoryGameRoundReset()
  1311. {
  1312. for (int i = 0; i < FadeList.Count; i++)
  1313. {
  1314. IdleList.Add(FadeList[i]);
  1315. }
  1316. NewFadeTime -= NewFadeTime * MemoryGameDecreaseRate;
  1317. FadeTimer = NewFadeTime;
  1318. FadeList = new List<Flower>();
  1319. IndexList = new List<int>();
  1320. List<int> randomList = new List<int>() { 1, 2, 4, 5, 7, 8 };
  1321. for (int i = 0; i < randomList.Count; i++)
  1322. {
  1323. IndexList.Add(randomList.Random(1, true, true)[0]);
  1324. i--;
  1325. }
  1326. ResetOprerate();
  1327. }
  1328. public static void MemoryGameRoundBegin()
  1329. {
  1330. ResourceManager.Get(ObjectLabel.D_Mask).TweenBacGra();
  1331. if (TutorialManager.MemoryMinigameTutorial)
  1332. {
  1333. TutorialManager.PlayMemoryGame();
  1334. }
  1335. }
  1336. public static void FindGameRoundEnd()
  1337. {
  1338. if (IdleList[0].ID == Award.FlowerID)
  1339. {
  1340. IdleList[0].StopNewFlowerEffec();
  1341. }
  1342. for (int i = 0; i < IdleList.Count; i++)
  1343. {
  1344. IdleList[i].FlowerIcon.TweenForSr();
  1345. }
  1346. ResourceManager.Get(ObjectLabel.D_FlowerBtn7).TweenBacCG();
  1347. ResourceManager.Get(ObjectLabel.D_FlowerBtn8).TweenBacCG();
  1348. ResourceManager.Get(ObjectLabel.D_FlowerBtn9).TweenBacCG();
  1349. Auxiliary.Instance.DelayCall
  1350. (
  1351. () =>
  1352. {
  1353. if (Game)
  1354. {
  1355. FindGameRoundReset();
  1356. FindGameRoundBegin();
  1357. }
  1358. },
  1359. 1.5f
  1360. );
  1361. }
  1362. public static void FindGameRoundReset(bool firstRound = false)
  1363. {
  1364. ExtList.ForEach(IdleList, flower => { flower.FlowerIcon.SetAlpha(1); flower.FlowerIcon.SetActive(true); flower.Retrieve();});
  1365. IdleList = new List<Flower>();
  1366. FindGameFlowerIDs = new List<int>();
  1367. List<int> slotList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  1368. FlowerInfo flowerInfo;
  1369. if (firstRound && !Award.FlowerLock)
  1370. {
  1371. flowerInfo = GardenManager.FlowerInfoDic[Award.FlowerID];
  1372. }
  1373. else
  1374. {
  1375. flowerInfo = GardenManager.FlowerInfoDic.Random(false, flowerIndo => { return flowerIndo.Unlock; });
  1376. }
  1377. FindGameFlowerIDs.Add(flowerInfo.ID_);
  1378. IdleList.Add(ResourceManager.GetFlower(flowerInfo, ResourceManager.Get("SlotMini" + slotList.Random(1, true, true)[0])));
  1379. while (slotList.Count > 0)
  1380. {
  1381. flowerInfo = GardenManager.FlowerInfoDic.Random(false, info => { return info.Unlock && info.ID_ != FindGameFlowerIDs[0]; });
  1382. if (slotList.Count == 1)
  1383. {
  1384. if (!FindGameFlowerIDs.Contains(flowerInfo.ID_))
  1385. {
  1386. continue;
  1387. }
  1388. }
  1389. else
  1390. {
  1391. FindGameFlowerIDs.UniqueAdd(flowerInfo.ID_);
  1392. }
  1393. int amt = Mathf.Min(Random.Range(2, 9), slotList.Count);
  1394. for (int i = 0; i < amt; i++)
  1395. {
  1396. IdleList.Add(ResourceManager.GetFlower(flowerInfo, ResourceManager.Get("SlotMini" + slotList.Random(1, true, true)[0])));
  1397. }
  1398. }
  1399. for (int i = 0; i < IdleList.Count; i++)
  1400. {
  1401. IdleList[i].FlowerIcon.CreateTweenSr(1, 0, 0.25f, true, false, Curve.EaseOutQuad, false, true).AlphaOnly = true;
  1402. IdleList[i].FlowerIcon.GetTweenSr().InDestination = true;
  1403. }
  1404. List<int> idList = new List<int>()
  1405. {
  1406. FindGameFlowerIDs[0],
  1407. };
  1408. if (FindGameFlowerIDs.Count == 2)
  1409. {
  1410. idList.Add(FindGameFlowerIDs[1]);
  1411. idList.Add(FindGameFlowerIDs[1]);
  1412. idList.RemoveAt(0);
  1413. idList.Insert(Random.Range(0, 3), FindGameFlowerIDs[0]);
  1414. }
  1415. else if (FindGameFlowerIDs.Count > 2)
  1416. {
  1417. idList.AddRange(FindGameFlowerIDs.Random(2, true, false, id => { return id != idList[0]; }));
  1418. idList = idList.Disturb();
  1419. }
  1420. else
  1421. {
  1422. throw new Exception();
  1423. }
  1424. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon7, GardenManager.FlowerInfoDic[idList[0]].Icon).Resize(true, 1.0625f, 1.0625f);
  1425. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon8, GardenManager.FlowerInfoDic[idList[1]].Icon).Resize(true, 1.0625f, 1.0625f);
  1426. ResourceManager.SetSprite(ObjectLabel.D_FlowerIcon9, GardenManager.FlowerInfoDic[idList[2]].Icon).Resize(true, 1.0625f, 1.0625f);
  1427. for (int i = 0; i < idList.Count; i++)
  1428. {
  1429. int id = idList[i];
  1430. int index = i;
  1431. if (firstRound && TutorialManager.FindMinigameTutorial && id == FindGameFlowerIDs[0])
  1432. {
  1433. FindGameCorrectBtn = ResourceManager.Get("D_FlowerBtn" + (7 + i));
  1434. ResourceManager.SetButtonEvent("D_FlowerBtn" + (7 + i), () => { OperateFindGame(id, (7 + index)); TutorialManager.EndClickCorrectButton(); });
  1435. }
  1436. else
  1437. {
  1438. ResourceManager.SetButtonEvent("D_FlowerBtn" + (7 + i), () => { OperateFindGame(id, (7 + index)); });
  1439. }
  1440. }
  1441. }
  1442. public static void FindGameRoundBegin(bool firstRound = false)
  1443. {
  1444. if (firstRound && !Award.FlowerLock)
  1445. {
  1446. IdleList[0].PlayNewFlowerEffec();
  1447. }
  1448. ResourceManager.Get(ObjectLabel.D_FlowerBtn7).TweenReForCG();
  1449. ResourceManager.Get(ObjectLabel.D_FlowerBtn8).TweenReForCG();
  1450. ResourceManager.Get(ObjectLabel.D_FlowerBtn9).TweenReForCG();
  1451. for (int i = 0; i < IdleList.Count; i++)
  1452. {
  1453. IdleList[i].FlowerIcon.TweenBacSr();
  1454. }
  1455. if (firstRound && TutorialManager.FindMinigameTutorial)
  1456. {
  1457. TutorialManager.ShowCorrectButton(FindGameCorrectBtn.GetChild(1), FindGameCorrectBtn);
  1458. }
  1459. }
  1460. public static int MemoryGameIndexMap(int slotIndex)
  1461. {
  1462. if (slotIndex == 1)
  1463. {
  1464. return 1;
  1465. }
  1466. else if (slotIndex == 2)
  1467. {
  1468. return 2;
  1469. }
  1470. else if (slotIndex == 4)
  1471. {
  1472. return 3;
  1473. }
  1474. else if (slotIndex == 5)
  1475. {
  1476. return 4;
  1477. }
  1478. else if (slotIndex == 7)
  1479. {
  1480. return 5;
  1481. }
  1482. else if (slotIndex == 8)
  1483. {
  1484. return 6;
  1485. }
  1486. else
  1487. {
  1488. throw new Exception();
  1489. }
  1490. }
  1491. public void OnApplicationPause(bool pause)
  1492. {
  1493. if (!pause)
  1494. {
  1495. if (!TutorialManager.NewplayerTutorial)
  1496. {
  1497. if (Game || Prepare)
  1498. {
  1499. ResourceManager.Get<Button>(ObjectLabel.D_Quit).onClick.Invoke();
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }