ManaMiniGame.cs 15 KB

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