123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- 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 = new List<float>();
- public List<float> Standard = new List<float>();
- #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)
- {
- #region 获得奖励
- #region Reset
- ManaReso.Get("Da_Info").TweenForCG();
- ManaReso.SetActive("Da_Lab", false);
- ManaReso.SetActive("Da_Quit", false);
- ManaReso.SetActive("Da_Cancel", false);
- ManaReso.SetActive("Da_VGroup", false);
- ManaReso.SetActive("Da_HGroup", false);
- ManaReso.SetActive("Da_ScoreTit", false);
- ManaReso.SetActive("Da_GetAward", false);
- ManaReso.SetActive("Da_FlowerGroup", false);
- ManaReso.SetActive("Da_DiamondGroup", false);
- bool flowerFlag = false;
- bool diamondFlag = false;
- #endregion
- #region Coin
- int coin = (int)Auxiliary.FmlParse(CoinFml, "s", score.ToString());
- coin = Mathf.FloorToInt(coin * (1 + ManaData.SkillPlus)) + BonusCoin;
- ManaData.Coin += coin;
- #endregion
- #region Diamond
- int diamond = 0;
- float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaData.Level, 1, 1000).ToString());
- if (Random.Range(0, 1f) <= diamondRate)
- {
- diamondFlag = true;
- diamond = Mathf.FloorToInt(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond);
- ManaData.Diamond += diamond;
- ManaReso.SetActive("Da_Diamond", true);
- }
- else
- {
- if (BonusDiamond > 0)
- {
- diamondFlag = true;
- ManaData.Diamond += BonusDiamond;
- ManaReso.SetActive("Da_Diamond", true);
- }
- }
- #endregion
- #region Rate
- int rate;
- if (score < Standard[1])
- {
- rate = 0;
- }
- else if (score < Standard[2])
- {
- rate = 1;
- }
- else
- {
- rate = 2;
- }
- #endregion
- #region Flower
- if (ManaTutorial.TutorialA)
- {
- flowerFlag = true;
- FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[1];
- Vector2 newSize = flowerInfo.Icon.rect.size;
- newSize.x *= 0.2f;
- newSize.y *= 0.2f;
- ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
- ManaReso.Get<Image>("Da_FlowerIcon").rectTransform.sizeDelta = newSize;
- ManaReso.SetText("Da_FlowerLab", Language.GetStr("FlowerName", "Flower" + flowerInfo.ID_));
- }
- else
- {
- 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[rate])
- {
- while (true)
- {
- FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
- if (flowerInfo.Unlock)
- {
- flowerFlag = true;
- Vector2 newSize = flowerInfo.Icon.rect.size;
- newSize.x *= 0.2f;
- newSize.y *= 0.2f;
- ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
- ManaReso.Get<Image>("Da_FlowerIcon").rectTransform.sizeDelta = newSize;
- ManaReso.SetText("Da_FlowerLab", Language.GetStr("FlowerName", "Flower" + flowerInfo.ID_));
- break;
- }
- }
- }
- }
- }
- BonusCoin = 0;
- BonusDiamond = 0;
- #endregion
- #endregion
- #region 构造动画
- #region Reset
- ManaReso.SetText("Da_CoinLab", "");
- ManaReso.SetText("Da_ScoreLab", "");
- ManaReso.SetText("Da_DiamondLab", "");
- ManaReso.SetActive("Da_VGroup", true);
- ManaReso.SetActive("Da_CoinGroup", true);
- ManaReso.SetActive("Da_FlowerGroup", true);
- if (diamondFlag)
- {
- ManaReso.SetActive("Da_DiamondGroup", true);
- }
- Auxiliary.Instance.DelayCall
- (
- () =>
- {
- ManaReso.SetActive("Da_FlowerGroup", false);
- ManaReso.SetActive("Da_DiamondGroup", false);
- ManaReso.Get<VerticalLayoutGroup>("Da_VGroup").enabled = false;
- },
- 1
- );
- float timeCoin = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(coin / 15f));
- float timeScore = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(score/50f));
- float timeDiamond = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(diamond / 15f));
- float time = Mathf.Max(timeCoin, timeDiamond);
- ManaReso.Get("Da_CoinLab").CreateTweenNumber(0, coin, time, true, true, Curve.EaseOutQuad);
- ManaReso.Get("Da_ScoreLab").CreateTweenNumber(0, score, timeScore, true, true, Curve.EaseOutQuad);
- ManaReso.Get("Da_DiamondLab").CreateTweenNumber(0, diamond, time, true, true, Curve.EaseOutQuad);
- #endregion
- #region 五角星
- Tween tween = ManaReso.Get("Da_Info").GetTweenCG();
- tween.OnForwardFinish = () =>
- {
- ManaReso.Get("Da_Star1").TweenForScale();
- ManaReso.SetActive("Da_HGroup", true);
- };
- tween = ManaReso.Get("Da_ScoreTit").GetTweenText();
- tween.InOrigin = true;
- tween = ManaReso.Get("Da_Star3").GetTweenScale();
- tween.InOrigin = true;
- tween = ManaReso.Get("Da_Star2").GetTweenScale();
- tween.InOrigin = true;
- tween = ManaReso.Get("Da_Star1").GetTweenScale();
- tween.InOrigin = true;
- if (rate == 0)
- {
- ManaReso.SetActive("Da_Star2", false);
- ManaReso.SetActive("Da_Star3", false);
- }
- else if (rate == 1)
- {
- ManaReso.SetActive("Da_Star2", true);
- ManaReso.SetActive("Da_Star3", false);
- tween = ManaReso.Get("Da_Star1").GetTweenScale();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_Star2").TweenForScale();
- }
- );
- tween = ManaReso.Get("Da_Star2").GetTweenScale();
- }
- else if (rate == 2)
- {
- ManaReso.SetActive("Da_Star2", true);
- ManaReso.SetActive("Da_Star3", true);
- tween = ManaReso.Get("Da_Star1").GetTweenScale();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_Star2").TweenForScale();
- }
- );
- tween = ManaReso.Get("Da_Star2").GetTweenScale();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_Star3").TweenForScale();
- }
- );
- tween = ManaReso.Get("Da_Star3").GetTweenScale();
- }
- #endregion
- #region 得分
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_ScoreTit").TweenForText();
- }
- );
- tween = ManaReso.Get("Da_ScoreTit").GetTweenText();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_ScoreLab").TweenForNumber();
- }
- );
- #endregion
- #region 金币钻石
- tween = ManaReso.Get("Da_ScoreLab").GetTweenNumber();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get<CanvasGroup>("Da_VGroup").alpha = 1;
- ManaReso.SetActive("Da_VGroup", true);
- ManaReso.Get("Da_CoinGroup").TweenForScale();
- if (diamondFlag)
- {
- ManaReso.Get("Da_DiamondGroup").TweenForScale();
- }
- }
- );
- tween = ManaReso.Get("Da_CoinGroup").GetTweenScale();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_CoinLab").TweenForNumber();
- }
- );
- if (diamondFlag)
- {
- tween = ManaReso.Get("Da_DiamondGroup").GetTweenScale();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_DiamondLab").TweenForNumber();
- }
- );
- }
- #endregion
- #region 花
- if (flowerFlag)
- {
- tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_FlowerGroup").TweenForScale();
- ManaReso.SetActive("Da_FlowerGroup", true);
- }
- );
- }
- #endregion
- #region 按钮
- if (flowerFlag)
- {
- tween = ManaReso.Get("Da_FlowerGroup").GetTweenScale();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_GetAward").TweenForCG();
- }
- );
- }
- else
- {
- tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("Da_GetAward").TweenForCG();
- }
- );
- }
- if (ManaTutorial.TutorialA)
- {
- tween = ManaReso.Get("Da_GetAward").GetTweenCG();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- Tutorial.HightScreen(ManaReso.Get("Da_GetAwardArrow0"), ManaReso.Get("Da_GetAwardArrow1"), ManaReso.Get("Da_GetAward"));
- }
- );
- }
- #endregion
- #endregion
- }
- }
- 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;
- TimerLab.text = _GameTimer.ToString("0.0");
- TimerBk.fillAmount = _GameTimer / GameTime;
- }
- }
- 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 Text BtnLab;
- public static Text TimerLab;
- public static Text PrepareLab;
- public static Image TimerBk;
- public static Award Award;
- public static List<Flower> OpList = new List<Flower>();
- public static List<Flower> IdleList = new List<Flower>();
- public static List<DropGold> GoldList = new List<DropGold>();
- public static List<DropDiamond> DiamondList = new List<DropDiamond>();
- public static int MiniGameIndex;
- public static bool TutorialValidA = true;
- public static bool DropDiamond;
- public static float OpTime = 1.5f;
- public static float OpTimer;
- public static float GoldTimer;
- public static float GameTime = 5;
- public static float PanaltyTime = 1;
- public static float PanaltyTimer;
- public static float DiamondTimer;
- #endregion
- private void FixedUpdate()
- {
- if (Game)
- {
- GameThread();
- }
- if (Prepare)
- {
- PrepareThread();
- }
- }
- private void GameThread()
- {
- if (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.03f;
- OpTimer = OpTime;
- CreateOperate();
- }
- }
- BonusThread();
- }
- private void BonusThread()
- {
- if (Pause)
- {
- 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());
- }
- }
- }
- private void PrepareThread()
- {
- PrepareTimer -= Time.fixedDeltaTime;
- if (PrepareTimer <= 0)
- {
- Prepare = false;
- GameBegin();
- PrepareLab.text = Language.GetStr("UI", "D_PrepareLab");
- PrepareLab.TweenForGra();
- PrepareLab.TweenForText();
- }
- }
- private void CreateOperate()
- {
- if (ManaTutorial.TutorialA && TutorialValidA)
- {
- Pause = true;
- TutorialValidA = false;
- Flower flower = IdleList[4];
- flower.CreateOp(OpList.Count, OpType.Water);
- OpList.Add(flower);
- IdleList.Remove(flower);
- Tutorial.HightScreen(ManaReso.Get("D_WaterArrow0"), ManaReso.Get("D_WaterArrow1"), ManaReso.Get("D_Water1"));
- SceneMask.SetArea(OpList[0].OperateIcon.transform, 0.1f, 0.125f);
- ManaReso.AddButtonEventOnetime
- (
- "D_Water2",
- () =>
- {
- Pause = false;
- Tutorial.HightDisable();
- }
- );
- }
- else
- {
- Flower flower = IdleList[Random.Range(0, IdleList.Count)];
- flower.CreateOp(OpList.Count);
- OpList.Add(flower);
- IdleList.Remove(flower);
- }
- }
- public override void RegistValueA()
- {
- OpTimer = OpTime;
- GameTimer = GameTime;
- MiniGameIndex = Data.GetPlayerInt("MiniGameIndex");
- Award = new Award(Data.GetAwardConfig());
- 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()
- {
- BtnLab = ManaReso.Get<Text>("D_BeginLab");
- TimerLab = ManaReso.Get<Text>("D_TimerLab");
- PrepareLab = ManaReso.Get<Text>("D_PrepareLab");
- TimerBk = ManaReso.Get<Image>("D_TimerIcon");
- }
- #region MiniGame
- public static void Operate(OpType opType)
- {
- if (Panalty || !OpList.Valid())
- {
- return;
- }
- if (OpList[0].Operate(opType))
- {
- IdleList.Add(OpList[0]);
- OpList.Remove(OpList[0]);
- if (OpList.Count >= 2)
- {
- OpList[0].FirstOp();
- OpList[1].SecondOp();
- }
- else if (OpList.Count >= 1)
- {
- OpList[0].FirstOp();
- }
- }
- else
- {
- Panalty = true;
- PanaltyTimer = PanaltyTime;
- }
- }
- public static void GameEnd()
- {
- Pause = false;
- Game = false;
- Panalty = false;
- Prepare = false;
- Score = 0;
- OpTimer = OpTime;
- GameTimer = GameTime;
- ManaReso.SetText("Da_Tit", string.Format(Language.GetStr("UI", "Da_Tit1")));
- ManaGarden.AwardValid = true;
- for (int i = 0; i < OpList.Count; i++)
- {
- OpList[i].GameOver();
- OpList.RemoveAt(i--);
- }
- for (int i = 0; i < IdleList.Count; i++)
- {
- IdleList[i].GameOver();
- IdleList.RemoveAt(i--);
- }
- for (int i = 0; i < GoldList.Count; i++)
- {
- GoldList[i].Retrieve();
- GoldList.RemoveAt(i--);
- }
- for (int i = 0; i < DiamondList.Count; i++)
- {
- DiamondList[i].Retrieve();
- DiamondList.RemoveAt(i--);
- }
- if (Game)
- {
- ManaReso.Get("C_MiniGame").TweenBacCG();
- ManaData.MiniValid = false;
- ManaData.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
- ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", ManaData.MiniTimer));
- }
- }
- public static void GameOver()
- {
- GameEnd();
- Award.GetAward(Score);
- ManaData.MiniGameAmt++;
- }
- public static void GameEnter()
- {
- int flowerAmt = 1;
- while (true)
- {
- FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
- if (flowerInfo.Unlock)
- {
- IdleList.Add(ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + flowerAmt)));
- flowerAmt++;
- if (flowerAmt == 10)
- {
- break;
- }
- }
- }
- ManaGarden.AwardValid = false;
- 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);
- ManaReso.SetActive("D_Rip1", false);
- ManaReso.SetActive("D_Begin", true);
- ManaReso.SetActive("D_Water1", false);
- ManaReso.SetActive("D_Fertilize1", false);
- }
- public static void GameBegin()
- {
- Game = true;
- OpTimer = OpTime;
- MiniGameIndex++;
- GoldTimer = Random.Range(3f, 6f);
- GameTimer = GameTime;
- DiamondTimer = Random.Range(0f, 40f);
- ManaDebug.Log(string.Format("第<color=red>{0}</color>次小游戏", MiniGameIndex));
- for (int i = 0; i < IdleList.Count; i++)
- {
- IdleList[i].GameBegin();
- }
- if (Random.Range(5, 9) <= MiniGameIndex)
- {
- MiniGameIndex = 0;
- DropDiamond = true;
- }
- else
- {
- if (Random.Range(0, 1f) <= 0.01f)
- {
- DropDiamond = true;
- }
- else
- {
- DropDiamond = false;
- }
- }
- }
- #endregion
- }
|