ManaMiniGame.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Xml;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using Random = UnityEngine.Random;
  9. public class Award
  10. {
  11. #region 变量
  12. public static int BonusCoin;
  13. public static int BonusDiamond;
  14. public int DiamondMin;
  15. public int DiamondMax;
  16. public string CoinFml;
  17. public string FlowerFml;
  18. public string DiamondFml;
  19. public List<float> Odds;
  20. public List<float> Standard;
  21. #endregion
  22. public Award(XmlAttributeCollection attribute)
  23. {
  24. CoinFml = attribute[1].Value;
  25. FlowerFml = attribute[4].Value;
  26. DiamondFml = attribute[3].Value;
  27. string[] strings = attribute[2].Value.Split(',');
  28. DiamondMin = int.Parse(strings[0]);
  29. DiamondMax = int.Parse(strings[1]);
  30. strings = attribute[5].Value.Split(',');
  31. Odds = new List<float>()
  32. {
  33. float.Parse(strings[0]),
  34. float.Parse(strings[1]),
  35. float.Parse(strings[2]),
  36. };
  37. strings = attribute[6].Value.Split(',');
  38. Standard = new List<float>()
  39. {
  40. float.Parse(strings[0]),
  41. float.Parse(strings[1]),
  42. float.Parse(strings[2]),
  43. };
  44. }
  45. public void GetAward(int score)
  46. {
  47. ManaReso.SetActive("Da_Flower", false);
  48. ManaReso.SetActive("Da_Diamond", false);
  49. int coin = (int) Auxiliary.FmlParse(CoinFml, "s", score.ToString());
  50. coin = (int) (coin * ManaData.SkillPlus) + BonusCoin;
  51. ManaData.Coin += coin;
  52. ManaReso.SetText("Da_CoinLab", coin.ToString());
  53. float diamondRate = (float) Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaData.Level, 1, 1000).ToString());
  54. if (Random.Range(0, 1f) <= diamondRate)
  55. {
  56. ManaReso.SetActive("Da_Diamond", true);
  57. int diamond = (int) Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond;
  58. ManaData.Diamond += diamond;
  59. ManaReso.SetText("Da_DiamondLab", diamond.ToString());
  60. }
  61. else
  62. {
  63. if (BonusDiamond > 0)
  64. {
  65. ManaReso.SetActive("Da_Diamond", true);
  66. ManaData.Diamond += BonusDiamond;
  67. ManaReso.SetText("Da_DiamondLab", BonusDiamond.ToString());
  68. }
  69. }
  70. int standard;
  71. if (score < Standard[0])
  72. {
  73. standard = 0;
  74. }
  75. else if (score < Standard[1])
  76. {
  77. standard = 1;
  78. }
  79. else
  80. {
  81. standard = 2;
  82. }
  83. float flowerRate = (float) Auxiliary.FmlParse(DiamondFml, "l", ManaData.Level.ToString(), "f", ManaGarden.MyFlower.ToString());
  84. if (Random.Range(0, 1f) <= flowerRate)
  85. {
  86. if (Random.Range(0, 1f) <= Odds[standard])
  87. {
  88. ManaReso.SetActive("Da_Flower", true);
  89. FlowerInfo flowerInfo;
  90. while (true)
  91. {
  92. flowerInfo = ManaGarden.FlowerInfoList.Random();
  93. if (flowerInfo.Unlock)
  94. {
  95. break;
  96. }
  97. }
  98. ManaReso.SetText("Da_FlowerLab", Language.GetStr("FlowerName", "Flower" + flowerInfo.Id));
  99. }
  100. }
  101. BonusCoin = 0;
  102. BonusDiamond = 0;
  103. }
  104. }
  105. public class ManaMiniGame : Regist
  106. {
  107. #region 变量
  108. public static int Score
  109. {
  110. get { return _Score; }
  111. set
  112. {
  113. _Score = value;
  114. ManaReso.SetText("D_ScoreLab", _Score.ToString());
  115. }
  116. }
  117. public static bool Game
  118. {
  119. get { return _Game; }
  120. set
  121. {
  122. _Game = value;
  123. if (_Game)
  124. {
  125. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  126. }
  127. else
  128. {
  129. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0"));
  130. }
  131. }
  132. }
  133. public static bool Pause
  134. {
  135. get { return _Pause; }
  136. set
  137. {
  138. _Pause = value;
  139. if (Game)
  140. {
  141. if (_Pause)
  142. {
  143. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2"));
  144. }
  145. else
  146. {
  147. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  148. }
  149. }
  150. }
  151. }
  152. public static bool Panalty
  153. {
  154. get { return _Panalty; }
  155. set
  156. {
  157. _Panalty = value;
  158. if (_Panalty)
  159. {
  160. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3"));
  161. }
  162. else
  163. {
  164. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  165. }
  166. }
  167. }
  168. public static bool Prepare
  169. {
  170. get { return _Prepare; }
  171. set
  172. {
  173. _Prepare = value;
  174. if (Prepare)
  175. {
  176. PrepareTimer = 3;
  177. ManaReso.Get("D_Rip1").SetActive(true);
  178. ManaReso.Get("D_Water1").SetActive(true);
  179. ManaReso.Get("D_Fertilize1").SetActive(true);
  180. ManaReso.Get("D_Begin").SetActive(false);
  181. PrepareLab.SetActive(true);
  182. }
  183. }
  184. }
  185. public static float GameTimer
  186. {
  187. get { return _GameTimer; }
  188. set
  189. {
  190. _GameTimer = value;
  191. TimerIcon.fillAmount = _GameTimer / GameTime;
  192. TimerLab.text = _GameTimer.ToString("0.0");
  193. }
  194. }
  195. public static float PrepareTimer
  196. {
  197. get { return _PrepareTimer; }
  198. set
  199. {
  200. _PrepareTimer = value;
  201. PrepareLab.text = Mathf.CeilToInt(_PrepareTimer).ToString();
  202. }
  203. }
  204. private static int _Score;
  205. private static bool _Game;
  206. private static bool _Pause;
  207. private static bool _Panalty;
  208. private static bool _Prepare;
  209. private static float _GameTimer;
  210. private static float _PrepareTimer;
  211. public static int MiniGameAmt;
  212. public static bool DropDiamond;
  213. public static List<DropGold> GoldList;
  214. public static List<DropDiamond> DiamondList;
  215. public static Text BtnLab;
  216. public static Text TimerLab;
  217. public static Text PrepareLab;
  218. public static Image TimerIcon;
  219. public static Award Award;
  220. public static List<Flower> OpList;
  221. public static List<Flower> IdleList;
  222. private static float OpTime;
  223. private static float OpTimer;
  224. private static float GoldTimer;
  225. private static float GameTime;
  226. private static float PanaltyTime;
  227. private static float PanaltyTimer;
  228. private static float DIamondTimer;
  229. #endregion
  230. private void FixedUpdate()
  231. {
  232. if (Pause)
  233. {
  234. return;
  235. }
  236. if (Prepare)
  237. {
  238. PrepareTimer -= Time.fixedDeltaTime;
  239. if (PrepareTimer <= 0)
  240. {
  241. GameBegin();
  242. PrepareLab.text = Language.GetStr("UI", "D_PrepareLab");
  243. PrepareLab.TweenForGra();
  244. PrepareLab.TweenForText();
  245. }
  246. }
  247. if (Game == false)
  248. {
  249. return;
  250. }
  251. GoldTimer -= Time.fixedDeltaTime;
  252. if (GoldTimer < 0)
  253. {
  254. GoldTimer = Random.Range(3f, 6f);
  255. GoldList.Add(ManaReso.GetGold());
  256. }
  257. if (DropDiamond)
  258. {
  259. DIamondTimer -= Time.fixedDeltaTime;
  260. if (DIamondTimer < 0)
  261. {
  262. DropDiamond = false;
  263. DiamondList.Add(ManaReso.GetDiamond());
  264. }
  265. }
  266. GameTimer -= Time.fixedDeltaTime;
  267. if (GameTimer <= 0)
  268. {
  269. GameOver();
  270. return;
  271. }
  272. if (Panalty)
  273. {
  274. PanaltyTimer -= Time.fixedDeltaTime;
  275. if (PanaltyTimer <= 0)
  276. {
  277. Panalty = false;
  278. }
  279. }
  280. if (IdleList.Count > 0)
  281. {
  282. OpTimer -= Time.fixedDeltaTime;
  283. if (OpTimer <= 0)
  284. {
  285. OpTime -= OpTime * 0.03f;
  286. OpTimer = OpTime;
  287. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  288. flower.CreateOp(OpList.Count);
  289. OpList.Add(flower);
  290. IdleList.Remove(flower);
  291. }
  292. }
  293. }
  294. public override void RegistValueA()
  295. {
  296. OpTime = 1.5f;
  297. GameTime = 45;
  298. PanaltyTime = 1;
  299. OpTimer = OpTime;
  300. GameTimer = GameTime;
  301. Award = new Award(Data.GetAwardConfig());
  302. PrepareLab.CreateTweenGra(ManaColor.Orange, new Color(ManaColor.Orange.r, ManaColor.Orange.g, ManaColor.Orange.b, 0), 0.25f, true, false, Curve.EaseOutQuad);
  303. Tween tween = PrepareLab.CreateTweenText(90, 100, 0.25f, true, false, Curve.EaseOutQuad);
  304. tween.OnForwardFinish += () =>
  305. {
  306. PrepareLab.color = ManaColor.Orange;
  307. PrepareLab.fontSize = 90;
  308. };
  309. }
  310. public override void RegistReference()
  311. {
  312. TimerIcon = ManaReso.Get<Image>("D_TimerIcon");
  313. BtnLab = ManaReso.Get<Text>("D_BeginLab");
  314. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  315. PrepareLab = ManaReso.Get<Text>("D_PrepareLab");
  316. }
  317. public override void TutorialRegistValue()
  318. {
  319. RegistValueA();
  320. }
  321. public override void TutorialRegistReference()
  322. {
  323. RegistReference();
  324. }
  325. #region MiniGame
  326. public static void Rip()
  327. {
  328. if (Panalty)
  329. {
  330. return;
  331. }
  332. if (OpList.Count == 0)
  333. {
  334. return;
  335. }
  336. if (OpList[0].Operate(OpType.Rip))
  337. {
  338. IdleList.Add(OpList[0]);
  339. OpList.Remove(OpList[0]);
  340. ResetOperate();
  341. }
  342. else
  343. {
  344. Panalty = true;
  345. PanaltyTimer = PanaltyTime;
  346. }
  347. }
  348. public static void Water()
  349. {
  350. if (Panalty)
  351. {
  352. return;
  353. }
  354. if (OpList.Count == 0)
  355. {
  356. return;
  357. }
  358. if (OpList[0].Operate(OpType.Water))
  359. {
  360. IdleList.Add(OpList[0]);
  361. OpList.Remove(OpList[0]);
  362. ResetOperate();
  363. }
  364. else
  365. {
  366. Panalty = true;
  367. PanaltyTimer = PanaltyTime;
  368. }
  369. }
  370. public static void Fertilize()
  371. {
  372. if (Panalty)
  373. {
  374. return;
  375. }
  376. if (OpList.Count == 0)
  377. {
  378. return;
  379. }
  380. if (OpList[0].Operate(OpType.Fertilize))
  381. {
  382. IdleList.Add(OpList[0]);
  383. OpList.Remove(OpList[0]);
  384. ResetOperate();
  385. }
  386. else
  387. {
  388. Panalty = true;
  389. PanaltyTimer = PanaltyTime;
  390. }
  391. }
  392. public static void GameOver()
  393. {
  394. ManaData.MiniGame++;
  395. Award.GetAward(Score);
  396. ManaReso.SetActive("Da_Info", true);
  397. ManaReso.SetActive("Da_Quit", false);
  398. ManaReso.SetActive("Da_Cancel", false);
  399. ManaReso.SetActive("Da_GetAward", true);
  400. GameAbort();
  401. }
  402. public static void GameBegin()
  403. {
  404. MiniGameAmt++;
  405. GoldTimer = Random.Range(3f, 6f);
  406. DIamondTimer = Random.Range(0f, 40f);
  407. ManaDebug.Log(string.Format("第<color=red>{0}</color>次小游戏", MiniGameAmt));
  408. if (Random.Range(5, 9) <= MiniGameAmt)
  409. {
  410. MiniGameAmt = 0;
  411. DropDiamond = true;
  412. }
  413. else
  414. {
  415. if (Random.Range(0, 1f) <= 0.01f)
  416. {
  417. DropDiamond = true;
  418. }
  419. else
  420. {
  421. DropDiamond = false;
  422. }
  423. }
  424. Score = 0;
  425. Game = true;
  426. Pause = false;
  427. Panalty = false;
  428. Prepare = false;
  429. OpTimer = OpTime;
  430. GameTimer = GameTime;
  431. PanaltyTimer = 0;
  432. for (int i = 0; i < IdleList.Count; i++)
  433. {
  434. IdleList[i].GameBegin();
  435. }
  436. }
  437. public static void GameAbort()
  438. {
  439. PrepareLab.SetActive(false);
  440. ManaGarden.AwardLock = false;
  441. for (int i = 0; i < GoldList.Count; i++)
  442. {
  443. GoldList[i].Retrieve();
  444. }
  445. for (int i = 0; i < DiamondList.Count; i++)
  446. {
  447. DiamondList[i].Retrieve();
  448. }
  449. if (Game)
  450. {
  451. ManaData.Mini = false;
  452. ManaData.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
  453. ManaReso.Get("C_MiniGame").TweenBacCG();
  454. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", ManaData.MiniTimer));
  455. }
  456. ManaReso.SetActive("D_Rip1", false);
  457. ManaReso.SetActive("D_Water1", false);
  458. ManaReso.SetActive("D_Fertilize1", false);
  459. ManaReso.SetActive("D_Begin", true);
  460. ManaReso.SetText("Da_Tit", string.Format(Language.GetStr("UI", "Da_Tit1")));
  461. ManaReso.SetText("Da_Lab", string.Format("{0}{1}", Language.GetStr("UI", "Da_Lab1"), Score));
  462. Score = 0;
  463. Game = false;
  464. Pause = false;
  465. Panalty = false;
  466. Prepare = false;
  467. OpTimer = OpTime;
  468. GameTimer = GameTime;
  469. PanaltyTimer = 0;
  470. for (int i = 0; i < IdleList.Count; i++)
  471. {
  472. IdleList[i].GameOver();
  473. }
  474. for (int i = 0; i < OpList.Count; i++)
  475. {
  476. OpList[i].GameOver();
  477. }
  478. }
  479. public static void GamePrepare()
  480. {
  481. GoldList = new List<DropGold>();
  482. DiamondList = new List<DropDiamond>();
  483. ManaReso.SetText("Da_CoinLab", "");
  484. ManaReso.SetText("Da_FlowerLab", "");
  485. ManaReso.SetText("Da_DiamondLab", "");
  486. ManaReso.SetActive("Da_Coin", true);
  487. ManaReso.SetActive("Da_Flower", true);
  488. ManaReso.SetActive("Da_Diamond", true);
  489. ManaGarden.AwardLock = true;
  490. OpList = new List<Flower>();
  491. IdleList = new List<Flower>();
  492. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[0], ManaReso.Get("SlotMini1")));
  493. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[1], ManaReso.Get("SlotMini2")));
  494. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[2], ManaReso.Get("SlotMini3")));
  495. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[3], ManaReso.Get("SlotMini4")));
  496. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[4], ManaReso.Get("SlotMini5")));
  497. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[5], ManaReso.Get("SlotMini6")));
  498. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[6], ManaReso.Get("SlotMini7")));
  499. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[7], ManaReso.Get("SlotMini8")));
  500. IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[8], ManaReso.Get("SlotMini9")));
  501. }
  502. public static void ResetOperate()
  503. {
  504. if (OpList.Count >= 2)
  505. {
  506. OpList[0].SetFirstOp();
  507. OpList[1].SetSecondOp();
  508. }
  509. else if (OpList.Count >= 1)
  510. {
  511. OpList[0].SetFirstOp();
  512. }
  513. }
  514. #endregion
  515. }