using UnityEngine; using UnityEngine.UI; using System; using System.Xml; using System.Collections; using System.Collections.Generic; using System.Linq; using Random = UnityEngine.Random; public class Sign { #region 变量 public int Coin { get { if (RoundBuff.Equal(-1)) { return Coin_; } else { return (int)(Coin_*RoundBuff*ManaSign.SignRound); } } set { Coin_ = value; } } public int Diamond { get { if (RoundBuff.Equal(-1)) { return Diamond_; } else { return (int)(Diamond_ * RoundBuff * ManaSign.SignRound); } } set { Diamond_ = value; } } public int Coin_; public int Diamond_; public float RoundBuff; public bool IsLottery; public Text Lab1; public Text Lab2; public Image Icon; public Image Mark; public Vector2 OriginSize; public List FlowerList = new List(); #endregion public Sign(int index, Transform tra, XmlAttributeCollection attribute) { Dictionary dic = new Dictionary(); Auxiliary.CompileDic(tra, dic); Lab1 = dic["Lab1"].GetComponent(); Lab2 = dic["Lab2"].GetComponent(); Icon = dic["Icon1"].GetComponent(); Mark = dic["Icon2"].GetComponent(); OriginSize = Icon.rectTransform.sizeDelta; Lab2.text = index.ToString(); Coin = Auxiliary.IntParse(attribute[4].Value, 0); IsLottery = Auxiliary.BoolParse(attribute[1].Value, false); Diamond = Auxiliary.IntParse(attribute[3].Value, 0); FlowerList = Auxiliary.IntListParse(',', attribute[2].Value, new List()); RoundBuff = Auxiliary.FloatParse(attribute[5].Value, -1); SetUI(); } public void Get() { if (IsLottery) { Lottery.EnterAnimation(); return; } ManaAudio.PlayClip(Clip.CurrentClip); Mark.SetActive(true); ResetSign(); ManaReso.SetActive("Bb_Get", false); ManaReso.SetActive("Bb_Rotate", true); ManaReso.SetActive("Bb_Confirm", true); if (FlowerList.Valid()) { for (int i = 0; i < FlowerList.Count; i++) { FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]]; if (flowerInfo.Unlock == false) { ManaReso.SetText("Bb_InfoLabA", flowerInfo.Name); ManaReso.SetActive("Bb_IconA", true); ManaReso.SetSprite("Bb_IconA0", flowerInfo.Icon); ManaReso.Get("Bb_IconA0").Resize(true, 0.65f, 0.65f); flowerInfo.Unlock = true; return; } } } if (Diamond > 0) { ManaReso.SetText("Bb_InfoLabB", Diamond.ToString()); ManaReso.SetSprite("Bb_IconB", ManaReso.LoadSprite("钻石", Folder.UI)); ManaReso.SetActive("Bb_IconB", true); ManaCenter.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Checkin); } else if (Coin > 0) { ManaReso.SetText("Bb_InfoLabB", Coin.ToString()); ManaReso.SetSprite("Bb_IconB", ManaReso.LoadSprite("金币", Folder.UI)); ManaReso.SetActive("Bb_IconB", true); ManaCenter.AddCoin(Coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Checkin); } else { throw new Exception(); } } public void SetUI() { if (IsLottery) { Icon.sprite = ManaReso.LoadSprite("礼包", Folder.Atlas); Icon.Resize(true, 0.3f, 0.3f); return; } if (FlowerList.Valid()) { for (int i = 0; i < FlowerList.Count; i++) { FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]]; if (flowerInfo.Unlock == false) { Icon.sprite = flowerInfo.Icon; Icon.Resize(true, 0.15f, 0.15f); return; } } } if (Diamond > 0) { Icon.sprite = ManaReso.LoadSprite("钻石", Folder.UI); Icon.Resize(false, OriginSize); Lab1.text = Diamond.ToString(); } else if (Coin > 0) { Icon.sprite = ManaReso.LoadSprite("金币", Folder.UI); Icon.Resize(false, OriginSize); Lab1.text = Coin.ToString(); } } public static void ResetSign() { ManaSign.SignTime = ManaServer.Time; ManaSign.SignIndex++; if (ManaSign.SignIndex == 22) { ManaSign.SignIndex = 1; ManaSign.SignRound++; ManaReso.Get("B_SignIn").GetTweenCG().AddEventOnetime ( EventType.BackwardFinish, () => { foreach (var kv in ManaSign.SignDic) { kv.Value.SetUI(); kv.Value.Mark.SetActive(false); } } ); } } } public class Lottery { #region Var public int PosIndex; public int Type; public int Value; public Text Lab; public Image Icon1; public Image Icon2; public Button Button; public Transform BK; public Transform Item; public static List TempTypeList = new List(); public static List TempValueList = new List(); public static List TempLotteryList = new List(); public static List TypeList = new List(); public static List RateList = new List(); public static List PosList = new List(); public static List> LeftBorderDList = new List>(); public static List> RightBorderDList = new List>(); #endregion public static void Configure(List attributeList) { PosList.Add(ManaReso.Get("Bc_LotteryItem1").position); PosList.Add(ManaReso.Get("Bc_LotteryItem2").position); PosList.Add(ManaReso.Get("Bc_LotteryItem3").position); for (int i = 0; i < attributeList.Count; i++) { RateList.Add((float) Auxiliary.FmlParse(attributeList[i][2].Value)); TypeList.Add((int) Auxiliary.FmlParse(attributeList[i][1].Value)); List leftBorderStrList = Auxiliary.StringListParse(',', attributeList[i][3].Value, null); List rightBorderStrList = Auxiliary.StringListParse(',', attributeList[i][4].Value, null); List leftBorderList = new List(); List rightBorderList = new List(); for (int j = 0; j < leftBorderStrList.Count; j++) { leftBorderList.Add((int)Auxiliary.FmlParse(leftBorderStrList[j], "l", ManaCenter.Level.ToString())); rightBorderList.Add((int)Auxiliary.FmlParse(rightBorderStrList[j], "l", ManaCenter.Level.ToString())); } LeftBorderDList.Add(leftBorderList); RightBorderDList.Add(rightBorderList); } } public static Lottery CreateLottery(int type, int posIndex, Transform lotteryItem) { Lottery lottery = new Lottery(); lottery.Type = type; lottery.Value = Random.Range(LeftBorderDList[0][0], RightBorderDList[0][0] + 1); if (lottery.Type == 3) { #region bool allUnlock = true; for (int j = 0; j < LeftBorderDList[type - 1].Count; j++) { for (int k = LeftBorderDList[type - 1][j]; k < RightBorderDList[type - 1][j] + 1; k++) { if (!ManaGarden.FlowerInfoDic[k].Unlock && !TempValueList.Contains(k)) { allUnlock = false; goto exit; } } } exit : if (allUnlock) { int index = Random.Range(0, LeftBorderDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderDList[type - 1][index], RightBorderDList[type - 1][index] + 1); FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[lottery.Value]; lottery.Value = flowerInfo.UnlockAmt/5; if (flowerInfo.UnlockCur == Current.Coin) { lottery.Type = 1; } else if (flowerInfo.UnlockCur == Current.Diamond) { lottery.Type = 2; } } else { int anticrush = 0; do { if (anticrush++ > 10000) { throw new Exception(); } int index = Random.Range(0, LeftBorderDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderDList[type - 1][index], RightBorderDList[type - 1][index] + 1); } while (ManaGarden.FlowerInfoDic[lottery.Value].Unlock || TempValueList.Contains(lottery.Value)); TempValueList.Add(lottery.Value); } #endregion } else if (lottery.Type == 4) { #region bool allBought = true; for (int j = 0; j < LeftBorderDList[type - 1].Count; j++) { for (int k = LeftBorderDList[type - 1][j]; k < RightBorderDList[type - 1][j] + 1; k++) { if (!ManaPlayer.CloseUnitDic[k].Bought && !TempValueList.Contains(k)) { allBought = false; goto exit; } } } exit : if (allBought) { int index = Random.Range(0, LeftBorderDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderDList[type - 1][index], RightBorderDList[type - 1][index] + 1); CloseUnit closeUnit = ManaPlayer.CloseUnitDic[lottery.Value]; lottery.Value = (int) closeUnit.BuyAmt/5; if (closeUnit.BuyCurrent == Current.Coin) { lottery.Type = 1; } else if (closeUnit.BuyCurrent == Current.Diamond) { lottery.Type = 2; } } else { int anticrush = 0; do { if (anticrush++ > 10000) { throw new Exception(); } int index = Random.Range(0, LeftBorderDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderDList[type - 1][index], RightBorderDList[type - 1][index] + 1); } while (ManaPlayer.CloseUnitDic[lottery.Value].Bought || TempValueList.Contains(lottery.Value)); TempValueList.Add(lottery.Value); } #endregion } else { int index = Random.Range(0, LeftBorderDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderDList[type - 1][index], RightBorderDList[type - 1][index] + 1); } lottery.PosIndex = posIndex; lottery.Item = lotteryItem; lottery.BK = lotteryItem.GetChild(0); lottery.Icon1 = lotteryItem.GetChild(1).GetChild(0).GetComponent(); lottery.Icon2 = lotteryItem.GetChild(1).GetChild(1).GetComponent(); lottery.Lab = lotteryItem.GetChild(1).GetChild(2).GetComponent(); lottery.Button = lotteryItem.GetChild(1).GetChild(3).GetComponent