123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664 |
- 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 static int BonusCoin;
- public static int BonusDiamond;
- 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());
- coin = (int) (coin * ManaData.SkillPlus) + BonusCoin;
-
- 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)) + BonusDiamond;
-
- ManaData.Diamond += diamond;
- ManaReso.SetText("Da_DiamondLab", diamond.ToString());
- }
- else
- {
- if (BonusDiamond > 0)
- {
- ManaReso.SetActive("Da_Diamond", true);
- ManaData.Diamond += BonusDiamond;
- ManaReso.SetText("Da_DiamondLab", BonusDiamond.ToString());
- }
- }
- int standard;
- if (score < Standard[0])
- {
- standard = 0;
- }
- else if (score < Standard[1])
- {
- standard = 1;
- }
- else
- {
- standard = 2;
- }
- 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[standard])
- {
- ManaReso.SetActive("Da_Flower", true);
- int Anti = 0;
- FlowerInfo flowerInfo;
- while (true)
- {
- Anti++;
- if (Anti > 1000)
- {
- ManaReso.SetText("Da_FlowerLab", "没有可用的花朵");
- break;
- }
- flowerInfo = ManaGarden.FlowerInfoList.Random();
- if (flowerInfo.Unlock)
- {
- ManaReso.SetText("Da_FlowerLab", Language.GetStr("FlowerName", "Flower" + flowerInfo.ID));
- break;
- }
- }
- }
- }
- BonusCoin = 0;
- BonusDiamond = 0;
- }
- }
- 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 bool Prepare
- {
- get { return _Prepare; }
- set
- {
- _Prepare = value;
- if (Prepare)
- {
- PrepareTimer = 3;
- ManaReso.Get("D_Rip1").SetActive(true);
- ManaReso.Get("D_Water1").SetActive(true);
- ManaReso.Get("D_Fertilize1").SetActive(true);
- ManaReso.Get("D_Begin").SetActive(false);
- PrepareLab.SetActive(true);
- }
- }
- }
- public static float GameTimer
- {
- get { return _GameTimer; }
- set
- {
- _GameTimer = value;
- TimerIcon.fillAmount = _GameTimer / GameTime;
-
- TimerLab.text = _GameTimer.ToString("0.0");
- }
- }
- public static float PrepareTimer
- {
- get { return _PrepareTimer; }
- set
- {
- _PrepareTimer = value;
- PrepareLab.text = Mathf.CeilToInt(_PrepareTimer).ToString();
- }
- }
- private static int _Score;
- private static bool _Game;
- private static bool _Pause;
- private static bool _Panalty;
- private static bool _Prepare;
- private static float _GameTimer;
- private static float _PrepareTimer;
- public static int MiniGameIndex;
- public static bool DropDiamond;
- public static List<DropGold> GoldList;
- public static List<DropDiamond> DiamondList;
- public static Text BtnLab;
- public static Text TimerLab;
- public static Text PrepareLab;
- public static Image TimerIcon;
- 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 GoldTimer;
- private static float GameTime;
- private static float PanaltyTime;
- private static float PanaltyTimer;
- private static float DIamondTimer;
- #endregion
- private void FixedUpdate()
- {
- if (Pause)
- {
- return;
- }
- if (Prepare)
- {
- PrepareTimer -= Time.fixedDeltaTime;
- if (PrepareTimer <= 0)
- {
- GameBegin();
- PrepareLab.text = Language.GetStr("UI", "D_PrepareLab");
- PrepareLab.TweenForGra();
- PrepareLab.TweenForText();
- }
- }
- if (Game == false)
- {
- return;
- }
- GoldTimer -= Time.fixedDeltaTime;
- if (GoldTimer < 0)
- {
- GoldTimer = Random.Range(3f, 6f);
- GoldList.Add(ManaReso.GetGold());
- }
- if (DropDiamond)
- {
- DIamondTimer -= Time.fixedDeltaTime;
- if (DIamondTimer < 0)
- {
- DropDiamond = false;
-
- DiamondList.Add(ManaReso.GetDiamond());
- }
- }
- 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.03f;
- OpTimer = OpTime;
- Flower flower = IdleList[Random.Range(0, IdleList.Count)];
- flower.CreateOp(OpList.Count);
- OpList.Add(flower);
- IdleList.Remove(flower);
- }
- }
- }
- public override void RegistValueA()
- {
- OpTime = 1.5f;
- GameTime = 45;
- PanaltyTime = 1;
- OpTimer = OpTime;
- GameTimer = GameTime;
- MiniGameIndex = Data.PlayerInt("MiniGameIndex");
- Award = new Award(Data.GetAwardConfig());
- PrepareLab.color = ManaColor.Orange;
- PrepareLab.CreateTweenGra(1, 0, 0.25f, true, false, Curve.EaseOutQuad);
- Tween tween = PrepareLab.CreateTweenText(90, 100, 0.25f, true, false, Curve.EaseOutQuad);
- tween.OnForwardFinish += () =>
- {
- PrepareLab.SetAlpha(1);
- PrepareLab.fontSize = 90;
- };
- }
- public override void RegistReference()
- {
- TimerIcon = ManaReso.Get<Image>("D_TimerIcon");
- BtnLab = ManaReso.Get<Text>("D_BeginLab");
- TimerLab = ManaReso.Get<Text>("D_TimerLab");
- PrepareLab = ManaReso.Get<Text>("D_PrepareLab");
- }
- public override void TutorialRegistValue()
- {
- RegistValueA();
- }
- public override void TutorialRegistReference()
- {
- RegistReference();
- }
- #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()
- {
- ManaData.MiniGame++;
- 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()
- {
- MiniGameIndex++;
- GoldTimer = Random.Range(3f, 6f);
- DIamondTimer = Random.Range(0f, 40f);
- ManaDebug.Log(string.Format("第<color=red>{0}</color>次小游戏", MiniGameIndex));
- if (Random.Range(5, 9) <= MiniGameIndex)
- {
- MiniGameIndex = 0;
- DropDiamond = true;
- }
- else
- {
- if (Random.Range(0, 1f) <= 0.01f)
- {
- DropDiamond = true;
- }
- else
- {
- DropDiamond = false;
- }
- }
- Score = 0;
- Game = true;
- Pause = false;
- Panalty = false;
- Prepare = false;
- OpTimer = OpTime;
- GameTimer = GameTime;
- PanaltyTimer = 0;
- for (int i = 0; i < IdleList.Count; i++)
- {
- IdleList[i].GameBegin();
- }
- }
- public static void GameAbort()
- {
- PrepareLab.SetActive(false);
- ManaGarden.AwardLock = false;
- for (int i = 0; i < GoldList.Count; i++)
- {
- GoldList[i].Retrieve();
- }
- for (int i = 0; i < DiamondList.Count; i++)
- {
- DiamondList[i].Retrieve();
- }
- if (Game)
- {
- ManaData.Mini = false;
- ManaData.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
- ManaReso.Get("C_MiniGame").TweenBacCG();
- ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", ManaData.MiniTimer));
- }
- 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;
- Prepare = 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()
- {
- GoldList = new List<DropGold>();
- DiamondList = new List<DropDiamond>();
-
- ManaReso.SetText("Da_CoinLab", "");
- ManaReso.SetText("Da_FlowerLab", "");
- ManaReso.SetText("Da_DiamondLab", "");
- ManaReso.SetActive("Da_Coin", true);
- ManaReso.SetActive("Da_Flower", true);
- ManaReso.SetActive("Da_Diamond", true);
- ManaGarden.AwardLock = true;
- 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
- }
|