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 SignItemLabel { public static string Amount = "Amount"; public static string Index = "Index"; public static string Award = "Award"; public static string Tick = "Tick"; } public class SignItem { #region Config public int Coin { get { if (RoundBuff.Equal(-1)) { return coin; } else { return (int)(coin*RoundBuff*SignManager.SignRound); } } set { coin = value; } } public int coin; public int Diamond { get { if (RoundBuff.Equal(-1)) { return diamond; } else { return (int)(diamond * RoundBuff * SignManager.SignRound); } } set { diamond = value; } } public int diamond; public float RoundBuff; //第几轮 每签21次加一轮 public bool LotteryAwardFlag; public Text AmountText; public Text IndexText; public Image Award; public Image Tick; public Vector2 OriginSpriteSize; public List AwardFlowerIDs = new List(); public static int MaxSignIndex = 22; #endregion public SignItem(int index, Transform tra, XmlAttributeCollection attribute) { Dictionary dic = new Dictionary(); Auxiliary.CompileDic(tra, dic); AmountText = dic[SignItemLabel.Amount].GetComponent(); IndexText = dic[SignItemLabel.Index].GetComponent(); Award = dic[SignItemLabel.Award].GetComponent(); Tick = dic[SignItemLabel.Tick].GetComponent(); OriginSpriteSize = Award.rectTransform.sizeDelta; IndexText.text = index.ToString(); Coin = Auxiliary.StringToInt(attribute[4].Value, 0); LotteryAwardFlag = Auxiliary.StringToBool(attribute[1].Value, false); Diamond = Auxiliary.StringToInt(attribute[3].Value, 0); AwardFlowerIDs = Auxiliary.StringToInts(',', attribute[2].Value, new List()); RoundBuff = Auxiliary.StringToFloat(attribute[5].Value, -1); SetupUI(); } public void Get() { if (LotteryAwardFlag) { Lottery.PlayAnimation(true); return; } AudioManager.PlayClip(AudioLabel.GetCurrent); Tick.SetActive(true); ResetSignRound(); ResourceManager.SetActive(CanvasLabel.Bb_Get, false); ResourceManager.SetActive(CanvasLabel.Bb_Rotate, true); ResourceManager.SetActive(CanvasLabel.Bb_Confirm, true); if (AwardFlowerIDs.Valid()) { for (int i = 0; i < AwardFlowerIDs.Count; i++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDictionary[AwardFlowerIDs[i]]; if (flowerInfo.Unlock == false) { ResourceManager.SetText(CanvasLabel.Bb_InfoLabA, flowerInfo.Name); ResourceManager.SetActive(CanvasLabel.Bb_IconA, true); ResourceManager.SetSprite(CanvasLabel.Bb_IconA0, flowerInfo.Icon); ResourceManager.Get(CanvasLabel.Bb_IconA0).Resize(true, 0.8125f, 0.8125f); flowerInfo.Add(); return; } } } if (Diamond > 0) { ResourceManager.SetText(CanvasLabel.Bb_InfoLabB, Diamond.ToString()); ResourceManager.SetSprite(CanvasLabel.Bb_IconB, Lib.DiamondSprite); ResourceManager.SetActive(CanvasLabel.Bb_IconB, true); Manager.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Checkin); } else if (Coin > 0) { ResourceManager.SetText(CanvasLabel.Bb_InfoLabB, Coin.ToString()); ResourceManager.SetSprite(CanvasLabel.Bb_IconB, Lib.GoldSprite); ResourceManager.SetActive(CanvasLabel.Bb_IconB, true); Manager.AddCoin(Coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Checkin); } else { throw new Exception(); } } public void SetupUI() { if (LotteryAwardFlag) { Award.sprite = Lib.PackSprite; Award.Resize(true, 0.3f, 0.3f); return; } if (AwardFlowerIDs.Valid()) { for (int i = 0; i < AwardFlowerIDs.Count; i++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDictionary[AwardFlowerIDs[i]]; if (flowerInfo.Unlock == false) { Award.sprite = flowerInfo.Icon; Award.Resize(true, 0.1875f, 0.1875f); return; } } } if (Diamond > 0) { Award.sprite = Lib.DiamondSprite; Award.Resize(false, OriginSpriteSize); AmountText.text = Diamond.ToString(); } else if (Coin > 0) { Award.sprite = Lib.GoldSprite; Award.Resize(false, OriginSpriteSize); AmountText.text = Coin.ToString(); } } public static void ResetSignRound() { SignManager.LastSignTime = HttpManager.CurrentDateTime; SignManager.SignIndex++; if (SignManager.SignIndex == MaxSignIndex) { SignManager.SignIndex = 1; SignManager.SignRound++; ResourceManager.Get(CanvasLabel.B_SignIn).GetTweenCG().AddEventOnetime ( EventType.BackwardFinish, () => { foreach (var kv in SignManager.SignItemDictionary) { kv.Value.SetupUI(); kv.Value.Tick.SetActive(false); } } ); } } } public class Lottery { private enum LotteryType { Coin=1, Diamond=2, Flower=3, Close=4, } #region Config public int Index; public int Type; public int Value; public Text DescriptionText; public Image Icon1; public Image Icon2; public Image Icon3; 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> LeftBorderIDList = new List>(); public static List> RightBorderIDList = new List>(); public static List PosList = new List(); public static bool ResetSignRound = false; #endregion public static void Init(List attributeList) { PosList.Add(ResourceManager.Get(CanvasLabel.Bc_LotteryItem1).position); PosList.Add(ResourceManager.Get(CanvasLabel.Bc_LotteryItem2).position); PosList.Add(ResourceManager.Get(CanvasLabel.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.GardenLevel+1).ToString())); rightBorderList.Add((int)Auxiliary.FmlParse(rightBorderStrList[j], "l", (Manager.GardenLevel+1).ToString())); } LeftBorderIDList.Add(leftBorderList); RightBorderIDList.Add(rightBorderList); } } public static Lottery CreateLottery(int type, int posIndex, Transform lotteryItem) { Lottery lottery = new Lottery(); lottery.Type = type; lottery.Value = Random.Range(LeftBorderIDList[0][0], RightBorderIDList[0][0] + 1); if (lottery.Type == LotteryType.Flower.GetHashCode()) { #region List flowerIDs = new List(); for (int j = 0; j < LeftBorderIDList[type - 1].Count; j++) { for (int k = LeftBorderIDList[type - 1][j]; k < RightBorderIDList[type - 1][j] + 1; k++) { if (!TempValueList.Contains(k)) { flowerIDs.Add(k); } } } lottery.Value = MinigameAward.SelectUnlockFlowerID(flowerIDs); TempValueList.Add(lottery.Value); #endregion } else if (lottery.Type == LotteryType.Close.GetHashCode()) { #region bool allBought = true; for (int j = 0; j < LeftBorderIDList[type - 1].Count; j++) { for (int k = LeftBorderIDList[type - 1][j]; k < RightBorderIDList[type - 1][j] + 1; k++) { if (!PlayerManager.CloseItemDictionary[k].IsBought && !TempValueList.Contains(k)) { allBought = false; goto exit; } } } exit : if (allBought) { int index = Random.Range(0, LeftBorderIDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderIDList[type - 1][index], RightBorderIDList[type - 1][index] + 1); CloseItem closeItem = PlayerManager.CloseItemDictionary[lottery.Value]; lottery.Value = (int) closeItem.BuyCost/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, LeftBorderIDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderIDList[type - 1][index], RightBorderIDList[type - 1][index] + 1); } while (PlayerManager.CloseItemDictionary[lottery.Value].IsBought || TempValueList.Contains(lottery.Value)); TempValueList.Add(lottery.Value); } #endregion } else { int index = Random.Range(0, LeftBorderIDList[type - 1].Count); lottery.Value = Random.Range(LeftBorderIDList[type - 1][index], RightBorderIDList[type - 1][index] + 1); } lottery.Index = 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.DescriptionText = lotteryItem.GetChild(1).GetChild(3).GetComponent(); lottery.Button = lotteryItem.GetChild(1).GetChild(4).GetComponent