using UnityEngine; using UnityEngine.UI; using System; using System.Xml; using System.Linq; using System.Collections; using System.Collections.Generic; using Random = UnityEngine.Random; public class Sign { #region Config public int Coin { get { if (RoundBuff.Equal(-1)) { return Coin_; } else { return (int)(Coin_*RoundBuff*SignManager.SignRound); } } set { Coin_ = value; } } public int Diamond { get { if (RoundBuff.Equal(-1)) { return Diamond_; } else { return (int)(Diamond_ * RoundBuff * SignManager.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.StringToInt(attribute[4].Value, 0); IsLottery = Auxiliary.StringToBool(attribute[1].Value, false); Diamond = Auxiliary.StringToInt(attribute[3].Value, 0); FlowerList = Auxiliary.StringToInts(',', attribute[2].Value, new List()); RoundBuff = Auxiliary.StringToFloat(attribute[5].Value, -1); SetUI(); } public void Get() { if (IsLottery) { Lottery.EnterAnimation(true); return; } AudioManager.PlayClip(Clip.CurrentClip); Mark.SetActive(true); ResetSign(); ResourceManager.SetActive(PrefabLabel.Bb_Get, false); ResourceManager.SetActive(PrefabLabel.Bb_Rotate, true); ResourceManager.SetActive(PrefabLabel.Bb_Confirm, true); if (FlowerList.Valid()) { for (int i = 0; i < FlowerList.Count; i++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[FlowerList[i]]; if (flowerInfo.Unlock == false) { ResourceManager.SetText(PrefabLabel.Bb_InfoLabA, flowerInfo.Name); ResourceManager.SetActive(PrefabLabel.Bb_IconA, true); ResourceManager.SetSprite(PrefabLabel.Bb_IconA0, flowerInfo.Icon); ResourceManager.Get(PrefabLabel.Bb_IconA0).Resize(true, 0.8125f, 0.8125f); flowerInfo.Add(); return; } } } if (Diamond > 0) { ResourceManager.SetText(PrefabLabel.Bb_InfoLabB, Diamond.ToString()); ResourceManager.SetSprite(PrefabLabel.Bb_IconB, Lib.DiamondSprite); ResourceManager.SetActive(PrefabLabel.Bb_IconB, true); Manager.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Checkin); } else if (Coin > 0) { ResourceManager.SetText(PrefabLabel.Bb_InfoLabB, Coin.ToString()); ResourceManager.SetSprite(PrefabLabel.Bb_IconB, Lib.GoldSprite); ResourceManager.SetActive(PrefabLabel.Bb_IconB, true); Manager.AddCoin(Coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Checkin); } else { throw new Exception(); } } public void SetUI() { if (IsLottery) { Icon.sprite = Lib.PackSprite; Icon.Resize(true, 0.3f, 0.3f); return; } if (FlowerList.Valid()) { for (int i = 0; i < FlowerList.Count; i++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[FlowerList[i]]; if (flowerInfo.Unlock == false) { Icon.sprite = flowerInfo.Icon; Icon.Resize(true, 0.1875f, 0.1875f); return; } } } if (Diamond > 0) { Icon.sprite = Lib.DiamondSprite; Icon.Resize(false, OriginSize); Lab1.text = Diamond.ToString(); } else if (Coin > 0) { Icon.sprite = Lib.GoldSprite; Icon.Resize(false, OriginSize); Lab1.text = Coin.ToString(); } } public static void ResetSign() { SignManager.SignTime = HttpManager.Time; SignManager.SignIndex++; if (SignManager.SignIndex == 22) { SignManager.SignIndex = 1; SignManager.SignRound++; ResourceManager.Get(PrefabLabel.B_SignIn).GetTweenCG().AddEventOnetime ( EventType.BackwardFinish, () => { foreach (var kv in SignManager.SignDic) { kv.Value.SetUI(); kv.Value.Mark.SetActive(false); } } ); } } } public class Lottery { private enum LotteryType { Coin=1, Diamond=2, Flower=3, Close=4, } #region Config public int PosIndex; public int Type; public int Value; public Text Lab; public Image Icon1; public Image Icon2; public Image Icon3; public Button Button; public Transform BK; public Transform Item; public static bool ResetSign = false; 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(ResourceManager.Get(PrefabLabel.Bc_LotteryItem1).position); PosList.Add(ResourceManager.Get(PrefabLabel.Bc_LotteryItem2).position); PosList.Add(ResourceManager.Get(PrefabLabel.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.StringToStrings(',', attributeList[i][3].Value, null); List rightBorderStrList = Auxiliary.StringToStrings(',', 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", (Manager.Level+1).ToString())); rightBorderList.Add((int)Auxiliary.FmlParse(rightBorderStrList[j], "l", (Manager.Level+1).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 == LotteryType.Flower.GetHashCode()) { #region List flowerIDs = new List(); 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 (!TempValueList.Contains(k)) { flowerIDs.Add(k); } } } lottery.Value = Award.SelectAwardFlowerID(flowerIDs); TempValueList.Add(lottery.Value); #endregion } else if (lottery.Type == LotteryType.Close.GetHashCode()) { #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 (!PlayerManager.CloseItemDic[k].Possess && !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); CloseItem closeItem = PlayerManager.CloseItemDic[lottery.Value]; lottery.Value = (int) closeItem.BuyAmt/5; if (closeItem.BuyCurrent == Current.Coin) { lottery.Type = LotteryType.Coin.GetHashCode(); } else if (closeItem.BuyCurrent == Current.Diamond) { lottery.Type = LotteryType.Diamond.GetHashCode(); } } 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 (PlayerManager.CloseItemDic[lottery.Value].Possess || 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.Icon3 = lotteryItem.GetChild(1).GetChild(2).GetComponent(); lottery.Lab = lotteryItem.GetChild(1).GetChild(3).GetComponent(); lottery.Button = lotteryItem.GetChild(1).GetChild(4).GetComponent