123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- 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<T1,T2>
- {
- 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.Flower, _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 TotalFlower
- {
- get { return _TotalFlower; }
- set { _TotalFlower = value; }
- }
- 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 _TotalFlower;
- private static int _TotalFlowerSpec;
- private static int _TotalFlowerRegu;
- public static bool Award = true;
- public static bool AwardLock;
- public static float AnimTimer = Random.Range(0f, 30f);
- public static float AwardTimer = Random.Range(20f, 60f);
- public static Slot SeleSlot;
- public static FlowerInfo SeleFlowerInfo;
- public static List<Slot> SlotList = new List<Slot>();
- public static List<Slot> PlantList = new List<Slot>();
- public static List<ObjType> AnimList = new List<ObjType>();
- public static Dictionary<int, FlowerInfo> FlowerInfoDic = new Dictionary<int, FlowerInfo>();
- #endregion
- public void FixedUpdate()
- {
- if (ManaTutorial.TutorialA)
- {
- TutorialFixedUpdate();
- }
- else
- {
- RegularFixedUpdate();
- }
- }
- private void TutorialFixedUpdate()
- {
- }
- private void RegularFixedUpdate()
- {
- AnimThread();
- AwardThread();
- }
- public void AnimThread()
- {
- AnimTimer -= Time.fixedDeltaTime;
-
- if (AnimTimer < 0)
- {
- AnimTimer = Random.Range(0f, 30f);
-
- if (AnimList.Count > 0 && PlantList.Count > 0)
- {
- PlantList.Random().Flower.PlayAnim(AnimList.Random());
- }
- }
- }
- public void AwardThread()
- {
- if (Award && !AwardLock)
- {
- AwardTimer -= Time.fixedDeltaTime;
- if (AwardTimer <= 0)
- {
- List<Flower> spareList = new List<Flower>();
- for (int i = 0; i < PlantList.Count; i++)
- {
- if (PlantList[i].Flower.Award == false)
- {
- spareList.Add(PlantList[i].Flower);
- }
- }
- if (spareList.Count == 0)
- {
- return;
- }
- if (spareList.Count == 1)
- {
- Award = false;
- spareList[0].Award = true;
- AwardTimer = Random.Range(20, 60);
- }
- else
- {
- spareList.Random().Award = true;
- AwardTimer = Random.Range(20, 60);
- }
- }
- }
- }
- public override void Instantiate()
- {
- ManaReso.Get("Garden", Folder.Garden, true, transform, true).AddScript<Garden>();
- #region 生成FlowerItem
- List<XmlAttributeCollection> 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()
- {
- SlotList = new List<Slot>()
- {
- ManaReso.Get("SlotA1").AddScript<Slot>(),
- ManaReso.Get("SlotA2").AddScript<Slot>(),
- ManaReso.Get("SlotA3").AddScript<Slot>(),
- ManaReso.Get("SlotA4").AddScript<Slot>(),
- ManaReso.Get("SlotA5").AddScript<Slot>(),
- ManaReso.Get("SlotA6").AddScript<Slot>(),
- ManaReso.Get("SlotA7").AddScript<Slot>(),
- ManaReso.Get("SlotA8").AddScript<Slot>(),
- ManaReso.Get("SlotA9").AddScript<Slot>(),
- ManaReso.Get("SlotB1").AddScript<Slot>(),
- ManaReso.Get("SlotB2").AddScript<Slot>(),
- ManaReso.Get("SlotB3").AddScript<Slot>(),
- ManaReso.Get("SlotB4").AddScript<Slot>(),
- ManaReso.Get("SlotB5").AddScript<Slot>(),
- ManaReso.Get("SlotB6").AddScript<Slot>(),
- ManaReso.Get("SlotB7").AddScript<Slot>(),
- ManaReso.Get("SlotB8").AddScript<Slot>(),
- ManaReso.Get("SlotB9").AddScript<Slot>(),
- };
- #region 读花朵存档
- List<int> flowerList = Data.GetFlowerList();
- for (int i = 0; i < flowerList.Count; i++)
- {
- FlowerInfoDic[flowerList[i]].Unlock = true;
- }
- List<KV<int, string>> plantList = Data.GetPlantList();
- for (int i = 0; i < plantList.Count; i++)
- {
- PlantFlower(plantList[i].Key - 1, plantList[i].Value);
- }
- #endregion
- }
- public static void UnlockSlot()
- {
- for (int i = 0; i < SlotList.Count; i++)
- {
- if (SlotList[i].Valid == false)
- {
- ManaData.Slot++;
- SlotList[i].Valid = true;
- SlotList[i].Available = true;
- return;
- }
- }
- ManaDebug.Log("所有土地已解锁");
- }
- public static void SetFlowerCard(FlowerInfo flowerInfo)
- {
- SeleFlowerInfo = flowerInfo;
- ManaText.Add(ManaReso.Get<Text>("H_Lab"), new LanStr("FlowerName", flowerInfo._Name));
- Image image = ManaReso.Get<Image>("H_Icon2");
- image.sprite = flowerInfo.Sprite;
- Vector2 newSize = flowerInfo.Sprite.rect.size;
- newSize.x *= 0.65f;
- newSize.y *= 0.65f;
- image.rectTransform.sizeDelta = newSize;
- }
- public static void ShowPlantCard(Slot slot, FlowerInfo flowerInfo)
- {
- ManaReso.Get("H_FlowerCard").TweenForCG();
- ManaReso.SetActive("H_Grid", true);
- ManaReso.SetActive("H_Prev", true);
- ManaReso.SetActive("H_Next", true);
- ManaReso.SetActive("H_Place", true);
- ManaReso.SetActive("H_Icon1", false);
- ManaReso.SetActive("H_Retrieve", false);
- SeleSlot = slot;
- SetFlowerCard(flowerInfo);
- }
- public static void ShowRetrieveCard(FlowerInfo flowerInfo)
- {
- SeleSlot = flowerInfo.Slot;
- SetFlowerCard(flowerInfo);
- ManaReso.SetActive("H_Grid", false);
- ManaReso.SetActive("H_Prev", false);
- ManaReso.SetActive("H_Next", false);
- ManaReso.SetActive("H_Place", false);
- ManaReso.SetActive("H_Icon1", true);
- ManaReso.SetActive("H_Retrieve", true);
- ManaReso.Get("H_FlowerCard").TweenForCG();
- }
- public static void RetriveFlower()
- {
- SeleSlot.Retrieve();
- if (PlantList.Count == 0)
- {
- Award = false;
- }
- }
- public static void RetriveFlowerAll()
- {
- for (int i = 0; i < PlantList.Count; i++)
- {
- PlantList[i].Retrieve();
- i--;
- }
- Award = false;
- }
- public static void PlantFlower()
- {
- SeleSlot.Plant(SeleFlowerInfo, true);
- }
- public static void PlantFlower(FlowerInfo flowerInfo)
- {
- if (flowerInfo.Plant)
- {
- ShowRetrieveCard(flowerInfo);
- }
- else
- {
- Slot slot = null;
- for (int i = 0; i < SlotList.Count; i++)
- {
- if (SlotList[i].Available)
- {
- slot = SlotList[i];
- break;
- }
- }
- if (slot == null)
- {
- ManaDebug.Log("已经没有空地了");
- }
- else
- {
- slot.Plant(flowerInfo, true);
- }
- }
- }
- public static void PlantFlower(int id, string parName)
- {
- Slot slot = ManaReso.Get<Slot>(parName);
- FlowerInfo flowerInfo = FlowerInfoDic[id];
- slot.Plant(flowerInfo, false);
- }
- }
|