using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using UnityEngine.EventSystems; using System; using System.Xml; using System.Linq; using System.Collections; using System.Collections.Generic; using Random = UnityEngine.Random; public struct KV { public T1 Key; public T2 Value; public KV(T1 key, T2 value) { Key = key; Value = value; } } public class ManaGarden : Regist { #region 变量 public static int MyFlower { get { return MyFlower_; } set { MyFlower_ = value; ManaAchieve.UpdateStatus(AchieveType.FlowerAmt, MyFlower_); ManaReso.SetText("F_FlowerLab", string.Format("{0}", MyFlower)); ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower)); } } public static int MyFlowerSpec { get { return MyFlowerSpec_; } set { MyFlowerSpec_ = value; MyFlower = MyFlowerSpec_ + MyFlowerRegu_; } } public static int MyFlowerRegu { get { return MyFlowerRegu_; } set { MyFlowerRegu_ = value; MyFlower = MyFlowerSpec_ + MyFlowerRegu_; } } public static int TotalFlowerSpec { get { return TotalFlowerSpec_; } set { TotalFlowerSpec_ = value; TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_; } } public static int TotalFlowerRegu { get { return TotalFlowerRegu_; } set { TotalFlowerRegu_ = value; TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_; } } private static int MyFlower_; private static int MyFlowerSpec_; private static int MyFlowerRegu_; private static int TotalFlowerSpec_; private static int TotalFlowerRegu_; public static int SlotAmt; public static int PageAmt; public static int TotalFlower; public static bool AwardValid = true; public static float ElfTimer; public static float AwardTimer; public static FlowerInfo SeleInfo; public static ManaGarden Instance; public static List SlotList = new List(); public static List PlantList = new List(); public static List ElfList = new List(); public static List PageList = new List(); public static Dictionary FlowerInfoDic = new Dictionary(); #endregion public void FixedUpdate() { if (ManaTutorial.TutorialA) { return; } ElfThread(); AwardThread(); } public void ElfThread() { ElfTimer -= Time.fixedDeltaTime; if (ElfTimer < 0) { ElfTimer = Random.Range(0f, 30f); if (ElfList.Count > 0 && PlantList.Count > 0) { PlantList.Random().Flower.PlayAnim(ElfList.Random()); } } } public void AwardThread() { if (AwardValid) { AwardTimer -= Time.fixedDeltaTime; if (AwardTimer <= 0) { AwardTimer = Random.Range(5, 15); List spareList = new List(); for (int i = 0; i < PlantList.Count; i++) { if (PlantList[i].Flower.Award == false) { spareList.Add(PlantList[i].Flower); } } if (spareList.Count > 0) { spareList.Random().Award = true; } } } } public static void Reload() { for (int i = 0; i < PageList.Count; i++) { ManaReso.Save(PageList[i]); } for (int i = 0; i < SlotList.Count; i++) { SlotList[i].Valid = false; SlotList[i].Available = false; Destroy(SlotList[i]); } for (int i = 0; i < PlantList.Count; i++) { PlantList[i].Retrieve(); } foreach (var kv in FlowerInfoDic) { kv.Value.Unlock = false; } SlotAmt = 0; PageAmt = 0; MyFlowerSpec = 0; MyFlowerRegu = 0; ElfList = new List(); SlotList = new List(); PageList = new List(); PlantList = new List(); CreatePage(); CreatePage(); Garden.TotPage = 1; Instance.RegistValueA(); } public override void Instantiate() { ManaReso.Get("Garden", Folder.Scene, true, transform, true, ObjType.Garden).AddScript(); CreatePage(); CreatePage(); Garden.TotPage=1; #region 生成FlowerItem List attributeList = Data.GetFlowerConfig(); for (int i = 0; i < attributeList.Count; i++) { FlowerInfo flowerInfo = new FlowerInfo(attributeList[i]); if (flowerInfo.Special) { TotalFlowerSpec++; } else { TotalFlowerRegu++; } FlowerInfoDic.Add(flowerInfo.ID_, flowerInfo); } #endregion } public override void RegistValueA() { Instance = this; ElfTimer = Random.Range(0f, 30f); AwardTimer = Random.Range(5, 15); #region 读花朵存档 for (int i = 0; i < Data.GetPlayerInt("Slot"); i++) { UnlockSlot(); } List flowerList = Data.GetFlowerList(); for (int i = 0; i < flowerList.Count; i++) { FlowerInfoDic[flowerList[i]].Unlock = true; } List> plantList = Data.GetPlantList(); for (int i = 0; i < plantList.Count; i++) { PlantFlower(plantList[i].Key, plantList[i].Value); } #endregion } public static void UnlockSlot() { for (int i = 0; i < SlotList.Count; i++) { if (SlotList[i].Valid == false) { SlotAmt++; SlotList[i].Valid = true; SlotList[i].Available = true; if (SlotAmt%9 == 7) { CreatePage(); } return; } } ManaDebug.Log("所有土地已解锁"); } public static void CreatePage() { Transform tra = ManaReso.Get("Page", Folder.Scene, false, ManaReso.Get("GardenPage"), false, ObjType.Page); float offset = PageAmt*19.2f; tra.SetLX(offset); Vector3 pos = ManaReso.Get("GardenPage").position; pos.x = -offset; Garden.PagePos.Add(pos); for (int i = 0; i < 9; i++) { Slot slot = tra.GetChild(i).AddScript(); slot.Index = SlotList.Count; SlotList.Add(slot); } PageList.Add(tra); PageAmt++; Garden.TotPage++; } public static void ShowFlowerCard(FlowerInfo flowerInfo) { SeleInfo = flowerInfo; ManaReso.Get("H_FlowerCard").TweenForCG(); ManaLan.Add(ManaReso.Get("H_Lab"), new LanStr("FlowerName", flowerInfo.ID)); Image image = ManaReso.Get("H_Icon2"); image.sprite = flowerInfo.Icon; image.Resize(0.65f, 0.65f); } public static void RetriveFlower() { SeleInfo.Slot.Retrieve(); } public static void RetriveFlowerAll() { for (int i = 0; i < PlantList.Count; i++) { PlantList[i--].Retrieve(); } } public static void PlantFlower(int id, int index) { Slot slot = SlotList[index]; FlowerInfo flowerInfo = FlowerInfoDic[id]; slot.Plant(flowerInfo, false); } public static void PlantFlower(FlowerInfo flowerInfo) { if (flowerInfo.Plant) { ManaAudio.PlayClip(Clip.BtnClip); ShowFlowerCard(flowerInfo); } else { Slot slot = null; for (int i = 0; i < SlotList.Count; i++) { if (SlotList[i].Available) { slot = SlotList[i]; break; } } if (slot == null) { Bubble.Show(null, Language.GetStr("Common", "NoValidSlot")); } else { slot.Plant(flowerInfo, true); ManaAudio.PlayClip(Clip.FlowerClip); } } } }