ManaGarden.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using Random = UnityEngine.Random;
  11. public enum ElfType
  12. {
  13. Bee_Red,
  14. Bee_Blue,
  15. Bee_White,
  16. Bee_Purple,
  17. Bee_Yellow,
  18. Beetle_Red,
  19. Beetle_Blue,
  20. Beetle_White,
  21. Beetle_Purple,
  22. Beetle_Yellow,
  23. Butterfly_Red,
  24. Butterfly_Blue,
  25. Butterfly_White,
  26. Butterfly_Purple,
  27. Butterfly_Yellow,
  28. Dragonfly_Red,
  29. Dragonfly_Blue,
  30. Dragonfly_White,
  31. Dragonfly_Purple,
  32. Dragonfly_Yellow,
  33. }
  34. public class ManaGarden : Regist
  35. {
  36. #region 变量
  37. public static int Slot
  38. {
  39. get { return Slot_; }
  40. set
  41. {
  42. Slot_ = value;
  43. ManaReso.SetText("G_CollectLab2", string.Format("{0}/{1}", Slot_, Page * 9));
  44. }
  45. }
  46. public static int Page
  47. {
  48. get { return PageList.Count; }
  49. }
  50. public static int MyFlower
  51. {
  52. get { return MyFlower_; }
  53. set
  54. {
  55. MyFlower_ = value;
  56. ManaAchieve.UpdateStatus(AchieveType.FlowerAmt, MyFlower_);
  57. ManaReso.SetText("F_FlowerLab", string.Format("{0}", MyFlower));
  58. ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower));
  59. if (MyFlower_ >= 2 && ManaCenter.Level >= 22)
  60. {
  61. if (ManaTutorial.TutorialE_)
  62. {
  63. ManaTutorial.EnterE1();
  64. }
  65. }
  66. }
  67. }
  68. public static int MyFlowerSpec
  69. {
  70. get { return MyFlowerSpec_; }
  71. set
  72. {
  73. MyFlowerSpec_ = value;
  74. MyFlower = MyFlowerSpec_ + MyFlowerRegu_;
  75. }
  76. }
  77. public static int MyFlowerRegu
  78. {
  79. get { return MyFlowerRegu_; }
  80. set
  81. {
  82. MyFlowerRegu_ = value;
  83. MyFlower = MyFlowerSpec_ + MyFlowerRegu_;
  84. }
  85. }
  86. public static int TotalFlowerSpec
  87. {
  88. get { return TotalFlowerSpec_; }
  89. set
  90. {
  91. TotalFlowerSpec_ = value;
  92. TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_;
  93. }
  94. }
  95. public static int TotalFlowerRegu
  96. {
  97. get { return TotalFlowerRegu_; }
  98. set
  99. {
  100. TotalFlowerRegu_ = value;
  101. TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_;
  102. }
  103. }
  104. public static int Slot_;
  105. private static int MyFlower_;
  106. private static int MyFlowerSpec_;
  107. private static int MyFlowerRegu_;
  108. private static int TotalFlowerSpec_;
  109. private static int TotalFlowerRegu_;
  110. public static int TotalFlower;
  111. public static bool MiniLock = true;
  112. public static float MinStarTime;
  113. public static float MaxStarTime;
  114. public static float ElfTimer;
  115. public static float StarTimer;
  116. public static float AwardTimer;
  117. public static FlowerInfo SeleInfo;
  118. public static ManaGarden Instance;
  119. public static List<Slot> SlotList = new List<Slot>();
  120. public static List<Slot> PlantList = new List<Slot>();
  121. public static List<Star> StarList = new List<Star>();
  122. public static List<ElfType> ElfList = new List<ElfType>();
  123. public static List<Transform> PageList = new List<Transform>();
  124. public static Dictionary<int, FlowerInfo> FlowerInfoDic = new Dictionary<int, FlowerInfo>();
  125. #endregion
  126. public void Update()
  127. {
  128. if (ManaTutorial.TutorialA || Player.InDressRoom)
  129. {
  130. return;
  131. }
  132. ElfThread();
  133. StarThread();
  134. AwardThread();
  135. }
  136. public void ElfThread()
  137. {
  138. if (!MiniLock)
  139. {
  140. return;
  141. }
  142. ElfTimer -= Time.deltaTime;
  143. if (ElfTimer < 0)
  144. {
  145. ElfTimer = Random.Range(5f, 30f);
  146. if (ElfList.Count > 0 && PlantList.Count > 0)
  147. {
  148. PlantList.Random()[0].Flower.GetElf(ElfList.Random()[0]);
  149. }
  150. }
  151. }
  152. public void StarThread()
  153. {
  154. if (MiniLock && !ManaCenter.MiniLock && !ManaVisit.InVisit)
  155. {
  156. StarTimer -= Time.deltaTime;
  157. if (StarTimer < 0)
  158. {
  159. StarTimer = Mathf.Lerp(MinStarTime, MaxStarTime, Random.Range(0f, 1f));
  160. StarList.Add(ManaReso.GetStar());
  161. }
  162. }
  163. }
  164. public void AwardThread()
  165. {
  166. if (MiniLock)
  167. {
  168. AwardTimer -= Time.deltaTime;
  169. if (AwardTimer <= 0)
  170. {
  171. AwardTimer = Random.Range(5f, 15);
  172. List<Flower> spareList = new List<Flower>();
  173. for (int i = 0; i < PlantList.Count; i++)
  174. {
  175. if (PlantList[i].Flower.Award == false)
  176. {
  177. spareList.Add(PlantList[i].Flower);
  178. }
  179. }
  180. if (spareList.Count > 0)
  181. {
  182. spareList.Random()[0].Award = true;
  183. }
  184. }
  185. }
  186. }
  187. public override void Instantiate()
  188. {
  189. ManaReso.Get("Garden", Folder.Discard, true, transform, true, ObjType.Garden).AddScript<Garden>();
  190. CreatePage();
  191. CreatePage();
  192. #region 生成FlowerItem
  193. List<XmlAttributeCollection> attributeList = ManaData.GetFlowerConfig();
  194. for (int i = 0; i < attributeList.Count; i++)
  195. {
  196. FlowerInfo flowerInfo = new FlowerInfo(attributeList[i]);
  197. if (flowerInfo.Special)
  198. {
  199. TotalFlowerSpec++;
  200. }
  201. else
  202. {
  203. TotalFlowerRegu++;
  204. }
  205. FlowerInfoDic.Add(flowerInfo.ID_, flowerInfo);
  206. }
  207. #endregion
  208. }
  209. public override void RegistValueA()
  210. {
  211. Instance = this;
  212. ElfTimer = Random.Range(5f, 30f);
  213. AwardTimer = Random.Range(5f, 15f);
  214. UnlockSlot();
  215. #region 读花朵存档
  216. List<int> flowerList = ManaData.GetFlowerList();
  217. for (int i = 0; i < flowerList.Count; i++)
  218. {
  219. FlowerInfoDic[flowerList[i]].Unlock = true;
  220. }
  221. List<KV<int, int>> plantList = ManaData.GetPlantList();
  222. for (int i = 0; i < plantList.Count; i++)
  223. {
  224. PlantFlower(plantList[i].Key, plantList[i].Value);
  225. }
  226. #endregion
  227. }
  228. //public static void LockSlot()
  229. //{
  230. // for (int i = 0; i < SlotList.Count; i++)
  231. // {
  232. // if (SlotList[i].Lock)
  233. // {
  234. // Slot--;
  235. // SlotList[i].Lock = false;
  236. // SlotList[i].Available = false;
  237. // return;
  238. // }
  239. // }
  240. // throw new Exception();
  241. //}
  242. public static void UnlockSlot()
  243. {
  244. for (int i = 0; i < SlotList.Count; i++)
  245. {
  246. if (SlotList[i].Lock == false)
  247. {
  248. Slot++;
  249. SlotList[i].Lock = true;
  250. SlotList[i].Available = true;
  251. if (Slot%9 == 7)
  252. {
  253. if (Slot/9 + 2 >= Page)
  254. {
  255. CreatePage();
  256. }
  257. }
  258. return;
  259. }
  260. }
  261. }
  262. public static void CreatePage()
  263. {
  264. Transform tra = ManaReso.Get("Page", Folder.Scene, false, ManaReso.Get("GardenPage"), false, ObjType.Page);
  265. float offset = Page*18.9f;
  266. tra.SetLX(offset);
  267. Vector3 pos = ManaReso.Get("GardenPage").position;
  268. pos.x = -offset;
  269. Garden.PagePos.Add(pos);
  270. for (int i = 0; i < 9; i++)
  271. {
  272. Slot slot = tra.GetChild(i).GetComponent<Slot>();
  273. if (slot == null)
  274. {
  275. slot = tra.GetChild(i).AddScript<Slot>();
  276. }
  277. slot.Index = SlotList.Count;
  278. SlotList.Add(slot);
  279. }
  280. PageList.Add(tra);
  281. }
  282. public static void ShowRetrieveCard(FlowerInfo flowerInfo)
  283. {
  284. SeleInfo = flowerInfo;
  285. ManaReso.Get("H_FlowerCard").TweenForCG();
  286. ManaReso.SetText("H_Lab", flowerInfo.Name);
  287. Image image = ManaReso.Get<Image>("H_Icon2");
  288. image.material = null;
  289. image.sprite = flowerInfo.Icon;
  290. image.Resize(true, 0.65f, 0.65f);
  291. ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab1"));
  292. ManaReso.Get<Image>("H_Btn").material = null;
  293. ManaReso.SetButtonEvent
  294. (
  295. "H_Btn",
  296. () =>
  297. {
  298. ManaAudio.PlayClip(Clip.BtnClip);
  299. ManaReso.Get("H_FlowerCard").TweenBacCG();
  300. RetriveFlower();
  301. }
  302. );
  303. }
  304. public static void ShowUnlockCard(FlowerInfo flowerInfo)
  305. {
  306. SeleInfo = flowerInfo;
  307. ManaReso.Get("H_FlowerCard").TweenForCG();
  308. ManaReso.SetText("H_Lab", flowerInfo.Name);
  309. Image image = ManaReso.Get<Image>("H_Icon2");
  310. image.material = Lib.GrayMat;
  311. image.sprite = flowerInfo.Icon;
  312. image.Resize(true, 0.65f, 0.65f);
  313. if (flowerInfo.UnlockCur == Current.Free)
  314. {
  315. ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab2"));
  316. ManaReso.Get<Image>("H_Btn").material = Lib.GrayMat;
  317. ManaReso.SetButtonEvent
  318. (
  319. "H_Btn",
  320. () =>
  321. {
  322. Bubble.Show(null, Language.GetStr("UI", "H_BtnLab3"));
  323. }
  324. );
  325. }
  326. else
  327. {
  328. ManaReso.SetText("H_BtnLab", Auxiliary.ImageParse(flowerInfo.UnlockCur) + flowerInfo.UnlockAmt);
  329. ManaReso.Get<Image>("H_Btn").material = null;
  330. ManaReso.SetButtonEvent
  331. (
  332. "H_Btn",
  333. () =>
  334. {
  335. ManaCenter.Pay
  336. (
  337. "",
  338. flowerInfo.UnlockAmt,
  339. flowerInfo.UnlockCur,
  340. () =>
  341. {
  342. flowerInfo.Unlock = true;
  343. Material material = new Material(ManaReso.Get<Image>("H_Icon2").material);
  344. MaterialUnit materialUnit = new MaterialUnit
  345. (
  346. material,
  347. ManaReso.Get("H_Icon2"),
  348. new List<string>()
  349. {
  350. "_GrayLerp",
  351. }
  352. );
  353. TweenMatFloat tweenMatFloat = materialUnit.CreateTweenMatFloat(1, 0, 1, true, true, Curve.EaseOutQuad, false);
  354. tweenMatFloat.OnForwardStart = () =>
  355. {
  356. materialUnit.Transform.GetComponent<Image>().material = materialUnit.Material;
  357. };
  358. tweenMatFloat.OnForwardFinish = () =>
  359. {
  360. ManaReso.Get<Image>("H_Icon2").material = null;
  361. };
  362. materialUnit.TweenForMatFloat();
  363. ManaAudio.PlayClip(Clip.CurrentClip);
  364. ManaReso.Get("H_Icon1").FindChild("UIFlashLight/UIParticle System").GetComponent<UIPartical>().Begin();
  365. ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab4"));
  366. ManaReso.SetButtonEvent
  367. (
  368. "H_Btn",
  369. () =>
  370. {
  371. PlantFlower(flowerInfo);
  372. ManaReso.Get("H_FlowerCard").TweenBacCG();
  373. }
  374. );
  375. },
  376. StaticsManager.ItemID.解锁花朵,
  377. StaticsManager.ConsumeModule.Shop,
  378. true,
  379. false,
  380. () =>
  381. {
  382. ManaReso.Get("H_FlowerCard").TweenBacCG();
  383. TweenCG tweenCg = ManaReso.Get("G_Flower").TweenBacCG();
  384. tweenCg.AddEventOnetime
  385. (
  386. EventType.BackwardFinish,
  387. () =>
  388. {
  389. ManaReso.Get("F_Manage0").TweenForVec();
  390. }
  391. );
  392. }
  393. );
  394. }
  395. );
  396. }
  397. }
  398. public static void RetriveFlower()
  399. {
  400. SeleInfo.Slot.Retrieve();
  401. }
  402. public static void RetriveFlowerAll()
  403. {
  404. for (int i = 0; i < PlantList.Count; i++)
  405. {
  406. PlantList[i--].Retrieve();
  407. }
  408. }
  409. public static void PlantFlower(int id, int index)
  410. {
  411. Slot slot = SlotList[index];
  412. FlowerInfo flowerInfo = FlowerInfoDic[id];
  413. slot.Plant(flowerInfo, false);
  414. }
  415. public static void PlantFlower(FlowerInfo flowerInfo)
  416. {
  417. Slot slot = null;
  418. for (int i = 0; i < SlotList.Count; i++)
  419. {
  420. if (SlotList[i].Available)
  421. {
  422. slot = SlotList[i];
  423. break;
  424. }
  425. }
  426. if (slot == null)
  427. {
  428. Bubble.Show(null, Language.GetStr("Common", "NoValidSlot"));
  429. }
  430. else
  431. {
  432. slot.Plant(flowerInfo, true);
  433. ManaAudio.PlayClip(Clip.FlowerClip);
  434. }
  435. }
  436. }