ManaGarden.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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)
  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 FixedUpdate()
  127. {
  128. if (ManaTutorial.TutorialA || Player.InDressRoom)
  129. {
  130. return;
  131. }
  132. ElfThread();
  133. StarThread();
  134. AwardThread();
  135. }
  136. public void ElfThread()
  137. {
  138. ElfTimer -= Time.fixedDeltaTime;
  139. if (ElfTimer < 0)
  140. {
  141. ElfTimer = Random.Range(5f, 30f);
  142. if (ElfList.Count > 0 && PlantList.Count > 0)
  143. {
  144. PlantList.Random()[0].Flower.GetElf(ElfList.Random()[0]);
  145. }
  146. }
  147. }
  148. public void StarThread()
  149. {
  150. if (MiniLock && !ManaCenter.MiniLock && !ManaVisit.InVisit)
  151. {
  152. StarTimer -= Time.fixedDeltaTime;
  153. if (StarTimer < 0)
  154. {
  155. StarTimer = Mathf.Lerp(MinStarTime, MaxStarTime, Random.Range(0f, 1f));
  156. StarList.Add(ManaReso.GetStar());
  157. }
  158. }
  159. }
  160. public void AwardThread()
  161. {
  162. if (MiniLock)
  163. {
  164. AwardTimer -= Time.fixedDeltaTime;
  165. if (AwardTimer <= 0)
  166. {
  167. AwardTimer = Random.Range(5f, 15);
  168. List<Flower> spareList = new List<Flower>();
  169. for (int i = 0; i < PlantList.Count; i++)
  170. {
  171. if (PlantList[i].Flower.Award == false)
  172. {
  173. spareList.Add(PlantList[i].Flower);
  174. }
  175. }
  176. if (spareList.Count > 0)
  177. {
  178. spareList.Random()[0].Award = true;
  179. }
  180. }
  181. }
  182. }
  183. public override void Instantiate()
  184. {
  185. ManaReso.Get("Garden", Folder.Discard, true, transform, true, ObjType.Garden).AddScript<Garden>();
  186. CreatePage();
  187. CreatePage();
  188. #region 生成FlowerItem
  189. List<XmlAttributeCollection> attributeList = ManaData.GetFlowerConfig();
  190. for (int i = 0; i < attributeList.Count; i++)
  191. {
  192. FlowerInfo flowerInfo = new FlowerInfo(attributeList[i]);
  193. if (flowerInfo.Special)
  194. {
  195. TotalFlowerSpec++;
  196. }
  197. else
  198. {
  199. TotalFlowerRegu++;
  200. }
  201. FlowerInfoDic.Add(flowerInfo.ID_, flowerInfo);
  202. }
  203. #endregion
  204. }
  205. public override void RegistValueA()
  206. {
  207. Instance = this;
  208. ElfTimer = Random.Range(5f, 30f);
  209. AwardTimer = Random.Range(5f, 15f);
  210. UnlockSlot();
  211. #region 读花朵存档
  212. List<int> flowerList = ManaData.GetFlowerList();
  213. for (int i = 0; i < flowerList.Count; i++)
  214. {
  215. FlowerInfoDic[flowerList[i]].Unlock = true;
  216. }
  217. List<KV<int, int>> plantList = ManaData.GetPlantList();
  218. for (int i = 0; i < plantList.Count; i++)
  219. {
  220. PlantFlower(plantList[i].Key, plantList[i].Value);
  221. }
  222. #endregion
  223. }
  224. public static void LockSlot()
  225. {
  226. for (int i = 0; i < SlotList.Count; i++)
  227. {
  228. if (SlotList[i].Lock)
  229. {
  230. Slot--;
  231. SlotList[i].Lock = false;
  232. SlotList[i].Available = false;
  233. return;
  234. }
  235. }
  236. throw new Exception();
  237. }
  238. public static void UnlockSlot()
  239. {
  240. for (int i = 0; i < SlotList.Count; i++)
  241. {
  242. if (SlotList[i].Lock == false)
  243. {
  244. Slot++;
  245. SlotList[i].Lock = true;
  246. SlotList[i].Available = true;
  247. if (Slot%9 == 7)
  248. {
  249. if (Slot/9 + 2 >= Page)
  250. {
  251. CreatePage();
  252. }
  253. }
  254. return;
  255. }
  256. }
  257. }
  258. public static void CreatePage()
  259. {
  260. Transform tra = ManaReso.Get("Page", Folder.Scene, false, ManaReso.Get("GardenPage"), false, ObjType.Page);
  261. float offset = Page*19.2f;
  262. tra.SetLX(offset);
  263. Vector3 pos = ManaReso.Get("GardenPage").position;
  264. pos.x = -offset;
  265. Garden.PagePos.Add(pos);
  266. for (int i = 0; i < 9; i++)
  267. {
  268. Slot slot = tra.GetChild(i).GetComponent<Slot>();
  269. if (slot == null)
  270. {
  271. slot = tra.GetChild(i).AddScript<Slot>();
  272. }
  273. slot.Index = SlotList.Count;
  274. SlotList.Add(slot);
  275. }
  276. PageList.Add(tra);
  277. }
  278. public static void ShowRetrieveCard(FlowerInfo flowerInfo)
  279. {
  280. SeleInfo = flowerInfo;
  281. ManaReso.Get("H_FlowerCard").TweenForCG();
  282. ManaReso.SetText("H_Lab", flowerInfo.Name);
  283. Image image = ManaReso.Get<Image>("H_Icon2");
  284. image.material = null;
  285. image.sprite = flowerInfo.Icon;
  286. image.Resize(true, 0.65f, 0.65f);
  287. ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab1"));
  288. ManaReso.Get<Image>("H_Btn").material = null;
  289. ManaReso.SetButtonEvent
  290. (
  291. "H_Btn",
  292. () =>
  293. {
  294. ManaAudio.PlayClip(Clip.BtnClip);
  295. ManaReso.Get("H_FlowerCard").TweenBacCG();
  296. RetriveFlower();
  297. }
  298. );
  299. }
  300. public static void ShowUnlockCard(FlowerInfo flowerInfo)
  301. {
  302. SeleInfo = flowerInfo;
  303. ManaReso.Get("H_FlowerCard").TweenForCG();
  304. ManaReso.SetText("H_Lab", flowerInfo.Name);
  305. Image image = ManaReso.Get<Image>("H_Icon2");
  306. image.material = Lib.GrayMat;
  307. image.sprite = flowerInfo.Icon;
  308. image.Resize(true, 0.65f, 0.65f);
  309. if (flowerInfo.UnlockCur == Current.Free)
  310. {
  311. ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab2"));
  312. ManaReso.Get<Image>("H_Btn").material = Lib.GrayMat;
  313. ManaReso.SetButtonEvent
  314. (
  315. "H_Btn",
  316. () =>
  317. {
  318. Bubble.Show(null, Language.GetStr("UI", "H_BtnLab3"));
  319. }
  320. );
  321. }
  322. else
  323. {
  324. ManaReso.SetText("H_BtnLab", Auxiliary.ImageParse(flowerInfo.UnlockCur) + flowerInfo.UnlockAmt);
  325. ManaReso.Get<Image>("H_Btn").material = null;
  326. ManaReso.SetButtonEvent
  327. (
  328. "H_Btn",
  329. () =>
  330. {
  331. ManaCenter.Pay
  332. (
  333. "",
  334. flowerInfo.UnlockAmt,
  335. flowerInfo.UnlockCur,
  336. () =>
  337. {
  338. flowerInfo.Unlock = true;
  339. Material material = new Material(ManaReso.Get<Image>("H_Icon2").material);
  340. MaterialUnit materialUnit = new MaterialUnit
  341. (
  342. material,
  343. ManaReso.Get("H_Icon2"),
  344. new List<string>()
  345. {
  346. "_GrayLerp",
  347. }
  348. );
  349. TweenMatFloat tweenMatFloat = materialUnit.CreateTweenMatFloat(1, 0, 1, true, true, Curve.EaseOutQuad, false);
  350. tweenMatFloat.OnForwardStart = () =>
  351. {
  352. materialUnit.Transform.GetComponent<Image>().material = materialUnit.Material;
  353. };
  354. tweenMatFloat.OnForwardFinish = () =>
  355. {
  356. ManaReso.Get<Image>("H_Icon2").material = null;
  357. };
  358. materialUnit.TweenForMatFloat();
  359. ManaAudio.PlayClip(Clip.CurrentClip);
  360. ManaReso.Get("H_Icon1").FindChild("UIFlashLight/UIParticle System").GetComponent<UIPartical>().Begin();
  361. ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab4"));
  362. ManaReso.SetButtonEvent
  363. (
  364. "H_Btn",
  365. () =>
  366. {
  367. PlantFlower(flowerInfo);
  368. ManaReso.Get("H_FlowerCard").TweenBacCG();
  369. }
  370. );
  371. },
  372. true,
  373. false,
  374. () =>
  375. {
  376. ManaReso.Get("H_FlowerCard").TweenBacCG();
  377. TweenCG tweenCg = ManaReso.Get("G_Flower").TweenBacCG();
  378. tweenCg.AddEventOnetime
  379. (
  380. EventType.BackwardFinish,
  381. () =>
  382. {
  383. ManaReso.Get("F_Manage0").TweenForVec();
  384. }
  385. );
  386. }
  387. );
  388. }
  389. );
  390. }
  391. }
  392. public static void RetriveFlower()
  393. {
  394. SeleInfo.Slot.Retrieve();
  395. }
  396. public static void RetriveFlowerAll()
  397. {
  398. for (int i = 0; i < PlantList.Count; i++)
  399. {
  400. PlantList[i--].Retrieve();
  401. }
  402. }
  403. public static void PlantFlower(int id, int index)
  404. {
  405. Slot slot = SlotList[index];
  406. FlowerInfo flowerInfo = FlowerInfoDic[id];
  407. slot.Plant(flowerInfo, false);
  408. }
  409. public static void PlantFlower(FlowerInfo flowerInfo)
  410. {
  411. Slot slot = null;
  412. for (int i = 0; i < SlotList.Count; i++)
  413. {
  414. if (SlotList[i].Available)
  415. {
  416. slot = SlotList[i];
  417. break;
  418. }
  419. }
  420. if (slot == null)
  421. {
  422. Bubble.Show(null, Language.GetStr("Common", "NoValidSlot"));
  423. }
  424. else
  425. {
  426. slot.Plant(flowerInfo, true);
  427. ManaAudio.PlayClip(Clip.FlowerClip);
  428. }
  429. }
  430. }
  431. #region 已测试内容
  432. //一共有3种花卡 回收卡 不能解锁卡 可以解锁卡
  433. //各种卡之间转换时的按钮变化(事件和Text)
  434. #endregion