ManaMiniGame.cs 15 KB

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