123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Serialization;
- using System;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- using Random = UnityEngine.Random;
- public class Award
- {
- #region 变量
- public int DiamondMin;
- public int DiamondMax;
- public string CoinFml;
- public string FlowerFml;
- public string DiamondFml;
- public List<float> Odds;
- public List<float> Standard;
- #endregion
- public Award(XmlAttributeCollection attribute)
- {
- CoinFml = attribute[1].Value;
- FlowerFml = attribute[4].Value;
- DiamondFml = attribute[3].Value;
-
- string[] strings = attribute[2].Value.Split(',');
- DiamondMin = int.Parse(strings[0]);
- DiamondMax = int.Parse(strings[1]);
- strings = attribute[5].Value.Split(',');
- Odds = new List<float>()
- {
- float.Parse(strings[0]),
- float.Parse(strings[1]),
- float.Parse(strings[2]),
- };
- strings = attribute[6].Value.Split(',');
- Standard = new List<float>()
- {
- float.Parse(strings[0]),
- float.Parse(strings[1]),
- float.Parse(strings[2]),
- };
- }
- public void GetAward(int score)
- {
- ManaReso.SetActive("Da_Flower", false);
- ManaReso.SetActive("Da_Diamond", false);
- int coin = (int) Auxiliary.FmlParse(CoinFml, "s", score.ToString());
- ManaData.Coin += coin;
- ManaReso.SetText("Da_CoinLab", coin.ToString());
-
- float diamondRate = (float) Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaData.Level, 1, 1000).ToString());
- if (Random.Range(0, 1f) <= diamondRate)
- {
- ManaReso.SetActive("Da_Diamond", true);
- int diamond = (int) Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f));
- ManaReso.SetText("Da_DiamondLab", diamond.ToString());
- ManaData.Diamond += diamond;
- }
- int grade;
- if (score < Standard[0])
- {
- grade = 0;
- }
- else if (score < Standard[1])
- {
- grade = 1;
- }
- else if (score < Standard[2])
- {
- grade = 2;
- }
- else
- {
- throw new Exception();
- }
- float flowerRate = (float) Auxiliary.FmlParse(DiamondFml, "l", ManaData.Level.ToString(), "f", ManaGarden.MyFlower.ToString());
- if (Random.Range(0, 1f) <= flowerRate)
- {
- if (Random.Range(0, 1f) <= Odds[grade])
- {
- ManaReso.SetActive("Da_Flower", true);
- FlowerInfo flowerInfo;
- while (true)
- {
- flowerInfo = ManaGarden.FlowerInfoList[Random.Range(0, ManaGarden.TotalFlower - 1)];
- if (flowerInfo.Unlock)
- {
- break;
- }
- }
- ManaReso.SetText("Da_FlowerLab", Language.GetStr("FlowerName", "Flower" + flowerInfo.Id));
- }
- }
- }
- }
- public class ManaMiniGame : Regist
- {
- #region 变量
- public static int Score
- {
- get { return _Score; }
- set
- {
- _Score = value;
- ManaReso.SetText("D_ScoreLab", _Score.ToString());
- }
- }
- public static bool Game
- {
- get { return _Game; }
- set
- {
- _Game = value;
- if (_Game)
- {
- ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
- }
- else
- {
- ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0"));
- }
- }
- }
- public static bool Pause
- {
- get { return _Pause; }
- set
- {
- _Pause = value;
- if (Game)
- {
- if (_Pause)
- {
- ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2"));
- }
- else
- {
- ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
- }
- }
- }
- }
- public static bool Panalty
- {
- get { return _Panalty; }
- set
- {
- _Panalty = value;
- if (_Panalty)
- {
- ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3"));
- }
- else
- {
- ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
- }
- }
- }
- public static float GameTimer
- {
- get { return _GameTimer; }
- set
- {
- _GameTimer = value;
- TimerBk.fillAmount = _GameTimer / GameTimer;
- TimerLab.text = _GameTimer.ToString("0.0");
- }
- }
- public static float PrepareTimer
- {
- get { return _PrepareTimer; }
- set
- {
- _PrepareTimer = value;
- BtnLab.text = PrepareStr + " " + Mathf.CeilToInt(_PrepareTimer);
- }
- }
- private static int _Score;
- private static bool _Game;
- private static bool _Pause;
- private static bool _Panalty;
- private static float _GameTimer;
- private static float _PrepareTimer;
- public static string PrepareStr;
- public static Text BtnLab;
- public static Text TimerLab;
- public static Image TimerBk;
- public static Award Award;
- public static List<Flower> OpList;
- public static List<Flower> IdleList;
- private static float OpTime;
- private static float OpTimer;
- private static float GameTime;
- private static float PanaltyTime;
- private static float PanaltyTimer;
- #endregion
- private void FixedUpdate()
- {
- if (PrepareTimer > 0)
- {
- PrepareTimer -= Time.fixedDeltaTime;
- if (PrepareTimer <= 0)
- {
- GameBegin();
- }
- }
- if (!Game || Pause)
- {
- return;
- }
- GameTimer -= Time.fixedDeltaTime;
- if (GameTimer <= 0)
- {
- GameOver();
- return;
- }
- if (Panalty)
- {
- PanaltyTimer -= Time.fixedDeltaTime;
- if (PanaltyTimer <= 0)
- {
- Panalty = false;
- }
- }
- if (IdleList.Count > 0)
- {
- OpTimer -= Time.fixedDeltaTime;
- if (OpTimer <= 0)
- {
- OpTime -= OpTime * 0.02f;
- OpTimer = OpTime;
- Flower flower = IdleList[Random.Range(0, IdleList.Count)];
- flower.CreateOp(OpList.Count);
- OpList.Add(flower);
- IdleList.Remove(flower);
- }
- }
- }
- public override void RegistValueA()
- {
- PrepareStr = Language.GetStr("UI", "D_BeginLab1");
- OpTime = 1.5f;
- GameTime = 45;
- PanaltyTime = 1;
- OpTimer = OpTime;
- GameTimer = GameTime;
- Award = new Award(Data.GetAwardConfig());
- }
- public override void RegistReference()
- {
- TimerBk = ManaReso.Get<Image>("D_TimerIcon");
- BtnLab = ManaReso.Get<Text>("D_BeginLab");
- TimerLab = ManaReso.Get<Text>("D_TimerLab");
- }
- #region MiniGame
- public static void Rip()
- {
- if (Panalty)
- {
- return;
- }
- if (OpList.Count == 0)
- {
- return;
- }
- if (OpList[0].Operate(OpType.Rip))
- {
- IdleList.Add(OpList[0]);
- OpList.Remove(OpList[0]);
- ResetOperate();
- }
- else
- {
- Panalty = true;
- PanaltyTimer = PanaltyTime;
- }
- }
- public static void Water()
- {
- if (Panalty)
- {
- return;
- }
- if (OpList.Count == 0)
- {
- return;
- }
- if (OpList[0].Operate(OpType.Water))
- {
- IdleList.Add(OpList[0]);
- OpList.Remove(OpList[0]);
- ResetOperate();
- }
- else
- {
- Panalty = true;
- PanaltyTimer = PanaltyTime;
- }
- }
- public static void Fertilize()
- {
- if (Panalty)
- {
- return;
- }
- if (OpList.Count == 0)
- {
- return;
- }
- if (OpList[0].Operate(OpType.Fertilize))
- {
- IdleList.Add(OpList[0]);
- OpList.Remove(OpList[0]);
- ResetOperate();
- }
- else
- {
- Panalty = true;
- PanaltyTimer = PanaltyTime;
- }
- }
- public static void GameOver()
- {
- Award.GetAward(Score);
- ManaReso.SetActive("Da_Info", true);
- ManaReso.SetActive("Da_Quit", false);
- ManaReso.SetActive("Da_Cancel", false);
- ManaReso.SetActive("Da_GetAward", true);
- GameAbort();
- }
- public static void GameBegin()
- {
- ManaReso.Get("D_Rip1").SetActive(true);
- ManaReso.Get("D_Water1").SetActive(true);
- ManaReso.Get("D_Fertilize1").SetActive(true);
- ManaReso.Get("D_Begin").SetActive(false);
- Score = 0;
- Game = true;
- Pause = false;
- Panalty = false;
- OpTimer = OpTime;
- GameTimer = GameTime;
- PanaltyTimer = 0;
- for (int i = 0; i < IdleList.Count; i++)
- {
- IdleList[i].GameBegin();
- }
- }
- public static void GameAbort()
- {
- ManaReso.SetActive("D_Rip1", false);
- ManaReso.SetActive("D_Water1", false);
- ManaReso.SetActive("D_Fertilize1", false);
- ManaReso.SetActive("D_Begin", true);
- ManaReso.SetText("Da_Tit", string.Format(Language.GetStr("UI", "Da_Tit1")));
- ManaReso.SetText("Da_Lab", string.Format("{0}{1}", Language.GetStr("UI", "Da_Lab1"), Score));
- Score = 0;
- Game = false;
- Pause = false;
- Panalty = false;
- OpTimer = OpTime;
- GameTimer = GameTime;
- PanaltyTimer = 0;
- for (int i = 0; i < IdleList.Count; i++)
- {
- IdleList[i].GameOver();
- }
- for (int i = 0; i < OpList.Count; i++)
- {
- OpList[i].GameOver();
- }
- }
- public static void GamePrepare()
- {
- OpList = new List<Flower>();
- IdleList = new List<Flower>();
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[0], ManaReso.Get("SlotMini1")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[1], ManaReso.Get("SlotMini2")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[2], ManaReso.Get("SlotMini3")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[3], ManaReso.Get("SlotMini4")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[4], ManaReso.Get("SlotMini5")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[5], ManaReso.Get("SlotMini6")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[6], ManaReso.Get("SlotMini7")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[7], ManaReso.Get("SlotMini8")));
- IdleList.Add(ManaReso.GetFlower(ManaGarden.FlowerInfoList[8], ManaReso.Get("SlotMini9")));
- }
- public static void ResetOperate()
- {
- if (OpList.Count >= 2)
- {
- OpList[0].SetFirstOp();
- OpList[1].SetSecondOp();
- }
- else if (OpList.Count >= 1)
- {
- OpList[0].SetFirstOp();
- }
- }
- #endregion
- }
|